blob: c96c4c26e24066dd54162bfebabdbacb809f38c3 [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 Yamadad5470d12019-06-04 19:14:03 +090023src-subdirs := $(patsubst $(src)/%/,%,$(wildcard $(src)/*/))
24gen-subdirs := $(patsubst $(gen)/%/,%,$(wildcard $(gen)/*/))
25all-subdirs := $(sort $(src-subdirs) $(gen-subdirs))
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090026
Masahiro Yamadad5470d12019-06-04 19:14:03 +090027src-headers := $(if $(src-subdirs), $(shell cd $(src) && find $(src-subdirs) -name '*.h'))
28src-headers := $(filter-out $(no-export-headers), $(src-headers))
29gen-headers := $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subdirs) -name '*.h'))
30gen-headers := $(filter-out $(no-export-headers), $(gen-headers))
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090031
Masahiro Yamadad5470d12019-06-04 19:14:03 +090032# If the same header is exported from source and generated directories,
33# the former takes precedence, but this should be warned.
34duplicated := $(filter $(gen-headers), $(src-headers))
35$(if $(duplicated), $(warning duplicated header export: $(duplicated)))
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090036
Masahiro Yamadad5470d12019-06-04 19:14:03 +090037gen-headers := $(filter-out $(duplicated), $(gen-headers))
Masahiro Yamada05d8cba2017-05-16 14:15:03 +090038
Masahiro Yamadad5470d12019-06-04 19:14:03 +090039# Add dst path prefix
40all-subdirs := $(addprefix $(dst)/, $(all-subdirs))
41src-headers := $(addprefix $(dst)/, $(src-headers))
42gen-headers := $(addprefix $(dst)/, $(gen-headers))
43all-headers := $(src-headers) $(gen-headers)
David Howells10b63952012-10-02 18:01:57 +010044
David Woodhousede789122006-09-24 22:15:14 +010045# Work out what needs to be removed
Masahiro Yamadad5470d12019-06-04 19:14:03 +090046old-subdirs := $(wildcard $(all-subdirs))
47old-headers := $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.h'))
48unwanted := $(filter-out $(all-headers), $(old-headers))
David Woodhousede789122006-09-24 22:15:14 +010049
Masahiro Yamadad5470d12019-06-04 19:14:03 +090050# Create directories
51existing-dirs := $(sort $(dir $(old-headers)))
52wanted-dirs := $(sort $(dir $(all-headers)))
53new-dirs := $(filter-out $(existing-dirs), $(wanted-dirs))
54$(if $(new-dirs), $(shell mkdir -p $(new-dirs)))
David Woodhousede789122006-09-24 22:15:14 +010055
Masahiro Yamadad5470d12019-06-04 19:14:03 +090056# Rules
David Woodhouse68475352006-06-18 12:02:10 +010057
Sam Ravnborg77124012008-06-15 21:41:09 +020058ifndef HDRCHECK
David Woodhousede789122006-09-24 22:15:14 +010059
Masahiro Yamadad5470d12019-06-04 19:14:03 +090060quiet_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 Ravnborg77124012008-06-15 21:41:09 +020064 $(call if_changed,install)
David Woodhousede789122006-09-24 22:15:14 +010065
Masahiro Yamadad5470d12019-06-04 19:14:03 +090066$(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctree)/scripts/headers_install.sh FORCE
67 $(call if_changed,install)
68
69quiet_cmd_remove = REMOVE $(unwanted)
70 cmd_remove = rm -f $(unwanted)
71
72__headers: $(all-headers)
73ifneq ($(unwanted),)
74 $(call cmd,remove)
75endif
Sam Ravnborg77124012008-06-15 21:41:09 +020076 @:
David Woodhouse8d730cf2006-06-18 11:58:39 +010077
Masahiro Yamadad5470d12019-06-04 19:14:03 +090078existing-headers := $(filter $(old-headers), $(all-headers))
79
80-include $(foreach f,$(existing-headers),$(dir $(f)).$(notdir $(f)).cmd)
81
82else
83
84quiet_cmd_check = HDRCHK $<
85 cmd_check = $(PERL) $(srctree)/scripts/headers_check.pl $(dst) $(SRCARCH) $<; touch $@
86
87check-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 Ravnborg4e420aa2008-06-05 16:52:15 +020094
David Woodhouse8d730cf2006-06-18 11:58:39 +010095endif
David Woodhouse8d730cf2006-06-18 11:58:39 +010096
Sam Ravnborg77124012008-06-15 21:41:09 +020097PHONY += FORCE
Masahiro Yamadad5470d12019-06-04 19:14:03 +090098FORCE:
Masahiro Yamadae474ed42017-11-13 19:33:19 +090099
100.PHONY: $(PHONY)