kbuild: add support for ensuring headers are self-contained
Sometimes it's useful to be able to explicitly ensure certain headers remain self-contained, i.e. that they are compilable as standalone units, by including and/or forward declaring everything they depend on. Add special target header-test-y where individual Makefiles can add headers to be tested if CONFIG_HEADER_TEST is enabled. This will generate a dummy C file per header that gets built as part of extra-y. Signed-off-by: Jani Nikula <jani.nikula@intel.com> Reviewed-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
This commit is contained in:
parent
0315bb7a25
commit
e846f0dc57
1
.gitignore
vendored
1
.gitignore
vendored
@ -22,6 +22,7 @@
|
|||||||
*.elf
|
*.elf
|
||||||
*.gcno
|
*.gcno
|
||||||
*.gz
|
*.gz
|
||||||
|
*.hdrtest.c
|
||||||
*.i
|
*.i
|
||||||
*.ko
|
*.ko
|
||||||
*.lex.c
|
*.lex.c
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
*.grep
|
*.grep
|
||||||
*.grp
|
*.grp
|
||||||
*.gz
|
*.gz
|
||||||
|
*.hdrtest.c
|
||||||
*.html
|
*.html
|
||||||
*.i
|
*.i
|
||||||
*.jpeg
|
*.jpeg
|
||||||
|
@ -1018,6 +1018,13 @@ When kbuild executes, the following steps are followed (roughly):
|
|||||||
In this example, extra-y is used to list object files that
|
In this example, extra-y is used to list object files that
|
||||||
shall be built, but shall not be linked as part of built-in.a.
|
shall be built, but shall not be linked as part of built-in.a.
|
||||||
|
|
||||||
|
header-test-y
|
||||||
|
|
||||||
|
header-test-y specifies headers (*.h) in the current directory that
|
||||||
|
should be compile tested to ensure they are self-contained,
|
||||||
|
i.e. compilable as standalone units. If CONFIG_HEADER_TEST is enabled,
|
||||||
|
this autogenerates dummy sources to include the headers, and builds them
|
||||||
|
as part of extra-y.
|
||||||
|
|
||||||
--- 6.7 Commands useful for building a boot image
|
--- 6.7 Commands useful for building a boot image
|
||||||
|
|
||||||
|
1
Makefile
1
Makefile
@ -1647,6 +1647,7 @@ clean: $(clean-dirs)
|
|||||||
-o -name '*.dwo' -o -name '*.lst' \
|
-o -name '*.dwo' -o -name '*.lst' \
|
||||||
-o -name '*.su' \
|
-o -name '*.su' \
|
||||||
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
|
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
|
||||||
|
-o -name '*.hdrtest.c' \
|
||||||
-o -name '*.lex.c' -o -name '*.tab.[ch]' \
|
-o -name '*.lex.c' -o -name '*.tab.[ch]' \
|
||||||
-o -name '*.asn1.[ch]' \
|
-o -name '*.asn1.[ch]' \
|
||||||
-o -name '*.symtypes' -o -name 'modules.order' \
|
-o -name '*.symtypes' -o -name 'modules.order' \
|
||||||
|
1
drivers/gpu/drm/i915/.gitignore
vendored
1
drivers/gpu/drm/i915/.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
header_test_*.c
|
|
@ -2,7 +2,7 @@
|
|||||||
# Copyright © 2019 Intel Corporation
|
# Copyright © 2019 Intel Corporation
|
||||||
|
|
||||||
# Test the headers are compilable as standalone units
|
# Test the headers are compilable as standalone units
|
||||||
header_test := \
|
header-test-$(CONFIG_DRM_I915_WERROR) := \
|
||||||
i915_active_types.h \
|
i915_active_types.h \
|
||||||
i915_gem_context_types.h \
|
i915_gem_context_types.h \
|
||||||
i915_priolist_types.h \
|
i915_priolist_types.h \
|
||||||
@ -35,13 +35,3 @@ header_test := \
|
|||||||
intel_sprite.h \
|
intel_sprite.h \
|
||||||
intel_tv.h \
|
intel_tv.h \
|
||||||
intel_workarounds_types.h
|
intel_workarounds_types.h
|
||||||
|
|
||||||
quiet_cmd_header_test = HDRTEST $@
|
|
||||||
cmd_header_test = echo "\#include \"$(<F)\"" > $@
|
|
||||||
|
|
||||||
header_test_%.c: %.h
|
|
||||||
$(call cmd,header_test)
|
|
||||||
|
|
||||||
i915-$(CONFIG_DRM_I915_WERROR) += $(foreach h,$(header_test),$(patsubst %.h,header_test_%.o,$(h)))
|
|
||||||
|
|
||||||
clean-files += $(foreach h,$(header_test),$(patsubst %.h,header_test_%.c,$(h)))
|
|
||||||
|
@ -96,6 +96,15 @@ config COMPILE_TEST
|
|||||||
here. If you are a user/distributor, say N here to exclude useless
|
here. If you are a user/distributor, say N here to exclude useless
|
||||||
drivers to be distributed.
|
drivers to be distributed.
|
||||||
|
|
||||||
|
config HEADER_TEST
|
||||||
|
bool "Compile test headers that should be standalone compilable"
|
||||||
|
help
|
||||||
|
Compile test headers listed in header-test-y target to ensure they are
|
||||||
|
self-contained, i.e. compilable as standalone units.
|
||||||
|
|
||||||
|
If you are a developer or tester and want to ensure the requested
|
||||||
|
headers are self-contained, say Y here. Otherwise, choose N.
|
||||||
|
|
||||||
config LOCALVERSION
|
config LOCALVERSION
|
||||||
string "Local version - append to kernel release"
|
string "Local version - append to kernel release"
|
||||||
help
|
help
|
||||||
|
@ -294,6 +294,15 @@ quiet_cmd_cc_lst_c = MKLST $@
|
|||||||
$(obj)/%.lst: $(src)/%.c FORCE
|
$(obj)/%.lst: $(src)/%.c FORCE
|
||||||
$(call if_changed_dep,cc_lst_c)
|
$(call if_changed_dep,cc_lst_c)
|
||||||
|
|
||||||
|
# Dummy C sources for header test (header-test-y target)
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
quiet_cmd_header_test = HDRTEST $@
|
||||||
|
cmd_header_test = echo "\#include \"$*.h\"" > $@
|
||||||
|
|
||||||
|
$(obj)/%.hdrtest.c:
|
||||||
|
$(call cmd,header_test)
|
||||||
|
|
||||||
# Compile assembler sources (.S)
|
# Compile assembler sources (.S)
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -66,6 +66,9 @@ extra-y += $(patsubst %.dtb,%.dt.yaml, $(dtb-y))
|
|||||||
extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
|
extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Test self-contained headers
|
||||||
|
extra-$(CONFIG_HEADER_TEST) += $(patsubst %.h,%.hdrtest.o,$(header-test-y))
|
||||||
|
|
||||||
# Add subdir path
|
# Add subdir path
|
||||||
|
|
||||||
extra-y := $(addprefix $(obj)/,$(extra-y))
|
extra-y := $(addprefix $(obj)/,$(extra-y))
|
||||||
|
Loading…
Reference in New Issue
Block a user