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