blob: 708fbd08a2c51d9321ac251605589c1e7a877005 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
David Woodhouse8d730cf2006-06-18 11:58:39 +01002# ==========================================================================
3# Installing headers
4#
Nicolas Dichtelfcc84872017-03-27 14:20:15 +02005# All headers under include/uapi, include/generated/uapi,
Nicolas Dichtel61562f982017-03-27 14:20:16 +02006# arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
Nicolas Dichtelfcc84872017-03-27 14:20:15 +02007# exported.
8# They are preprocessed to remove __KERNEL__ section of the file.
David Woodhouse8d730cf2006-06-18 11:58:39 +01009#
10# ==========================================================================
11
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090012PHONY := __headers
13__headers:
14
15include scripts/Kbuild.include
16
Masahiro Yamadad5470d12019-06-04 19:14:03 +090017src := $(srctree)/$(obj)
18gen := $(objtree)/$(subst include/,include/generated/,$(obj))
19dst := usr/include
Richard Genoud2f263d12017-06-15 10:36:22 +020020
Masahiro Yamadad5470d12019-06-04 19:14:03 +090021-include $(src)/Kbuild
Richard Genoud2f263d12017-06-15 10:36:22 +020022
Masahiro Yamada7ff4f082019-06-22 15:55:20 +090023# $(filter %/, ...) is a workaround for GNU Make <= 4.2.1, where
24# $(wildcard $(src)/*/) contains not only directories but also regular files.
25src-subdirs := $(patsubst $(src)/%/,%,$(filter %/, $(wildcard $(src)/*/)))
26gen-subdirs := $(patsubst $(gen)/%/,%,$(filter %/, $(wildcard $(gen)/*/)))
Masahiro Yamadad5470d12019-06-04 19:14:03 +090027all-subdirs := $(sort $(src-subdirs) $(gen-subdirs))
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090028
Masahiro Yamadad5470d12019-06-04 19:14:03 +090029src-headers := $(if $(src-subdirs), $(shell cd $(src) && find $(src-subdirs) -name '*.h'))
30src-headers := $(filter-out $(no-export-headers), $(src-headers))
31gen-headers := $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subdirs) -name '*.h'))
32gen-headers := $(filter-out $(no-export-headers), $(gen-headers))
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090033
Masahiro Yamadad5470d12019-06-04 19:14:03 +090034# If the same header is exported from source and generated directories,
35# the former takes precedence, but this should be warned.
36duplicated := $(filter $(gen-headers), $(src-headers))
37$(if $(duplicated), $(warning duplicated header export: $(duplicated)))
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090038
Masahiro Yamadad5470d12019-06-04 19:14:03 +090039gen-headers := $(filter-out $(duplicated), $(gen-headers))
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090040
Masahiro Yamadad5470d12019-06-04 19:14:03 +090041# Add dst path prefix
42all-subdirs := $(addprefix $(dst)/, $(all-subdirs))
43src-headers := $(addprefix $(dst)/, $(src-headers))
44gen-headers := $(addprefix $(dst)/, $(gen-headers))
45all-headers := $(src-headers) $(gen-headers)
David Howells10b63952012-10-02 18:01:57 +010046
David Woodhousede789122006-09-24 22:15:14 +010047# Work out what needs to be removed
Masahiro Yamadad5470d12019-06-04 19:14:03 +090048old-subdirs := $(wildcard $(all-subdirs))
49old-headers := $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.h'))
50unwanted := $(filter-out $(all-headers), $(old-headers))
David Woodhousede789122006-09-24 22:15:14 +010051
Masahiro Yamadad5470d12019-06-04 19:14:03 +090052# Create directories
53existing-dirs := $(sort $(dir $(old-headers)))
54wanted-dirs := $(sort $(dir $(all-headers)))
55new-dirs := $(filter-out $(existing-dirs), $(wanted-dirs))
56$(if $(new-dirs), $(shell mkdir -p $(new-dirs)))
David Woodhousede789122006-09-24 22:15:14 +010057
Masahiro Yamadad5470d12019-06-04 19:14:03 +090058# Rules
Masahiro Yamadad5470d12019-06-04 19:14:03 +090059quiet_cmd_install = HDRINST $@
Masahiro Yamada555187a2019-06-04 19:14:05 +090060 cmd_install = $(CONFIG_SHELL) $(srctree)/scripts/headers_install.sh $< $@
Masahiro Yamadad5470d12019-06-04 19:14:03 +090061
62$(src-headers): $(dst)/%.h: $(src)/%.h $(srctree)/scripts/headers_install.sh FORCE
Sam Ravnborg77124012008-06-15 21:41:09 +020063 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +010064
Masahiro Yamadad5470d12019-06-04 19:14:03 +090065$(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctree)/scripts/headers_install.sh FORCE
66 $(call if_changed,install)
67
68quiet_cmd_remove = REMOVE $(unwanted)
69 cmd_remove = rm -f $(unwanted)
70
71__headers: $(all-headers)
72ifneq ($(unwanted),)
73 $(call cmd,remove)
74endif
Sam Ravnborg77124012008-06-15 21:41:09 +020075 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +010076
Masahiro Yamadad5470d12019-06-04 19:14:03 +090077existing-headers := $(filter $(old-headers), $(all-headers))
78
79-include $(foreach f,$(existing-headers),$(dir $(f)).$(notdir $(f)).cmd)
80
Sam Ravnborg77124012008-06-15 21:41:09 +020081PHONY += FORCE
Masahiro Yamadad5470d12019-06-04 19:14:03 +090082FORCE:
Masahiro Yamadae474ed42017-11-13 19:33:19 +090083
84.PHONY: $(PHONY)