1 PROJECT := xnu/darwintests
4 override DSTROOT = $(BASEDSTROOT)
9 OTHER_LTE_INCLUDE_FILES += \
10 /System/Library/PrivateFrameworks/LoggingSupport.framework, \
11 /System/Library/PrivateFrameworks/MobileKeyBag.framework, \
12 /System/Library/Frameworks/IOSurface.framework, \
13 /usr/local/lib/libdarwintest_utils.dylib, \
14 /usr/lib/libapple_crypto.dylib,
16 DEVELOPER_DIR ?= $(shell xcode-select -p)
18 # the xnu build system will only ever call us with the default target
19 .DEFAULT_GOAL := install
21 SDKROOT ?= driverkit.internal
23 include $(DEVELOPER_DIR)/AppleInternal/Makefiles/darwintest/Makefile.common
25 DRIVERKIT_DIR := $(TARGETSDK)/System/DriverKit
26 DRIVERKIT_TARGET := x86_64-apple-driverkit$(shell xcrun --sdk driverkit.internal --show-sdk-version)
28 IIG := $(shell xcrun --sdk "$(SDKROOT)" -f iig)
30 # Enumerate all directories in this folder, excluding the "build" directory
31 DEXT_SRCS = $(filter-out build,$(shell find . -type d -depth 1 | sed -e "s:./::g"))
33 # hack: reuse the default CXXFLAGS and LDFLAGS but remove -mmacosx-version-min and -arch. Also adds a few other required flags
34 # These are used for both iig and clang
35 DEXT_SHARED_CXXFLAGS := $(filter-out -mmacosx-version-min=%, $(shell echo $(CXXFLAGS) $(OTHER_CXXFLAGS) | sed -e "s/-arch [a-zA-Z0-9_]*//g")) -isystem$(DRIVERKIT_DIR)/usr/include -iframework$(DRIVERKIT_DIR)/System/Library/Frameworks -std=gnu++14
37 # These are used just for clang
38 DEXT_CXXFLAGS := $(DEXT_SHARED_CXXFLAGS) -target $(DRIVERKIT_TARGET)
40 # These are used just for iig
41 IIGFLAGS := -- $(DEXT_SHARED_CXXFLAGS) -D__IIG=1 -x c++
43 # Used just for clang. LDFLAGS are not needed for iig
44 DEXT_LDFLAGS := $(filter-out -mmacosx-version-min=%, $(shell echo $(LDFLAGS) $(OTHER_LDFLAGS) | sed -e "s/-arch [a-zA-Z0-9_]*//g")) -target $(DRIVERKIT_TARGET) -L$(DRIVERKIT_DIR)/usr/lib -F$(DRIVERKIT_DIR)/System/Library/Frameworks -framework DriverKit
47 # This generates rules to create dexts from each directory specified in DEXT_SRCS
48 define GENERATE_DEXT_RULE
49 ## Given the following directory structure:
52 ## test_driver_123.entitlements
53 ## [cpp and iig files]
54 ## This produces a dext called com.apple.test_driver_123.dext:
55 ## com.apple.test_driver_123.dext/
56 ## com.apple.test_driver_123 [dext executable]
60 CUSTOM_TARGETS += com.apple.$1.dext
62 com.apple.$1.dext : $(patsubst $1/%.cpp,$(OBJROOT)/$1/%.o,$(wildcard $1/*.cpp)) $(patsubst $1/%.iig,$(OBJROOT)/$1/DerivedSources/%.iig.o,$(wildcard $1/*.iig))
63 # Create bundle directory
64 mkdir -p $(SYMROOT)/$$@
66 $(CXX) $(DEXT_LDFLAGS) $$^ -o $(SYMROOT)/$$@/com.apple.$1
67 # Copy Info.plist and sign
68 cp $1/Info.plist $(SYMROOT)/$$@
69 codesign -vvv --force --sign - --entitlements $1/$1.entitlements --timestamp=none $(SYMROOT)/$$@
71 install-com.apple.$1.dext: com.apple.$1.dext
72 mkdir -p $(INSTALLDIR)
73 cp -R $(SYMROOT)/com.apple.$1.dext $(INSTALLDIR)
75 $(OBJROOT)/$1/DerivedSources/%.iig.o: $(OBJROOT)/$1/DerivedSources/%.iig.cpp
76 mkdir -p $(OBJROOT)/$1/DerivedSources
77 # Compile *.iig.cpp to object file
78 $(CXX) $(DEXT_CXXFLAGS) -I$1/ -I$(OBJROOT)/$1/DerivedSources -c $$^ -o $$@
80 $(OBJROOT)/$1/DerivedSources/%.iig.cpp: $1/%.iig
81 mkdir -p $(OBJROOT)/$1/DerivedSources
82 # Generate *.iig.cpp and *.h header files from *.iig
83 $(IIG) --def $$^ --impl $$@ --header $$(patsubst %.iig.cpp,%.h,$$@) $(IIGFLAGS)
85 # Tell make not to delete the intermediate *.iig.cpp file since it is useful for debugging
86 .PRECIOUS :: $(OBJROOT)/$1/DerivedSources/%.iig.cpp
88 $(OBJROOT)/$1/%.o: $1/%.cpp $(patsubst $1/%.iig,$(OBJROOT)/$1/DerivedSources/%.iig.o,$(wildcard $1/*.iig))
89 # Compile c++ file. The additional dependency is for headers emitted by iig
90 $(CXX) $(DEXT_CXXFLAGS) -I$1/ -I$(OBJROOT)/$1/DerivedSources -c $$< -o $$@
94 ifeq ($(PLATFORM),MacOSX)
95 $(foreach DEXTSRCDIR,$(DEXT_SRCS),$(eval $(call GENERATE_DEXT_RULE,$(DEXTSRCDIR))))
97 EXCLUDED_SOURCES += $(DEXT_SRCS)
100 include $(DEVELOPER_DIR)/AppleInternal/Makefiles/darwintest/Makefile.targets