Skip to content

Commit

Permalink
kbuild: asm-generic support
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
sravnborg authored and michal42 committed Apr 28, 2011
1 parent 28bc20d commit d8ecc5c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ modules.builtin
include/config
include/linux/version.h
include/generated
arch/*/include/generated

# stgit generated dirs
patches-*
Expand Down
36 changes: 36 additions & 0 deletions Documentation/kbuild/makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ This document describes the Linux kernel Makefiles.
--- 6.6 Commands useful for building a boot image
--- 6.7 Custom kbuild commands
--- 6.8 Preprocessing linker scripts
--- 6.9 Generic header files

=== 7 Kbuild syntax for exported headers
--- 7.1 header-y
--- 7.2 objhdr-y
--- 7.3 destination-y
--- 7.4 generic-y

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

--- 6.9 Generic header files

The directory include/asm-generic contains the header files
that may be shared between individual architectures.
The recommended approach how to use a generic header file is
to list the file in the Kbuild file.
See "7.4 generic-y" for further info on syntax etc.

=== 7 Kbuild syntax for exported headers

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

--- 7.4 generic-y

If an architecture uses a verbatim copy of a header from
include/asm-generic then this is listed in the file
arch/$(ARCH)/include/asm/Kbuild like this:

Example:
#arch/x86/include/asm/Kbuild
generic-y += termios.h
generic-y += rtc.h

During the prepare phase of the build a wrapper include
file is generated in the directory:

arch/$(ARCH)/include/generated/asm

When a header is exported where the architecture uses
the generic header a similar wrapper is generated as part
of the set of exported headers in the directory:

usr/include/asm

The generated wrapper will in both cases look like the following:

Example: termios.h
#include <asm-generic/termios.h>

=== 8 Kbuild Variables

Expand Down
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ CFLAGS_GCOV = -fprofile-arcs -ftest-coverage

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

Expand Down Expand Up @@ -417,6 +418,12 @@ ifneq ($(KBUILD_SRC),)
$(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
endif

# Support for using generic headers in asm-generic
PHONY += asm-generic
asm-generic:
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
obj=arch/$(SRCARCH)/include/generated/asm

# To make sure we do not include .config for any of the *config targets
# catch them early, and hand them over to scripts/kconfig/Makefile
# It is allowed to specify more targets when calling make, including
Expand Down Expand Up @@ -954,7 +961,7 @@ ifneq ($(KBUILD_SRC),)
endif

# prepare2 creates a makefile if using a separate output directory
prepare2: prepare3 outputmakefile
prepare2: prepare3 outputmakefile asm-generic

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

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

PHONY += headers_install_all
Expand Down Expand Up @@ -1143,7 +1150,8 @@ CLEAN_FILES += vmlinux System.map \
.tmp_kallsyms* .tmp_version .tmp_vmlinux* .tmp_System.map

# Directories & files removed with 'make mrproper'
MRPROPER_DIRS += include/config usr/include include/generated
MRPROPER_DIRS += include/config usr/include include/generated \
arch/*/include/generated
MRPROPER_FILES += .config .config.old .version .old_version \
include/linux/version.h \
Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
Expand Down
23 changes: 23 additions & 0 deletions scripts/Makefile.asm-generic
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# include/asm-generic contains a lot of files that are used
# verbatim by several architectures.
#
# This Makefile reads the file arch/$(SRCARCH)/include/asm/Kbuild
# and for each file listed in this file with generic-y creates
# a small wrapper file in $(obj) (arch/$(SRCARCH)/include/generated/asm)

kbuild-file := $(srctree)/arch/$(SRCARCH)/include/asm/Kbuild
include $(kbuild-file)

include scripts/Kbuild.include

# Create output directory if not already present
_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))

quiet_cmd_wrap = WRAP $@
cmd_wrap = echo "\#include <asm-generic/$*.h>" >$@

all: $(patsubst %, $(obj)/%, $(generic-y))

$(obj)/%.h:
$(call cmd,wrap)

10 changes: 9 additions & 1 deletion scripts/Makefile.headersinst
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ header-y := $(filter-out %/, $(header-y))
install-file := $(install)/.install
check-file := $(install)/.check

# generic-y list all files an architecture uses from asm-generic
# Use this to build a list of headers which require a wrapper
wrapper-files := $(filter $(header-y), $(generic-y))

# all headers files for this dir
all-files := $(header-y) $(objhdr-y)
header-y := $(filter-out $(generic-y), $(header-y))
all-files := $(header-y) $(objhdr-y) $(wrapper-files)
input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
$(addprefix $(objtree)/$(obj)/,$(objhdr-y))
output-files := $(addprefix $(install)/, $(all-files))
Expand All @@ -47,6 +52,9 @@ quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
cmd_install = \
$(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
$(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \
for F in $(wrapper-files); do \
echo "\#include <asm-generic/$$F>" > $(install)/$$F; \
done; \
touch $@

quiet_cmd_remove = REMOVE $(unwanted)
Expand Down

0 comments on commit d8ecc5c

Please sign in to comment.