162306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci# ========================================================================== 362306a36Sopenharmony_ci# Installing headers 462306a36Sopenharmony_ci# 562306a36Sopenharmony_ci# All headers under include/uapi, include/generated/uapi, 662306a36Sopenharmony_ci# arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are 762306a36Sopenharmony_ci# exported. 862306a36Sopenharmony_ci# They are preprocessed to remove __KERNEL__ section of the file. 962306a36Sopenharmony_ci# 1062306a36Sopenharmony_ci# ========================================================================== 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ciPHONY := __headers 1362306a36Sopenharmony_ci__headers: 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciinclude $(srctree)/scripts/Kbuild.include 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_cisrc := $(srctree)/$(obj) 1862306a36Sopenharmony_cigen := $(objtree)/$(subst include/,include/generated/,$(obj)) 1962306a36Sopenharmony_cidst := usr/include 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci-include $(src)/Kbuild 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci# $(filter %/, ...) is a workaround for GNU Make <= 4.2.1, where 2462306a36Sopenharmony_ci# $(wildcard $(src)/*/) contains not only directories but also regular files. 2562306a36Sopenharmony_cisrc-subdirs := $(patsubst $(src)/%/,%,$(filter %/, $(wildcard $(src)/*/))) 2662306a36Sopenharmony_cigen-subdirs := $(patsubst $(gen)/%/,%,$(filter %/, $(wildcard $(gen)/*/))) 2762306a36Sopenharmony_ciall-subdirs := $(sort $(src-subdirs) $(gen-subdirs)) 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_cisrc-headers := $(if $(src-subdirs), $(shell cd $(src) && find $(src-subdirs) -name '*.h')) 3062306a36Sopenharmony_cisrc-headers := $(filter-out $(no-export-headers), $(src-headers)) 3162306a36Sopenharmony_cigen-headers := $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subdirs) -name '*.h')) 3262306a36Sopenharmony_cigen-headers := $(filter-out $(no-export-headers), $(gen-headers)) 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci# If the same header is exported from source and generated directories, 3562306a36Sopenharmony_ci# the former takes precedence, but this should be warned. 3662306a36Sopenharmony_ciduplicated := $(filter $(gen-headers), $(src-headers)) 3762306a36Sopenharmony_ci$(if $(duplicated), $(warning duplicated header export: $(duplicated))) 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_cigen-headers := $(filter-out $(duplicated), $(gen-headers)) 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci# Add dst path prefix 4262306a36Sopenharmony_ciall-subdirs := $(addprefix $(dst)/, $(all-subdirs)) 4362306a36Sopenharmony_cisrc-headers := $(addprefix $(dst)/, $(src-headers)) 4462306a36Sopenharmony_cigen-headers := $(addprefix $(dst)/, $(gen-headers)) 4562306a36Sopenharmony_ciall-headers := $(src-headers) $(gen-headers) 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci# Work out what needs to be removed 4862306a36Sopenharmony_ciold-subdirs := $(wildcard $(all-subdirs)) 4962306a36Sopenharmony_ciold-headers := $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.h')) 5062306a36Sopenharmony_ciunwanted := $(filter-out $(all-headers), $(old-headers)) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci# Create directories 5362306a36Sopenharmony_ciexisting-dirs := $(sort $(dir $(old-headers))) 5462306a36Sopenharmony_ciwanted-dirs := $(sort $(dir $(all-headers))) 5562306a36Sopenharmony_cinew-dirs := $(filter-out $(existing-dirs), $(wanted-dirs)) 5662306a36Sopenharmony_ci$(if $(new-dirs), $(shell mkdir -p $(new-dirs))) 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci# Rules 5962306a36Sopenharmony_ciquiet_cmd_install = HDRINST $@ 6062306a36Sopenharmony_ci cmd_install = $(CONFIG_SHELL) $(srctree)/scripts/headers_install.sh $< $@ 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci$(src-headers): $(dst)/%.h: $(src)/%.h $(srctree)/scripts/headers_install.sh FORCE 6362306a36Sopenharmony_ci $(call if_changed,install) 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci$(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctree)/scripts/headers_install.sh FORCE 6662306a36Sopenharmony_ci $(call if_changed,install) 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ciquiet_cmd_remove = REMOVE $(unwanted) 6962306a36Sopenharmony_ci cmd_remove = rm -f $(unwanted) 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci__headers: $(all-headers) 7262306a36Sopenharmony_ciifneq ($(unwanted),) 7362306a36Sopenharmony_ci $(call cmd,remove) 7462306a36Sopenharmony_ciendif 7562306a36Sopenharmony_ci @: 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ciexisting-headers := $(filter $(old-headers), $(all-headers)) 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci-include $(foreach f,$(existing-headers),$(dir $(f)).$(notdir $(f)).cmd) 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ciPHONY += FORCE 8262306a36Sopenharmony_ciFORCE: 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci.PHONY: $(PHONY) 85