xref: /linux/scripts/Makefile.headersinst (revision 283039fb7ded6b863eacc9cfd67232297622e52d)
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
10UNIFDEF := scripts/unifdef -U__KERNEL__
11
12# Eliminate the contents of (and inclusions of) compiler.h
13HDRSED  := 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
26kbuild-file := $(srctree)/$(obj)/Kbuild
27include $(kbuild-file)
28
29include 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.
36ifeq ($(obj),include/asm-$(ARCH)$(BIASMDIR))
37     _dst := include/asm
38endif
39
40header-y	:= $(sort $(header-y) $(unifdef-y))
41subdir-y	:= $(patsubst %/,%,$(filter %/, $(header-y)))
42header-y	:= $(filter-out %/, $(header-y))
43
44# stamp files for header checks
45check-y		:= $(patsubst %,.check.%,$(header-y) $(objhdr-y))
46
47# Work out what needs to be removed
48oldheaders	:= $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/*.h))
49unwanted	:= $(filter-out $(header-y) $(objhdr-y),$(oldheaders))
50
51oldcheckstamps	:= $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/.check.*.h))
52unwanted	+= $(filter-out $(check-y),$(oldcheckstamps))
53
54# Prefix them all with full paths to $(INSTALL_HDR_PATH)
55header-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(header-y))
56objhdr-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(objhdr-y))
57check-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(check-y))
58
59quiet_cmd_o_hdr_install   = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
60      cmd_o_hdr_install   = cp $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(objtree)/$(obj)/%,$@) \
61			    $(INSTALL_HDR_PATH)/$(_dst)
62
63quiet_cmd_unifdef	  = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
64      cmd_unifdef	  = $(UNIFDEF) $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(srctree)/$(obj)/%,$@) \
65				   | $(HDRSED) > $@ || :
66
67quiet_cmd_check		  = CHECK   $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/.check.%,$(_dst)/%,$@)
68      cmd_check		  = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
69                              $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@
70
71quiet_cmd_remove	  = REMOVE  $(_dst)/$@
72      cmd_remove	  = rm -f $(INSTALL_HDR_PATH)/$(_dst)/$@
73
74quiet_cmd_mkdir		  = MKDIR   $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
75      cmd_mkdir		  = mkdir -p $@
76
77.PHONY: __headersinst __headerscheck
78
79ifdef HDRCHECK
80__headerscheck: $(subdir-y) $(check-y)
81	@true
82
83$(check-y) : $(INSTALL_HDR_PATH)/$(_dst)/.check.%.h : $(INSTALL_HDR_PATH)/$(_dst)/%.h
84	$(call cmd,check)
85
86# Other dependencies for $(check-y)
87include /dev/null $(wildcard $(check-y))
88
89# ... but leave $(check-y) as .PHONY for now until those deps are actually correct.
90.PHONY: $(check-y)
91
92else
93# Rules for installing headers
94__headersinst: $(subdir-y) $(header-y) $(objhdr-y)
95	@true
96
97$(objhdr-y) $(subdir-y) $(header-y): | $(INSTALL_HDR_PATH)/$(_dst) $(unwanted)
98
99$(INSTALL_HDR_PATH)/$(_dst):
100	$(call cmd,mkdir)
101
102.PHONY: $(unwanted)
103$(unwanted):
104	$(call cmd,remove)
105
106$(objhdr-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(objtree)/$(obj)/%.h $(kbuild-file)
107	$(call cmd,o_hdr_install)
108
109$(header-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(kbuild-file)
110	$(call cmd,unifdef)
111
112endif
113
114hdrinst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
115
116# Recursion
117.PHONY: $(subdir-y)
118$(subdir-y):
119	$(Q)$(MAKE) $(hdrinst)=$(obj)/$@ dst=$(_dst)/$@ rel=../$(rel)
120