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

Unified · Split

3 files
  1. Makefile +15 −8
  2. lib/Kconfig.debug +1 −3
  3. scripts/Makefile.headersinst +4 −4
Makefile+15−8
@@ -262,7 +262,7 @@ old_version_h := include/linux/version.h · 261 unmodified lines
262clean-targets := %clean mrproper cleandocs262clean-targets := %clean mrproper cleandocs
263no-dot-config-targets := $(clean-targets) \263no-dot-config-targets := $(clean-targets) \
264 cscope gtags TAGS tags help% %docs check% coccicheck \264 cscope gtags TAGS tags help% %docs check% coccicheck \
265 $(version_h) headers_% archheaders archscripts \265 $(version_h) headers headers_% archheaders archscripts \
266 %asm-generic kernelversion %src-pkg266 %asm-generic kernelversion %src-pkg
267no-sync-config-targets := $(no-dot-config-targets) install %install \267no-sync-config-targets := $(no-dot-config-targets) install %install \
268 kernelrelease268 kernelrelease
@@ -1178,25 +1178,32 @@ headerdep: · 909 unmodified lines
1178#Default location for installed headers1178#Default location for installed headers
1179export INSTALL_HDR_PATH = $(objtree)/usr1179export INSTALL_HDR_PATH = $(objtree)/usr
1180 1180
1181PHONY += archheaders archscripts1181quiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include
1182 1182 cmd_headers_install = \
1183PHONY += __headers1183 mkdir -p $(INSTALL_HDR_PATH); \
1184__headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts1184 rsync -mrl --include='*/' --include='*\.h' --exclude='*' \
1185 usr/include $(INSTALL_HDR_PATH)
1185 1186
1186PHONY += headers_install1187PHONY += headers_install
1187headers_install: __headers1188headers_install: headers
1189 $(call cmd,headers_install)
1190
1191PHONY += archheaders archscripts
1192
1193PHONY += headers
1194headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts
1188 $(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \1195 $(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \
1189 $(error Headers not exportable for the $(SRCARCH) architecture))1196 $(error Headers not exportable for the $(SRCARCH) architecture))
1190 $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include1197 $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include
1191 $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include1198 $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include
1192 1199
1193PHONY += headers_check1200PHONY += headers_check
1194headers_check: headers_install1201headers_check: headers
1195 $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include HDRCHECK=11202 $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include HDRCHECK=1
1196 $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include HDRCHECK=11203 $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include HDRCHECK=1
1197 1204
1198ifdef CONFIG_HEADERS_INSTALL1205ifdef CONFIG_HEADERS_INSTALL
1199prepare: headers_install1206prepare: headers
1200endif1207endif
1201 1208
1202ifdef CONFIG_HEADERS_CHECK1209ifdef CONFIG_HEADERS_CHECK
lib/Kconfig.debug+1−3
@@ -324,9 +324,7 @@ config HEADERS_CHECK · 323 unmodified lines
324 attempt to include files which were not exported, etc.324 attempt to include files which were not exported, etc.
325 325
326 If you're making modifications to header files which are326 If you're making modifications to header files which are
327 relevant for userspace, say 'Y', and check the headers327 relevant for userspace, say 'Y'.
328 exported to $(INSTALL_HDR_PATH) (usually 'usr/include' in
329 your build tree), to make sure they're suitable.
330 328
331config OPTIMIZE_INLINING329config OPTIMIZE_INLINING
332 bool "Allow compiler to uninline functions marked 'inline'"330 bool "Allow compiler to uninline functions marked 'inline'"
scripts/Makefile.headersinst+4−4
@@ -41,7 +41,7 @@ ifeq ($(skip-inst),) · 40 unmodified lines
41kbuild-file := $(srctree)/$(obj)/Kbuild41kbuild-file := $(srctree)/$(obj)/Kbuild
42-include $(kbuild-file)42-include $(kbuild-file)
43 43
44installdir := $(INSTALL_HDR_PATH)/$(dst)44installdir := usr/$(dst)
45gendir := $(objtree)/$(subst include/,include/generated/,$(obj))45gendir := $(objtree)/$(subst include/,include/generated/,$(obj))
46header-files := $(notdir $(wildcard $(srcdir)/*.h))46header-files := $(notdir $(wildcard $(srcdir)/*.h))
47header-files := $(filter-out $(no-export-headers), $(header-files))47header-files := $(filter-out $(no-export-headers), $(header-files))
@@ -60,10 +60,10 @@ output-files := $(addprefix $(installdir)/, $(all-files)) · 12 unmodified lines
60oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))60oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
61unwanted := $(filter-out $(all-files),$(oldheaders))61unwanted := $(filter-out $(all-files),$(oldheaders))
62 62
63# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)63# Prefix unwanted with full paths to objtree
64unwanted-file := $(addprefix $(installdir)/, $(unwanted))64unwanted-file := $(addprefix $(installdir)/, $(unwanted))
65 65
66printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))66printdir = $(patsubst %/,%,$(dir $@))
67 67
68quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\68quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
69 file$(if $(word 2, $(all-files)),s))69 file$(if $(word 2, $(all-files)),s))
@@ -81,7 +81,7 @@ quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) · 11 unmodified lines
81 cmd_check = for f in $(all-files); do \81 cmd_check = for f in $(all-files); do \
82 echo "$(installdir)/$${f}"; done \82 echo "$(installdir)/$${f}"; done \
83 | xargs \83 | xargs \
84 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \84 $(PERL) $< usr/include $(SRCARCH); \
85 touch $@85 touch $@
86 86
87ifndef HDRCHECK87ifndef HDRCHECK