b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) # SPDX-License-Identifier: GPL-2.0
8d730cfb50cc7 (David Woodhouse 2006-06-18 11:58:39 +0100 2) # ==========================================================================
8d730cfb50cc7 (David Woodhouse 2006-06-18 11:58:39 +0100 3) # Installing headers
8d730cfb50cc7 (David Woodhouse 2006-06-18 11:58:39 +0100 4) #
fcc8487d477a3 (Nicolas Dichtel 2017-03-27 14:20:15 +0200 5) # All headers under include/uapi, include/generated/uapi,
61562f981e928 (Nicolas Dichtel 2017-03-27 14:20:16 +0200 6) # arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
fcc8487d477a3 (Nicolas Dichtel 2017-03-27 14:20:15 +0200 7) # exported.
fcc8487d477a3 (Nicolas Dichtel 2017-03-27 14:20:15 +0200 8) # They are preprocessed to remove __KERNEL__ section of the file.
8d730cfb50cc7 (David Woodhouse 2006-06-18 11:58:39 +0100 9) #
8d730cfb50cc7 (David Woodhouse 2006-06-18 11:58:39 +0100 10) # ==========================================================================
8d730cfb50cc7 (David Woodhouse 2006-06-18 11:58:39 +0100 11)
05d8cba4a1e8c (Masahiro Yamada 2017-05-16 14:15:03 +0900 12) PHONY := __headers
05d8cba4a1e8c (Masahiro Yamada 2017-05-16 14:15:03 +0900 13) __headers:
05d8cba4a1e8c (Masahiro Yamada 2017-05-16 14:15:03 +0900 14)
3204a7fb98a3b (Masahiro Yamada 2021-02-28 15:10:26 +0900 15) include $(srctree)/scripts/Kbuild.include
05d8cba4a1e8c (Masahiro Yamada 2017-05-16 14:15:03 +0900 16)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 17) src := $(srctree)/$(obj)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 18) gen := $(objtree)/$(subst include/,include/generated/,$(obj))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 19) dst := usr/include
2f263d145140e (Richard Genoud 2017-06-15 10:36:22 +0200 20)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 21) -include $(src)/Kbuild
2f263d145140e (Richard Genoud 2017-06-15 10:36:22 +0200 22)
7ff4f0805eb50 (Masahiro Yamada 2019-06-22 15:55:20 +0900 23) # $(filter %/, ...) is a workaround for GNU Make <= 4.2.1, where
7ff4f0805eb50 (Masahiro Yamada 2019-06-22 15:55:20 +0900 24) # $(wildcard $(src)/*/) contains not only directories but also regular files.
7ff4f0805eb50 (Masahiro Yamada 2019-06-22 15:55:20 +0900 25) src-subdirs := $(patsubst $(src)/%/,%,$(filter %/, $(wildcard $(src)/*/)))
7ff4f0805eb50 (Masahiro Yamada 2019-06-22 15:55:20 +0900 26) gen-subdirs := $(patsubst $(gen)/%/,%,$(filter %/, $(wildcard $(gen)/*/)))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 27) all-subdirs := $(sort $(src-subdirs) $(gen-subdirs))
05d8cba4a1e8c (Masahiro Yamada 2017-05-16 14:15:03 +0900 28)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 29) src-headers := $(if $(src-subdirs), $(shell cd $(src) && find $(src-subdirs) -name '*.h'))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 30) src-headers := $(filter-out $(no-export-headers), $(src-headers))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 31) gen-headers := $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subdirs) -name '*.h'))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 32) gen-headers := $(filter-out $(no-export-headers), $(gen-headers))
05d8cba4a1e8c (Masahiro Yamada 2017-05-16 14:15:03 +0900 33)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 34) # If the same header is exported from source and generated directories,
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 35) # the former takes precedence, but this should be warned.
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 36) duplicated := $(filter $(gen-headers), $(src-headers))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 37) $(if $(duplicated), $(warning duplicated header export: $(duplicated)))
05d8cba4a1e8c (Masahiro Yamada 2017-05-16 14:15:03 +0900 38)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 39) gen-headers := $(filter-out $(duplicated), $(gen-headers))
05d8cba4a1e8c (Masahiro Yamada 2017-05-16 14:15:03 +0900 40)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 41) # Add dst path prefix
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 42) all-subdirs := $(addprefix $(dst)/, $(all-subdirs))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 43) src-headers := $(addprefix $(dst)/, $(src-headers))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 44) gen-headers := $(addprefix $(dst)/, $(gen-headers))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 45) all-headers := $(src-headers) $(gen-headers)
8d730cfb50cc7 (David Woodhouse 2006-06-18 11:58:39 +0100 46)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 47) # Work out what needs to be removed
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 48) old-subdirs := $(wildcard $(all-subdirs))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 49) old-headers := $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.h'))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 50) unwanted := $(filter-out $(all-headers), $(old-headers))
de78912582bc1 (David Woodhouse 2006-09-24 22:15:14 +0100 51)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 52) # Create directories
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 53) existing-dirs := $(sort $(dir $(old-headers)))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 54) wanted-dirs := $(sort $(dir $(all-headers)))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 55) new-dirs := $(filter-out $(existing-dirs), $(wanted-dirs))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 56) $(if $(new-dirs), $(shell mkdir -p $(new-dirs)))
de78912582bc1 (David Woodhouse 2006-09-24 22:15:14 +0100 57)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 58) # Rules
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 59) quiet_cmd_install = HDRINST $@
555187a8791d4 (Masahiro Yamada 2019-06-04 19:14:05 +0900 60) cmd_install = $(CONFIG_SHELL) $(srctree)/scripts/headers_install.sh $< $@
de78912582bc1 (David Woodhouse 2006-09-24 22:15:14 +0100 61)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 62) $(src-headers): $(dst)/%.h: $(src)/%.h $(srctree)/scripts/headers_install.sh FORCE
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 63) $(call if_changed,install)
684753599afc7 (David Woodhouse 2006-06-18 12:02:10 +0100 64)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 65) $(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctree)/scripts/headers_install.sh FORCE
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 66) $(call if_changed,install)
8d730cfb50cc7 (David Woodhouse 2006-06-18 11:58:39 +0100 67)
7712401ae9006 (Sam Ravnborg 2008-06-15 21:41:09 +0200 68) quiet_cmd_remove = REMOVE $(unwanted)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 69) cmd_remove = rm -f $(unwanted)
de78912582bc1 (David Woodhouse 2006-09-24 22:15:14 +0100 70)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 71) __headers: $(all-headers)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 72) ifneq ($(unwanted),)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 73) $(call cmd,remove)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 74) endif
7712401ae9006 (Sam Ravnborg 2008-06-15 21:41:09 +0200 75) @:
de78912582bc1 (David Woodhouse 2006-09-24 22:15:14 +0100 76)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 77) existing-headers := $(filter $(old-headers), $(all-headers))
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 78)
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 79) -include $(foreach f,$(existing-headers),$(dir $(f)).$(notdir $(f)).cmd)
de78912582bc1 (David Woodhouse 2006-09-24 22:15:14 +0100 80)
7712401ae9006 (Sam Ravnborg 2008-06-15 21:41:09 +0200 81) PHONY += FORCE
d5470d14431e9 (Masahiro Yamada 2019-06-04 19:14:03 +0900 82) FORCE:
e474ed45777bc (Masahiro Yamada 2017-11-13 19:33:19 +0900 83)
e474ed45777bc (Masahiro Yamada 2017-11-13 19:33:19 +0900 84) .PHONY: $(PHONY)