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