Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / scripts / Makefile.headersinst
CommitLineData
8d730cfb
DW
1# ==========================================================================
2# Installing headers
3#
fcc8487d 4# All headers under include/uapi, include/generated/uapi,
61562f98 5# arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
fcc8487d
ND
6# exported.
7# They are preprocessed to remove __KERNEL__ section of the file.
8d730cfb
DW
8#
9# ==========================================================================
10
05d8cba4
MY
11PHONY := __headers
12__headers:
13
14include scripts/Kbuild.include
15
16srcdir := $(srctree)/$(obj)
2f263d14
RG
17
18# When make is run under a fakechroot environment, the function
19# $(wildcard $(srcdir)/*/.) doesn't only return directories, but also regular
20# files. So, we are using a combination of sort/dir/wildcard which works
21# with fakechroot.
22subdirs := $(patsubst $(srcdir)/%/,%,\
23 $(filter-out $(srcdir)/,\
24 $(sort $(dir $(wildcard $(srcdir)/*/)))))
25
05d8cba4
MY
26# caller may set destination dir (when installing to asm/)
27_dst := $(if $(dst),$(dst),$(obj))
28
29# Recursion
30__headers: $(subdirs)
31
32.PHONY: $(subdirs)
33$(subdirs):
34 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
35
36# Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi.
37# We have only sub-directories there.
38skip-inst := $(if $(filter %/uapi,$(obj)),1)
39
40ifeq ($(skip-inst),)
41
cb97914b
PA
42# generated header directory
43gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
44
fcc8487d 45# Kbuild file is optional
283039fb 46kbuild-file := $(srctree)/$(obj)/Kbuild
fcc8487d 47-include $(kbuild-file)
8d730cfb 48
10b63956
DH
49old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
50ifneq ($(wildcard $(old-kbuild-file)),)
51include $(old-kbuild-file)
52endif
c7bb349e 53
10b63956 54installdir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
8d730cfb 55
fcc8487d 56gendir := $(objtree)/$(gen)
fcc8487d
ND
57header-files := $(notdir $(wildcard $(srcdir)/*.h))
58header-files += $(notdir $(wildcard $(srcdir)/*.agh))
59header-files := $(filter-out $(no-export-headers), $(header-files))
60genhdr-files := $(notdir $(wildcard $(gendir)/*.h))
61genhdr-files := $(filter-out $(header-files), $(genhdr-files))
de789125 62
7712401a 63# files used to track state of install/check
10b63956
DH
64install-file := $(installdir)/.install
65check-file := $(installdir)/.check
de789125 66
d8ecc5cd
SR
67# generic-y list all files an architecture uses from asm-generic
68# Use this to build a list of headers which require a wrapper
fcc8487d
ND
69generic-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h))
70wrapper-files := $(filter $(generic-files), $(generic-y))
71wrapper-files := $(filter-out $(header-files), $(wrapper-files))
10b63956 72
7712401a 73# all headers files for this dir
fcc8487d 74all-files := $(header-files) $(genhdr-files) $(wrapper-files)
10b63956
DH
75output-files := $(addprefix $(installdir)/, $(all-files))
76
fcc8487d
ND
77ifneq ($(mandatory-y),)
78missing := $(filter-out $(all-files),$(mandatory-y))
79ifneq ($(missing),)
80$(error Some mandatory headers ($(missing)) are missing in $(obj))
81endif
82endif
de789125 83
7712401a 84# Work out what needs to be removed
10b63956 85oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
7712401a 86unwanted := $(filter-out $(all-files),$(oldheaders))
8d730cfb 87
7712401a 88# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
10b63956 89unwanted-file := $(addprefix $(installdir)/, $(unwanted))
de789125 90
7712401a 91printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
68475359 92
7712401a
SR
93quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
94 file$(if $(word 2, $(all-files)),s))
db1bec4f 95 cmd_install = \
fcc8487d
ND
96 $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
97 $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \
d8ecc5cd 98 for F in $(wrapper-files); do \
10b63956 99 echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \
d8ecc5cd 100 done; \
db1bec4f 101 touch $@
8d730cfb 102
7712401a
SR
103quiet_cmd_remove = REMOVE $(unwanted)
104 cmd_remove = rm -f $(unwanted-file)
8d730cfb 105
7712401a 106quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
7211b8b9
SP
107# Headers list can be pretty long, xargs helps to avoid
108# the "Argument list too long" error.
109 cmd_check = for f in $(all-files); do \
10b63956 110 echo "$(installdir)/$${f}"; done \
7211b8b9
SP
111 | xargs \
112 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
7712401a 113 touch $@
de789125 114
7712401a
SR
115ifndef HDRCHECK
116# Rules for installing headers
05d8cba4 117__headers: $(install-file)
7712401a 118 @:
de789125 119
7712401a 120targets += $(install-file)
7c025b2a 121$(install-file): scripts/headers_install.sh \
fcc8487d
ND
122 $(addprefix $(srcdir)/,$(header-files)) \
123 $(addprefix $(gendir)/,$(genhdr-files)) FORCE
7712401a
SR
124 $(if $(unwanted),$(call cmd,remove),)
125 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
126 $(call if_changed,install)
de789125 127
68475359 128else
05d8cba4 129__headers: $(check-file)
7712401a 130 @:
8d730cfb 131
7712401a
SR
132targets += $(check-file)
133$(check-file): scripts/headers_check.pl $(output-files) FORCE
134 $(call if_changed,check)
8d730cfb 135
7712401a 136endif
de789125 137
7712401a
SR
138targets := $(wildcard $(sort $(targets)))
139cmd_files := $(wildcard \
140 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
4e420aa9 141
7712401a
SR
142ifneq ($(cmd_files),)
143 include $(cmd_files)
8d730cfb
DW
144endif
145
05d8cba4
MY
146endif # skip-inst
147
7712401a
SR
148.PHONY: $(PHONY)
149PHONY += FORCE
150FORCE: ;