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
2433ifneq ($(DKMS_BUILD ) ,)
2534
2635# DKMS
2736
2837KERN_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
3140evdi-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
3241evdi-$(CONFIG_COMPAT) += evdi_ioc32.o
3342obj-m := evdi.o
43+ $(eval $(call evdi_conftest))
3444
3545KBUILD_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 )
5363evdi-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
5464evdi-$(CONFIG_COMPAT) += evdi_ioc32.o
5565CONFIG_DRM_EVDI ?= m
5666obj-$(CONFIG_DRM_EVDI) := evdi.o
5767obj-y += tests/
68+ $(eval $(call evdi_conftest))
5869
5970else
6071
@@ -87,7 +98,7 @@ module:
8798 $(MAKE ) -C $(KDIR ) M=$$ PWD
8899
89100clean :
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
92103install :
93104 $(MAKE ) -C $(KDIR ) M=$$ PWD INSTALL_MOD_PATH=$(DESTDIR ) INSTALL_MOD_DIR=$(MOD_KERNEL_PATH ) modules_install
0 commit comments