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