xref: /linux/scripts/Makefile.headersinst (revision 7712401ae9006fc9d9b9a3e7861dc73781429a89)
1# ==========================================================================
2# Installing headers
3#
4# header-y  - list files to be installed. They are preprocessed
5#             to remove __KERNEL__ section of the file
6# unifdef-y - Same as header-y. Obsolete
7# objhdr-y  - Same as header-y but for generated files
8#
9# ==========================================================================
10
11# called may set destination dir (when installing to asm/)
12_dst := $(if $(dst),$(dst),$(obj))
13
14kbuild-file := $(srctree)/$(obj)/Kbuild
15include $(kbuild-file)
16
17include scripts/Kbuild.include
18
19install       := $(INSTALL_HDR_PATH)/$(_dst)
20
21header-y      := $(sort $(header-y) $(unifdef-y))
22subdirs       := $(patsubst %/,%,$(filter %/, $(header-y)))
23header-y      := $(filter-out %/, $(header-y))
24
25# files used to track state of install/check
26install-file  := $(install)/.install
27check-file    := $(install)/.check
28
29# all headers files for this dir
30all-files     := $(header-y) $(objhdr-y)
31input-files   := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
32                 $(addprefix $(objtree)/$(obj)/,$(objhdr-y))
33output-files  := $(addprefix $(install)/, $(all-files))
34
35# Work out what needs to be removed
36oldheaders    := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
37unwanted      := $(filter-out $(all-files),$(oldheaders))
38
39# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
40unwanted-file := $(addprefix $(install)/, $(unwanted))
41
42printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
43
44quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
45                            file$(if $(word 2, $(all-files)),s))
46      cmd_install = $(PERL) $< $(srctree)/$(obj) $(install) $(header-y); \
47                    $(PERL) $< $(objtree)/$(obj) $(install) $(objhdr-y); \
48	            touch $@
49
50quiet_cmd_remove = REMOVE  $(unwanted)
51      cmd_remove = rm -f $(unwanted-file)
52
53quiet_cmd_check = CHECK   $(printdir) ($(words $(all-files)) files)
54      cmd_check = $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH) \
55                  $(addprefix $(install)/, $(all-files));           \
56	          touch $@
57
58PHONY += __headersinst __headerscheck
59
60ifndef HDRCHECK
61# Rules for installing headers
62__headersinst: $(subdirs) $(install-file)
63	@:
64
65targets += $(install-file)
66$(install-file): scripts/headers_install.pl $(input-files) FORCE
67	$(if $(unwanted),$(call cmd,remove),)
68	$(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
69	$(call if_changed,install)
70
71else
72__headerscheck: $(subdirs) $(check-file)
73	@:
74
75targets += $(check-file)
76$(check-file): scripts/headers_check.pl $(output-files) FORCE
77	$(call if_changed,check)
78
79endif
80
81# Recursion
82hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
83.PHONY: $(subdirs)
84$(subdirs):
85	$(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
86
87targets := $(wildcard $(sort $(targets)))
88cmd_files := $(wildcard \
89             $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
90
91ifneq ($(cmd_files),)
92	include $(cmd_files)
93endif
94
95.PHONY: $(PHONY)
96PHONY += FORCE
97FORCE: ;
98