xref: /linux/scripts/Makefile.headersinst (revision b24413180f5600bcb3bb70fbed5cf186b60864bd)
1*b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
28d730cfbSDavid Woodhouse# ==========================================================================
38d730cfbSDavid Woodhouse# Installing headers
48d730cfbSDavid Woodhouse#
5fcc8487dSNicolas Dichtel# All headers under include/uapi, include/generated/uapi,
661562f98SNicolas Dichtel# arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
7fcc8487dSNicolas Dichtel# exported.
8fcc8487dSNicolas Dichtel# They are preprocessed to remove __KERNEL__ section of the file.
98d730cfbSDavid Woodhouse#
108d730cfbSDavid Woodhouse# ==========================================================================
118d730cfbSDavid Woodhouse
1205d8cba4SMasahiro YamadaPHONY := __headers
1305d8cba4SMasahiro Yamada__headers:
1405d8cba4SMasahiro Yamada
1505d8cba4SMasahiro Yamadainclude scripts/Kbuild.include
1605d8cba4SMasahiro Yamada
1705d8cba4SMasahiro Yamadasrcdir        := $(srctree)/$(obj)
182f263d14SRichard Genoud
192f263d14SRichard Genoud# When make is run under a fakechroot environment, the function
202f263d14SRichard Genoud# $(wildcard $(srcdir)/*/.) doesn't only return directories, but also regular
212f263d14SRichard Genoud# files. So, we are using a combination of sort/dir/wildcard which works
222f263d14SRichard Genoud# with fakechroot.
232f263d14SRichard Genoudsubdirs       := $(patsubst $(srcdir)/%/,%,\
242f263d14SRichard Genoud		 $(filter-out $(srcdir)/,\
252f263d14SRichard Genoud		 $(sort $(dir $(wildcard $(srcdir)/*/)))))
262f263d14SRichard Genoud
2705d8cba4SMasahiro Yamada# Recursion
2805d8cba4SMasahiro Yamada__headers: $(subdirs)
2905d8cba4SMasahiro Yamada
3005d8cba4SMasahiro Yamada.PHONY: $(subdirs)
3105d8cba4SMasahiro Yamada$(subdirs):
32a8ff49a1SMasahiro Yamada	$(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(dst)/$@
3305d8cba4SMasahiro Yamada
3405d8cba4SMasahiro Yamada# Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi.
3505d8cba4SMasahiro Yamada# We have only sub-directories there.
3605d8cba4SMasahiro Yamadaskip-inst := $(if $(filter %/uapi,$(obj)),1)
3705d8cba4SMasahiro Yamada
3805d8cba4SMasahiro Yamadaifeq ($(skip-inst),)
3905d8cba4SMasahiro Yamada
40fcc8487dSNicolas Dichtel# Kbuild file is optional
41283039fbSSam Ravnborgkbuild-file := $(srctree)/$(obj)/Kbuild
42fcc8487dSNicolas Dichtel-include $(kbuild-file)
43de789125SDavid Woodhouse
44a8ff49a1SMasahiro Yamadainstalldir    := $(INSTALL_HDR_PATH)/$(dst)
4587ebb94eSMasahiro Yamadagendir        := $(objtree)/$(subst include/,include/generated/,$(obj))
46fcc8487dSNicolas Dichtelheader-files  := $(notdir $(wildcard $(srcdir)/*.h))
47fcc8487dSNicolas Dichtelheader-files  += $(notdir $(wildcard $(srcdir)/*.agh))
48fcc8487dSNicolas Dichtelheader-files  := $(filter-out $(no-export-headers), $(header-files))
49fcc8487dSNicolas Dichtelgenhdr-files  := $(notdir $(wildcard $(gendir)/*.h))
50fcc8487dSNicolas Dichtelgenhdr-files  := $(filter-out $(header-files), $(genhdr-files))
518d730cfbSDavid Woodhouse
527712401aSSam Ravnborg# files used to track state of install/check
5310b63956SDavid Howellsinstall-file  := $(installdir)/.install
5410b63956SDavid Howellscheck-file    := $(installdir)/.check
557712401aSSam Ravnborg
567712401aSSam Ravnborg# all headers files for this dir
5709c3776cSMasahiro Yamadaall-files     := $(header-files) $(genhdr-files)
5810b63956SDavid Howellsoutput-files  := $(addprefix $(installdir)/, $(all-files))
5910b63956SDavid Howells
60fcc8487dSNicolas Dichtelifneq ($(mandatory-y),)
61fcc8487dSNicolas Dichtelmissing       := $(filter-out $(all-files),$(mandatory-y))
62fcc8487dSNicolas Dichtelifneq ($(missing),)
63fcc8487dSNicolas Dichtel$(error Some mandatory headers ($(missing)) are missing in $(obj))
64fcc8487dSNicolas Dichtelendif
65fcc8487dSNicolas Dichtelendif
66de789125SDavid Woodhouse
67de789125SDavid Woodhouse# Work out what needs to be removed
6810b63956SDavid Howellsoldheaders    := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
697712401aSSam Ravnborgunwanted      := $(filter-out $(all-files),$(oldheaders))
70de789125SDavid Woodhouse
717712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
7210b63956SDavid Howellsunwanted-file := $(addprefix $(installdir)/, $(unwanted))
73de789125SDavid Woodhouse
747712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
75de789125SDavid Woodhouse
767712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
777712401aSSam Ravnborg                            file$(if $(word 2, $(all-files)),s))
78db1bec4fSSam Ravnborg      cmd_install = \
79fcc8487dSNicolas Dichtel        $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
80fcc8487dSNicolas Dichtel        $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
817712401aSSam Ravnborg        touch $@
828d730cfbSDavid Woodhouse
837712401aSSam Ravnborgquiet_cmd_remove = REMOVE  $(unwanted)
847712401aSSam Ravnborg      cmd_remove = rm -f $(unwanted-file)
858d730cfbSDavid Woodhouse
867712401aSSam Ravnborgquiet_cmd_check = CHECK   $(printdir) ($(words $(all-files)) files)
877211b8b9SSergei Poselenov# Headers list can be pretty long, xargs helps to avoid
887211b8b9SSergei Poselenov# the "Argument list too long" error.
897211b8b9SSergei Poselenov      cmd_check = for f in $(all-files); do                          \
9010b63956SDavid Howells                  echo "$(installdir)/$${f}"; done                      \
917211b8b9SSergei Poselenov                  | xargs                                            \
927211b8b9SSergei Poselenov                  $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
937712401aSSam Ravnborg	          touch $@
9468475359SDavid Woodhouse
957712401aSSam Ravnborgifndef HDRCHECK
967712401aSSam Ravnborg# Rules for installing headers
9705d8cba4SMasahiro Yamada__headers: $(install-file)
987712401aSSam Ravnborg	@:
99de789125SDavid Woodhouse
1007712401aSSam Ravnborgtargets += $(install-file)
1017c025b2aSNicolas Dichtel$(install-file): scripts/headers_install.sh \
102fcc8487dSNicolas Dichtel		 $(addprefix $(srcdir)/,$(header-files)) \
103fcc8487dSNicolas Dichtel		 $(addprefix $(gendir)/,$(genhdr-files)) FORCE
1047712401aSSam Ravnborg	$(if $(unwanted),$(call cmd,remove),)
1057712401aSSam Ravnborg	$(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
1067712401aSSam Ravnborg	$(call if_changed,install)
107de789125SDavid Woodhouse
10868475359SDavid Woodhouseelse
10905d8cba4SMasahiro Yamada__headers: $(check-file)
1107712401aSSam Ravnborg	@:
1118d730cfbSDavid Woodhouse
1127712401aSSam Ravnborgtargets += $(check-file)
1137712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE
1147712401aSSam Ravnborg	$(call if_changed,check)
1154e420aa9SSam Ravnborg
1168d730cfbSDavid Woodhouseendif
1178d730cfbSDavid Woodhouse
1187712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets)))
1197712401aSSam Ravnborgcmd_files := $(wildcard \
1207712401aSSam Ravnborg             $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
1217712401aSSam Ravnborg
1227712401aSSam Ravnborgifneq ($(cmd_files),)
1237712401aSSam Ravnborg	include $(cmd_files)
1247712401aSSam Ravnborgendif
1257712401aSSam Ravnborg
12605d8cba4SMasahiro Yamadaendif # skip-inst
12705d8cba4SMasahiro Yamada
1287712401aSSam Ravnborg.PHONY: $(PHONY)
1297712401aSSam RavnborgPHONY += FORCE
1307712401aSSam RavnborgFORCE: ;
131