Skip to content

Commit 59b2bd0

Browse files
committed
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. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent bdd7714 commit 59b2bd0

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

‎Makefile‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ old_version_h := include/linux/version.h
262262
clean-targets := %clean mrproper cleandocs
263263
no-dot-config-targets := $(clean-targets) \
264264
cscope gtags TAGS tags help% %docs check% coccicheck \
265-
$(version_h) headers_% archheaders archscripts \
265+
$(version_h) headers headers_% archheaders archscripts \
266266
%asm-generic kernelversion %src-pkg
267267
no-sync-config-targets := $(no-dot-config-targets) install %install \
268268
kernelrelease
@@ -1178,25 +1178,32 @@ headerdep:
11781178
#Default location for installed headers
11791179
export INSTALL_HDR_PATH = $(objtree)/usr
11801180

1181-
PHONY += archheaders archscripts
1182-
1183-
PHONY += __headers
1184-
__headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts
1181+
quiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include
1182+
cmd_headers_install = \
1183+
mkdir -p $(INSTALL_HDR_PATH); \
1184+
rsync -mrl --include='*/' --include='*\.h' --exclude='*' \
1185+
usr/include $(INSTALL_HDR_PATH)
11851186

11861187
PHONY += headers_install
1187-
headers_install: __headers
1188+
headers_install: headers
1189+
$(call cmd,headers_install)
1190+
1191+
PHONY += archheaders archscripts
1192+
1193+
PHONY += headers
1194+
headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts
11881195
$(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \
11891196
$(error Headers not exportable for the $(SRCARCH) architecture))
11901197
$(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include
11911198
$(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include
11921199

11931200
PHONY += headers_check
1194-
headers_check: headers_install
1201+
headers_check: headers
11951202
$(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include HDRCHECK=1
11961203
$(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi dst=include HDRCHECK=1
11971204

11981205
ifdef CONFIG_HEADERS_INSTALL
1199-
prepare: headers_install
1206+
prepare: headers
12001207
endif
12011208

12021209
ifdef CONFIG_HEADERS_CHECK

‎lib/Kconfig.debug‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,7 @@ config HEADERS_CHECK
324324
attempt to include files which were not exported, etc.
325325

326326
If you're making modifications to header files which are
327-
relevant for userspace, say 'Y', and check the headers
328-
exported to $(INSTALL_HDR_PATH) (usually 'usr/include' in
329-
your build tree), to make sure they're suitable.
327+
relevant for userspace, say 'Y'.
330328

331329
config OPTIMIZE_INLINING
332330
bool "Allow compiler to uninline functions marked 'inline'"

‎scripts/Makefile.headersinst‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ifeq ($(skip-inst),)
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))
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)
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

0 commit comments

Comments
 (0)