blob: d3bae5e7b6018d7429c518681a706179e00c6d81 [file] [log] [blame]
David Woodhouse8d730cf2006-06-18 11:58:39 +01001# ==========================================================================
2# Installing headers
3#
Sam Ravnborg77124012008-06-15 21:41:09 +02004# header-y - list files to be installed. They are preprocessed
5# to remove __KERNEL__ section of the file
Sam Ravnborg77124012008-06-15 21:41:09 +02006# objhdr-y - Same as header-y but for generated files
H. Peter Anvincb979142011-11-11 15:20:34 -08007# genhdr-y - Same as objhdr-y but in a generated/ directory
David Woodhouse8d730cf2006-06-18 11:58:39 +01008#
9# ==========================================================================
10
Sam Ravnborg77124012008-06-15 21:41:09 +020011# called may set destination dir (when installing to asm/)
David Woodhouse8d730cf2006-06-18 11:58:39 +010012_dst := $(if $(dst),$(dst),$(obj))
13
H. Peter Anvincb979142011-11-11 15:20:34 -080014# generated header directory
15gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
16
Sam Ravnborg283039f2008-06-05 19:19:47 +020017kbuild-file := $(srctree)/$(obj)/Kbuild
18include $(kbuild-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010019
Sam Ravnborgc7bb3492009-04-10 08:52:43 +020020_dst := $(if $(destination-y),$(destination-y),$(_dst))
21
Sam Ravnborg283039f2008-06-05 19:19:47 +020022include scripts/Kbuild.include
David Woodhousede789122006-09-24 22:15:14 +010023
Sam Ravnborg77124012008-06-15 21:41:09 +020024install := $(INSTALL_HDR_PATH)/$(_dst)
Sam Ravnborg62284a32008-06-07 13:18:26 +020025
Sam Ravnborg7cfddee2010-08-14 10:22:58 +020026header-y := $(sort $(header-y))
Sam Ravnborg77124012008-06-15 21:41:09 +020027subdirs := $(patsubst %/,%,$(filter %/, $(header-y)))
28header-y := $(filter-out %/, $(header-y))
David Woodhouse8d730cf2006-06-18 11:58:39 +010029
Sam Ravnborg77124012008-06-15 21:41:09 +020030# files used to track state of install/check
31install-file := $(install)/.install
32check-file := $(install)/.check
33
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020034# generic-y list all files an architecture uses from asm-generic
35# Use this to build a list of headers which require a wrapper
36wrapper-files := $(filter $(header-y), $(generic-y))
37
Sam Ravnborg77124012008-06-15 21:41:09 +020038# all headers files for this dir
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020039header-y := $(filter-out $(generic-y), $(header-y))
H. Peter Anvincb979142011-11-11 15:20:34 -080040all-files := $(header-y) $(objhdr-y) $(genhdr-y) $(wrapper-files)
Sam Ravnborg77124012008-06-15 21:41:09 +020041input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \
H. Peter Anvincb979142011-11-11 15:20:34 -080042 $(addprefix $(objtree)/$(obj)/,$(objhdr-y)) \
43 $(addprefix $(objtree)/$(gen)/,$(genhdr-y))
Sam Ravnborg77124012008-06-15 21:41:09 +020044output-files := $(addprefix $(install)/, $(all-files))
David Woodhousede789122006-09-24 22:15:14 +010045
46# Work out what needs to be removed
Sam Ravnborg77124012008-06-15 21:41:09 +020047oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
48unwanted := $(filter-out $(all-files),$(oldheaders))
David Woodhousede789122006-09-24 22:15:14 +010049
Sam Ravnborg77124012008-06-15 21:41:09 +020050# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
51unwanted-file := $(addprefix $(install)/, $(unwanted))
David Woodhousede789122006-09-24 22:15:14 +010052
Sam Ravnborg77124012008-06-15 21:41:09 +020053printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
David Woodhousede789122006-09-24 22:15:14 +010054
Sam Ravnborg77124012008-06-15 21:41:09 +020055quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
56 file$(if $(word 2, $(all-files)),s))
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020057 cmd_install = \
58 $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \
59 $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \
H. Peter Anvincb979142011-11-11 15:20:34 -080060 $(PERL) $< $(objtree)/$(gen) $(install) $(SRCARCH) $(genhdr-y); \
Sam Ravnborgd8ecc5c2011-04-27 22:29:49 +020061 for F in $(wrapper-files); do \
62 echo "\#include <asm-generic/$$F>" > $(install)/$$F; \
63 done; \
Sam Ravnborgdb1bec42008-06-16 21:29:38 +020064 touch $@
David Woodhouse8d730cf2006-06-18 11:58:39 +010065
Sam Ravnborg77124012008-06-15 21:41:09 +020066quiet_cmd_remove = REMOVE $(unwanted)
67 cmd_remove = rm -f $(unwanted-file)
David Woodhouse8d730cf2006-06-18 11:58:39 +010068
Sam Ravnborg77124012008-06-15 21:41:09 +020069quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files)
Sergei Poselenov7211b8b2009-06-05 16:11:09 +040070# Headers list can be pretty long, xargs helps to avoid
71# the "Argument list too long" error.
72 cmd_check = for f in $(all-files); do \
73 echo "$(install)/$${f}"; done \
74 | xargs \
75 $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
Sam Ravnborg77124012008-06-15 21:41:09 +020076 touch $@
David Woodhouse68475352006-06-18 12:02:10 +010077
Sam Ravnborg77124012008-06-15 21:41:09 +020078PHONY += __headersinst __headerscheck
David Woodhouse8d730cf2006-06-18 11:58:39 +010079
Sam Ravnborg77124012008-06-15 21:41:09 +020080ifndef HDRCHECK
81# Rules for installing headers
82__headersinst: $(subdirs) $(install-file)
83 @:
David Woodhousede789122006-09-24 22:15:14 +010084
Sam Ravnborg77124012008-06-15 21:41:09 +020085targets += $(install-file)
86$(install-file): scripts/headers_install.pl $(input-files) FORCE
87 $(if $(unwanted),$(call cmd,remove),)
88 $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
89 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +010090
David Woodhouse68475352006-06-18 12:02:10 +010091else
Sam Ravnborg77124012008-06-15 21:41:09 +020092__headerscheck: $(subdirs) $(check-file)
93 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +010094
Sam Ravnborg77124012008-06-15 21:41:09 +020095targets += $(check-file)
96$(check-file): scripts/headers_check.pl $(output-files) FORCE
97 $(call if_changed,check)
Sam Ravnborg4e420aa2008-06-05 16:52:15 +020098
David Woodhouse8d730cf2006-06-18 11:58:39 +010099endif
David Woodhouse8d730cf2006-06-18 11:58:39 +0100100
David Woodhouse8d730cf2006-06-18 11:58:39 +0100101# Recursion
Sam Ravnborg77124012008-06-15 21:41:09 +0200102hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
103.PHONY: $(subdirs)
104$(subdirs):
Sam Ravnborg62284a32008-06-07 13:18:26 +0200105 $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
Sam Ravnborg77124012008-06-15 21:41:09 +0200106
107targets := $(wildcard $(sort $(targets)))
108cmd_files := $(wildcard \
109 $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
110
111ifneq ($(cmd_files),)
112 include $(cmd_files)
113endif
114
115.PHONY: $(PHONY)
116PHONY += FORCE
117FORCE: ;