blob: 599adc63b84cc9cba9a65e717a116f28984b3700 [file] [log] [blame]
David Woodhouse8d730cf2006-06-18 11:58:39 +01001# ==========================================================================
2# Installing headers
3#
4# header-y files will be installed verbatim
5# unifdef-y are the files where unifdef will be run before installing files
6# objhdr-y are generated files that will be installed verbatim
7#
8# ==========================================================================
9
Sam Ravnborg07aea3a2006-07-23 20:47:50 +020010UNIFDEF := scripts/unifdef -U__KERNEL__
David Woodhouse8d730cf2006-06-18 11:58:39 +010011
12# Eliminate the contents of (and inclusions of) compiler.h
Sam Ravnborg62284a32008-06-07 13:18:26 +020013HDRSED := sed -e "s/ inline / __inline__ /g" \
Mike Frysingerc0519032007-07-09 11:43:55 -070014 -e "s/[[:space:]]__user[[:space:]]\{1,\}/ /g" \
15 -e "s/(__user[[:space:]]\{1,\}/ (/g" \
16 -e "s/[[:space:]]__force[[:space:]]\{1,\}/ /g" \
17 -e "s/(__force[[:space:]]\{1,\}/ (/g" \
18 -e "s/[[:space:]]__iomem[[:space:]]\{1,\}/ /g" \
19 -e "s/(__iomem[[:space:]]\{1,\}/ (/g" \
20 -e "s/[[:space:]]__attribute_const__[[:space:]]\{1,\}/\ /g" \
David Woodhouse8d730cf2006-06-18 11:58:39 +010021 -e "s/[[:space:]]__attribute_const__$$//" \
22 -e "/^\#include <linux\/compiler.h>/d"
23
24_dst := $(if $(dst),$(dst),$(obj))
25
Sam Ravnborg283039f2008-06-05 19:19:47 +020026kbuild-file := $(srctree)/$(obj)/Kbuild
27include $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010028
Sam Ravnborg283039f2008-06-05 19:19:47 +020029include scripts/Kbuild.include
David Woodhousede789122006-09-24 22:15:14 +010030
Sam Ravnborg283039f2008-06-05 19:19:47 +020031# If this is include/asm-$(ARCH) then override $(_dst) so that
32# we install to include/asm directly.
David Woodhousede789122006-09-24 22:15:14 +010033# Unless $(BIASMDIR) is set, in which case we're probably doing
34# a 'headers_install_all' build and we should keep the -$(ARCH)
35# in the directory name.
Sam Ravnborg283039f2008-06-05 19:19:47 +020036ifeq ($(obj),include/asm-$(ARCH)$(BIASMDIR))
David Woodhouse8d730cf2006-06-18 11:58:39 +010037 _dst := include/asm
38endif
39
Sam Ravnborg62284a32008-06-07 13:18:26 +020040install := $(INSTALL_HDR_PATH)/$(_dst)
41
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020042header-y := $(sort $(header-y) $(unifdef-y))
David Woodhouse8d730cf2006-06-18 11:58:39 +010043subdir-y := $(patsubst %/,%,$(filter %/, $(header-y)))
44header-y := $(filter-out %/, $(header-y))
David Woodhouse8d730cf2006-06-18 11:58:39 +010045
David Woodhousede789122006-09-24 22:15:14 +010046# stamp files for header checks
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020047check-y := $(patsubst %,.check.%,$(header-y) $(objhdr-y))
David Woodhousede789122006-09-24 22:15:14 +010048
49# Work out what needs to be removed
Sam Ravnborg62284a32008-06-07 13:18:26 +020050oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
51unwanted := $(filter-out $(header-y) $(objhdr-y),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010052
Sam Ravnborg62284a32008-06-07 13:18:26 +020053oldcheckstamps := $(patsubst $(install)/%,%,$(wildcard $(install)/.check.*.h))
54unwanted += $(filter-out $(check-y),$(oldcheckstamps))
David Woodhousede789122006-09-24 22:15:14 +010055
56# Prefix them all with full paths to $(INSTALL_HDR_PATH)
Sam Ravnborg62284a32008-06-07 13:18:26 +020057header-y := $(patsubst %,$(install)/%,$(header-y))
58objhdr-y := $(patsubst %,$(install)/%,$(objhdr-y))
59check-y := $(patsubst %,$(install)/%,$(check-y))
David Woodhousede789122006-09-24 22:15:14 +010060
Sam Ravnborg62284a32008-06-07 13:18:26 +020061quiet_cmd_o_hdr_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
62 cmd_o_hdr_install = cp $(patsubst $(install)/%,$(objtree)/$(obj)/%,$@) \
63 $(install)
David Woodhouse8d730cf2006-06-18 11:58:39 +010064
Sam Ravnborg62284a32008-06-07 13:18:26 +020065quiet_cmd_unifdef = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
66 cmd_unifdef = $(UNIFDEF) $(patsubst $(install)/%,$(srctree)/$(obj)/%,$@)\
67 | $(HDRSED) > $@ || :
David Woodhouse8d730cf2006-06-18 11:58:39 +010068
Sam Ravnborg62284a32008-06-07 13:18:26 +020069quiet_cmd_check = CHECK $(patsubst $(install)/.check.%,$(_dst)/%,$@)
70 cmd_check = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
71 $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@
David Woodhouse68475352006-06-18 12:02:10 +010072
Sam Ravnborg62284a32008-06-07 13:18:26 +020073quiet_cmd_remove = REMOVE $(_dst)/$@
74 cmd_remove = rm -f $(install)/$@
David Woodhouse8d730cf2006-06-18 11:58:39 +010075
Sam Ravnborg62284a32008-06-07 13:18:26 +020076quiet_cmd_mkdir = MKDIR $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
77 cmd_mkdir = mkdir -p $@
David Woodhousede789122006-09-24 22:15:14 +010078
David Woodhousede789122006-09-24 22:15:14 +010079.PHONY: __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010080
David Woodhouse68475352006-06-18 12:02:10 +010081ifdef HDRCHECK
David Woodhousede789122006-09-24 22:15:14 +010082__headerscheck: $(subdir-y) $(check-y)
83 @true
84
Sam Ravnborg62284a32008-06-07 13:18:26 +020085$(check-y) : $(install)/.check.%.h : $(install)/%.h
David Woodhouse68475352006-06-18 12:02:10 +010086 $(call cmd,check)
David Woodhousede789122006-09-24 22:15:14 +010087
88# Other dependencies for $(check-y)
David Woodhousedf5f6312007-05-21 19:53:35 -040089include /dev/null $(wildcard $(check-y))
David Woodhousede789122006-09-24 22:15:14 +010090
Sam Ravnborg62284a32008-06-07 13:18:26 +020091# but leave $(check-y) as .PHONY for now until those
92# deps are actually correct.
David Woodhousede789122006-09-24 22:15:14 +010093.PHONY: $(check-y)
94
David Woodhouse68475352006-06-18 12:02:10 +010095else
David Woodhouse8d730cf2006-06-18 11:58:39 +010096# Rules for installing headers
Sam Ravnborg283039f2008-06-05 19:19:47 +020097__headersinst: $(subdir-y) $(header-y) $(objhdr-y)
David Woodhousede789122006-09-24 22:15:14 +010098 @true
David Woodhouse8d730cf2006-06-18 11:58:39 +010099
Sam Ravnborg62284a32008-06-07 13:18:26 +0200100$(objhdr-y) $(subdir-y) $(header-y): | $(install) $(unwanted)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100101
Sam Ravnborg62284a32008-06-07 13:18:26 +0200102$(install):
David Woodhouse8d730cf2006-06-18 11:58:39 +0100103 $(call cmd,mkdir)
104
Sam Ravnborg62284a32008-06-07 13:18:26 +0200105# Rules for removing unwanted header files
David Woodhousede789122006-09-24 22:15:14 +0100106.PHONY: $(unwanted)
107$(unwanted):
108 $(call cmd,remove)
109
Sam Ravnborg62284a32008-06-07 13:18:26 +0200110# Install generated files
111$(objhdr-y): $(install)/%.h: $(objtree)/$(obj)/%.h $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100112 $(call cmd,o_hdr_install)
113
Sam Ravnborg62284a32008-06-07 13:18:26 +0200114# Unifdef header files and install them
115$(header-y): $(install)/%.h: $(srctree)/$(obj)/%.h $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100116 $(call cmd,unifdef)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200117
David Woodhouse8d730cf2006-06-18 11:58:39 +0100118endif
David Woodhouse8d730cf2006-06-18 11:58:39 +0100119
Sam Ravnborg62284a32008-06-07 13:18:26 +0200120hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
David Woodhouse8d730cf2006-06-18 11:58:39 +0100121
David Woodhouse8d730cf2006-06-18 11:58:39 +0100122# Recursion
David Woodhousede789122006-09-24 22:15:14 +0100123.PHONY: $(subdir-y)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100124$(subdir-y):
Sam Ravnborg62284a32008-06-07 13:18:26 +0200125 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@