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 |
David Howells | 40f1d4c | 2012-10-02 18:01:56 +0100 | [diff] [blame] | 6 | # genhdr-y - Same as header-y but in a generated/ directory |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 7 | # |
| 8 | # ========================================================================== |
| 9 | |
H. Peter Anvin | cb97914 | 2011-11-11 15:20:34 -0800 | [diff] [blame] | 10 | # generated header directory |
| 11 | gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj))) |
| 12 | |
Sam Ravnborg | 283039f | 2008-06-05 19:19:47 +0200 | [diff] [blame] | 13 | kbuild-file := $(srctree)/$(obj)/Kbuild |
| 14 | include $(kbuild-file) |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 15 | |
Jesper Nilsson | 9b58b92 | 2013-02-02 11:18:35 +0100 | [diff] [blame] | 16 | # called may set destination dir (when installing to asm/) |
Sam Ravnborg | c4619bc | 2013-03-04 21:36:24 +0100 | [diff] [blame] | 17 | _dst := $(if $(destination-y),$(destination-y),$(if $(dst),$(dst),$(obj))) |
Jesper Nilsson | 9b58b92 | 2013-02-02 11:18:35 +0100 | [diff] [blame] | 18 | |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 19 | old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild |
| 20 | ifneq ($(wildcard $(old-kbuild-file)),) |
| 21 | include $(old-kbuild-file) |
| 22 | endif |
Sam Ravnborg | c7bb349 | 2009-04-10 08:52:43 +0200 | [diff] [blame] | 23 | |
Sam Ravnborg | 283039f | 2008-06-05 19:19:47 +0200 | [diff] [blame] | 24 | include scripts/Kbuild.include |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 25 | |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 26 | installdir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst)) |
Sam Ravnborg | 62284a3 | 2008-06-07 13:18:26 +0200 | [diff] [blame] | 27 | |
Sam Ravnborg | 7cfddee | 2010-08-14 10:22:58 +0200 | [diff] [blame] | 28 | header-y := $(sort $(header-y)) |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 29 | subdirs := $(patsubst %/,%,$(filter %/, $(header-y))) |
| 30 | header-y := $(filter-out %/, $(header-y)) |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 31 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 32 | # files used to track state of install/check |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 33 | install-file := $(installdir)/.install |
| 34 | check-file := $(installdir)/.check |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 35 | |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 36 | # generic-y list all files an architecture uses from asm-generic |
| 37 | # Use this to build a list of headers which require a wrapper |
| 38 | wrapper-files := $(filter $(header-y), $(generic-y)) |
| 39 | |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 40 | srcdir := $(srctree)/$(obj) |
| 41 | gendir := $(objtree)/$(gen) |
| 42 | |
| 43 | oldsrcdir := $(srctree)/$(subst /uapi,,$(obj)) |
| 44 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 45 | # all headers files for this dir |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 46 | header-y := $(filter-out $(generic-y), $(header-y)) |
David Howells | 40f1d4c | 2012-10-02 18:01:56 +0100 | [diff] [blame] | 47 | all-files := $(header-y) $(genhdr-y) $(wrapper-files) |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 48 | output-files := $(addprefix $(installdir)/, $(all-files)) |
| 49 | |
Nicolas Dichtel | c0ff68f | 2013-04-29 14:15:51 +0200 | [diff] [blame] | 50 | input-files1 := $(foreach hdr, $(header-y), \ |
Sam Ravnborg | c4619bc | 2013-03-04 21:36:24 +0100 | [diff] [blame] | 51 | $(if $(wildcard $(srcdir)/$(hdr)), \ |
Nicolas Dichtel | c0ff68f | 2013-04-29 14:15:51 +0200 | [diff] [blame] | 52 | $(wildcard $(srcdir)/$(hdr))) \ |
| 53 | ) |
| 54 | input-files1-name := $(notdir $(input-files1)) |
| 55 | input-files2 := $(foreach hdr, $(header-y), \ |
| 56 | $(if $(wildcard $(srcdir)/$(hdr)),, \ |
Sam Ravnborg | c4619bc | 2013-03-04 21:36:24 +0100 | [diff] [blame] | 57 | $(if $(wildcard $(oldsrcdir)/$(hdr)), \ |
| 58 | $(wildcard $(oldsrcdir)/$(hdr)), \ |
| 59 | $(error Missing UAPI file $(srcdir)/$(hdr))) \ |
Nicolas Dichtel | c0ff68f | 2013-04-29 14:15:51 +0200 | [diff] [blame] | 60 | )) |
| 61 | input-files2-name := $(notdir $(input-files2)) |
| 62 | input-files3 := $(foreach hdr, $(genhdr-y), \ |
Sam Ravnborg | c4619bc | 2013-03-04 21:36:24 +0100 | [diff] [blame] | 63 | $(if $(wildcard $(gendir)/$(hdr)), \ |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 64 | $(wildcard $(gendir)/$(hdr)), \ |
| 65 | $(error Missing generated UAPI file $(gendir)/$(hdr)) \ |
| 66 | )) |
Nicolas Dichtel | c0ff68f | 2013-04-29 14:15:51 +0200 | [diff] [blame] | 67 | input-files3-name := $(notdir $(input-files3)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 68 | |
| 69 | # Work out what needs to be removed |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 70 | oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 71 | unwanted := $(filter-out $(all-files),$(oldheaders)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 72 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 73 | # Prefix unwanted with full paths to $(INSTALL_HDR_PATH) |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 74 | unwanted-file := $(addprefix $(installdir)/, $(unwanted)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 75 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 76 | printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 77 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 78 | quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ |
| 79 | file$(if $(word 2, $(all-files)),s)) |
Sam Ravnborg | db1bec4 | 2008-06-16 21:29:38 +0200 | [diff] [blame] | 80 | cmd_install = \ |
Nicolas Dichtel | c0ff68f | 2013-04-29 14:15:51 +0200 | [diff] [blame] | 81 | $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(input-files1-name); \ |
| 82 | $(CONFIG_SHELL) $< $(installdir) $(oldsrcdir) $(input-files2-name); \ |
| 83 | $(CONFIG_SHELL) $< $(installdir) $(gendir) $(input-files3-name); \ |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 84 | for F in $(wrapper-files); do \ |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 85 | echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 86 | done; \ |
Sam Ravnborg | db1bec4 | 2008-06-16 21:29:38 +0200 | [diff] [blame] | 87 | touch $@ |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 88 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 89 | quiet_cmd_remove = REMOVE $(unwanted) |
| 90 | cmd_remove = rm -f $(unwanted-file) |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 91 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 92 | quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) |
Sergei Poselenov | 7211b8b | 2009-06-05 16:11:09 +0400 | [diff] [blame] | 93 | # Headers list can be pretty long, xargs helps to avoid |
| 94 | # the "Argument list too long" error. |
| 95 | cmd_check = for f in $(all-files); do \ |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 96 | echo "$(installdir)/$${f}"; done \ |
Sergei Poselenov | 7211b8b | 2009-06-05 16:11:09 +0400 | [diff] [blame] | 97 | | xargs \ |
| 98 | $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 99 | touch $@ |
David Woodhouse | 6847535 | 2006-06-18 12:02:10 +0100 | [diff] [blame] | 100 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 101 | PHONY += __headersinst __headerscheck |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 102 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 103 | ifndef HDRCHECK |
| 104 | # Rules for installing headers |
| 105 | __headersinst: $(subdirs) $(install-file) |
| 106 | @: |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 107 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 108 | targets += $(install-file) |
Nicolas Dichtel | c0ff68f | 2013-04-29 14:15:51 +0200 | [diff] [blame] | 109 | $(install-file): scripts/headers_install.sh $(input-files1) $(input-files2) $(input-files3) FORCE |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 110 | $(if $(unwanted),$(call cmd,remove),) |
| 111 | $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) |
| 112 | $(call if_changed,install) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 113 | |
David Woodhouse | 6847535 | 2006-06-18 12:02:10 +0100 | [diff] [blame] | 114 | else |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 115 | __headerscheck: $(subdirs) $(check-file) |
| 116 | @: |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 117 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 118 | targets += $(check-file) |
| 119 | $(check-file): scripts/headers_check.pl $(output-files) FORCE |
| 120 | $(call if_changed,check) |
Sam Ravnborg | 4e420aa | 2008-06-05 16:52:15 +0200 | [diff] [blame] | 121 | |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 122 | endif |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 123 | |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 124 | # Recursion |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 125 | hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj |
| 126 | .PHONY: $(subdirs) |
| 127 | $(subdirs): |
Sam Ravnborg | 62284a3 | 2008-06-07 13:18:26 +0200 | [diff] [blame] | 128 | $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 129 | |
| 130 | targets := $(wildcard $(sort $(targets))) |
| 131 | cmd_files := $(wildcard \ |
| 132 | $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd)) |
| 133 | |
| 134 | ifneq ($(cmd_files),) |
| 135 | include $(cmd_files) |
| 136 | endif |
| 137 | |
| 138 | .PHONY: $(PHONY) |
| 139 | PHONY += FORCE |
| 140 | FORCE: ; |