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