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