-# Make the definitions visible for recursive make invocations
-export ALTARCH
-export ARCHDEF
-export ALTARCHDEF
-
-quiet_cmd_o_hdr_install = INSTALL $(_dst)/$@
- cmd_o_hdr_install = cp $(objtree)/$(obj)/$@ $(INSTALL_HDR_PATH)/$(_dst)
-
-quiet_cmd_headers_install = INSTALL $(_dst)/$@
- cmd_headers_install = $(HDRSED) $(srctree)/$(obj)/$@ \
- > $(INSTALL_HDR_PATH)/$(_dst)/$@
-
-quiet_cmd_unifdef = UNIFDEF $(_dst)/$@
- cmd_unifdef = $(UNIFDEF) $(srctree)/$(obj)/$@ | $(HDRSED) \
- > $(INSTALL_HDR_PATH)/$(_dst)/$@ || :
-
-quiet_cmd_check = CHECK $(_dst)/$@
- cmd_check = $(srctree)/scripts/hdrcheck.sh \
- $(INSTALL_HDR_PATH)/include \
- $(INSTALL_HDR_PATH)/$(_dst)/$@
-
-quiet_cmd_mkdir = MKDIR $@
- cmd_mkdir = mkdir -p $(INSTALL_HDR_PATH)/$@
-
-quiet_cmd_gen = GEN $(_dst)/$@
- cmd_gen = \
-STUBDEF=__ASM_STUB_`echo $@ | tr a-z. A-Z_`; \
-(echo "/* File autogenerated by 'make headers_install' */" ; \
-echo "\#ifndef $$STUBDEF" ; \
-echo "\#define $$STUBDEF" ; \
-echo "\# if $(ARCHDEF)" ; \
-if [ -r $(INSTALL_HDR_PATH)/include/$(archasm)/$@ ]; then \
- echo "\# include <$(archasm)/$@>" ; \
-else \
- echo "\# error $(archasm)/$@ does not exist in" \
- "the $(ARCH) architecture" ; \
-fi ; \
-echo "\# elif $(ALTARCHDEF)" ; \
-if [ -r $(INSTALL_HDR_PATH)/include/$(altarchasm)/$@ ]; then \
- echo "\# include <$(altarchasm)/$@>" ; \
-else \
- echo "\# error $(altarchasm)/$@ does not exist in" \
- "the $(ALTARCH) architecture" ; \
-fi ; \
-echo "\# else" ; \
-echo "\# warning This machine appears to be" \
- "neither $(ARCH) nor $(ALTARCH)." ; \
-echo "\# endif" ; \
-echo "\#endif /* $$STUBDEF */" ; \
-) > $(INSTALL_HDR_PATH)/$(_dst)/$@
-
-__headersinst: $(subdir-y) $(header-y) $(unifdef-y) $(altarch-y) $(objhdr-y)
-
-.PHONY: $(header-y) $(unifdef-y) $(subdir-y)
-
-ifdef HDRCHECK
-# Rules for checking headers
-$(objhdr-y) $(header-y) $(unifdef-y):
- $(call cmd,check)
-else
-# Rules for installing headers
+# all headers files for this dir
+all-files := $(header-y) $(objhdr-y)
+input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
+ $(addprefix $(objtree)/$(obj)/,$(objhdr-y))
+output-files := $(addprefix $(install)/, $(all-files))
+
+# Work out what needs to be removed
+oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
+unwanted := $(filter-out $(all-files),$(oldheaders))