Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 2 | # ========================================================================== |
| 3 | # Installing headers |
| 4 | # |
Nicolas Dichtel | fcc8487 | 2017-03-27 14:20:15 +0200 | [diff] [blame] | 5 | # All headers under include/uapi, include/generated/uapi, |
Nicolas Dichtel | 61562f98 | 2017-03-27 14:20:16 +0200 | [diff] [blame] | 6 | # arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are |
Nicolas Dichtel | fcc8487 | 2017-03-27 14:20:15 +0200 | [diff] [blame] | 7 | # exported. |
| 8 | # They are preprocessed to remove __KERNEL__ section of the file. |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 9 | # |
| 10 | # ========================================================================== |
| 11 | |
Masahiro Yamada | 05d8cba | 2017-05-16 14:15:03 +0900 | [diff] [blame] | 12 | PHONY := __headers |
| 13 | __headers: |
| 14 | |
| 15 | include scripts/Kbuild.include |
| 16 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 17 | src := $(srctree)/$(obj) |
| 18 | gen := $(objtree)/$(subst include/,include/generated/,$(obj)) |
| 19 | dst := usr/include |
Richard Genoud | 2f263d1 | 2017-06-15 10:36:22 +0200 | [diff] [blame] | 20 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 21 | -include $(src)/Kbuild |
Richard Genoud | 2f263d1 | 2017-06-15 10:36:22 +0200 | [diff] [blame] | 22 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 23 | src-subdirs := $(patsubst $(src)/%/,%,$(wildcard $(src)/*/)) |
| 24 | gen-subdirs := $(patsubst $(gen)/%/,%,$(wildcard $(gen)/*/)) |
| 25 | all-subdirs := $(sort $(src-subdirs) $(gen-subdirs)) |
Masahiro Yamada | 05d8cba | 2017-05-16 14:15:03 +0900 | [diff] [blame] | 26 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 27 | src-headers := $(if $(src-subdirs), $(shell cd $(src) && find $(src-subdirs) -name '*.h')) |
| 28 | src-headers := $(filter-out $(no-export-headers), $(src-headers)) |
| 29 | gen-headers := $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subdirs) -name '*.h')) |
| 30 | gen-headers := $(filter-out $(no-export-headers), $(gen-headers)) |
Masahiro Yamada | 05d8cba | 2017-05-16 14:15:03 +0900 | [diff] [blame] | 31 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 32 | # If the same header is exported from source and generated directories, |
| 33 | # the former takes precedence, but this should be warned. |
| 34 | duplicated := $(filter $(gen-headers), $(src-headers)) |
| 35 | $(if $(duplicated), $(warning duplicated header export: $(duplicated))) |
Masahiro Yamada | 05d8cba | 2017-05-16 14:15:03 +0900 | [diff] [blame] | 36 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 37 | gen-headers := $(filter-out $(duplicated), $(gen-headers)) |
Masahiro Yamada | 05d8cba | 2017-05-16 14:15:03 +0900 | [diff] [blame] | 38 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 39 | # Add dst path prefix |
| 40 | all-subdirs := $(addprefix $(dst)/, $(all-subdirs)) |
| 41 | src-headers := $(addprefix $(dst)/, $(src-headers)) |
| 42 | gen-headers := $(addprefix $(dst)/, $(gen-headers)) |
| 43 | all-headers := $(src-headers) $(gen-headers) |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 44 | |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 45 | # Work out what needs to be removed |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 46 | old-subdirs := $(wildcard $(all-subdirs)) |
| 47 | old-headers := $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.h')) |
| 48 | unwanted := $(filter-out $(all-headers), $(old-headers)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 49 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 50 | # Create directories |
| 51 | existing-dirs := $(sort $(dir $(old-headers))) |
| 52 | wanted-dirs := $(sort $(dir $(all-headers))) |
| 53 | new-dirs := $(filter-out $(existing-dirs), $(wanted-dirs)) |
| 54 | $(if $(new-dirs), $(shell mkdir -p $(new-dirs))) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 55 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 56 | # Rules |
David Woodhouse | 6847535 | 2006-06-18 12:02:10 +0100 | [diff] [blame] | 57 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 58 | ifndef HDRCHECK |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 59 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 60 | quiet_cmd_install = HDRINST $@ |
| 61 | cmd_install = $(CONFIG_SHELL) $(srctree)/scripts/headers_install.sh $(@D) $(<D) $(@F) |
| 62 | |
| 63 | $(src-headers): $(dst)/%.h: $(src)/%.h $(srctree)/scripts/headers_install.sh FORCE |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 64 | $(call if_changed,install) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 65 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 66 | $(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctree)/scripts/headers_install.sh FORCE |
| 67 | $(call if_changed,install) |
| 68 | |
| 69 | quiet_cmd_remove = REMOVE $(unwanted) |
| 70 | cmd_remove = rm -f $(unwanted) |
| 71 | |
| 72 | __headers: $(all-headers) |
| 73 | ifneq ($(unwanted),) |
| 74 | $(call cmd,remove) |
| 75 | endif |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 76 | @: |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 77 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 78 | existing-headers := $(filter $(old-headers), $(all-headers)) |
| 79 | |
| 80 | -include $(foreach f,$(existing-headers),$(dir $(f)).$(notdir $(f)).cmd) |
| 81 | |
| 82 | else |
| 83 | |
| 84 | quiet_cmd_check = HDRCHK $< |
| 85 | cmd_check = $(PERL) $(srctree)/scripts/headers_check.pl $(dst) $(SRCARCH) $<; touch $@ |
| 86 | |
| 87 | check-files := $(addsuffix .chk, $(all-headers)) |
| 88 | |
| 89 | $(check-files): $(dst)/%.chk : $(dst)/% $(srctree)/scripts/headers_check.pl |
| 90 | $(call cmd,check) |
| 91 | |
| 92 | __headers: $(check-files) |
| 93 | @: |
Sam Ravnborg | 4e420aa | 2008-06-05 16:52:15 +0200 | [diff] [blame] | 94 | |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 95 | endif |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 96 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 97 | PHONY += FORCE |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame^] | 98 | FORCE: |
Masahiro Yamada | e474ed4 | 2017-11-13 19:33:19 +0900 | [diff] [blame] | 99 | |
| 100 | .PHONY: $(PHONY) |