Makefile.headersinst 3.7 KB
Newer Older
1 2 3
# ==========================================================================
# Installing headers
#
4 5 6
# header-y  - list files to be installed. They are preprocessed
#             to remove __KERNEL__ section of the file
# objhdr-y  - Same as header-y but for generated files
7 8 9
#
# ==========================================================================

10
# called may set destination dir (when installing to asm/)
11 12
_dst := $(if $(dst),$(dst),$(obj))

13 14
kbuild-file := $(srctree)/$(obj)/Kbuild
include $(kbuild-file)
15

16 17
_dst := $(if $(destination-y),$(destination-y),$(_dst))

18
include scripts/Kbuild.include
19

20
install       := $(INSTALL_HDR_PATH)/$(_dst)
21

S
Sam Ravnborg 已提交
22
header-y      := $(sort $(header-y))
23 24
subdirs       := $(patsubst %/,%,$(filter %/, $(header-y)))
header-y      := $(filter-out %/, $(header-y))
25

26 27 28
# files used to track state of install/check
install-file  := $(install)/.install
check-file    := $(install)/.check
29

S
Sam Ravnborg 已提交
30 31 32 33
# generic-y list all files an architecture uses from asm-generic
# Use this to build a list of headers which require a wrapper
wrapper-files := $(filter $(header-y), $(generic-y))

34
# all headers files for this dir
S
Sam Ravnborg 已提交
35 36
header-y      := $(filter-out $(generic-y), $(header-y))
all-files     := $(header-y) $(objhdr-y) $(wrapper-files)
37 38 39
input-files   := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
                 $(addprefix $(objtree)/$(obj)/,$(objhdr-y))
output-files  := $(addprefix $(install)/, $(all-files))
40

41 42 43
# Work out what needs to be removed
oldheaders    := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
unwanted      := $(filter-out $(all-files),$(oldheaders))
44

45 46
# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
unwanted-file := $(addprefix $(install)/, $(unwanted))
47

48
printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
49

50 51
quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
                            file$(if $(word 2, $(all-files)),s))
52 53 54
      cmd_install = \
        $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
        $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \
S
Sam Ravnborg 已提交
55 56 57
        for F in $(wrapper-files); do                                   \
                echo "\#include <asm-generic/$$F>" > $(install)/$$F;    \
        done;                                                           \
58
        touch $@
59

60 61
quiet_cmd_remove = REMOVE  $(unwanted)
      cmd_remove = rm -f $(unwanted-file)
62

63
quiet_cmd_check = CHECK   $(printdir) ($(words $(all-files)) files)
64 65 66 67 68 69
# Headers list can be pretty long, xargs helps to avoid
# the "Argument list too long" error.
      cmd_check = for f in $(all-files); do                          \
                  echo "$(install)/$${f}"; done                      \
                  | xargs                                            \
                  $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
70
	          touch $@
71

72
PHONY += __headersinst __headerscheck
73

74 75 76 77
ifndef HDRCHECK
# Rules for installing headers
__headersinst: $(subdirs) $(install-file)
	@:
78

79 80 81 82 83
targets += $(install-file)
$(install-file): scripts/headers_install.pl $(input-files) FORCE
	$(if $(unwanted),$(call cmd,remove),)
	$(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
	$(call if_changed,install)
84

85
else
86 87
__headerscheck: $(subdirs) $(check-file)
	@:
88

89 90 91
targets += $(check-file)
$(check-file): scripts/headers_check.pl $(output-files) FORCE
	$(call if_changed,check)
92

93
endif
94

95 96 97 98 99
# Recursion
hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
.PHONY: $(subdirs)
$(subdirs):
	$(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
100

101 102 103
targets := $(wildcard $(sort $(targets)))
cmd_files := $(wildcard \
             $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
104

105 106
ifneq ($(cmd_files),)
	include $(cmd_files)
107 108
endif

109 110 111
.PHONY: $(PHONY)
PHONY += FORCE
FORCE: ;