blob: 599503f0e5f2a80fd2ec28c038ced4b0b676d74a [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 Ravnborg62284a32008-06-07 13:18:26 +020031install := $(INSTALL_HDR_PATH)/$(_dst)
32
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020033header-y := $(sort $(header-y) $(unifdef-y))
David Woodhouse8d730cf2006-06-18 11:58:39 +010034subdir-y := $(patsubst %/,%,$(filter %/, $(header-y)))
35header-y := $(filter-out %/, $(header-y))
David Woodhouse8d730cf2006-06-18 11:58:39 +010036
David Woodhousede789122006-09-24 22:15:14 +010037# stamp files for header checks
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020038check-y := $(patsubst %,.check.%,$(header-y) $(objhdr-y))
David Woodhousede789122006-09-24 22:15:14 +010039
40# Work out what needs to be removed
Sam Ravnborg62284a32008-06-07 13:18:26 +020041oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
42unwanted := $(filter-out $(header-y) $(objhdr-y),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010043
Sam Ravnborg62284a32008-06-07 13:18:26 +020044oldcheckstamps := $(patsubst $(install)/%,%,$(wildcard $(install)/.check.*.h))
45unwanted += $(filter-out $(check-y),$(oldcheckstamps))
David Woodhousede789122006-09-24 22:15:14 +010046
47# Prefix them all with full paths to $(INSTALL_HDR_PATH)
Sam Ravnborg62284a32008-06-07 13:18:26 +020048header-y := $(patsubst %,$(install)/%,$(header-y))
49objhdr-y := $(patsubst %,$(install)/%,$(objhdr-y))
50check-y := $(patsubst %,$(install)/%,$(check-y))
David Woodhousede789122006-09-24 22:15:14 +010051
Sam Ravnborg62284a32008-06-07 13:18:26 +020052quiet_cmd_o_hdr_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
53 cmd_o_hdr_install = cp $(patsubst $(install)/%,$(objtree)/$(obj)/%,$@) \
54 $(install)
David Woodhouse8d730cf2006-06-18 11:58:39 +010055
Sam Ravnborg62284a32008-06-07 13:18:26 +020056quiet_cmd_unifdef = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
57 cmd_unifdef = $(UNIFDEF) $(patsubst $(install)/%,$(srctree)/$(obj)/%,$@)\
58 | $(HDRSED) > $@ || :
David Woodhouse8d730cf2006-06-18 11:58:39 +010059
Sam Ravnborg62284a32008-06-07 13:18:26 +020060quiet_cmd_check = CHECK $(patsubst $(install)/.check.%,$(_dst)/%,$@)
61 cmd_check = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
62 $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@
David Woodhouse68475352006-06-18 12:02:10 +010063
Sam Ravnborg62284a32008-06-07 13:18:26 +020064quiet_cmd_remove = REMOVE $(_dst)/$@
65 cmd_remove = rm -f $(install)/$@
David Woodhouse8d730cf2006-06-18 11:58:39 +010066
Sam Ravnborg62284a32008-06-07 13:18:26 +020067quiet_cmd_mkdir = MKDIR $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
68 cmd_mkdir = mkdir -p $@
David Woodhousede789122006-09-24 22:15:14 +010069
David Woodhousede789122006-09-24 22:15:14 +010070.PHONY: __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010071
David Woodhouse68475352006-06-18 12:02:10 +010072ifdef HDRCHECK
David Woodhousede789122006-09-24 22:15:14 +010073__headerscheck: $(subdir-y) $(check-y)
74 @true
75
Sam Ravnborg62284a32008-06-07 13:18:26 +020076$(check-y) : $(install)/.check.%.h : $(install)/%.h
David Woodhouse68475352006-06-18 12:02:10 +010077 $(call cmd,check)
David Woodhousede789122006-09-24 22:15:14 +010078
79# Other dependencies for $(check-y)
David Woodhousedf5f6312007-05-21 19:53:35 -040080include /dev/null $(wildcard $(check-y))
David Woodhousede789122006-09-24 22:15:14 +010081
Sam Ravnborg62284a32008-06-07 13:18:26 +020082# but leave $(check-y) as .PHONY for now until those
83# deps are actually correct.
David Woodhousede789122006-09-24 22:15:14 +010084.PHONY: $(check-y)
85
David Woodhouse68475352006-06-18 12:02:10 +010086else
David Woodhouse8d730cf2006-06-18 11:58:39 +010087# Rules for installing headers
Sam Ravnborg283039f2008-06-05 19:19:47 +020088__headersinst: $(subdir-y) $(header-y) $(objhdr-y)
David Woodhousede789122006-09-24 22:15:14 +010089 @true
David Woodhouse8d730cf2006-06-18 11:58:39 +010090
Sam Ravnborg62284a32008-06-07 13:18:26 +020091$(objhdr-y) $(subdir-y) $(header-y): | $(install) $(unwanted)
David Woodhouse8d730cf2006-06-18 11:58:39 +010092
Sam Ravnborg62284a32008-06-07 13:18:26 +020093$(install):
David Woodhouse8d730cf2006-06-18 11:58:39 +010094 $(call cmd,mkdir)
95
Sam Ravnborg62284a32008-06-07 13:18:26 +020096# Rules for removing unwanted header files
David Woodhousede789122006-09-24 22:15:14 +010097.PHONY: $(unwanted)
98$(unwanted):
99 $(call cmd,remove)
100
Sam Ravnborg62284a32008-06-07 13:18:26 +0200101# Install generated files
102$(objhdr-y): $(install)/%.h: $(objtree)/$(obj)/%.h $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100103 $(call cmd,o_hdr_install)
104
Sam Ravnborg62284a32008-06-07 13:18:26 +0200105# Unifdef header files and install them
106$(header-y): $(install)/%.h: $(srctree)/$(obj)/%.h $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100107 $(call cmd,unifdef)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +0200108
David Woodhouse8d730cf2006-06-18 11:58:39 +0100109endif
David Woodhouse8d730cf2006-06-18 11:58:39 +0100110
Sam Ravnborg62284a32008-06-07 13:18:26 +0200111hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
David Woodhouse8d730cf2006-06-18 11:58:39 +0100112
David Woodhouse8d730cf2006-06-18 11:58:39 +0100113# Recursion
David Woodhousede789122006-09-24 22:15:14 +0100114.PHONY: $(subdir-y)
David Woodhouse8d730cf2006-06-18 11:58:39 +0100115$(subdir-y):
Sam Ravnborg62284a32008-06-07 13:18:26 +0200116 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@