xref: /xnu-12377.1.9/config/Makefile (revision f6217f891ac0bb64f3d375211650a4c1ff8ca1ea)
1*f6217f89SApple OSS Distributionsexport MakeInc_cmd=${SRCROOT}/makedefs/MakeInc.cmd
2*f6217f89SApple OSS Distributionsexport MakeInc_def=${SRCROOT}/makedefs/MakeInc.def
3*f6217f89SApple OSS Distributionsexport MakeInc_rule=${SRCROOT}/makedefs/MakeInc.rule
4*f6217f89SApple OSS Distributionsexport MakeInc_dir=${SRCROOT}/makedefs/MakeInc.dir
5*f6217f89SApple OSS Distributions
6*f6217f89SApple OSS Distributionsinclude $(MakeInc_cmd)
7*f6217f89SApple OSS Distributionsinclude $(MakeInc_def)
8*f6217f89SApple OSS Distributions
9*f6217f89SApple OSS Distributions# config is not a COMPONENT but we still want to build most files in a TARGET subdir
10*f6217f89SApple OSS Distributionsoverride TARGET := $(OBJPATH)/config
11*f6217f89SApple OSS Distributions
12*f6217f89SApple OSS DistributionsMD_SUPPORTED_KPI_FILENAME := SupportedKPIs-${CURRENT_ARCH_CONFIG_LC}.txt
13*f6217f89SApple OSS DistributionsMI_SUPPORTED_KPI_FILENAME := SupportedKPIs-all-archs.txt
14*f6217f89SApple OSS Distributions
15*f6217f89SApple OSS DistributionsINSTALL_KEXT_DIR = $(DSTROOT)$(INSTALL_EXTENSIONS_DIR)
16*f6217f89SApple OSS Distributions
17*f6217f89SApple OSS DistributionsKEXT_PLIST_LIST := \
18*f6217f89SApple OSS Distributions	System.kext/Info.plist \
19*f6217f89SApple OSS Distributions	System.kext/PlugIns/Kasan.kext/Info.plist \
20*f6217f89SApple OSS Distributions	System.kext/PlugIns/Kcov.kext/Info.plist \
21*f6217f89SApple OSS Distributions	System.kext/PlugIns/AppleNMI.kext/Info.plist \
22*f6217f89SApple OSS Distributions	System.kext/PlugIns/ApplePlatformFamily.kext/Info.plist \
23*f6217f89SApple OSS Distributions	System.kext/PlugIns/IONVRAMFamily.kext/Info.plist \
24*f6217f89SApple OSS Distributions	System.kext/PlugIns/IOSystemManagement.kext/Info.plist
25*f6217f89SApple OSS Distributions
26*f6217f89SApple OSS DistributionsSYMBOL_COMPONENT_LIST :=	\
27*f6217f89SApple OSS Distributions        BSDKernel	\
28*f6217f89SApple OSS Distributions        IOKit		\
29*f6217f89SApple OSS Distributions        Libkern		\
30*f6217f89SApple OSS Distributions        Mach		\
31*f6217f89SApple OSS Distributions        MACFramework	\
32*f6217f89SApple OSS Distributions        Unsupported	\
33*f6217f89SApple OSS Distributions        Private
34*f6217f89SApple OSS Distributions
35*f6217f89SApple OSS DistributionsSYMBOL_SET_PLIST_COMPONENT_LIST := $(SYMBOL_COMPONENT_LIST) Kasan Kcov
36*f6217f89SApple OSS Distributions
37*f6217f89SApple OSS DistributionsKEXT_PLIST_LIST += $(foreach symbolset,$(SYMBOL_COMPONENT_LIST),System.kext/PlugIns/$(symbolset).kext/Info.plist)
38*f6217f89SApple OSS Distributions
39*f6217f89SApple OSS Distributions# In general you want it to be possible to have a CPU sub-type's symbol exports
40*f6217f89SApple OSS Distributions# alias to the parent type's exports. This is a special-case way to handle it
41*f6217f89SApple OSS Distributions# for now:
42*f6217f89SApple OSS Distributionsifeq ($(CURRENT_ARCH_CONFIG_LC),x86_64h)
43*f6217f89SApple OSS DistributionsEXPORT_SOURCE_ARCH_CONFIG_LC := x86_64
44*f6217f89SApple OSS Distributionselse
45*f6217f89SApple OSS DistributionsEXPORT_SOURCE_ARCH_CONFIG_LC := $(CURRENT_ARCH_CONFIG_LC)
46*f6217f89SApple OSS Distributionsendif
47*f6217f89SApple OSS Distributions
48*f6217f89SApple OSS DistributionsEXPORTS_FILES := $(foreach symbolset,$(SYMBOL_COMPONENT_LIST),$(symbolset).exports \
49*f6217f89SApple OSS Distributions	$(symbolset).$(EXPORT_SOURCE_ARCH_CONFIG_LC).exports \
50*f6217f89SApple OSS Distributions	$(notdir $(wildcard $(SOURCE)/$(symbolset).$(EXPORT_SOURCE_ARCH_CONFIG_LC).$(PLATFORM).exports))) \
51*f6217f89SApple OSS Distributions	Unused.exports
52*f6217f89SApple OSS DistributionsEXPORTS_FILES += $(TIGHTBEAM_EXPORTS)
53*f6217f89SApple OSS DistributionsPrivate_OTHER_EXPORTS += $(TIGHTBEAM_EXPORTS)
54*f6217f89SApple OSS Distributions
55*f6217f89SApple OSS Distributions
56*f6217f89SApple OSS DistributionsKasan_EXPORTS := $(SRCROOT)/config/Kasan_disabled.exports
57*f6217f89SApple OSS DistributionsKcov_EXPORTS := $(SRCROOT)/config/Kcov_disabled.exports
58*f6217f89SApple OSS Distributions
59*f6217f89SApple OSS Distributionsifneq ($(filter $(CURRENT_KERNEL_CONFIG),$(KCOV_RUNTIME)),)
60*f6217f89SApple OSS DistributionsKcov_EXPORTS := $(SRCROOT)/config/Kcov_enabled.exports
61*f6217f89SApple OSS Distributionsendif
62*f6217f89SApple OSS Distributions
63*f6217f89SApple OSS Distributionsifeq ($(KASAN),1)
64*f6217f89SApple OSS Distributionsifeq ($(CURRENT_ARCH_CONFIG_LC),x86_64h)
65*f6217f89SApple OSS DistributionsKASAN_ARCH_SUFFIX := x86_64
66*f6217f89SApple OSS Distributionselse
67*f6217f89SApple OSS DistributionsKASAN_ARCH_SUFFIX := $(CURRENT_ARCH_CONFIG_LC)
68*f6217f89SApple OSS Distributionsendif
69*f6217f89SApple OSS DistributionsKasan_EXPORTS := $(SRCROOT)/config/Kasan_enabled.$(KASAN_ARCH_SUFFIX).exports
70*f6217f89SApple OSS Distributionsendif
71*f6217f89SApple OSS Distributions
72*f6217f89SApple OSS Distributionsdefine symbol_set_template
73*f6217f89SApple OSS Distributions$(1)_EXPORTS := $$(addprefix $$(SOURCE)/,$$(filter $(1)%,$$(EXPORTS_FILES)))
74*f6217f89SApple OSS Distributionsifneq "$$($(1)_OTHER_EXPORTS)" ""
75*f6217f89SApple OSS Distributions$(1)_EXPORTS += $$($(1)_OTHER_EXPORTS)
76*f6217f89SApple OSS Distributionsendif
77*f6217f89SApple OSS Distributions$$(TARGET)/$(1).symbolset: MY_EXPORTS_ARGS := $$(foreach file,$$($(1)_EXPORTS),-export $$(file))
78*f6217f89SApple OSS Distributions$$(TARGET)/$(1).symbolset: $$($(1)_EXPORTS) $$(TARGET)/allsymbols $$(KEXT_CREATE_SYMBOL_SET)
79*f6217f89SApple OSS Distributions	@$$(LOG_SYMBOLSET) "$(1)$$(Color0) ($$(ColorLF)$$(CURRENT_ARCH_CONFIG_LC)$$(Color0))"
80*f6217f89SApple OSS Distributions	$$(_v)$$(KEXT_CREATE_SYMBOL_SET)			\
81*f6217f89SApple OSS Distributions		$$(ARCH_FLAGS_$$(CURRENT_ARCH_CONFIG))	\
82*f6217f89SApple OSS Distributions		-import $$(TARGET)/allsymbols		\
83*f6217f89SApple OSS Distributions		$$(MY_EXPORTS_ARGS)			\
84*f6217f89SApple OSS Distributions		-output $$@ $$(_vstdout)
85*f6217f89SApple OSS Distributions
86*f6217f89SApple OSS DistributionsSYMBOL_SET_BUILD += $$(TARGET)/$(1).symbolset
87*f6217f89SApple OSS Distributionsendef
88*f6217f89SApple OSS Distributions
89*f6217f89SApple OSS Distributions# Each parallel invocation of this target must use a distinct location, as it is
90*f6217f89SApple OSS Distributions# not safe to call multiple NEWVERS on the same file concurrently (rdar://66173684)
91*f6217f89SApple OSS Distributionsdefine kext_plist_template
92*f6217f89SApple OSS Distributions$$(TARGET)/$(1): $$(SOURCE)/$(1) $$(NEWVERS) $$(XNU_VERSION)
93*f6217f89SApple OSS Distributions	@$$(LOG_GENERATE) "$(1)"
94*f6217f89SApple OSS Distributions	$$(_v)$$(MKDIR) $$(@D)
95*f6217f89SApple OSS Distributions	$$(_v)$$(CP) $$< $$@
96*f6217f89SApple OSS Distributions	$$(_v)$$(NEWVERS) $$@ > /dev/null
97*f6217f89SApple OSS Distributions
98*f6217f89SApple OSS DistributionsKEXT_PLIST_BUILD += $$(TARGET)/$(1)
99*f6217f89SApple OSS DistributionsSYMROOT_INSTALL_KEXT_PLISTS += $$(SYMROOT)/$(1)
100*f6217f89SApple OSS DistributionsDSTROOT_INSTALL_KEXT_PLISTS += $$(INSTALL_KEXT_DIR)/$(1)
101*f6217f89SApple OSS Distributionsendef
102*f6217f89SApple OSS Distributions
103*f6217f89SApple OSS Distributionsdefine symbol_set_plist_template
104*f6217f89SApple OSS Distributions$(1)_KEXT_PLIST := $$(filter %/$(1).kext/Info.plist,$$(KEXT_PLIST_LIST))
105*f6217f89SApple OSS Distributions$$(TARGET)/$(1).symbolset.plist: $$(TARGET)/$$($(1)_KEXT_PLIST) $$($(1)_EXPORTS)
106*f6217f89SApple OSS Distributions	@$$(LOG_SYMBOLSETPLIST) "$(1)$$(Color0) ($$(ColorLF)$$(CURRENT_ARCH_CONFIG_LC)$$(Color0))"
107*f6217f89SApple OSS Distributions	$$(_v)$$(SOURCE)/generate_symbolset_plist.sh $$@ $$+ $$(_vstdout)
108*f6217f89SApple OSS Distributions	$$(_v)$$(PLUTIL) -lint -s $$@
109*f6217f89SApple OSS Distributions
110*f6217f89SApple OSS DistributionsSYMBOL_SET_PLIST_BUILD += $$(TARGET)/$(1).symbolset.plist
111*f6217f89SApple OSS Distributionsendef
112*f6217f89SApple OSS Distributions
113*f6217f89SApple OSS Distributions$(foreach symbolset,$(SYMBOL_COMPONENT_LIST),$(eval $(call symbol_set_template,$(symbolset))))
114*f6217f89SApple OSS Distributions$(foreach plist,$(KEXT_PLIST_LIST),$(eval $(call kext_plist_template,$(plist))))
115*f6217f89SApple OSS Distributions$(foreach symbolset,$(SYMBOL_SET_PLIST_COMPONENT_LIST),$(eval $(call symbol_set_plist_template,$(symbolset))))
116*f6217f89SApple OSS Distributions
117*f6217f89SApple OSS Distributions$(OBJPATH)/symbolsets.plist: $(SYMBOL_SET_PLIST_BUILD)
118*f6217f89SApple OSS Distributions	$(_v)$(SOURCE)/generate_combined_symbolsets_plist.sh $@ $^ $(_vstdout)
119*f6217f89SApple OSS Distributions	$(_v)$(PLUTIL) -convert binary1 -s $@
120*f6217f89SApple OSS Distributions
121*f6217f89SApple OSS Distributionsbuild_symbol_set_plists: $(KEXT_PLIST_BUILD) $(OBJPATH)/symbolsets.plist
122*f6217f89SApple OSS Distributions
123*f6217f89SApple OSS Distributions$(TARGET)/allsymbols: $(OBJPATH)/$(KERNEL_FILE_NAME)
124*f6217f89SApple OSS Distributions	$(_v)$(NM) -gj $< | sort -u > $@
125*f6217f89SApple OSS Distributions
126*f6217f89SApple OSS Distributionscheck_all_exports: $(TARGET)/allsymbols $(KEXT_CREATE_SYMBOL_SET)
127*f6217f89SApple OSS Distributions	$(_v)$(KEXT_CREATE_SYMBOL_SET)					\
128*f6217f89SApple OSS Distributions		$(ARCH_FLAGS_$(CURRENT_ARCH_CONFIG))			\
129*f6217f89SApple OSS Distributions		-import $(TARGET)/allsymbols				\
130*f6217f89SApple OSS Distributions		$(foreach symbolset,$(filter-out Private,$(SYMBOL_COMPONENT_LIST)),	\
131*f6217f89SApple OSS Distributions			-export $(SOURCE)/$(symbolset).exports		\
132*f6217f89SApple OSS Distributions			-export $(SOURCE)/$(symbolset).$(EXPORT_SOURCE_ARCH_CONFIG_LC).exports)	\
133*f6217f89SApple OSS Distributions		-output /dev/null $(_vstdout)
134*f6217f89SApple OSS Distributions	$(_v)$(KEXT_CREATE_SYMBOL_SET)					\
135*f6217f89SApple OSS Distributions		$(ARCH_FLAGS_$(CURRENT_ARCH_CONFIG))			\
136*f6217f89SApple OSS Distributions		-import $(TARGET)/allsymbols				\
137*f6217f89SApple OSS Distributions		$(foreach symbolset,$(filter-out Unsupported,$(SYMBOL_COMPONENT_LIST)),	\
138*f6217f89SApple OSS Distributions			-export $(SOURCE)/$(symbolset).exports		\
139*f6217f89SApple OSS Distributions			-export $(SOURCE)/$(symbolset).$(EXPORT_SOURCE_ARCH_CONFIG_LC).exports)	\
140*f6217f89SApple OSS Distributions		-output /dev/null $(_vstdout)
141*f6217f89SApple OSS Distributions
142*f6217f89SApple OSS Distributions$(OBJPATH)/$(MD_SUPPORTED_KPI_FILENAME): $(EXPORTS_FILES)
143*f6217f89SApple OSS Distributions	@$(LOG_SUPPORTED_KPI) "$(CURRENT_ARCH_CONFIG_LC)"
144*f6217f89SApple OSS Distributions	$(_v)$(SRCROOT)/config/list_supported.sh $(SOURCE) $(EXPORT_SOURCE_ARCH_CONFIG_LC) $@
145*f6217f89SApple OSS Distributions
146*f6217f89SApple OSS Distributions$(OBJPATH)/$(MI_SUPPORTED_KPI_FILENAME): $(EXPORTS_FILES)
147*f6217f89SApple OSS Distributions	@$(LOG_SUPPORTED_KPI) "all"
148*f6217f89SApple OSS Distributions	$(_v)$(SRCROOT)/config/list_supported.sh $(SOURCE) all $@
149*f6217f89SApple OSS Distributions
150*f6217f89SApple OSS Distributionsbuild_symbol_sets: check_all_exports $(SYMBOL_SET_BUILD) $(TARGET)/allsymbols \
151*f6217f89SApple OSS Distributions			$(OBJPATH)/$(MD_SUPPORTED_KPI_FILENAME) \
152*f6217f89SApple OSS Distributions			$(OBJPATH)/$(MI_SUPPORTED_KPI_FILENAME)
153*f6217f89SApple OSS Distributions
154*f6217f89SApple OSS Distributions# Generate rules for symroot fat kexts with dependencies on every corresponding symbolset for each build config.
155*f6217f89SApple OSS Distributions# This target must only run from do_config_install for a single build config after the do_config_all phases for
156*f6217f89SApple OSS Distributions# all build configs have completed. This ensures every unique slice built by any config is pulled into the fat
157*f6217f89SApple OSS Distributions# symbolset kext (note that not all slices are reflected as distinct xnu build config ARCHS!) (rdar://70703349)
158*f6217f89SApple OSS Distributionsdefine symroot_symbol_set_template
159*f6217f89SApple OSS Distributions$$(SYMROOT_SYSTEM_KEXT_PATH)/$(1).kext/$(1): $$(addsuffix /config/$(1).symbolset, \
160*f6217f89SApple OSS Distributions		$$(addprefix $$(OBJROOT)/,$$(foreach bc,$(BUILD_CONFIGS),$$(call function_convert_build_config_to_objdir,$$(bc)))))
161*f6217f89SApple OSS Distributions	@$$(LOG_INSTALLSYM) "$$(Color0)symbolset $$(ColorF)$(1)"
162*f6217f89SApple OSS Distributions	$$(_v)$$(MKDIR) $$(@D)
163*f6217f89SApple OSS Distributions	$$(_v)$$(LIPO) -create `(echo $$^ | xargs -L 1 lipo -detailed_info) | \
164*f6217f89SApple OSS Distributions		awk '/is architecture/ {s[$$$$6]=$$$$3} END {for (a in s) {print s[a]}}'` -output $$@ $$(_vstdout)
165*f6217f89SApple OSS Distributions
166*f6217f89SApple OSS DistributionsSYMROOT_INSTALL_KEXT_MACHO_FILES += $$(SYMROOT_SYSTEM_KEXT_PATH)/$(1).kext/$(1)
167*f6217f89SApple OSS DistributionsDSTROOT_INSTALL_KEXT_MACHO_FILES += $$(DSTROOT_SYSTEM_KEXT_PATH)/$(1).kext/$(1)
168*f6217f89SApple OSS Distributionsendef
169*f6217f89SApple OSS Distributions$(foreach symbolset,$(SYMBOL_COMPONENT_LIST),$(eval $(call symroot_symbol_set_template,$(symbolset))))
170*f6217f89SApple OSS Distributions
171*f6217f89SApple OSS Distributions$(SYMROOT_INSTALL_KEXT_PLISTS): $(SYMROOT)/% : $(TARGET)/%
172*f6217f89SApple OSS Distributions	$(_v)$(MKDIR) $(@D)
173*f6217f89SApple OSS Distributions	@$(LOG_INSTALLSYM) "$(Color0)kextplist $(ColorF)$*"
174*f6217f89SApple OSS Distributions	$(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@
175*f6217f89SApple OSS Distributions
176*f6217f89SApple OSS Distributions$(DSTROOT_INSTALL_KEXT_PLISTS): $(INSTALL_KEXT_DIR)/% : $(SYMROOT)/%
177*f6217f89SApple OSS Distributions	$(_v)$(MKDIR) $(@D)
178*f6217f89SApple OSS Distributions	@$(LOG_INSTALL) "$(Color0)kextplist $(ColorF)$*"
179*f6217f89SApple OSS Distributions	$(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@
180*f6217f89SApple OSS Distributions
181*f6217f89SApple OSS Distributions$(DSTROOT_INSTALL_KEXT_MACHO_FILES): $(DSTROOT_SYSTEM_KEXT_PATH)/% : $(SYMROOT_SYSTEM_KEXT_PATH)/%
182*f6217f89SApple OSS Distributions	$(_v)$(MKDIR) $(@D)
183*f6217f89SApple OSS Distributions	@$(LOG_INSTALL) "$(Color0)symbolset $(ColorF)$(@F)"
184*f6217f89SApple OSS Distributions	$(_v)$(INSTALL) $(EXEC_INSTALL_FLAGS) $< $@
185*f6217f89SApple OSS Distributions
186*f6217f89SApple OSS Distributions$(DSTROOT)/$(KRESDIR)/$(MD_SUPPORTED_KPI_FILENAME) $(DSTROOT)/$(KRESDIR)/$(MI_SUPPORTED_KPI_FILENAME): $(DSTROOT)/$(KRESDIR)/% : $(OBJPATH)/%
187*f6217f89SApple OSS Distributions	$(_v)$(MKDIR) $(@D)
188*f6217f89SApple OSS Distributions	@$(LOG_INSTALL) "$*"
189*f6217f89SApple OSS Distributions	$(_v)$(INSTALL) $(INSTALL_FLAGS) $< $@
190*f6217f89SApple OSS Distributions
191*f6217f89SApple OSS Distributionsifneq ($(RC_ProjectName),xnu_libraries)
192*f6217f89SApple OSS Distributions
193*f6217f89SApple OSS Distributionsdo_build_all:: build_symbol_set_plists
194*f6217f89SApple OSS Distributionsdo_config_all:: build_symbol_sets
195*f6217f89SApple OSS Distributions
196*f6217f89SApple OSS Distributionsifneq ($(INSTALL_KASAN_ONLY),1)
197*f6217f89SApple OSS Distributions
198*f6217f89SApple OSS Distributionsdo_config_install_primary:: \
199*f6217f89SApple OSS Distributions				$(DSTROOT)/$(KRESDIR)/$(MD_SUPPORTED_KPI_FILENAME)
200*f6217f89SApple OSS Distributions
201*f6217f89SApple OSS Distributionsdo_config_install:: \
202*f6217f89SApple OSS Distributions				$(SYMROOT_INSTALL_KEXT_MACHO_FILES) \
203*f6217f89SApple OSS Distributions				$(SYMROOT_INSTALL_KEXT_PLISTS) \
204*f6217f89SApple OSS Distributions				$(DSTROOT_INSTALL_KEXT_MACHO_FILES) \
205*f6217f89SApple OSS Distributions				$(DSTROOT_INSTALL_KEXT_PLISTS) \
206*f6217f89SApple OSS Distributions				$(DSTROOT)/$(KRESDIR)/$(MI_SUPPORTED_KPI_FILENAME)
207*f6217f89SApple OSS Distributionsendif
208*f6217f89SApple OSS Distributions
209*f6217f89SApple OSS Distributionselse
210*f6217f89SApple OSS Distributions# We are building XNU as a static library - avoid creating symbol sets
211*f6217f89SApple OSS Distributionsendif
212*f6217f89SApple OSS Distributions
213*f6217f89SApple OSS Distributions$(OBJPATH)/all-kpi.exp: $(EXPORTS_FILES)
214*f6217f89SApple OSS Distributions	$(_v)$(SOURCE)/generate_linker_exports.sh $@ $+ $(Kasan_EXPORTS) $(Kcov_EXPORTS)
215*f6217f89SApple OSS Distributions
216*f6217f89SApple OSS Distributions$(OBJPATH)/all-alias.exp: $(EXPORTS_FILES)
217*f6217f89SApple OSS Distributions	$(_v)$(SOURCE)/generate_linker_aliases.sh $@ $+ $(Kasan_EXPORTS) $(Kcov_EXPORTS)
218*f6217f89SApple OSS Distributions
219*f6217f89SApple OSS Distributionsdo_build_all:: $(OBJPATH)/all-kpi.exp $(OBJPATH)/all-alias.exp
220*f6217f89SApple OSS Distributions
221*f6217f89SApple OSS Distributionsinclude $(MakeInc_rule)
222*f6217f89SApple OSS Distributionsinclude $(MakeInc_dir)
223*f6217f89SApple OSS Distributions
224*f6217f89SApple OSS Distributions.PHONY: build_symbol_set_plists build_symbol_sets check_all_exports
225