xref: /linux/scripts/Makefile.headersinst (revision 87ebb94e28ccac00bacba0d6a0dac0aac5b9c63b)
18d730cfbSDavid Woodhouse# ==========================================================================
28d730cfbSDavid Woodhouse# Installing headers
38d730cfbSDavid Woodhouse#
4fcc8487dSNicolas Dichtel# All headers under include/uapi, include/generated/uapi,
561562f98SNicolas Dichtel# arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
6fcc8487dSNicolas Dichtel# exported.
7fcc8487dSNicolas Dichtel# They are preprocessed to remove __KERNEL__ section of the file.
88d730cfbSDavid Woodhouse#
98d730cfbSDavid Woodhouse# ==========================================================================
108d730cfbSDavid Woodhouse
1105d8cba4SMasahiro YamadaPHONY := __headers
1205d8cba4SMasahiro Yamada__headers:
1305d8cba4SMasahiro Yamada
1405d8cba4SMasahiro Yamadainclude scripts/Kbuild.include
1505d8cba4SMasahiro Yamada
1605d8cba4SMasahiro Yamadasrcdir        := $(srctree)/$(obj)
172f263d14SRichard Genoud
182f263d14SRichard Genoud# When make is run under a fakechroot environment, the function
192f263d14SRichard Genoud# $(wildcard $(srcdir)/*/.) doesn't only return directories, but also regular
202f263d14SRichard Genoud# files. So, we are using a combination of sort/dir/wildcard which works
212f263d14SRichard Genoud# with fakechroot.
222f263d14SRichard Genoudsubdirs       := $(patsubst $(srcdir)/%/,%,\
232f263d14SRichard Genoud		 $(filter-out $(srcdir)/,\
242f263d14SRichard Genoud		 $(sort $(dir $(wildcard $(srcdir)/*/)))))
252f263d14SRichard Genoud
2605d8cba4SMasahiro Yamada# caller may set destination dir (when installing to asm/)
2705d8cba4SMasahiro Yamada_dst          := $(if $(dst),$(dst),$(obj))
2805d8cba4SMasahiro Yamada
2905d8cba4SMasahiro Yamada# Recursion
3005d8cba4SMasahiro Yamada__headers: $(subdirs)
3105d8cba4SMasahiro Yamada
3205d8cba4SMasahiro Yamada.PHONY: $(subdirs)
3305d8cba4SMasahiro Yamada$(subdirs):
3405d8cba4SMasahiro Yamada	$(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
3505d8cba4SMasahiro Yamada
3605d8cba4SMasahiro Yamada# Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi.
3705d8cba4SMasahiro Yamada# We have only sub-directories there.
3805d8cba4SMasahiro Yamadaskip-inst := $(if $(filter %/uapi,$(obj)),1)
3905d8cba4SMasahiro Yamada
4005d8cba4SMasahiro Yamadaifeq ($(skip-inst),)
4105d8cba4SMasahiro Yamada
42fcc8487dSNicolas Dichtel# Kbuild file is optional
43283039fbSSam Ravnborgkbuild-file := $(srctree)/$(obj)/Kbuild
44fcc8487dSNicolas Dichtel-include $(kbuild-file)
45de789125SDavid Woodhouse
4610b63956SDavid Howellsold-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
4710b63956SDavid Howellsifneq ($(wildcard $(old-kbuild-file)),)
4810b63956SDavid Howellsinclude $(old-kbuild-file)
4910b63956SDavid Howellsendif
50c7bb349eSSam Ravnborg
5110b63956SDavid Howellsinstalldir    := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
5262284a37SSam Ravnborg
53*87ebb94eSMasahiro Yamadagendir        := $(objtree)/$(subst include/,include/generated/,$(obj))
54fcc8487dSNicolas Dichtelheader-files  := $(notdir $(wildcard $(srcdir)/*.h))
55fcc8487dSNicolas Dichtelheader-files  += $(notdir $(wildcard $(srcdir)/*.agh))
56fcc8487dSNicolas Dichtelheader-files  := $(filter-out $(no-export-headers), $(header-files))
57fcc8487dSNicolas Dichtelgenhdr-files  := $(notdir $(wildcard $(gendir)/*.h))
58fcc8487dSNicolas Dichtelgenhdr-files  := $(filter-out $(header-files), $(genhdr-files))
598d730cfbSDavid Woodhouse
607712401aSSam Ravnborg# files used to track state of install/check
6110b63956SDavid Howellsinstall-file  := $(installdir)/.install
6210b63956SDavid Howellscheck-file    := $(installdir)/.check
637712401aSSam Ravnborg
64d8ecc5cdSSam Ravnborg# generic-y list all files an architecture uses from asm-generic
65d8ecc5cdSSam Ravnborg# Use this to build a list of headers which require a wrapper
66fcc8487dSNicolas Dichtelgeneric-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h))
67fcc8487dSNicolas Dichtelwrapper-files := $(filter $(generic-files), $(generic-y))
68fcc8487dSNicolas Dichtelwrapper-files := $(filter-out $(header-files), $(wrapper-files))
6910b63956SDavid Howells
707712401aSSam Ravnborg# all headers files for this dir
71fcc8487dSNicolas Dichtelall-files     := $(header-files) $(genhdr-files) $(wrapper-files)
7210b63956SDavid Howellsoutput-files  := $(addprefix $(installdir)/, $(all-files))
7310b63956SDavid Howells
74fcc8487dSNicolas Dichtelifneq ($(mandatory-y),)
75fcc8487dSNicolas Dichtelmissing       := $(filter-out $(all-files),$(mandatory-y))
76fcc8487dSNicolas Dichtelifneq ($(missing),)
77fcc8487dSNicolas Dichtel$(error Some mandatory headers ($(missing)) are missing in $(obj))
78fcc8487dSNicolas Dichtelendif
79fcc8487dSNicolas Dichtelendif
80de789125SDavid Woodhouse
81de789125SDavid Woodhouse# Work out what needs to be removed
8210b63956SDavid Howellsoldheaders    := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
837712401aSSam Ravnborgunwanted      := $(filter-out $(all-files),$(oldheaders))
84de789125SDavid Woodhouse
857712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
8610b63956SDavid Howellsunwanted-file := $(addprefix $(installdir)/, $(unwanted))
87de789125SDavid Woodhouse
887712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
89de789125SDavid Woodhouse
907712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
917712401aSSam Ravnborg                            file$(if $(word 2, $(all-files)),s))
92db1bec4fSSam Ravnborg      cmd_install = \
93fcc8487dSNicolas Dichtel        $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
94fcc8487dSNicolas Dichtel        $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
95d8ecc5cdSSam Ravnborg        for F in $(wrapper-files); do                                   \
9610b63956SDavid Howells                echo "\#include <asm-generic/$$F>" > $(installdir)/$$F;    \
97d8ecc5cdSSam Ravnborg        done;                                                           \
987712401aSSam Ravnborg        touch $@
998d730cfbSDavid Woodhouse
1007712401aSSam Ravnborgquiet_cmd_remove = REMOVE  $(unwanted)
1017712401aSSam Ravnborg      cmd_remove = rm -f $(unwanted-file)
1028d730cfbSDavid Woodhouse
1037712401aSSam Ravnborgquiet_cmd_check = CHECK   $(printdir) ($(words $(all-files)) files)
1047211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid
1057211b8b9SSergei Poselenov# the "Argument list too long" error.
1067211b8b9SSergei Poselenov      cmd_check = for f in $(all-files); do                          \
10710b63956SDavid Howells                  echo "$(installdir)/$${f}"; done                      \
1087211b8b9SSergei Poselenov                  | xargs                                            \
1097211b8b9SSergei Poselenov                  $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
1107712401aSSam Ravnborg	          touch $@
11168475359SDavid Woodhouse
1127712401aSSam Ravnborgifndef HDRCHECK
1137712401aSSam Ravnborg# Rules for installing headers
11405d8cba4SMasahiro Yamada__headers: $(install-file)
1157712401aSSam Ravnborg	@:
116de789125SDavid Woodhouse
1177712401aSSam Ravnborgtargets += $(install-file)
1187c025b2aSNicolas Dichtel$(install-file): scripts/headers_install.sh \
119fcc8487dSNicolas Dichtel		 $(addprefix $(srcdir)/,$(header-files)) \
120fcc8487dSNicolas Dichtel		 $(addprefix $(gendir)/,$(genhdr-files)) FORCE
1217712401aSSam Ravnborg	$(if $(unwanted),$(call cmd,remove),)
1227712401aSSam Ravnborg	$(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
1237712401aSSam Ravnborg	$(call if_changed,install)
124de789125SDavid Woodhouse
12568475359SDavid Woodhouseelse
12605d8cba4SMasahiro Yamada__headers: $(check-file)
1277712401aSSam Ravnborg	@:
1288d730cfbSDavid Woodhouse
1297712401aSSam Ravnborgtargets += $(check-file)
1307712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE
1317712401aSSam Ravnborg	$(call if_changed,check)
1324e420aa9SSam Ravnborg
1338d730cfbSDavid Woodhouseendif
1348d730cfbSDavid Woodhouse
1357712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets)))
1367712401aSSam Ravnborgcmd_files := $(wildcard \
1377712401aSSam Ravnborg             $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
1387712401aSSam Ravnborg
1397712401aSSam Ravnborgifneq ($(cmd_files),)
1407712401aSSam Ravnborg	include $(cmd_files)
1417712401aSSam Ravnborgendif
1427712401aSSam Ravnborg
14305d8cba4SMasahiro Yamadaendif # skip-inst
14405d8cba4SMasahiro Yamada
1457712401aSSam Ravnborg.PHONY: $(PHONY)
1467712401aSSam RavnborgPHONY += FORCE
1477712401aSSam RavnborgFORCE: ;
148