History

kbuild: add 'headers' target to build up uapi headers in usr/include

In Linux build system, build targets and installation targets are separated. Examples are: - 'make vmlinux' -> 'make install' - 'make modules' -> 'make modules_install' - 'make dtbs' -> 'make dtbs_install' - 'make vdso' -> 'make vdso_install' The intention is to run the build targets under the normal privilege, then the installation targets under the root privilege since we need the write permission to the system directories. We have 'make headers_install' but the corresponding 'make headers' stage does not exist. The purpose of headers_install is to provide the kernel interface to C library. So, nobody would try to install headers to /usr/include directly. If 'sudo make INSTALL_HDR_PATH=/usr/include headers_install' were run, some build artifacts in the kernel tree would be owned by root because some of uapi headers are generated by 'uapi-asm-generic', 'archheaders' targets. Anyway, I believe it makes sense to split the header installation into two stages. [1] 'make headers' Process headers in uapi directories by scripts/headers_install.sh and copy them to usr/include [2] 'make headers_install' Copy '*.h' verbatim from usr/include to $(INSTALL_HDR_PATH)/include For the backward compatibility, 'headers_install' depends on 'headers'. Some samples expect uapi headers in usr/include. So, the 'headers' target is useful to build up them in the fixed location usr/include irrespective of INSTALL_HDR_PATH. Another benefit is to stop polluting the final destination with the time-stamp files '.install' and '.check'. Maybe you can see them in your toolchains. Lastly, my main motivation is to prepare for compile-testing uapi headers. To build something, we have to save an object and .*.cmd somewhere. The usr/include/ will be the work directory for that.

Masahiro Yamada committed 7 years ago

Commit 59b2bd01 parent bdd77143 files · +20 −15Browse files

Showing the changes to scripts (1 of 3 files). Show all

Unified · Split

scripts/Makefile.headersinst+4−4
@@ -41,7 +41,7 @@ ifeq ($(skip-inst),) · 40 unmodified lines
4141 kbuild-file := $(srctree)/$(obj)/Kbuild
4242 -include $(kbuild-file)
4343
44−installdir := $(INSTALL_HDR_PATH)/$(dst)
44+installdir := usr/$(dst)
4545 gendir := $(objtree)/$(subst include/,include/generated/,$(obj))
4646 header-files := $(notdir $(wildcard $(srcdir)/*.h))
4747 header-files := $(filter-out $(no-export-headers), $(header-files))
@@ -60,10 +60,10 @@ output-files := $(addprefix $(installdir)/, $(all-files)) · 12 unmodified lines
6060 oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
6161 unwanted := $(filter-out $(all-files),$(oldheaders))
6262
63−# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
63+# Prefix unwanted with full paths to objtree
6464 unwanted-file := $(addprefix $(installdir)/, $(unwanted))
6565
66−printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
66+printdir = $(patsubst %/,%,$(dir $@))
6767
6868 quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
6969 file$(if $(word 2, $(all-files)),s))
@@ -81,7 +81,7 @@ quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) · 11 unmodified lines
8181 cmd_check = for f in $(all-files); do \
8282 echo "$(installdir)/$${f}"; done \
8383 | xargs \
84− $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
84+ $(PERL) $< usr/include $(SRCARCH); \
8585 touch $@
8686
8787 ifndef HDRCHECK