Back to home page

LXR

 
 

    


0001 # ==========================================================================
0002 # Installing headers
0003 #
0004 # header-y  - list files to be installed. They are preprocessed
0005 #             to remove __KERNEL__ section of the file
0006 # genhdr-y  - Same as header-y but in a generated/ directory
0007 #
0008 # ==========================================================================
0009 
0010 # generated header directory
0011 gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
0012 
0013 kbuild-file := $(srctree)/$(obj)/Kbuild
0014 include $(kbuild-file)
0015 
0016 # called may set destination dir (when installing to asm/)
0017 _dst := $(if $(destination-y),$(destination-y),$(if $(dst),$(dst),$(obj)))
0018 
0019 old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
0020 ifneq ($(wildcard $(old-kbuild-file)),)
0021 include $(old-kbuild-file)
0022 endif
0023 
0024 include scripts/Kbuild.include
0025 
0026 installdir    := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
0027 
0028 header-y      := $(sort $(header-y))
0029 subdirs       := $(patsubst %/,%,$(filter %/, $(header-y)))
0030 header-y      := $(filter-out %/, $(header-y))
0031 
0032 # files used to track state of install/check
0033 install-file  := $(installdir)/.install
0034 check-file    := $(installdir)/.check
0035 
0036 # generic-y list all files an architecture uses from asm-generic
0037 # Use this to build a list of headers which require a wrapper
0038 wrapper-files := $(filter $(header-y), $(generic-y))
0039 
0040 srcdir        := $(srctree)/$(obj)
0041 gendir        := $(objtree)/$(gen)
0042 
0043 oldsrcdir     := $(srctree)/$(subst /uapi,,$(obj))
0044 
0045 # all headers files for this dir
0046 header-y      := $(filter-out $(generic-y), $(header-y))
0047 all-files     := $(header-y) $(genhdr-y) $(wrapper-files)
0048 output-files  := $(addprefix $(installdir)/, $(all-files))
0049 
0050 input-files1  := $(foreach hdr, $(header-y), \
0051                    $(if $(wildcard $(srcdir)/$(hdr)), \
0052                         $(wildcard $(srcdir)/$(hdr))) \
0053                    )
0054 input-files1-name := $(notdir $(input-files1))
0055 input-files2  := $(foreach hdr, $(header-y), \
0056                    $(if  $(wildcard $(srcdir)/$(hdr)),, \
0057                         $(if $(wildcard $(oldsrcdir)/$(hdr)), \
0058                                 $(wildcard $(oldsrcdir)/$(hdr)), \
0059                                 $(error Missing UAPI file $(srcdir)/$(hdr))) \
0060                    ))
0061 input-files2-name := $(notdir $(input-files2))
0062 input-files3  := $(foreach hdr, $(genhdr-y), \
0063                    $(if $(wildcard $(gendir)/$(hdr)), \
0064                         $(wildcard $(gendir)/$(hdr)), \
0065                         $(error Missing generated UAPI file $(gendir)/$(hdr)) \
0066                    ))
0067 input-files3-name := $(notdir $(input-files3))
0068 
0069 # Work out what needs to be removed
0070 oldheaders    := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
0071 unwanted      := $(filter-out $(all-files),$(oldheaders))
0072 
0073 # Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
0074 unwanted-file := $(addprefix $(installdir)/, $(unwanted))
0075 
0076 printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
0077 
0078 quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
0079                             file$(if $(word 2, $(all-files)),s))
0080       cmd_install = \
0081         $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(input-files1-name); \
0082         $(CONFIG_SHELL) $< $(installdir) $(oldsrcdir) $(input-files2-name); \
0083         $(CONFIG_SHELL) $< $(installdir) $(gendir) $(input-files3-name); \
0084         for F in $(wrapper-files); do                                   \
0085                 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F;    \
0086         done;                                                           \
0087         touch $@
0088 
0089 quiet_cmd_remove = REMOVE  $(unwanted)
0090       cmd_remove = rm -f $(unwanted-file)
0091 
0092 quiet_cmd_check = CHECK   $(printdir) ($(words $(all-files)) files)
0093 # Headers list can be pretty long, xargs helps to avoid
0094 # the "Argument list too long" error.
0095       cmd_check = for f in $(all-files); do                          \
0096                   echo "$(installdir)/$${f}"; done                      \
0097                   | xargs                                            \
0098                   $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ 
0099                   touch $@
0100 
0101 PHONY += __headersinst __headerscheck
0102 
0103 ifndef HDRCHECK
0104 # Rules for installing headers
0105 __headersinst: $(subdirs) $(install-file)
0106         @:
0107 
0108 targets += $(install-file)
0109 $(install-file): scripts/headers_install.sh $(input-files1) $(input-files2) $(input-files3) FORCE
0110         $(if $(unwanted),$(call cmd,remove),)
0111         $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
0112         $(call if_changed,install)
0113 
0114 else
0115 __headerscheck: $(subdirs) $(check-file)
0116         @:
0117 
0118 targets += $(check-file)
0119 $(check-file): scripts/headers_check.pl $(output-files) FORCE
0120         $(call if_changed,check)
0121 
0122 endif
0123 
0124 # Recursion
0125 .PHONY: $(subdirs)
0126 $(subdirs):
0127         $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
0128 
0129 targets := $(wildcard $(sort $(targets)))
0130 cmd_files := $(wildcard \
0131              $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
0132 
0133 ifneq ($(cmd_files),)
0134         include $(cmd_files)
0135 endif
0136 
0137 .PHONY: $(PHONY)
0138 PHONY += FORCE
0139 FORCE: ;