Skip to content

Commit 0c53c8e

Browse files
author
Sam Ravnborg
committed
kbuild: check for wrong use of CFLAGS
External modules have in a few cases modifed gcc option by modifying CFLAGS. This has never been documented and was a bad practice. With the check to use KBUILD_CFLAGS it will no longer work so we better error out and tell what was wrong as a service to the external module users. This check can be overruled if KBUILD_NOPEDANTIC is set to something. Addid this possibility may allow older external module to build without any code modifications but potentially only loosing some un-important gcc options. Signed-off-by: Sam Ravnborg <[email protected]>
1 parent a0f97e0 commit 0c53c8e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

scripts/Makefile.build

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,20 @@ EXTRA_LDFLAGS :=
2828

2929
include scripts/Kbuild.include
3030

31+
# For backward compatibility check that these variables does not change
32+
save-cflags := $(CFLAGS)
33+
3134
# The filename Kbuild has precedence over Makefile
3235
kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
33-
include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile)
34-
36+
kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
37+
include $(kbuild-file)
38+
39+
# If the save-* variables changed error out
40+
ifeq ($(KBUILD_NOPEDANTIC),)
41+
ifneq ("$(save-cflags)","$(CFLAGS)")
42+
$(error CFLAGS was changed in "$(kbuild-file)". Fix it to use EXTRA_CFLAGS)
43+
endif
44+
endif
3545
include scripts/Makefile.lib
3646

3747
ifdef host-progs

0 commit comments

Comments
 (0)