kbuild: code refactoring in Makefile.headerinst
[deliverable/linux.git] / scripts / Makefile.headersinst
1 # ==========================================================================
2 # Installing headers
3 #
4 # header-y files will be installed verbatim
5 # unifdef-y are the files where unifdef will be run before installing files
6 # objhdr-y are generated files that will be installed verbatim
7 #
8 # ==========================================================================
9
10 UNIFDEF := scripts/unifdef -U__KERNEL__
11
12 # Eliminate the contents of (and inclusions of) compiler.h
13 HDRSED := sed -e "s/ inline / __inline__ /g" \
14 -e "s/[[:space:]]__user[[:space:]]\{1,\}/ /g" \
15 -e "s/(__user[[:space:]]\{1,\}/ (/g" \
16 -e "s/[[:space:]]__force[[:space:]]\{1,\}/ /g" \
17 -e "s/(__force[[:space:]]\{1,\}/ (/g" \
18 -e "s/[[:space:]]__iomem[[:space:]]\{1,\}/ /g" \
19 -e "s/(__iomem[[:space:]]\{1,\}/ (/g" \
20 -e "s/[[:space:]]__attribute_const__[[:space:]]\{1,\}/\ /g" \
21 -e "s/[[:space:]]__attribute_const__$$//" \
22 -e "/^\#include <linux\/compiler.h>/d"
23
24 _dst := $(if $(dst),$(dst),$(obj))
25
26 kbuild-file := $(srctree)/$(obj)/Kbuild
27 include $(kbuild-file)
28
29 include scripts/Kbuild.include
30
31 # If this is include/asm-$(ARCH) then override $(_dst) so that
32 # we install to include/asm directly.
33 # Unless $(BIASMDIR) is set, in which case we're probably doing
34 # a 'headers_install_all' build and we should keep the -$(ARCH)
35 # in the directory name.
36 ifeq ($(obj),include/asm-$(ARCH)$(BIASMDIR))
37 _dst := include/asm
38 endif
39
40 install := $(INSTALL_HDR_PATH)/$(_dst)
41
42 header-y := $(sort $(header-y) $(unifdef-y))
43 subdir-y := $(patsubst %/,%,$(filter %/, $(header-y)))
44 header-y := $(filter-out %/, $(header-y))
45
46 # stamp files for header checks
47 check-y := $(patsubst %,.check.%,$(header-y) $(objhdr-y))
48
49 # Work out what needs to be removed
50 oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
51 unwanted := $(filter-out $(header-y) $(objhdr-y),$(oldheaders))
52
53 oldcheckstamps := $(patsubst $(install)/%,%,$(wildcard $(install)/.check.*.h))
54 unwanted += $(filter-out $(check-y),$(oldcheckstamps))
55
56 # Prefix them all with full paths to $(INSTALL_HDR_PATH)
57 header-y := $(patsubst %,$(install)/%,$(header-y))
58 objhdr-y := $(patsubst %,$(install)/%,$(objhdr-y))
59 check-y := $(patsubst %,$(install)/%,$(check-y))
60
61 quiet_cmd_o_hdr_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
62 cmd_o_hdr_install = cp $(patsubst $(install)/%,$(objtree)/$(obj)/%,$@) \
63 $(install)
64
65 quiet_cmd_unifdef = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
66 cmd_unifdef = $(UNIFDEF) $(patsubst $(install)/%,$(srctree)/$(obj)/%,$@)\
67 | $(HDRSED) > $@ || :
68
69 quiet_cmd_check = CHECK $(patsubst $(install)/.check.%,$(_dst)/%,$@)
70 cmd_check = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
71 $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@
72
73 quiet_cmd_remove = REMOVE $(_dst)/$@
74 cmd_remove = rm -f $(install)/$@
75
76 quiet_cmd_mkdir = MKDIR $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
77 cmd_mkdir = mkdir -p $@
78
79 .PHONY: __headersinst __headerscheck
80
81 ifdef HDRCHECK
82 __headerscheck: $(subdir-y) $(check-y)
83 @true
84
85 $(check-y) : $(install)/.check.%.h : $(install)/%.h
86 $(call cmd,check)
87
88 # Other dependencies for $(check-y)
89 include /dev/null $(wildcard $(check-y))
90
91 # but leave $(check-y) as .PHONY for now until those
92 # deps are actually correct.
93 .PHONY: $(check-y)
94
95 else
96 # Rules for installing headers
97 __headersinst: $(subdir-y) $(header-y) $(objhdr-y)
98 @true
99
100 $(objhdr-y) $(subdir-y) $(header-y): | $(install) $(unwanted)
101
102 $(install):
103 $(call cmd,mkdir)
104
105 # Rules for removing unwanted header files
106 .PHONY: $(unwanted)
107 $(unwanted):
108 $(call cmd,remove)
109
110 # Install generated files
111 $(objhdr-y): $(install)/%.h: $(objtree)/$(obj)/%.h $(kbuild-file)
112 $(call cmd,o_hdr_install)
113
114 # Unifdef header files and install them
115 $(header-y): $(install)/%.h: $(srctree)/$(obj)/%.h $(kbuild-file)
116 $(call cmd,unifdef)
117
118 endif
119
120 hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
121
122 # Recursion
123 .PHONY: $(subdir-y)
124 $(subdir-y):
125 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
This page took 0.035213 seconds and 6 git commands to generate.