Skip to content

Commit e846f0d

Browse files
jnikulamasahir0y
authored andcommitted
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>
1 parent 0315bb7 commit e846f0d

File tree

9 files changed

+32
-12
lines changed

9 files changed

+32
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*.elf
2323
*.gcno
2424
*.gz
25+
*.hdrtest.c
2526
*.i
2627
*.ko
2728
*.lex.c

Documentation/dontdiff

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*.grep
2020
*.grp
2121
*.gz
22+
*.hdrtest.c
2223
*.html
2324
*.i
2425
*.jpeg

Documentation/kbuild/makefiles.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,13 @@ When kbuild executes, the following steps are followed (roughly):
10181018
In this example, extra-y is used to list object files that
10191019
shall be built, but shall not be linked as part of built-in.a.
10201020

1021+
header-test-y
1022+
1023+
header-test-y specifies headers (*.h) in the current directory that
1024+
should be compile tested to ensure they are self-contained,
1025+
i.e. compilable as standalone units. If CONFIG_HEADER_TEST is enabled,
1026+
this autogenerates dummy sources to include the headers, and builds them
1027+
as part of extra-y.
10211028

10221029
--- 6.7 Commands useful for building a boot image
10231030

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,7 @@ clean: $(clean-dirs)
16471647
-o -name '*.dwo' -o -name '*.lst' \
16481648
-o -name '*.su' \
16491649
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
1650+
-o -name '*.hdrtest.c' \
16501651
-o -name '*.lex.c' -o -name '*.tab.[ch]' \
16511652
-o -name '*.asn1.[ch]' \
16521653
-o -name '*.symtypes' -o -name 'modules.order' \

drivers/gpu/drm/i915/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

drivers/gpu/drm/i915/Makefile.header-test

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright © 2019 Intel Corporation
33

44
# Test the headers are compilable as standalone units
5-
header_test := \
5+
header-test-$(CONFIG_DRM_I915_WERROR) := \
66
i915_active_types.h \
77
i915_gem_context_types.h \
88
i915_priolist_types.h \
@@ -35,13 +35,3 @@ header_test := \
3535
intel_sprite.h \
3636
intel_tv.h \
3737
intel_workarounds_types.h
38-
39-
quiet_cmd_header_test = HDRTEST $@
40-
cmd_header_test = echo "\#include \"$(<F)\"" > $@
41-
42-
header_test_%.c: %.h
43-
$(call cmd,header_test)
44-
45-
i915-$(CONFIG_DRM_I915_WERROR) += $(foreach h,$(header_test),$(patsubst %.h,header_test_%.o,$(h)))
46-
47-
clean-files += $(foreach h,$(header_test),$(patsubst %.h,header_test_%.c,$(h)))

init/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ config COMPILE_TEST
9696
here. If you are a user/distributor, say N here to exclude useless
9797
drivers to be distributed.
9898

99+
config HEADER_TEST
100+
bool "Compile test headers that should be standalone compilable"
101+
help
102+
Compile test headers listed in header-test-y target to ensure they are
103+
self-contained, i.e. compilable as standalone units.
104+
105+
If you are a developer or tester and want to ensure the requested
106+
headers are self-contained, say Y here. Otherwise, choose N.
107+
99108
config LOCALVERSION
100109
string "Local version - append to kernel release"
101110
help

scripts/Makefile.build

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,15 @@ quiet_cmd_cc_lst_c = MKLST $@
294294
$(obj)/%.lst: $(src)/%.c FORCE
295295
$(call if_changed_dep,cc_lst_c)
296296

297+
# Dummy C sources for header test (header-test-y target)
298+
# ---------------------------------------------------------------------------
299+
300+
quiet_cmd_header_test = HDRTEST $@
301+
cmd_header_test = echo "\#include \"$*.h\"" > $@
302+
303+
$(obj)/%.hdrtest.c:
304+
$(call cmd,header_test)
305+
297306
# Compile assembler sources (.S)
298307
# ---------------------------------------------------------------------------
299308

scripts/Makefile.lib

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ extra-y += $(patsubst %.dtb,%.dt.yaml, $(dtb-y))
6666
extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
6767
endif
6868

69+
# Test self-contained headers
70+
extra-$(CONFIG_HEADER_TEST) += $(patsubst %.h,%.hdrtest.o,$(header-test-y))
71+
6972
# Add subdir path
7073

7174
extra-y := $(addprefix $(obj)/,$(extra-y))

0 commit comments

Comments
 (0)