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 |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 6 | # objhdr-y - Same as header-y but for generated files |
H. Peter Anvin | cb97914 | 2011-11-11 15:20:34 -0800 | [diff] [blame^] | 7 | # genhdr-y - Same as objhdr-y but in a generated/ directory |
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 | |
H. Peter Anvin | cb97914 | 2011-11-11 15:20:34 -0800 | [diff] [blame^] | 14 | # generated header directory |
| 15 | gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj))) |
| 16 | |
Sam Ravnborg | 283039f | 2008-06-05 19:19:47 +0200 | [diff] [blame] | 17 | kbuild-file := $(srctree)/$(obj)/Kbuild |
| 18 | include $(kbuild-file) |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 19 | |
Sam Ravnborg | c7bb349 | 2009-04-10 08:52:43 +0200 | [diff] [blame] | 20 | _dst := $(if $(destination-y),$(destination-y),$(_dst)) |
| 21 | |
Sam Ravnborg | 283039f | 2008-06-05 19:19:47 +0200 | [diff] [blame] | 22 | include scripts/Kbuild.include |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 23 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 24 | install := $(INSTALL_HDR_PATH)/$(_dst) |
Sam Ravnborg | 62284a3 | 2008-06-07 13:18:26 +0200 | [diff] [blame] | 25 | |
Sam Ravnborg | 7cfddee | 2010-08-14 10:22:58 +0200 | [diff] [blame] | 26 | header-y := $(sort $(header-y)) |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 27 | subdirs := $(patsubst %/,%,$(filter %/, $(header-y))) |
| 28 | header-y := $(filter-out %/, $(header-y)) |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 29 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 30 | # files used to track state of install/check |
| 31 | install-file := $(install)/.install |
| 32 | check-file := $(install)/.check |
| 33 | |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 34 | # generic-y list all files an architecture uses from asm-generic |
| 35 | # Use this to build a list of headers which require a wrapper |
| 36 | wrapper-files := $(filter $(header-y), $(generic-y)) |
| 37 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 38 | # all headers files for this dir |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 39 | header-y := $(filter-out $(generic-y), $(header-y)) |
H. Peter Anvin | cb97914 | 2011-11-11 15:20:34 -0800 | [diff] [blame^] | 40 | all-files := $(header-y) $(objhdr-y) $(genhdr-y) $(wrapper-files) |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 41 | input-files := $(addprefix $(srctree)/$(obj)/,$(header-y)) \ |
H. Peter Anvin | cb97914 | 2011-11-11 15:20:34 -0800 | [diff] [blame^] | 42 | $(addprefix $(objtree)/$(obj)/,$(objhdr-y)) \ |
| 43 | $(addprefix $(objtree)/$(gen)/,$(genhdr-y)) |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 44 | output-files := $(addprefix $(install)/, $(all-files)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 45 | |
| 46 | # Work out what needs to be removed |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 47 | oldheaders := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h)) |
| 48 | unwanted := $(filter-out $(all-files),$(oldheaders)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 49 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 50 | # Prefix unwanted with full paths to $(INSTALL_HDR_PATH) |
| 51 | unwanted-file := $(addprefix $(install)/, $(unwanted)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 52 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 53 | printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 54 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 55 | quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ |
| 56 | file$(if $(word 2, $(all-files)),s)) |
Sam Ravnborg | db1bec4 | 2008-06-16 21:29:38 +0200 | [diff] [blame] | 57 | cmd_install = \ |
| 58 | $(PERL) $< $(srctree)/$(obj) $(install) $(SRCARCH) $(header-y); \ |
| 59 | $(PERL) $< $(objtree)/$(obj) $(install) $(SRCARCH) $(objhdr-y); \ |
H. Peter Anvin | cb97914 | 2011-11-11 15:20:34 -0800 | [diff] [blame^] | 60 | $(PERL) $< $(objtree)/$(gen) $(install) $(SRCARCH) $(genhdr-y); \ |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 61 | for F in $(wrapper-files); do \ |
| 62 | echo "\#include <asm-generic/$$F>" > $(install)/$$F; \ |
| 63 | done; \ |
Sam Ravnborg | db1bec4 | 2008-06-16 21:29:38 +0200 | [diff] [blame] | 64 | touch $@ |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 65 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 66 | quiet_cmd_remove = REMOVE $(unwanted) |
| 67 | cmd_remove = rm -f $(unwanted-file) |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 68 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 69 | quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) |
Sergei Poselenov | 7211b8b | 2009-06-05 16:11:09 +0400 | [diff] [blame] | 70 | # 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 Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 76 | touch $@ |
David Woodhouse | 6847535 | 2006-06-18 12:02:10 +0100 | [diff] [blame] | 77 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 78 | PHONY += __headersinst __headerscheck |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 79 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 80 | ifndef HDRCHECK |
| 81 | # Rules for installing headers |
| 82 | __headersinst: $(subdirs) $(install-file) |
| 83 | @: |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 84 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 85 | targets += $(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 Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 90 | |
David Woodhouse | 6847535 | 2006-06-18 12:02:10 +0100 | [diff] [blame] | 91 | else |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 92 | __headerscheck: $(subdirs) $(check-file) |
| 93 | @: |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 94 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 95 | targets += $(check-file) |
| 96 | $(check-file): scripts/headers_check.pl $(output-files) FORCE |
| 97 | $(call if_changed,check) |
Sam Ravnborg | 4e420aa | 2008-06-05 16:52:15 +0200 | [diff] [blame] | 98 | |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 99 | endif |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 100 | |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 101 | # Recursion |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 102 | hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj |
| 103 | .PHONY: $(subdirs) |
| 104 | $(subdirs): |
Sam Ravnborg | 62284a3 | 2008-06-07 13:18:26 +0200 | [diff] [blame] | 105 | $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 106 | |
| 107 | targets := $(wildcard $(sort $(targets))) |
| 108 | cmd_files := $(wildcard \ |
| 109 | $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) |
| 110 | |
| 111 | ifneq ($(cmd_files),) |
| 112 | include $(cmd_files) |
| 113 | endif |
| 114 | |
| 115 | .PHONY: $(PHONY) |
| 116 | PHONY += FORCE |
| 117 | FORCE: ; |