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