Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 <sam@ravnborg.org>
Acked-by: Guan Xuetao <guanxuetao@mprc.pku.edu.cn>
Tested-by: Guan Xuetao <guanxuetao@mprc.pku.edu.cn>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Cc: Remis Lima Baima <remis.developer@googlemail.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>
  • Loading branch information...
commit d8ecc5cd8e227bc318513b5306ae88a474b8886d 1 parent 28bc20d
Sam Ravnborg authored michal42 committed
1  .gitignore
@@ -57,6 +57,7 @@ modules.builtin
57 57 include/config
58 58 include/linux/version.h
59 59 include/generated
  60 +arch/*/include/generated
60 61
61 62 # stgit generated dirs
62 63 patches-*
36 Documentation/kbuild/makefiles.txt
@@ -40,11 +40,13 @@ This document describes the Linux kernel Makefiles.
40 40 --- 6.6 Commands useful for building a boot image
41 41 --- 6.7 Custom kbuild commands
42 42 --- 6.8 Preprocessing linker scripts
  43 + --- 6.9 Generic header files
43 44
44 45 === 7 Kbuild syntax for exported headers
45 46 --- 7.1 header-y
46 47 --- 7.2 objhdr-y
47 48 --- 7.3 destination-y
  49 + --- 7.4 generic-y
48 50
49 51 === 8 Kbuild Variables
50 52 === 9 Makefile language
@@ -1214,6 +1216,14 @@ When kbuild executes, the following steps are followed (roughly):
1214 1216 The kbuild infrastructure for *lds file are used in several
1215 1217 architecture-specific files.
1216 1218
  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 +
1217 1227 === 7 Kbuild syntax for exported headers
1218 1228
1219 1229 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.
1270 1280 In the example above all exported headers in the Kbuild file
1271 1281 will be located in the directory "include/linux" when exported.
1272 1282
  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>
1273 1309
1274 1310 === 8 Kbuild Variables
1275 1311
16 Makefile
@@ -349,7 +349,8 @@ CFLAGS_GCOV = -fprofile-arcs -ftest-coverage
349 349
350 350 # Use LINUXINCLUDE when you must reference the include/ directory.
351 351 # 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 \
353 354 $(if $(KBUILD_SRC), -I$(srctree)/include) \
354 355 -include include/generated/autoconf.h
355 356
@@ -417,6 +418,12 @@ ifneq ($(KBUILD_SRC),)
417 418 $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
418 419 endif
419 420
  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 +
420 427 # To make sure we do not include .config for any of the *config targets
421 428 # catch them early, and hand them over to scripts/kconfig/Makefile
422 429 # It is allowed to specify more targets when calling make, including
@@ -954,7 +961,7 @@ ifneq ($(KBUILD_SRC),)
954 961 endif
955 962
956 963 # prepare2 creates a makefile if using a separate output directory
957   -prepare2: prepare3 outputmakefile
  964 +prepare2: prepare3 outputmakefile asm-generic
958 965
959 966 prepare1: prepare2 include/linux/version.h include/generated/utsrelease.h \
960 967 include/config/auto.conf
@@ -1028,7 +1035,7 @@ hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
1028 1035 hdr-dst = $(if $(KBUILD_HEADERS), dst=include/asm-$(hdr-arch), dst=include/asm)
1029 1036
1030 1037 PHONY += __headers
1031   -__headers: include/linux/version.h scripts_basic FORCE
  1038 +__headers: include/linux/version.h scripts_basic asm-generic FORCE
1032 1039 $(Q)$(MAKE) $(build)=scripts build_unifdef
1033 1040
1034 1041 PHONY += headers_install_all
@@ -1143,7 +1150,8 @@ CLEAN_FILES += vmlinux System.map \
1143 1150 .tmp_kallsyms* .tmp_version .tmp_vmlinux* .tmp_System.map
1144 1151
1145 1152 # 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
1147 1155 MRPROPER_FILES += .config .config.old .version .old_version \
1148 1156 include/linux/version.h \
1149 1157 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
23 scripts/Makefile.asm-generic
... ... @@ -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 +
10 scripts/Makefile.headersinst
@@ -27,8 +27,13 @@ header-y := $(filter-out %/, $(header-y))
27 27 install-file := $(install)/.install
28 28 check-file := $(install)/.check
29 29
  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 +
30 34 # 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)
32 37 input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
33 38 $(addprefix $(objtree)/$(obj)/,$(objhdr-y))
34 39 output-files := $(addprefix $(install)/, $(all-files))
@@ -47,6 +52,9 @@ quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
47 52 cmd_install = \
48 53 $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
49 54 $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \
  55 + for F in $(wrapper-files); do \
  56 + echo "\#include <asm-generic/$$F>" > $(install)/$$F; \
  57 + done; \
50 58 touch $@
51 59
52 60 quiet_cmd_remove = REMOVE $(unwanted)

0 comments on commit d8ecc5c

Please sign in to comment.
Something went wrong with that request. Please try again.