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 | |
Masahiro Yamada | 3204a7f | 2021-02-28 15:10:26 +0900 | [diff] [blame] | 15 | include $(srctree)/scripts/Kbuild.include |
Masahiro Yamada | 05d8cba | 2017-05-16 14:15:03 +0900 | [diff] [blame] | 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 | 7ff4f08 | 2019-06-22 15:55:20 +0900 | [diff] [blame] | 23 | # $(filter %/, ...) is a workaround for GNU Make <= 4.2.1, where |
| 24 | # $(wildcard $(src)/*/) contains not only directories but also regular files. |
| 25 | src-subdirs := $(patsubst $(src)/%/,%,$(filter %/, $(wildcard $(src)/*/))) |
| 26 | gen-subdirs := $(patsubst $(gen)/%/,%,$(filter %/, $(wildcard $(gen)/*/))) |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame] | 27 | all-subdirs := $(sort $(src-subdirs) $(gen-subdirs)) |
Masahiro Yamada | 05d8cba | 2017-05-16 14:15:03 +0900 | [diff] [blame] | 28 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame] | 29 | src-headers := $(if $(src-subdirs), $(shell cd $(src) && find $(src-subdirs) -name '*.h')) |
| 30 | src-headers := $(filter-out $(no-export-headers), $(src-headers)) |
| 31 | gen-headers := $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subdirs) -name '*.h')) |
| 32 | gen-headers := $(filter-out $(no-export-headers), $(gen-headers)) |
Masahiro Yamada | 05d8cba | 2017-05-16 14:15:03 +0900 | [diff] [blame] | 33 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame] | 34 | # If the same header is exported from source and generated directories, |
| 35 | # the former takes precedence, but this should be warned. |
| 36 | duplicated := $(filter $(gen-headers), $(src-headers)) |
| 37 | $(if $(duplicated), $(warning duplicated header export: $(duplicated))) |
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 | gen-headers := $(filter-out $(duplicated), $(gen-headers)) |
Masahiro Yamada | 05d8cba | 2017-05-16 14:15:03 +0900 | [diff] [blame] | 40 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame] | 41 | # Add dst path prefix |
| 42 | all-subdirs := $(addprefix $(dst)/, $(all-subdirs)) |
| 43 | src-headers := $(addprefix $(dst)/, $(src-headers)) |
| 44 | gen-headers := $(addprefix $(dst)/, $(gen-headers)) |
| 45 | all-headers := $(src-headers) $(gen-headers) |
David Howells | 10b6395 | 2012-10-02 18:01:57 +0100 | [diff] [blame] | 46 | |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 47 | # Work out what needs to be removed |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame] | 48 | old-subdirs := $(wildcard $(all-subdirs)) |
| 49 | old-headers := $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.h')) |
| 50 | unwanted := $(filter-out $(all-headers), $(old-headers)) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 51 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame] | 52 | # Create directories |
| 53 | existing-dirs := $(sort $(dir $(old-headers))) |
| 54 | wanted-dirs := $(sort $(dir $(all-headers))) |
| 55 | new-dirs := $(filter-out $(existing-dirs), $(wanted-dirs)) |
| 56 | $(if $(new-dirs), $(shell mkdir -p $(new-dirs))) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 57 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame] | 58 | # Rules |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame] | 59 | quiet_cmd_install = HDRINST $@ |
Masahiro Yamada | 555187a | 2019-06-04 19:14:05 +0900 | [diff] [blame] | 60 | cmd_install = $(CONFIG_SHELL) $(srctree)/scripts/headers_install.sh $< $@ |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame] | 61 | |
| 62 | $(src-headers): $(dst)/%.h: $(src)/%.h $(srctree)/scripts/headers_install.sh FORCE |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 63 | $(call if_changed,install) |
David Woodhouse | de78912 | 2006-09-24 22:15:14 +0100 | [diff] [blame] | 64 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame] | 65 | $(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctree)/scripts/headers_install.sh FORCE |
| 66 | $(call if_changed,install) |
| 67 | |
| 68 | quiet_cmd_remove = REMOVE $(unwanted) |
| 69 | cmd_remove = rm -f $(unwanted) |
| 70 | |
| 71 | __headers: $(all-headers) |
| 72 | ifneq ($(unwanted),) |
| 73 | $(call cmd,remove) |
| 74 | endif |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 75 | @: |
David Woodhouse | 8d730cf | 2006-06-18 11:58:39 +0100 | [diff] [blame] | 76 | |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame] | 77 | existing-headers := $(filter $(old-headers), $(all-headers)) |
| 78 | |
| 79 | -include $(foreach f,$(existing-headers),$(dir $(f)).$(notdir $(f)).cmd) |
| 80 | |
Sam Ravnborg | 7712401 | 2008-06-15 21:41:09 +0200 | [diff] [blame] | 81 | PHONY += FORCE |
Masahiro Yamada | d5470d1 | 2019-06-04 19:14:03 +0900 | [diff] [blame] | 82 | FORCE: |
Masahiro Yamada | e474ed4 | 2017-11-13 19:33:19 +0900 | [diff] [blame] | 83 | |
| 84 | .PHONY: $(PHONY) |