summaryrefslogtreecommitdiffstats
path: root/scripts/Makefile.headersinst
blob: 1fb8c003920fb4857282eb9860dbf4e16ae615d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# ==========================================================================
# Installing headers
#
# header-y files will be installed verbatim
# unifdef-y are the files where unifdef will be run before installing files
# objhdr-y are generated files that will be installed verbatim
#
# ==========================================================================

UNIFDEF := scripts/unifdef -U__KERNEL__

# Eliminate the contents of (and inclusions of) compiler.h
HDRSED  := sed 	-e "s/ inline / __inline__ /g" \
		-e "s/[[:space:]]__user[[:space:]]\{1,\}/ /g" \
		-e "s/(__user[[:space:]]\{1,\}/ (/g" \
		-e "s/[[:space:]]__force[[:space:]]\{1,\}/ /g" \
		-e "s/(__force[[:space:]]\{1,\}/ (/g" \
		-e "s/[[:space:]]__iomem[[:space:]]\{1,\}/ /g" \
		-e "s/(__iomem[[:space:]]\{1,\}/ (/g" \
		-e "s/[[:space:]]__attribute_const__[[:space:]]\{1,\}/\ /g" \
		-e "s/[[:space:]]__attribute_const__$$//" \
		-e "/^\#include <linux\/compiler.h>/d"

_dst := $(if $(dst),$(dst),$(obj))

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

include scripts/Kbuild.include

# If this is include/asm-$(ARCH) then override $(_dst) so that
# we install to include/asm directly.
# Unless $(BIASMDIR) is set, in which case we're probably doing
# a 'headers_install_all' build and we should keep the -$(ARCH)
# in the directory name.
ifeq ($(obj),include/asm-$(ARCH)$(BIASMDIR))
     _dst := include/asm
endif

header-y	:= $(sort $(header-y) $(unifdef-y))
subdir-y	:= $(patsubst %/,%,$(filter %/, $(header-y)))
header-y	:= $(filter-out %/, $(header-y))

# stamp files for header checks
check-y		:= $(patsubst %,.check.%,$(header-y) $(objhdr-y))

# Work out what needs to be removed
oldheaders	:= $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/*.h))
unwanted	:= $(filter-out $(header-y) $(objhdr-y),$(oldheaders))

oldcheckstamps	:= $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,%,$(wildcard $(INSTALL_HDR_PATH)/$(_dst)/.check.*.h))
unwanted	+= $(filter-out $(check-y),$(oldcheckstamps))

# Prefix them all with full paths to $(INSTALL_HDR_PATH)
header-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(header-y))
objhdr-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(objhdr-y))
check-y 	:= $(patsubst %,$(INSTALL_HDR_PATH)/$(_dst)/%,$(check-y))

quiet_cmd_o_hdr_install   = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
      cmd_o_hdr_install   = cp $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(objtree)/$(obj)/%,$@) \
			    $(INSTALL_HDR_PATH)/$(_dst)

quiet_cmd_unifdef	  = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
      cmd_unifdef	  = $(UNIFDEF) $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/%,$(srctree)/$(obj)/%,$@) \
				   | $(HDRSED) > $@ || :

quiet_cmd_check		  = CHECK   $(patsubst $(INSTALL_HDR_PATH)/$(_dst)/.check.%,$(_dst)/%,$@)
      cmd_check		  = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
                              $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@

quiet_cmd_remove	  = REMOVE  $(_dst)/$@
      cmd_remove	  = rm -f $(INSTALL_HDR_PATH)/$(_dst)/$@

quiet_cmd_mkdir		  = MKDIR   $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
      cmd_mkdir		  = mkdir -p $@

.PHONY: __headersinst __headerscheck

ifdef HDRCHECK
__headerscheck: $(subdir-y) $(check-y)
	@true

$(check-y) : $(INSTALL_HDR_PATH)/$(_dst)/.check.%.h : $(INSTALL_HDR_PATH)/$(_dst)/%.h 
	$(call cmd,check)

# Other dependencies for $(check-y)
include /dev/null $(wildcard $(check-y))

# ... but leave $(check-y) as .PHONY for now until those deps are actually correct.
.PHONY: $(check-y)

else
# Rules for installing headers
__headersinst: $(subdir-y) $(header-y) $(objhdr-y)
	@true

$(objhdr-y) $(subdir-y) $(header-y): | $(INSTALL_HDR_PATH)/$(_dst) $(unwanted)

$(INSTALL_HDR_PATH)/$(_dst):
	$(call cmd,mkdir)

.PHONY: $(unwanted)
$(unwanted):
	$(call cmd,remove)

$(objhdr-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(objtree)/$(obj)/%.h $(kbuild-file)
	$(call cmd,o_hdr_install)

$(header-y): $(INSTALL_HDR_PATH)/$(_dst)/%.h: $(srctree)/$(obj)/%.h $(kbuild-file)
	$(call cmd,unifdef)

endif

hdrinst := -rR -f $(srctree)/scripts/Makefile.headersinst obj

# Recursion
.PHONY: $(subdir-y)
$(subdir-y):
	$(Q)$(MAKE) $(hdrinst)=$(obj)/$@ dst=$(_dst)/$@ rel=../$(rel)
OpenPOWER on IntegriCloud