Skip to content

Commit 9f3f1fd

Browse files
Matthias Kaehlckemasahir0y
authored andcommitted
kbuild: Add __cc-option macro
cc-option uses KBUILD_CFLAGS and KBUILD_CPPFLAGS when it determines whether an option is supported or not. This is fine for options used to build the kernel itself, however some components like the x86 boot code use a different set of flags. Add the new macro __cc-option which is a more generic version of cc-option with additional parameters. One parameter is the compiler with which the check should be performed, the other the compiler options to be used instead KBUILD_C*FLAGS. Refactor cc-option and hostcc-option to use __cc-option and move hostcc-option to scripts/Kbuild.include. Suggested-by: Arnd Bergmann <arnd@arndb.de> Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com> Signed-off-by: Matthias Kaehlcke <mka@chromium.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Michal Marek <mmarek@suse.com> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent 39a33ff commit 9f3f1fd

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
296296

297297
HOSTCC = gcc
298298
HOSTCXX = g++
299-
HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
299+
HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
300300
HOSTCXXFLAGS = -O2
301301

302302
ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)

scripts/Kbuild.include

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,25 @@ as-option = $(call try-run,\
108108
as-instr = $(call try-run,\
109109
printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
110110

111+
# __cc-option
112+
# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
113+
__cc-option = $(call try-run,\
114+
$(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4))
115+
111116
# Do not attempt to build with gcc plugins during cc-option tests.
112117
# (And this uses delayed resolution so the flags will be up to date.)
113118
CC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
114119

115120
# cc-option
116121
# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
117122

118-
cc-option = $(call try-run,\
119-
$(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
123+
cc-option = $(call __cc-option, $(CC),\
124+
$(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2))
125+
126+
# hostcc-option
127+
# Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586)
128+
hostcc-option = $(call __cc-option, $(HOSTCC),\
129+
$(HOSTCFLAGS) $(HOST_EXTRACFLAGS),$(1),$(2))
120130

121131
# cc-option-yn
122132
# Usage: flag := $(call cc-option-yn,-march=winchip-c6)

scripts/Makefile.host

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
# Will compile qconf as a C++ program, and menu as a C program.
2121
# They are linked as C++ code to the executable qconf
2222

23-
# hostcc-option
24-
# Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586)
25-
26-
hostcc-option = $(call try-run,\
27-
$(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
28-
2923
__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
3024
host-cshlib := $(sort $(hostlibs-y) $(hostlibs-m))
3125
host-cxxshlib := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))

0 commit comments

Comments
 (0)