UAPI: x86: Differentiate the generated UAPI and internal headers
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / scripts / Makefile.headersinst
CommitLineData
8d730cfb
DW
1# ==========================================================================
2# Installing headers
3#
7712401a
SR
4# header-y - list files to be installed. They are preprocessed
5# to remove __KERNEL__ section of the file
40f1d4c2 6# genhdr-y - Same as header-y but in a generated/ directory
8d730cfb
DW
7#
8# ==========================================================================
9
7712401a 10# called may set destination dir (when installing to asm/)
8d730cfb
DW
11_dst := $(if $(dst),$(dst),$(obj))
12
cb97914b
PA
13# generated header directory
14gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
15
283039fb
SR
16kbuild-file := $(srctree)/$(obj)/Kbuild
17include $(kbuild-file)
8d730cfb 18
c7bb349e
SR
19_dst := $(if $(destination-y),$(destination-y),$(_dst))
20
283039fb 21include scripts/Kbuild.include
de789125 22
7712401a 23install := $(INSTALL_HDR_PATH)/$(_dst)
8d730cfb 24
7cfddeef 25header-y := $(sort $(header-y))
7712401a
SR
26subdirs := $(patsubst %/,%,$(filter %/, $(header-y)))
27header-y := $(filter-out %/, $(header-y))
de789125 28
7712401a
SR
29# files used to track state of install/check
30install-file := $(install)/.install
31check-file := $(install)/.check
de789125 32
d8ecc5cd
SR
33# generic-y list all files an architecture uses from asm-generic
34# Use this to build a list of headers which require a wrapper
35wrapper-files := $(filter $(header-y), $(generic-y))
36
7712401a 37# all headers files for this dir
d8ecc5cd 38header-y := $(filter-out $(generic-y), $(header-y))
40f1d4c2 39all-files := $(header-y) $(genhdr-y) $(wrapper-files)
7712401a 40input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
cb97914b 41 $(addprefix $(objtree)/$(gen)/,$(genhdr-y))
7712401a 42output-files := $(addprefix $(install)/, $(all-files))
de789125 43
7712401a
SR
44# Work out what needs to be removed
45oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
46unwanted := $(filter-out $(all-files),$(oldheaders))
8d730cfb 47
7712401a
SR
48# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
49unwanted-file := $(addprefix $(install)/, $(unwanted))
de789125 50
7712401a 51printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
68475359 52
7712401a
SR
53quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
54 file$(if $(word 2, $(all-files)),s))
db1bec4f
SR
55 cmd_install = \
56 $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
cb97914b 57 $(PERL) $< $(objtree)/$(gen) $(install) $(SRCARCH) $(genhdr-y); \
d8ecc5cd
SR
58 for F in $(wrapper-files); do \
59 echo "\#include <asm-generic/$$F>" > $(install)/$$F; \
60 done; \
db1bec4f 61 touch $@
8d730cfb 62
7712401a
SR
63quiet_cmd_remove = REMOVE $(unwanted)
64 cmd_remove = rm -f $(unwanted-file)
8d730cfb 65
7712401a 66quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
7211b8b9
SP
67# Headers list can be pretty long, xargs helps to avoid
68# the "Argument list too long" error.
69 cmd_check = for f in $(all-files); do \
70 echo "$(install)/$${f}"; done \
71 | xargs \
72 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
7712401a 73 touch $@
de789125 74
7712401a 75PHONY += __headersinst __headerscheck
de789125 76
7712401a
SR
77ifndef HDRCHECK
78# Rules for installing headers
79__headersinst: $(subdirs) $(install-file)
80 @:
de789125 81
7712401a
SR
82targets += $(install-file)
83$(install-file): scripts/headers_install.pl $(input-files) FORCE
84 $(if $(unwanted),$(call cmd,remove),)
85 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
86 $(call if_changed,install)
de789125 87
68475359 88else
7712401a
SR
89__headerscheck: $(subdirs) $(check-file)
90 @:
8d730cfb 91
7712401a
SR
92targets += $(check-file)
93$(check-file): scripts/headers_check.pl $(output-files) FORCE
94 $(call if_changed,check)
8d730cfb 95
7712401a 96endif
de789125 97
7712401a
SR
98# Recursion
99hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
100.PHONY: $(subdirs)
101$(subdirs):
102 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
8d730cfb 103
7712401a
SR
104targets := $(wildcard $(sort $(targets)))
105cmd_files := $(wildcard \
106 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
4e420aa9 107
7712401a
SR
108ifneq ($(cmd_files),)
109 include $(cmd_files)
8d730cfb
DW
110endif
111
7712401a
SR
112.PHONY: $(PHONY)
113PHONY += FORCE
114FORCE: ;