1Product=$(shell tconf --product)
2Embedded=$(shell tconf --test TARGET_OS_EMBEDDED)
3
4ifeq "$(Embedded)" "YES"
5XILogFLAG =
6else
7XILogFLAG = -framework XILog
8endif
9
10CC=gcc $(SYSROOT)
11
12ifdef RC_BUILDIT
13DOING_BUILDIT=yes
14endif
15
16ifdef RC_OS
17DOING_BUILDIT=yes
18endif
19
20ifdef DOING_BUILDIT
21include $(MAKEFILEPATH)/CoreOS/ReleaseControl/Common.make
22MY_ARCH = $(patsubst %, -arch %, $(RC_ARCHS)) 
23install:: xnu_quick_test
24else
25	ifndef SRCROOT
26		SRCROOT=$(shell /bin/pwd)
27	endif
28	ifndef OBJROOT
29		OBJROOT=$(SRCROOT)/BUILD/obj
30	endif
31	ifndef DSTROOT
32		DSTROOT=$(SRCROOT)/BUILD/dst
33	endif
34	
35	ifndef ARCH
36		ARCH=i386 x86_64 ppc ppc64
37		# this hack should be removed once tconf gets
38		# <rdar://problem/5667139>
39		ifeq "$(Product)" "iPhone"
40		ARCH=armv6
41		endif
42		ifeq "$(Product)" "AppleTV"
43		ARCH=i386
44		endif
45	endif
46	
47	ifdef ARCH
48		MY_ARCH = $(patsubst %, -arch %, $(ARCH)) # allows building multiple archs.
49	endif
50
51	CFLAGS += $(MY_ARCH)
52endif
53
54CFLAGS += -g -I /System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/ -F/AppleInternal/Library/Frameworks/ $(MORECFLAGS)
55LIBFLAGS = -I /System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders -F/AppleInternal/Library/Frameworks/ $(XILogFLAG)
56
57#CFLAGS+= $(MY_ARCH) -g -D_POSIX_C_SOURCE=200112L
58
59MY_OBJECTS = $(OBJROOT)/main.o $(OBJROOT)/memory_tests.o $(OBJROOT)/misc.o \
60			 $(OBJROOT)/sema_tests.o $(OBJROOT)/shared_memory_tests.o \
61			 $(OBJROOT)/socket_tests.o $(OBJROOT)/tests.o $(OBJROOT)/xattr_tests.o
62
63
64xnu_quick_test : $(OBJROOT) $(DSTROOT) $(MY_OBJECTS) helpers
65	sudo rm -rf $(DSTROOT)/xnu_quick_test
66	$(CC) $(MY_ARCH) $(LIBFLAGS) -o $(DSTROOT)/xnu_quick_test $(MY_OBJECTS)
67	sudo chown root $(DSTROOT)/xnu_quick_test
68	sudo chmod 4755 $(DSTROOT)/xnu_quick_test
69
70# The helper binaries are used to test exec()'ing between 64bit and 32bit. 
71# Creates test binaries with page zero sizes = 4KB and 4GB. Also creates 32-bit
72# helper processes for the 64-bit version of xnu_quick_test to test the conversion
73# from a 32-bit process to a 64-bit process.
74helpers : helpers/sleep.c helpers/launch.c helpers/arch.c helperdir $(OBJROOT)/misc.o
75ifneq "$(Product)" "iPhone"
76	$(CC) -arch i386                              helpers/sleep.c -o $(DSTROOT)/helpers/sleep-i386
77endif
78ifeq "$(Product)" "MacOSX"
79	$(CC) -arch x86_64 -pagezero_size 0x100000000 helpers/sleep.c -o $(DSTROOT)/helpers/sleep-x86_64-4G
80	$(CC) -arch x86_64 -pagezero_size 0x1000      helpers/sleep.c -o $(DSTROOT)/helpers/sleep-x86_64-4K
81	$(CC) -arch ppc                               helpers/sleep.c -o $(DSTROOT)/helpers/sleep-ppc32
82	$(CC) -arch ppc64  -pagezero_size 0x100000000 helpers/sleep.c -o $(DSTROOT)/helpers/sleep-ppc64-4G
83	$(CC) -arch ppc64  -pagezero_size 0x1000      helpers/sleep.c -o $(DSTROOT)/helpers/sleep-ppc64-4K
84endif
85ifneq "$(Product)" "iPhone"
86	$(CC) $(LIBFLAGS) -arch i386	$(OBJROOT)/misc.o helpers/launch.c -o $(DSTROOT)/helpers/launch-i386
87endif
88ifeq "$(Product)" "MacOS"
89	$(CC) $(LIBFLAGS) -arch x86_64	$(OBJROOT)/misc.o helpers/launch.c -o $(DSTROOT)/helpers/launch-x86_64
90	$(CC) $(LIBFLAGS) -arch ppc	$(OBJROOT)/misc.o helpers/launch.c -o $(DSTROOT)/helpers/launch-ppc
91	$(CC) $(LIBFLAGS) -arch ppc64	$(OBJROOT)/misc.o helpers/launch.c -o $(DSTROOT)/helpers/launch-ppc64
92	$(CC) $(MY_ARCH) 	helpers/arch.c -o $(DSTROOT)/helpers/arch
93endif
94ifeq "$(Product)" "iPhone"
95	$(CC) -arch armv6 helpers/sleep.c -o $(DSTROOT)/helpers/sleep-arm
96	$(CC) $(LIBFLAGS) -arch armv6 $(OBJROOT)/misc.o helpers/launch.c -o $(DSTROOT)/helpers/launch-arm
97endif
98	
99	
100helperdir :
101	mkdir -p $(DSTROOT)/helpers
102
103$(OBJROOT) :
104	mkdir -p $(OBJROOT);
105	
106$(DSTROOT) :
107	mkdir -p $(DSTROOT);
108
109INCLUDES = /Developer/SDKs/Purple/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/
110
111$(OBJROOT)/main.o : main.c tests.h
112	$(CC) $(CFLAGS) -c main.c  -o $@
113	
114$(OBJROOT)/memory_tests.o : memory_tests.c tests.h
115	$(CC) $(CFLAGS) -c memory_tests.c  -o $@
116
117# misc.o has to be built 4-way for the helpers to link
118$(OBJROOT)/misc.o : misc.c tests.h
119ifeq "$(Product)" "iPhone"
120	$(CC) -arch armv6 $(CFLAGS) -c misc.c   -o $@
121else
122	$(CC) -arch i386 -arch x86_64 -arch ppc -arch ppc64 $(CFLAGS) -c misc.c   -o $@
123endif
124	
125$(OBJROOT)/sema_tests.o : sema_tests.c tests.h
126	$(CC) $(CFLAGS) -c sema_tests.c   -o $@
127	
128$(OBJROOT)/shared_memory_tests.o : shared_memory_tests.c tests.h
129	$(CC) $(CFLAGS) -c shared_memory_tests.c   -o $@
130
131$(OBJROOT)/socket_tests.o : socket_tests.c tests.h
132	$(CC) $(CFLAGS) -c socket_tests.c   -o $@
133
134$(OBJROOT)/tests.o : tests.c tests.h
135	$(CC) $(CFLAGS) -c tests.c    -o $@
136
137$(OBJROOT)/xattr_tests.o : xattr_tests.c tests.h
138	$(CC) $(CFLAGS) -c xattr_tests.c    -o $@
139
140
141ifndef DOING_BUILDIT
142.PHONY : clean
143clean :
144	sudo rm -f $(DSTROOT)/xnu_quick_test
145	sudo rm -f $(DSTROOT)/helpers/*
146	rm -f $(OBJROOT)/*.o
147endif
148