18d730cfbSDavid Woodhouse# ==========================================================================
28d730cfbSDavid Woodhouse# Installing headers
38d730cfbSDavid Woodhouse#
47712401aSSam Ravnborg# header-y  - list files to be installed. They are preprocessed
57712401aSSam Ravnborg#             to remove __KERNEL__ section of the file
67712401aSSam Ravnborg# unifdef-y - Same as header-y. Obsolete
77712401aSSam Ravnborg# objhdr-y  - Same as header-y but for generated files
88d730cfbSDavid Woodhouse#
98d730cfbSDavid Woodhouse# ==========================================================================
108d730cfbSDavid Woodhouse
117712401aSSam Ravnborg# called may set destination dir (when installing to asm/)
128d730cfbSDavid Woodhouse_dst := $(if $(dst),$(dst),$(obj))
138d730cfbSDavid Woodhouse
14283039fbSSam Ravnborgkbuild-file := $(srctree)/$(obj)/Kbuild
15283039fbSSam Ravnborginclude $(kbuild-file)
16de789125SDavid Woodhouse
17*c7bb349eSSam Ravnborg_dst := $(if $(destination-y),$(destination-y),$(_dst))
18*c7bb349eSSam Ravnborg
198d730cfbSDavid Woodhouseinclude scripts/Kbuild.include
208d730cfbSDavid Woodhouse
2162284a37SSam Ravnborginstall       := $(INSTALL_HDR_PATH)/$(_dst)
2262284a37SSam Ravnborg
234e420aa9SSam Ravnborgheader-y      := $(sort $(header-y) $(unifdef-y))
247712401aSSam Ravnborgsubdirs       := $(patsubst %/,%,$(filter %/, $(header-y)))
258d730cfbSDavid Woodhouseheader-y      := $(filter-out %/, $(header-y))
268d730cfbSDavid Woodhouse
277712401aSSam Ravnborg# files used to track state of install/check
287712401aSSam Ravnborginstall-file  := $(install)/.install
297712401aSSam Ravnborgcheck-file    := $(install)/.check
307712401aSSam Ravnborg
317712401aSSam Ravnborg# all headers files for this dir
327712401aSSam Ravnborgall-files     := $(header-y) $(objhdr-y)
337712401aSSam Ravnborginput-files   := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
347712401aSSam Ravnborg                 $(addprefix $(objtree)/$(obj)/,$(objhdr-y))
357712401aSSam Ravnborgoutput-files  := $(addprefix $(install)/, $(all-files))
36de789125SDavid Woodhouse
37de789125SDavid Woodhouse# Work out what needs to be removed
3862284a37SSam Ravnborgoldheaders    := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
397712401aSSam Ravnborgunwanted      := $(filter-out $(all-files),$(oldheaders))
40de789125SDavid Woodhouse
417712401aSSam Ravnborg# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
427712401aSSam Ravnborgunwanted-file := $(addprefix $(install)/, $(unwanted))
43de789125SDavid Woodhouse
447712401aSSam Ravnborgprintdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
45de789125SDavid Woodhouse
467712401aSSam Ravnborgquiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
477712401aSSam Ravnborg                            file$(if $(word 2, $(all-files)),s))
48db1bec4fSSam Ravnborg      cmd_install = \
49db1bec4fSSam Ravnborg        $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
50db1bec4fSSam Ravnborg        $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \
517712401aSSam Ravnborg        touch $@
528d730cfbSDavid Woodhouse
537712401aSSam Ravnborgquiet_cmd_remove = REMOVE  $(unwanted)
547712401aSSam Ravnborg      cmd_remove = rm -f $(unwanted-file)
558d730cfbSDavid Woodhouse
567712401aSSam Ravnborgquiet_cmd_check = CHECK   $(printdir) ($(words $(all-files)) files)
577712401aSSam Ravnborg      cmd_check = $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH) \
587712401aSSam Ravnborg                  $(addprefix $(install)/, $(all-files));           \
597712401aSSam Ravnborg	          touch $@
6068475359SDavid Woodhouse
617712401aSSam RavnborgPHONY += __headersinst __headerscheck
628d730cfbSDavid Woodhouse
637712401aSSam Ravnborgifndef HDRCHECK
647712401aSSam Ravnborg# Rules for installing headers
657712401aSSam Ravnborg__headersinst: $(subdirs) $(install-file)
667712401aSSam Ravnborg	@:
67de789125SDavid Woodhouse
687712401aSSam Ravnborgtargets += $(install-file)
697712401aSSam Ravnborg$(install-file): scripts/headers_install.pl $(input-files) FORCE
707712401aSSam Ravnborg	$(if $(unwanted),$(call cmd,remove),)
717712401aSSam Ravnborg	$(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
727712401aSSam Ravnborg	$(call if_changed,install)
73de789125SDavid Woodhouse
7468475359SDavid Woodhouseelse
757712401aSSam Ravnborg__headerscheck: $(subdirs) $(check-file)
767712401aSSam Ravnborg	@:
778d730cfbSDavid Woodhouse
787712401aSSam Ravnborgtargets += $(check-file)
797712401aSSam Ravnborg$(check-file): scripts/headers_check.pl $(output-files) FORCE
807712401aSSam Ravnborg	$(call if_changed,check)
814e420aa9SSam Ravnborg
828d730cfbSDavid Woodhouseendif
838d730cfbSDavid Woodhouse
848d730cfbSDavid Woodhouse# Recursion
857712401aSSam Ravnborghdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
867712401aSSam Ravnborg.PHONY: $(subdirs)
877712401aSSam Ravnborg$(subdirs):
8862284a37SSam Ravnborg	$(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
897712401aSSam Ravnborg
907712401aSSam Ravnborgtargets := $(wildcard $(sort $(targets)))
917712401aSSam Ravnborgcmd_files := $(wildcard \
927712401aSSam Ravnborg             $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
937712401aSSam Ravnborg
947712401aSSam Ravnborgifneq ($(cmd_files),)
957712401aSSam Ravnborg	include $(cmd_files)
967712401aSSam Ravnborgendif
977712401aSSam Ravnborg
987712401aSSam Ravnborg.PHONY: $(PHONY)
997712401aSSam RavnborgPHONY += FORCE
1007712401aSSam RavnborgFORCE: ;
101