Skip to content

Commit d8ecc5c

Browse files
sravnborgmichal42
authored andcommitted
kbuild: asm-generic support
There is an increasing amount of header files shared between individual architectures in asm-generic. To avoid a lot of dummy wrapper files that just include the corresponding file in asm-generic provide some basic support in kbuild for this. With the following patch an architecture can maintain a list of files in the file arch/$(ARCH)/include/asm/Kbuild To use a generic file just add: generic-y += <name-of-header-file.h> For each file listed kbuild will generate the necessary wrapper in arch/$(ARCH)/include/generated/asm. When installing userspace headers a wrapper is likewise created. The original inspiration for this came from the unicore32 patchset - although a different method is used. The patch includes several improvements from Arnd Bergmann. Michael Marek contributed Makefile.asm-generic. Remis Baima did an intial implementation along to achive the same - see https://patchwork.kernel.org/patch/13352/ Signed-off-by: Sam Ravnborg <[email protected]> Acked-by: Guan Xuetao <[email protected]> Tested-by: Guan Xuetao <[email protected]> Acked-by: Arnd Bergmann <[email protected]> Cc: Remis Lima Baima <[email protected]> Signed-off-by: Michal Marek <[email protected]>
1 parent 28bc20d commit d8ecc5c

File tree

5 files changed

+81
-5
lines changed

5 files changed

+81
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ modules.builtin
5757
include/config
5858
include/linux/version.h
5959
include/generated
60+
arch/*/include/generated
6061

6162
# stgit generated dirs
6263
patches-*

Documentation/kbuild/makefiles.txt

+36
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ This document describes the Linux kernel Makefiles.
4040
--- 6.6 Commands useful for building a boot image
4141
--- 6.7 Custom kbuild commands
4242
--- 6.8 Preprocessing linker scripts
43+
--- 6.9 Generic header files
4344

4445
=== 7 Kbuild syntax for exported headers
4546
--- 7.1 header-y
4647
--- 7.2 objhdr-y
4748
--- 7.3 destination-y
49+
--- 7.4 generic-y
4850

4951
=== 8 Kbuild Variables
5052
=== 9 Makefile language
@@ -1214,6 +1216,14 @@ When kbuild executes, the following steps are followed (roughly):
12141216
The kbuild infrastructure for *lds file are used in several
12151217
architecture-specific files.
12161218

1219+
--- 6.9 Generic header files
1220+
1221+
The directory include/asm-generic contains the header files
1222+
that may be shared between individual architectures.
1223+
The recommended approach how to use a generic header file is
1224+
to list the file in the Kbuild file.
1225+
See "7.4 generic-y" for further info on syntax etc.
1226+
12171227
=== 7 Kbuild syntax for exported headers
12181228

12191229
The kernel include a set of headers that is exported to userspace.
@@ -1270,6 +1280,32 @@ See subsequent chapter for the syntax of the Kbuild file.
12701280
In the example above all exported headers in the Kbuild file
12711281
will be located in the directory "include/linux" when exported.
12721282

1283+
--- 7.4 generic-y
1284+
1285+
If an architecture uses a verbatim copy of a header from
1286+
include/asm-generic then this is listed in the file
1287+
arch/$(ARCH)/include/asm/Kbuild like this:
1288+
1289+
Example:
1290+
#arch/x86/include/asm/Kbuild
1291+
generic-y += termios.h
1292+
generic-y += rtc.h
1293+
1294+
During the prepare phase of the build a wrapper include
1295+
file is generated in the directory:
1296+
1297+
arch/$(ARCH)/include/generated/asm
1298+
1299+
When a header is exported where the architecture uses
1300+
the generic header a similar wrapper is generated as part
1301+
of the set of exported headers in the directory:
1302+
1303+
usr/include/asm
1304+
1305+
The generated wrapper will in both cases look like the following:
1306+
1307+
Example: termios.h
1308+
#include <asm-generic/termios.h>
12731309

12741310
=== 8 Kbuild Variables
12751311

Makefile

+12-4
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ CFLAGS_GCOV = -fprofile-arcs -ftest-coverage
349349

350350
# Use LINUXINCLUDE when you must reference the include/ directory.
351351
# Needed to be compatible with the O= option
352-
LINUXINCLUDE := -I$(srctree)/arch/$(hdr-arch)/include -Iinclude \
352+
LINUXINCLUDE := -I$(srctree)/arch/$(hdr-arch)/include \
353+
-Iarch/$(hdr-arch)/include/generated -Iinclude \
353354
$(if $(KBUILD_SRC), -I$(srctree)/include) \
354355
-include include/generated/autoconf.h
355356

@@ -417,6 +418,12 @@ ifneq ($(KBUILD_SRC),)
417418
$(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
418419
endif
419420

421+
# Support for using generic headers in asm-generic
422+
PHONY += asm-generic
423+
asm-generic:
424+
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
425+
obj=arch/$(SRCARCH)/include/generated/asm
426+
420427
# To make sure we do not include .config for any of the *config targets
421428
# catch them early, and hand them over to scripts/kconfig/Makefile
422429
# It is allowed to specify more targets when calling make, including
@@ -954,7 +961,7 @@ ifneq ($(KBUILD_SRC),)
954961
endif
955962

956963
# prepare2 creates a makefile if using a separate output directory
957-
prepare2: prepare3 outputmakefile
964+
prepare2: prepare3 outputmakefile asm-generic
958965

959966
prepare1: prepare2 include/linux/version.h include/generated/utsrelease.h \
960967
include/config/auto.conf
@@ -1028,7 +1035,7 @@ hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
10281035
hdr-dst = $(if $(KBUILD_HEADERS), dst=include/asm-$(hdr-arch), dst=include/asm)
10291036

10301037
PHONY += __headers
1031-
__headers: include/linux/version.h scripts_basic FORCE
1038+
__headers: include/linux/version.h scripts_basic asm-generic FORCE
10321039
$(Q)$(MAKE) $(build)=scripts build_unifdef
10331040

10341041
PHONY += headers_install_all
@@ -1143,7 +1150,8 @@ CLEAN_FILES += vmlinux System.map \
11431150
.tmp_kallsyms* .tmp_version .tmp_vmlinux* .tmp_System.map
11441151

11451152
# Directories & files removed with 'make mrproper'
1146-
MRPROPER_DIRS += include/config usr/include include/generated
1153+
MRPROPER_DIRS += include/config usr/include include/generated \
1154+
arch/*/include/generated
11471155
MRPROPER_FILES += .config .config.old .version .old_version \
11481156
include/linux/version.h \
11491157
Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS

scripts/Makefile.asm-generic

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# include/asm-generic contains a lot of files that are used
2+
# verbatim by several architectures.
3+
#
4+
# This Makefile reads the file arch/$(SRCARCH)/include/asm/Kbuild
5+
# and for each file listed in this file with generic-y creates
6+
# a small wrapper file in $(obj) (arch/$(SRCARCH)/include/generated/asm)
7+
8+
kbuild-file := $(srctree)/arch/$(SRCARCH)/include/asm/Kbuild
9+
include $(kbuild-file)
10+
11+
include scripts/Kbuild.include
12+
13+
# Create output directory if not already present
14+
_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
15+
16+
quiet_cmd_wrap = WRAP $@
17+
cmd_wrap = echo "\#include <asm-generic/$*.h>" >$@
18+
19+
all: $(patsubst %, $(obj)/%, $(generic-y))
20+
21+
$(obj)/%.h:
22+
$(call cmd,wrap)
23+

scripts/Makefile.headersinst

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ header-y := $(filter-out %/, $(header-y))
2727
install-file := $(install)/.install
2828
check-file := $(install)/.check
2929

30+
# generic-y list all files an architecture uses from asm-generic
31+
# Use this to build a list of headers which require a wrapper
32+
wrapper-files := $(filter $(header-y), $(generic-y))
33+
3034
# all headers files for this dir
31-
all-files := $(header-y) $(objhdr-y)
35+
header-y := $(filter-out $(generic-y), $(header-y))
36+
all-files := $(header-y) $(objhdr-y) $(wrapper-files)
3237
input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
3338
$(addprefix $(objtree)/$(obj)/,$(objhdr-y))
3439
output-files := $(addprefix $(install)/, $(all-files))
@@ -47,6 +52,9 @@ quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
4752
cmd_install = \
4853
$(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
4954
$(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \
55+
for F in $(wrapper-files); do \
56+
echo "\#include <asm-generic/$$F>" > $(install)/$$F; \
57+
done; \
5058
touch $@
5159

5260
quiet_cmd_remove = REMOVE $(unwanted)

0 commit comments

Comments
 (0)