David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 1 | # ========================================================================== |
| 2 | # Installing headers |
| 3 | # |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 4 | # header-y - list files to be installed. They are preprocessed |
| 5 | # to remove __KERNEL__ section of the file |
| 6 | # unifdef-y - Same as header-y. Obsolete |
| 7 | # objhdr-y - Same as header-y but for generated files |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 8 | # |
| 9 | # ========================================================================== |
| 10 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 11 | # called may set destination dir (when installing to asm/) |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 12 | _dst := $(if $(dst),$(dst),$(obj)) |
| 13 | |
Sam Ravnborg | 283039f | 2008-06-05 19:19:47 +0200 | [diff] [blame] | 14 | kbuild-file := $(srctree)/$(obj)/Kbuild |
| 15 | include $(kbuild-file) |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 16 | |
Sam Ravnborg | c7bb349 | 2009-04-10 08:52:43 +0200 | [diff] [blame] | 17 | _dst := $(if $(destination-y),$(destination-y),$(_dst)) |
| 18 | |
Sam Ravnborg | 283039f | 2008-06-05 19:19:47 +0200 | [diff] [blame] | 19 | include scripts/Kbuild.include |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 20 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 21 | install := $(INSTALL_HDR_PATH)/$(_dst) |
Sam Ravnborg | 62284a3 | 2008-06-07 13:18:26 +0200 | [diff] [blame] | 22 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 23 | header-y := $(sort $(header-y) $(unifdef-y)) |
| 24 | subdirs := $(patsubst %/,%,$(filter %/, $(header-y))) |
| 25 | header-y := $(filter-out %/, $(header-y)) |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 26 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 27 | # files used to track state of install/check |
| 28 | install-file := $(install)/.install |
| 29 | check-file := $(install)/.check |
| 30 | |
| 31 | # all headers files for this dir |
| 32 | all-files := $(header-y) $(objhdr-y) |
| 33 | input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \ |
| 34 | $(addprefix $(objtree)/$(obj)/,$(objhdr-y)) |
| 35 | output-files := $(addprefix $(install)/, $(all-files)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 36 | |
| 37 | # Work out what needs to be removed |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 38 | oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h)) |
| 39 | unwanted := $(filter-out $(all-files),$(oldheaders)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 40 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 41 | # Prefix unwanted with full paths to $(INSTALL_HDR_PATH) |
| 42 | unwanted-file := $(addprefix $(install)/, $(unwanted)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 43 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 44 | printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 45 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 46 | quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ |
| 47 | file$(if $(word 2, $(all-files)),s)) |
Sam Ravnborg | db1bec4 | 2008-06-16 21:29:38 +0200 | [diff] [blame] | 48 | cmd_install = \ |
| 49 | $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \ |
| 50 | $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \ |
| 51 | touch $@ |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 52 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 53 | quiet_cmd_remove = REMOVE $(unwanted) |
| 54 | cmd_remove = rm -f $(unwanted-file) |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 55 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 56 | quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) |
Sergei Poselenov | 7211b8b | 2009-06-05 16:11:09 +0400 | [diff] [blame] | 57 | # Headers list can be pretty long, xargs helps to avoid |
| 58 | # the "Argument list too long" error. |
| 59 | cmd_check = for f in $(all-files); do \ |
| 60 | echo "$(install)/$${f}"; done \ |
| 61 | | xargs \ |
| 62 | $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 63 | touch $@ |
David Woodhouse | 6847535 | 2006-06-18 12:02:10 +0100 | [diff] [blame] | 64 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 65 | PHONY += __headersinst __headerscheck |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 66 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 67 | ifndef HDRCHECK |
| 68 | # Rules for installing headers |
| 69 | __headersinst: $(subdirs) $(install-file) |
| 70 | @: |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 71 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 72 | targets += $(install-file) |
| 73 | $(install-file): scripts/headers_install.pl $(input-files) FORCE |
| 74 | $(if $(unwanted),$(call cmd,remove),) |
| 75 | $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) |
| 76 | $(call if_changed,install) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 77 | |
David Woodhouse | 6847535 | 2006-06-18 12:02:10 +0100 | [diff] [blame] | 78 | else |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 79 | __headerscheck: $(subdirs) $(check-file) |
| 80 | @: |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 81 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 82 | targets += $(check-file) |
| 83 | $(check-file): scripts/headers_check.pl $(output-files) FORCE |
| 84 | $(call if_changed,check) |
Sam Ravnborg | 4e420aa | 2008-06-05 16:52:15 +0200 | [diff] [blame] | 85 | |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 86 | endif |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 87 | |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 88 | # Recursion |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 89 | hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj |
| 90 | .PHONY: $(subdirs) |
| 91 | $(subdirs): |
Sam Ravnborg | 62284a3 | 2008-06-07 13:18:26 +0200 | [diff] [blame] | 92 | $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 93 | |
| 94 | targets := $(wildcard $(sort $(targets))) |
| 95 | cmd_files := $(wildcard \ |
| 96 | $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) |
| 97 | |
| 98 | ifneq ($(cmd_files),) |
| 99 | include $(cmd_files) |
| 100 | endif |
| 101 | |
| 102 | .PHONY: $(PHONY) |
| 103 | PHONY += FORCE |
| 104 | FORCE: ; |