David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 1 | # ========================================================================== |
| 2 | # Installing headers |
| 3 | # |
Nicolas Dichtel | fcc8487 | 2017-03-27 14:20:15 +0200 | [diff] [blame] | 4 | # All headers under include/uapi, include/generated/uapi, |
Nicolas Dichtel | 61562f9 | 2017-03-27 14:20:16 +0200 | [diff] [blame] | 5 | # arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are |
Nicolas Dichtel | fcc8487 | 2017-03-27 14:20:15 +0200 | [diff] [blame] | 6 | # exported. |
| 7 | # They are preprocessed to remove __KERNEL__ section of the file. |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 8 | # |
| 9 | # ========================================================================== |
| 10 | |
Masahiro Yamada | 05d8cba | 2017-05-16 14:15:03 +0900 | [diff] [blame] | 11 | PHONY := __headers |
| 12 | __headers: |
| 13 | |
| 14 | include scripts/Kbuild.include |
| 15 | |
| 16 | srcdir := $(srctree)/$(obj) |
| 17 | subdirs := $(patsubst $(srcdir)/%/.,%,$(wildcard $(srcdir)/*/.)) |
| 18 | # caller may set destination dir (when installing to asm/) |
| 19 | _dst := $(if $(dst),$(dst),$(obj)) |
| 20 | |
| 21 | # Recursion |
| 22 | __headers: $(subdirs) |
| 23 | |
| 24 | .PHONY: $(subdirs) |
| 25 | $(subdirs): |
| 26 | $(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@ |
| 27 | |
| 28 | # Skip header install/check for include/uapi and arch/$(hdr-arch)/include/uapi. |
| 29 | # We have only sub-directories there. |
| 30 | skip-inst := $(if $(filter %/uapi,$(obj)),1) |
| 31 | |
| 32 | ifeq ($(skip-inst),) |
| 33 | |
H. Peter Anvin | cb97914 | 2011-11-11 15:20:34 -0800 | [diff] [blame] | 34 | # generated header directory |
| 35 | gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj))) |
| 36 | |
Nicolas Dichtel | fcc8487 | 2017-03-27 14:20:15 +0200 | [diff] [blame] | 37 | # Kbuild file is optional |
Sam Ravnborg | 283039f | 2008-06-05 19:19:47 +0200 | [diff] [blame] | 38 | kbuild-file := $(srctree)/$(obj)/Kbuild |
Nicolas Dichtel | fcc8487 | 2017-03-27 14:20:15 +0200 | [diff] [blame] | 39 | -include $(kbuild-file) |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 40 | |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 41 | old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild |
| 42 | ifneq ($(wildcard $(old-kbuild-file)),) |
| 43 | include $(old-kbuild-file) |
| 44 | endif |
Sam Ravnborg | c7bb349 | 2009-04-10 08:52:43 +0200 | [diff] [blame] | 45 | |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 46 | installdir := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst)) |
Sam Ravnborg | 62284a3 | 2008-06-07 13:18:26 +0200 | [diff] [blame] | 47 | |
Nicolas Dichtel | fcc8487 | 2017-03-27 14:20:15 +0200 | [diff] [blame] | 48 | gendir := $(objtree)/$(gen) |
Nicolas Dichtel | fcc8487 | 2017-03-27 14:20:15 +0200 | [diff] [blame] | 49 | header-files := $(notdir $(wildcard $(srcdir)/*.h)) |
| 50 | header-files += $(notdir $(wildcard $(srcdir)/*.agh)) |
| 51 | header-files := $(filter-out $(no-export-headers), $(header-files)) |
| 52 | genhdr-files := $(notdir $(wildcard $(gendir)/*.h)) |
| 53 | genhdr-files := $(filter-out $(header-files), $(genhdr-files)) |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 54 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 55 | # files used to track state of install/check |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 56 | install-file := $(installdir)/.install |
| 57 | check-file := $(installdir)/.check |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 58 | |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 59 | # generic-y list all files an architecture uses from asm-generic |
| 60 | # Use this to build a list of headers which require a wrapper |
Nicolas Dichtel | fcc8487 | 2017-03-27 14:20:15 +0200 | [diff] [blame] | 61 | generic-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h)) |
| 62 | wrapper-files := $(filter $(generic-files), $(generic-y)) |
| 63 | wrapper-files := $(filter-out $(header-files), $(wrapper-files)) |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 64 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 65 | # all headers files for this dir |
Nicolas Dichtel | fcc8487 | 2017-03-27 14:20:15 +0200 | [diff] [blame] | 66 | all-files := $(header-files) $(genhdr-files) $(wrapper-files) |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 67 | output-files := $(addprefix $(installdir)/, $(all-files)) |
| 68 | |
Nicolas Dichtel | fcc8487 | 2017-03-27 14:20:15 +0200 | [diff] [blame] | 69 | ifneq ($(mandatory-y),) |
| 70 | missing := $(filter-out $(all-files),$(mandatory-y)) |
| 71 | ifneq ($(missing),) |
| 72 | $(error Some mandatory headers ($(missing)) are missing in $(obj)) |
| 73 | endif |
| 74 | endif |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 75 | |
| 76 | # Work out what needs to be removed |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 77 | oldheaders := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h)) |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 78 | unwanted := $(filter-out $(all-files),$(oldheaders)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 79 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 80 | # Prefix unwanted with full paths to $(INSTALL_HDR_PATH) |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 81 | unwanted-file := $(addprefix $(installdir)/, $(unwanted)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 82 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 83 | printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@)) |
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 | quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\ |
| 86 | file$(if $(word 2, $(all-files)),s)) |
Sam Ravnborg | db1bec4 | 2008-06-16 21:29:38 +0200 | [diff] [blame] | 87 | cmd_install = \ |
Nicolas Dichtel | fcc8487 | 2017-03-27 14:20:15 +0200 | [diff] [blame] | 88 | $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \ |
| 89 | $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-files); \ |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 90 | for F in $(wrapper-files); do \ |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 91 | echo "\#include <asm-generic/$$F>" > $(installdir)/$$F; \ |
Sam Ravnborg | d8ecc5c | 2011-04-27 22:29:49 +0200 | [diff] [blame] | 92 | done; \ |
Sam Ravnborg | db1bec4 | 2008-06-16 21:29:38 +0200 | [diff] [blame] | 93 | touch $@ |
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 | quiet_cmd_remove = REMOVE $(unwanted) |
| 96 | cmd_remove = rm -f $(unwanted-file) |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 97 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 98 | quiet_cmd_check = CHECK $(printdir) ($(words $(all-files)) files) |
Sergei Poselenov | 7211b8b | 2009-06-05 16:11:09 +0400 | [diff] [blame] | 99 | # Headers list can be pretty long, xargs helps to avoid |
| 100 | # the "Argument list too long" error. |
| 101 | cmd_check = for f in $(all-files); do \ |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 102 | echo "$(installdir)/$${f}"; done \ |
Sergei Poselenov | 7211b8b | 2009-06-05 16:11:09 +0400 | [diff] [blame] | 103 | | xargs \ |
| 104 | $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \ |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 105 | touch $@ |
David Woodhouse | 6847535 | 2006-06-18 12:02:10 +0100 | [diff] [blame] | 106 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 107 | ifndef HDRCHECK |
| 108 | # Rules for installing headers |
Masahiro Yamada | 05d8cba | 2017-05-16 14:15:03 +0900 | [diff] [blame] | 109 | __headers: $(install-file) |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 110 | @: |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 111 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 112 | targets += $(install-file) |
Nicolas Dichtel | 7c025b2 | 2017-03-27 14:20:09 +0200 | [diff] [blame] | 113 | $(install-file): scripts/headers_install.sh \ |
Nicolas Dichtel | fcc8487 | 2017-03-27 14:20:15 +0200 | [diff] [blame] | 114 | $(addprefix $(srcdir)/,$(header-files)) \ |
| 115 | $(addprefix $(gendir)/,$(genhdr-files)) FORCE |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 116 | $(if $(unwanted),$(call cmd,remove),) |
| 117 | $(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@))) |
| 118 | $(call if_changed,install) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 119 | |
David Woodhouse | 6847535 | 2006-06-18 12:02:10 +0100 | [diff] [blame] | 120 | else |
Masahiro Yamada | 05d8cba | 2017-05-16 14:15:03 +0900 | [diff] [blame] | 121 | __headers: $(check-file) |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 122 | @: |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 123 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 124 | targets += $(check-file) |
| 125 | $(check-file): scripts/headers_check.pl $(output-files) FORCE |
| 126 | $(call if_changed,check) |
Sam Ravnborg | 4e420aa | 2008-06-05 16:52:15 +0200 | [diff] [blame] | 127 | |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 128 | endif |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 129 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 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 | |
Masahiro Yamada | 05d8cba | 2017-05-16 14:15:03 +0900 | [diff] [blame] | 138 | endif # skip-inst |
| 139 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 140 | .PHONY: $(PHONY) |
| 141 | PHONY += FORCE |
| 142 | FORCE: ; |