Skip to content

Commit 5449531

Browse files
committed
Use probes instead of version/distribution conditionals
1 parent 979ebd3 commit 5449531

19 files changed

Lines changed: 524 additions & 177 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module/.tmp_versions/
1313
module/built-in.a
1414
module/evdi.mod
1515
module/evdi.mod.c
16+
module/evdi_detect.h
17+
module/evdi_detect.h.tmp
1618

1719
site/
1820
tmp/

module/Makefile

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,41 @@
66
# more details.
77
#
88

9-
include /etc/os-release
10-
11-
ifneq (,$(findstring rhel,$(ID_LIKE)))
12-
ELFLAG := -DEL$(shell echo $(VERSION_ID) | cut -d. -f1)
13-
endif
14-
15-
ifneq (,$(findstring centos,$(ID)))
16-
CENTOSFLAG := -DCENTOS$(shell echo $(VERSION_ID) | cut -d. -f1)
17-
endif
18-
19-
Raspbian := $(shell grep -Eic 'raspb(erry|ian)' /proc/cpuinfo /etc/os-release 2>/dev/null )
20-
ifeq (,$(findstring 0, $(Raspbian)))
21-
RPIFLAG := -DRPI
22-
endif
9+
# Kernel API differences are detected at build time by conftest.sh (which
10+
# test-compiles probes against the target kernel headers) rather than guessed
11+
# from the distribution. See conftest.sh and the EVDI_HAVE_* macros it emits
12+
# into the generated evdi_detect.h.
13+
#
14+
# Generate evdi_detect.h, force-include it into every object, and make every
15+
# object depend on it. Used from the kbuild-context branches below, where the
16+
# kernel compiler ($(CC)) and its include/cflags are available. The header is
17+
# regenerated each build but only rewritten when its contents change, so
18+
# incremental builds and kernel switches both behave correctly.
19+
define evdi_conftest
20+
ccflags-y += -include $$(obj)/evdi_detect.h
21+
clean-files := evdi_detect.h evdi_detect.h.tmp
22+
# Explicit (not pattern) prerequisite: GNU make merges prerequisites from
23+
# explicit rules with kbuild's own $(obj)/%.o pattern rule, so the header is
24+
# generated before any object is compiled. Cover the optional COMPAT object too.
25+
$$(addprefix $$(obj)/, $$(evdi-y) evdi_ioc32.o): $$(obj)/evdi_detect.h
26+
$$(obj)/evdi_detect.h: $$(src)/conftest.sh FORCE
27+
$$(Q)$$(CONFIG_SHELL) $$(src)/conftest.sh "$$(CC)" \
28+
"$$(NOSTDINC_FLAGS) $$(LINUXINCLUDE) $$(KBUILD_CPPFLAGS) $$(KBUILD_CFLAGS) -DMODULE" \
29+
$$@.tmp
30+
$$(Q)cmp -s $$@.tmp $$@ 2>/dev/null && rm -f $$@.tmp || mv $$@.tmp $$@
31+
endef
2332

2433
ifneq ($(DKMS_BUILD),)
2534

2635
# DKMS
2736

2837
KERN_DIR := /lib/modules/$(KERNELRELEASE)/build
2938

30-
ccflags-y := -Iinclude/uapi/drm -Iinclude/drm $(ELFLAG) $(CENTOSFLAG) $(RPIFLAG)
39+
ccflags-y := -Iinclude/uapi/drm -Iinclude/drm
3140
evdi-y := evdi_platform_drv.o evdi_platform_dev.o evdi_sysfs.o evdi_modeset.o evdi_connector.o evdi_encoder.o evdi_drm_drv.o evdi_fb.o evdi_gem.o evdi_painter.o evdi_params.o evdi_cursor.o evdi_debug.o evdi_i2c.o
3241
evdi-$(CONFIG_COMPAT) += evdi_ioc32.o
3342
obj-m := evdi.o
43+
$(eval $(call evdi_conftest))
3444

3545
KBUILD_VERBOSE ?= 1
3646

@@ -49,12 +59,13 @@ ifneq ($(KERNELRELEASE),)
4959

5060
# inside kbuild
5161
# Note: this can be removed once it is in kernel tree and Kconfig is properly used
52-
ccflags-y := -isystem include/uapi/drm $(CFLAGS) $(ELFLAG) $(CENTOSFLAG) $(RPIFLAG)
62+
ccflags-y := -isystem include/uapi/drm $(CFLAGS)
5363
evdi-y := evdi_platform_drv.o evdi_platform_dev.o evdi_sysfs.o evdi_modeset.o evdi_connector.o evdi_encoder.o evdi_drm_drv.o evdi_fb.o evdi_gem.o evdi_painter.o evdi_params.o evdi_cursor.o evdi_debug.o evdi_i2c.o
5464
evdi-$(CONFIG_COMPAT) += evdi_ioc32.o
5565
CONFIG_DRM_EVDI ?= m
5666
obj-$(CONFIG_DRM_EVDI) := evdi.o
5767
obj-y += tests/
68+
$(eval $(call evdi_conftest))
5869

5970
else
6071

@@ -87,7 +98,7 @@ module:
8798
$(MAKE) -C $(KDIR) M=$$PWD
8899

89100
clean:
90-
$(RM) -rf *.o *.a *.ko .tmp* .*.*.cmd Module.symvers evdi.mod.c modules.order
101+
$(RM) -rf *.o *.a *.ko .tmp* .*.*.cmd Module.symvers evdi.mod.c modules.order evdi_detect.h evdi_detect.h.tmp
91102

92103
install:
93104
$(MAKE) -C $(KDIR) M=$$PWD INSTALL_MOD_PATH=$(DESTDIR) INSTALL_MOD_DIR=$(MOD_KERNEL_PATH) modules_install

0 commit comments

Comments
 (0)