1*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun# ========================================================================== 3*4882a593Smuzhiyun# Installing headers 4*4882a593Smuzhiyun# 5*4882a593Smuzhiyun# All headers under include/uapi, include/generated/uapi, 6*4882a593Smuzhiyun# arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are 7*4882a593Smuzhiyun# exported. 8*4882a593Smuzhiyun# They are preprocessed to remove __KERNEL__ section of the file. 9*4882a593Smuzhiyun# 10*4882a593Smuzhiyun# ========================================================================== 11*4882a593Smuzhiyun 12*4882a593SmuzhiyunPHONY := __headers 13*4882a593Smuzhiyun__headers: 14*4882a593Smuzhiyun 15*4882a593Smuzhiyuninclude scripts/Kbuild.include 16*4882a593Smuzhiyun 17*4882a593Smuzhiyunsrcdir := $(srctree)/$(obj) 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun# When make is run under a fakechroot environment, the function 20*4882a593Smuzhiyun# $(wildcard $(srcdir)/*/.) doesn't only return directories, but also regular 21*4882a593Smuzhiyun# files. So, we are using a combination of sort/dir/wildcard which works 22*4882a593Smuzhiyun# with fakechroot. 23*4882a593Smuzhiyunsubdirs := $(patsubst $(srcdir)/%/,%,\ 24*4882a593Smuzhiyun $(filter-out $(srcdir)/,\ 25*4882a593Smuzhiyun $(sort $(dir $(wildcard $(srcdir)/*/))))) 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun# Recursion 28*4882a593Smuzhiyun__headers: $(subdirs) 29*4882a593Smuzhiyun 30*4882a593SmuzhiyunPHONY += $(subdirs) 31*4882a593Smuzhiyun$(subdirs): 32*4882a593Smuzhiyun $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(dst)/$@ 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun# Skip header install/check for include/uapi and arch/$(SRCARCH)/include/uapi. 35*4882a593Smuzhiyun# We have only sub-directories there. 36*4882a593Smuzhiyunskip-inst := $(if $(filter %/uapi,$(obj)),1) 37*4882a593Smuzhiyun 38*4882a593Smuzhiyunifeq ($(skip-inst),) 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun# Kbuild file is optional 41*4882a593Smuzhiyunkbuild-file := $(srctree)/$(obj)/Kbuild 42*4882a593Smuzhiyun-include $(kbuild-file) 43*4882a593Smuzhiyun 44*4882a593Smuzhiyuninstalldir := $(INSTALL_HDR_PATH)/$(dst) 45*4882a593Smuzhiyungendir := $(objtree)/$(subst include/,include/generated/,$(obj)) 46*4882a593Smuzhiyunheader-files := $(notdir $(wildcard $(srcdir)/*.h)) 47*4882a593Smuzhiyunheader-files += $(notdir $(wildcard $(srcdir)/*.agh)) 48*4882a593Smuzhiyunheader-files := $(filter-out $(no-export-headers), $(header-files)) 49*4882a593Smuzhiyungenhdr-files := $(notdir $(wildcard $(gendir)/*.h)) 50*4882a593Smuzhiyungenhdr-files := $(filter-out $(header-files), $(genhdr-files)) 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun# files used to track state of install/check 53*4882a593Smuzhiyuninstall-file := $(installdir)/.install 54*4882a593Smuzhiyuncheck-file := $(installdir)/.check 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun# all headers files for this dir 57*4882a593Smuzhiyunall-files := $(header-files) $(genhdr-files) 58*4882a593Smuzhiyunoutput-files := $(addprefix $(installdir)/, $(all-files)) 59*4882a593Smuzhiyun 60*4882a593Smuzhiyunifneq ($(mandatory-y),) 61*4882a593Smuzhiyunmissing := $(filter-out $(all-files),$(mandatory-y)) 62*4882a593Smuzhiyunifneq ($(missing),) 63*4882a593Smuzhiyun$(error Some mandatory headers ($(missing)) are missing in $(obj)) 64*4882a593Smuzhiyunendif 65*4882a593Smuzhiyunendif 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun# Work out what needs to be removed 68*4882a593Smuzhiyunoldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) 69*4882a593Smuzhiyununwanted := $(filter-out $(all-files),$(oldheaders)) 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun# Prefix unwanted with full paths to $(INSTALL_HDR_PATH) 72*4882a593Smuzhiyununwanted-file := $(addprefix $(installdir)/, $(unwanted)) 73*4882a593Smuzhiyun 74*4882a593Smuzhiyunprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) 75*4882a593Smuzhiyun 76*4882a593Smuzhiyunquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ 77*4882a593Smuzhiyun file$(if $(word 2, $(all-files)),s)) 78*4882a593Smuzhiyun cmd_install = \ 79*4882a593Smuzhiyun $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \ 80*4882a593Smuzhiyun $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \ 81*4882a593Smuzhiyun touch $@ 82*4882a593Smuzhiyun 83*4882a593Smuzhiyunquiet_cmd_remove = REMOVE $(unwanted) 84*4882a593Smuzhiyun cmd_remove = rm -f $(unwanted-file) 85*4882a593Smuzhiyun 86*4882a593Smuzhiyunquiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) 87*4882a593Smuzhiyun# Headers list can be pretty long, xargs helps to avoid 88*4882a593Smuzhiyun# the "Argument list too long" error. 89*4882a593Smuzhiyun cmd_check = for f in $(all-files); do \ 90*4882a593Smuzhiyun echo "$(installdir)/$${f}"; done \ 91*4882a593Smuzhiyun | xargs \ 92*4882a593Smuzhiyun $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 93*4882a593Smuzhiyun touch $@ 94*4882a593Smuzhiyun 95*4882a593Smuzhiyunifndef HDRCHECK 96*4882a593Smuzhiyun# Rules for installing headers 97*4882a593Smuzhiyun__headers: $(install-file) 98*4882a593Smuzhiyun @: 99*4882a593Smuzhiyun 100*4882a593Smuzhiyuntargets += $(install-file) 101*4882a593Smuzhiyun$(install-file): scripts/headers_install.sh \ 102*4882a593Smuzhiyun $(addprefix $(srcdir)/,$(header-files)) \ 103*4882a593Smuzhiyun $(addprefix $(gendir)/,$(genhdr-files)) FORCE 104*4882a593Smuzhiyun $(if $(unwanted),$(call cmd,remove),) 105*4882a593Smuzhiyun $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) 106*4882a593Smuzhiyun $(call if_changed,install) 107*4882a593Smuzhiyun 108*4882a593Smuzhiyunelse 109*4882a593Smuzhiyun__headers: $(check-file) 110*4882a593Smuzhiyun @: 111*4882a593Smuzhiyun 112*4882a593Smuzhiyuntargets += $(check-file) 113*4882a593Smuzhiyun$(check-file): scripts/headers_check.pl $(output-files) FORCE 114*4882a593Smuzhiyun $(call if_changed,check) 115*4882a593Smuzhiyun 116*4882a593Smuzhiyunendif 117*4882a593Smuzhiyun 118*4882a593Smuzhiyuncmd_files := $(wildcard \ 119*4882a593Smuzhiyun $(foreach f,$(sort $(targets)),$(dir $(f)).$(notdir $(f)).cmd)) 120*4882a593Smuzhiyun 121*4882a593Smuzhiyunifneq ($(cmd_files),) 122*4882a593Smuzhiyun include $(cmd_files) 123*4882a593Smuzhiyunendif 124*4882a593Smuzhiyun 125*4882a593Smuzhiyunendif # skip-inst 126*4882a593Smuzhiyun 127*4882a593SmuzhiyunPHONY += FORCE 128*4882a593SmuzhiyunFORCE: ; 129*4882a593Smuzhiyun 130*4882a593Smuzhiyun.PHONY: $(PHONY) 131