Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 # ==========================================================================
0003 # Installing headers
0004 #
0005 # All headers under include/uapi, include/generated/uapi,
0006 # arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
0007 # exported.
0008 # They are preprocessed to remove __KERNEL__ section of the file.
0009 #
0010 # ==========================================================================
0011 
0012 PHONY := __headers
0013 __headers:
0014 
0015 include $(srctree)/scripts/Kbuild.include
0016 
0017 src := $(srctree)/$(obj)
0018 gen := $(objtree)/$(subst include/,include/generated/,$(obj))
0019 dst := usr/include
0020 
0021 -include $(src)/Kbuild
0022 
0023 # $(filter %/, ...) is a workaround for GNU Make <= 4.2.1, where
0024 # $(wildcard $(src)/*/) contains not only directories but also regular files.
0025 src-subdirs := $(patsubst $(src)/%/,%,$(filter %/, $(wildcard $(src)/*/)))
0026 gen-subdirs := $(patsubst $(gen)/%/,%,$(filter %/, $(wildcard $(gen)/*/)))
0027 all-subdirs := $(sort $(src-subdirs) $(gen-subdirs))
0028 
0029 src-headers := $(if $(src-subdirs), $(shell cd $(src) && find $(src-subdirs) -name '*.h'))
0030 src-headers := $(filter-out $(no-export-headers), $(src-headers))
0031 gen-headers := $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subdirs) -name '*.h'))
0032 gen-headers := $(filter-out $(no-export-headers), $(gen-headers))
0033 
0034 # If the same header is exported from source and generated directories,
0035 # the former takes precedence, but this should be warned.
0036 duplicated := $(filter $(gen-headers), $(src-headers))
0037 $(if $(duplicated), $(warning duplicated header export: $(duplicated)))
0038 
0039 gen-headers := $(filter-out $(duplicated), $(gen-headers))
0040 
0041 # Add dst path prefix
0042 all-subdirs := $(addprefix $(dst)/, $(all-subdirs))
0043 src-headers := $(addprefix $(dst)/, $(src-headers))
0044 gen-headers := $(addprefix $(dst)/, $(gen-headers))
0045 all-headers := $(src-headers) $(gen-headers)
0046 
0047 # Work out what needs to be removed
0048 old-subdirs := $(wildcard $(all-subdirs))
0049 old-headers := $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.h'))
0050 unwanted    := $(filter-out $(all-headers), $(old-headers))
0051 
0052 # Create directories
0053 existing-dirs := $(sort $(dir $(old-headers)))
0054 wanted-dirs   := $(sort $(dir $(all-headers)))
0055 new-dirs      := $(filter-out $(existing-dirs), $(wanted-dirs))
0056 $(if $(new-dirs), $(shell mkdir -p $(new-dirs)))
0057 
0058 # Rules
0059 quiet_cmd_install = HDRINST $@
0060       cmd_install = $(CONFIG_SHELL) $(srctree)/scripts/headers_install.sh $< $@
0061 
0062 $(src-headers): $(dst)/%.h: $(src)/%.h $(srctree)/scripts/headers_install.sh FORCE
0063         $(call if_changed,install)
0064 
0065 $(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctree)/scripts/headers_install.sh FORCE
0066         $(call if_changed,install)
0067 
0068 quiet_cmd_remove = REMOVE  $(unwanted)
0069       cmd_remove = rm -f $(unwanted)
0070 
0071 __headers: $(all-headers)
0072 ifneq ($(unwanted),)
0073         $(call cmd,remove)
0074 endif
0075         @:
0076 
0077 existing-headers := $(filter $(old-headers), $(all-headers))
0078 
0079 -include $(foreach f,$(existing-headers),$(dir $(f)).$(notdir $(f)).cmd) 
0080 
0081 PHONY += FORCE
0082 FORCE:
0083 
0084 .PHONY: $(PHONY)