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