-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
429 lines (334 loc) · 14.5 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# use LDFLAGS not LFLAGS
# seg-addr-table, sect-order
#
# Simple makefile for building objc4 on Darwin
#
# These make variables (or environment variables) are used
# if defined:
# SRCROOT path location of root of source hierarchy;
# defaults to ".", but must be set to a
# destination path for installsrc target.
# OBJROOT path location where .o files will be put;
# defaults to SRCROOT.
# SYMROOT path location where build products will be
# put; defaults to SRCROOT.
# DSTROOT path location where installed products will
# be put; defaults to / .
# OBJROOT and SYMROOT should not be directories shared with other
# built projects.
# PLATFORM name of platform being built on
# USER name of user building the project
# ARCHS list of archs for which to build
# RC_ARCHS more archs for which to build (build system)
# OTHER_CFLAGS other flags to be passed to compiler
# RC_CFLAGS more flags to be passed to compiler (build system)
# OTHER_LDFLAGS other flags to be passed to the link stage
#
# Default targets
default: build
all: build
info:
$(ECHO) "info: $(shell uname) $(ARCHS) $(CC) $(CFLAGS_PROFILE) "$<" -c -o "$@" $(OBJROOT)"
.SUFFIXES:
.PHONY: default all build optimized debug profile installsrc installhdrs install clean prebuild build-optimized build-debug build-profile prebuild-optimized prevuild-debug prebuild-profile compile-optimized compile-debug compile-profile link-optimized link-debug link-profile postbuild info
CURRENT_PROJECT_VERSION = 218
VERSION_NAME = A
# First figure out the platform if not specified, so we can use it in the
# rest of this file. Currently defined values: Darwin
ifeq "$(PLATFORM)" ""
PLATFORM := $(shell uname)
endif
ifndef SRCROOT
SRCROOT = .
endif
ifndef OBJROOT
OBJROOT = $(SRCROOT)
endif
ifndef SYMROOT
SYMROOT = $(SRCROOT)
endif
ifndef DSTROOT
DSTROOT = /
endif
ifeq "$(PLATFORM)" "Darwin"
#CC = /usr/bin/cc
CC = /Applications/Xcode_4.5.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
else
CC = /usr/bin/gcc
endif
ECHO = @/bin/echo
MKDIRS = /bin/mkdir -p
CD = cd
COPY = /bin/cp
COPY_RECUR = /bin/cp -r
REMOVE = /bin/rm
REMOVE_RECUR = /bin/rm -rf
SYMLINK = /bin/ln -s
CHMOD = /bin/chmod
CHOWN = /usr/sbin/chown
TAR = /usr/bin/tar
STRIP = /usr/bin/strip
NMEDIT = /usr/bin/nmedit
ifeq "$(PLATFORM)" "Darwin"
WARNING_FLAGS = -Wmost -Wno-precomp -Wno-four-char-constants
endif
ARCH_LIST=
ifeq "$(PLATFORM)" "Darwin"
ifneq "$(ARCHS)" ""
ARCH_LIST += $(ARCHS)
else
ifneq "$(RC_ARCHS)" ""
ARCH_LIST += $(RC_ARCHS)
else
ARCH_LIST += i386
endif
endif
ARCH_FLAGS = $(foreach A, $(ARCH_LIST), $(addprefix -arch , $(A)))
endif
ifeq "$(USER)" ""
USER = unknown
endif
CFLAGS = -g -fno-common -pipe $(PLATFORM_CFLAGS) $(WARNING_FLAGS) -I$(SYMROOT) -I. -I$(SYMROOT)/ProjectHeaders
LDFLAGS = -framework CoreFoundation
LIBRARY_EXT = .dylib
PUBLIC_HEADER_INSTALLDIR = usr/include/objc
OTHER_HEADER_INSTALLDIR = usr/local/include/objc
INSTALLDIR = usr/lib
ifeq "$(PLATFORM)" "Darwin"
CFLAGS += $(ARCH_FLAGS)
LDFLAGS += $(ARCH_FLAGS) -dynamiclib -dynamic -compatibility_version 1 -current_version $(CURRENT_PROJECT_VERSION)
endif
CFLAGS += $(OTHER_CFLAGS) $(RC_CFLAGS)
LDFLAGS += $(OTHER_LDFLAGS)
ifndef OPTIMIZATION_CFLAGS
OPTIMIZATION_CFLAGS = -Os
endif
ifndef DEBUG_CFLAGS
DEBUG_CFLAGS = -DDEBUG
endif
ifndef PROFILE_CFLAGS
PROFILE_CFLAGS = -DPROFILE -pg -Os
endif
CFLAGS_OPTIMIZED = $(CFLAGS) $(OPTIMIZATION_CFLAGS)
CFLAGS_DEBUG = $(CFLAGS) $(DEBUG_CFLAGS)
CFLAGS_PROFILE = $(CFLAGS) $(PROFILE_CFLAGS)
LDFLAGS_OPTIMIZED = $(LDFLAGS)
LDFLAGS_DEBUG = $(LDFLAGS) -g
LDFLAGS_PROFILE = $(LDFLAGS) -g -pg
SUBDIRS = . runtime runtime/OldClasses.subproj runtime/Messengers.subproj
# files to compile
SOURCES=
# files to not compile
OTHER_SOURCES=
# headers to install in /usr/include/objc
PUBLIC_HEADERS=
# headers that don't get installed
PRIVATE_HEADERS=
# headers to install in /usr/local/include/objc
OTHER_HEADERS=
# runtime
SOURCES += $(addprefix runtime/, \
Object.m Protocol.m hashtable2.m maptable.m objc-class.m objc-errors.m \
objc-file.m objc-load.m objc-moninit.c objc-runtime.m objc-sel.m \
)
PUBLIC_HEADERS += $(addprefix runtime/, \
objc-class.h objc-api.h objc-load.h objc-runtime.h objc.h Object.h \
Protocol.h error.h hashtable2.h \
)
PRIVATE_HEADERS += runtime/objc-private.h runtime/objc-config.h
OTHER_HEADERS += runtime/maptable.h
# OldClasses
SOURCES += runtime/OldClasses.subproj/List.m
PUBLIC_HEADERS += runtime/OldClasses.subproj/List.h
# Messengers
SOURCES += runtime/Messengers.subproj/objc-msg.s
OTHER_SOURCES += runtime/Messengers.subproj/objc-msg-ppc.s runtime/Messengers.subproj/objc-msg-i386.s
# project root
OTHER_SOURCES += Makefile APPLE_LICENSE objc-exports
OBJECTS = $(addprefix $(OBJROOT)/, $(addsuffix .o, $(basename $(SOURCES) ) ) )
OBJECTS_OPTIMIZED = $(OBJECTS:.o=.opt.o)
OBJECTS_DEBUG = $(OBJECTS:.o=.debug.o)
OBJECTS_PROFILE = $(OBJECTS:.o=.profile.o)
# For simplicity, each object target depends on all objc headers. Most of
# them come close to requiring this anyway, and rebuild from scratch is fast.
DEPEND_HEADERS = $(addprefix $(SRCROOT)/, \
$(PUBLIC_HEADERS) $(PRIVATE_HEADERS) $(OTHER_HEADERS) )
$(OBJROOT)/%.opt.o : $(SRCROOT)/%.m $(DEPEND_HEADERS)
$(SILENT) $(ECHO) " ... $<"
$(SILENT) $(CC) $(CFLAGS_OPTIMIZED) "$<" -c -o "$@"
$(OBJROOT)/%.debug.o : $(SRCROOT)/%.m $(DEPEND_HEADERS)
$(SILENT) $(ECHO) " ... $<"
$(SILENT) $(CC) $(CFLAGS_DEBUG) "$<" -c -o "$@"
$(OBJROOT)/%.profile.o : $(SRCROOT)/%.m $(DEPEND_HEADERS)
$(SILENT) $(ECHO) " ... $<"
$(SILENT) $(CC) $(CFLAGS_PROFILE) "$<" -c -o "$@"
$(OBJROOT)/%.opt.o : $(SRCROOT)/%.c $(DEPEND_HEADERS)
$(SILENT) $(ECHO) " ... $<"
$(SILENT) $(CC) $(CFLAGS_OPTIMIZED) "$<" -c -o "$@"
$(OBJROOT)/%.debug.o : $(SRCROOT)/%.c $(DEPEND_HEADERS)
$(SILENT) $(ECHO) " ... $<"
$(SILENT) $(CC) $(CFLAGS_DEBUG) "$<" -c -o "$@"
$(OBJROOT)/%.profile.o : $(SRCROOT)/%.c $(DEPEND_HEADERS)
$(SILENT) $(ECHO) " ... $<"
$(SILENT) $(CC) $(CFLAGS_PROFILE) "$<" -c -o "$@"
$(OBJROOT)/%.opt.o : $(SRCROOT)/%.s $(DEPEND_HEADERS)
$(SILENT) $(ECHO) " ... $<"
$(SILENT) $(CC) $(CFLAGS_OPTIMIZED) "$<" -c -o "$@"
$(OBJROOT)/%.debug.o : $(SRCROOT)/%.s $(DEPEND_HEADERS)
$(SILENT) $(ECHO) " ... $<"
$(SILENT) $(CC) $(CFLAGS_DEBUG) "$<" -c -o "$@"
$(OBJROOT)/%.profile.o : $(SRCROOT)/%.s $(DEPEND_HEADERS)
$(SILENT) $(ECHO) " ... $<"
$(SILENT) $(CC) $(CFLAGS_PROFILE) "$<" -c -o "$@"
# Additional dependency: objc-msg.s depends on objc-msg-ppc.s and
# objc-msg-i386.s, which it includes.
$(OBJROOT)/runtime/Messengers.subproj/objc-msg.opt.o \
$(OBJROOT)/runtime/Messengers.subproj/objc-msg.debug.o \
$(OBJROOT)/runtime/Messengers.subproj/objc-msg.profile.o : \
$(SRCROOT)/runtime/Messengers.subproj/objc-msg-ppc.s \
$(SRCROOT)/runtime/Messengers.subproj/objc-msg-i386.s
# These are the main targets:
# build builds the library to OBJROOT and SYMROOT
# installsrc copies the sources to SRCROOT
# installhdrs install only the headers to DSTROOT
# install build, then install the headers and library to DSTROOT
# clean removes build products in OBJROOT and SYMROOT
#
# optimized same as 'build' but builds optimized library only
# debug same as 'build' but builds debug library only
# profile same as 'build' but builds profile library only
# Default build doesn't currently build the debug library.
build: prebuild build-optimized build-profile postbuild
optimized: prebuild build-optimized postbuild
debug: prebuild build-debug postbuild
profile: prebuild build-profile postbuild
installsrc:
$(SILENT) $(ECHO) "Installing source from . to $(SRCROOT)..."
ifeq "$(SRCROOT)" "."
$(SILENT) $(ECHO) "SRCROOT must be defined to be the destination directory; it cannot be '.'"
exit 1
endif
$(SILENT) $(TAR) -cf $(SRCROOT)/objc4.sources.tar $(SOURCES) $(PUBLIC_HEADERS) $(PRIVATE_HEADERS) $(OTHER_HEADERS) $(OTHER_SOURCES)
$(SILENT) $(CD) $(SRCROOT) && $(TAR) -xf $(SRCROOT)/objc4.sources.tar
$(SILENT) $(REMOVE) -f $(SRCROOT)/objc4.sources.tar
installhdrs:
$(SILENT) $(ECHO) "Installing headers from $(SRCROOT) to $(DSTROOT)/$(HEADER_INSTALLDIR)..."
$(SILENT) $(MKDIRS) $(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)
-$(SILENT) $(CHMOD) +w $(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)/*.h
$(SILENT) $(COPY) $(addprefix $(SRCROOT)/, $(PUBLIC_HEADERS) ) \
$(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)
# duplicate hashtable2.h to hashtable.h
$(SILENT) $(COPY) $(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)/hashtable2.h \
$(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)/hashtable.h
$(SILENT) $(CHMOD) -w $(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)/*.h
$(SILENT) $(CHMOD) a+r $(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)/*.h
$(SILENT) $(MKDIRS) $(DSTROOT)/$(OTHER_HEADER_INSTALLDIR)
-$(SILENT) $(CHMOD) +w $(DSTROOT)/$(OTHER_HEADER_INSTALLDIR)/*.h
$(SILENT) $(COPY) $(addprefix $(SRCROOT)/, $(OTHER_HEADERS) ) \
$(DSTROOT)/$(OTHER_HEADER_INSTALLDIR)
$(SILENT) $(CHMOD) -w $(DSTROOT)/$(OTHER_HEADER_INSTALLDIR)/*.h
$(SILENT) $(CHMOD) a+r $(DSTROOT)/$(OTHER_HEADER_INSTALLDIR)/*.h
$(SILENT) $(RM) -f $(DSTROOT)$(PUBLIC_HEADER_DIR)$(PUBLIC_HEADER_DIR_SUFFIX)/hashtable.h
install: build installhdrs
$(SILENT) $(ECHO) "Installing products from $(SYMROOT) to $(DSTROOT)..."
$(SILENT) $(MKDIRS) $(DSTROOT)/$(INSTALLDIR)
-$(SILENT) $(CHMOD) +w $(DSTROOT)/$(INSTALLDIR)
$(SILENT) $(REMOVE) -f $(DSTROOT)/$(INSTALLDIR)/libobjc.$(VERSION_NAME)$(LIBRARY_EXT)
$(SILENT) $(REMOVE) -f $(DSTROOT)/$(INSTALLDIR)/libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT)
$(SILENT) $(REMOVE) -f $(DSTROOT)/$(INSTALLDIR)/libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT)
# optimized
$(SILENT) $(COPY) $(SYMROOT)/libobjc.$(VERSION_NAME)$(LIBRARY_EXT) $(DSTROOT)/$(INSTALLDIR)
-$(SILENT) $(CHOWN) root:wheel $(DSTROOT)/$(INSTALLDIR)/libobjc.$(VERSION_NAME)$(LIBRARY_EXT)
$(SILENT) $(CHMOD) 755 $(DSTROOT)/$(INSTALLDIR)/libobjc.$(VERSION_NAME)$(LIBRARY_EXT)
$(SILENT) $(CD) $(DSTROOT)/$(INSTALLDIR) && \
$(SYMLINK) libobjc.$(VERSION_NAME)$(LIBRARY_EXT) libobjc$(LIBRARY_EXT)
# debug (allowed not to exist)
-$(SILENT) $(COPY) $(SYMROOT)/libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT) $(DSTROOT)/$(INSTALLDIR)
-$(SILENT) $(CHOWN) root:wheel $(DSTROOT)/$(INSTALLDIR)/libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT)
-$(SILENT) $(CHMOD) 755 $(DSTROOT)/$(INSTALLDIR)/libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT)
-$(SILENT) $(CD) $(DSTROOT)/$(INSTALLDIR) && \
test -e libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT) && \
$(SYMLINK) libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT) libobjc_debug$(LIBRARY_EXT) && \
$(SYMLINK) libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT) libobjc.$(VERSION_NAME)_debug$(LIBRARY_EXT)
# profile (allowed not to exist)
-$(SILENT) $(COPY) $(SYMROOT)/libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT) $(DSTROOT)/$(INSTALLDIR)
-$(SILENT) $(CHOWN) root:wheel $(DSTROOT)/$(INSTALLDIR)/libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT)
-$(SILENT) $(CHMOD) 755 $(DSTROOT)/$(INSTALLDIR)/libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT)
-$(SILENT) $(CD) $(DSTROOT)/$(INSTALLDIR) && \
test -e libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT) && \
$(SYMLINK) libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT) libobjc_profile$(LIBRARY_EXT) && \
$(SYMLINK) libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT) libobjc.$(VERSION_NAME)_profile$(LIBRARY_EXT)
clean:
$(SILENT) $(ECHO) "Deleting build products..."
$(foreach A, $(ARCH_LIST), \
$(SILENT) $(REMOVE) -f $(OBJROOT)/libobjc_debug.$A.o $(OBJROOT)/libobjc_profile.$A.o $(OBJROOT)/libobjc.$A.o ; )
$(SILENT) $(REMOVE) -f $(SYMROOT)/libobjc.optimized.o
$(SILENT) $(REMOVE) -f $(SYMROOT)/libobjc.debug.o
$(SILENT) $(REMOVE) -f $(SYMROOT)/libobjc.profile.o
$(SILENT) $(REMOVE) -f $(SYMROOT)/libobjc.$(VERSION_NAME)$(LIBRARY_EXT)
$(SILENT) $(REMOVE) -f $(SYMROOT)/libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT)
$(SILENT) $(REMOVE) -f $(SYMROOT)/libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT)
$(SILENT) $(REMOVE) -f $(OBJECTS_OPTIMIZED)
$(SILENT) $(REMOVE) -f $(OBJECTS_DEBUG)
$(SILENT) $(REMOVE) -f $(OBJECTS_PROFILE)
$(SILENT) $(REMOVE) -rf $(SYMROOT)/ProjectHeaders
prebuild:
$(SILENT) $(ECHO) "Prebuild-setup..."
# Install headers into $(SYMROOT)/ProjectHeaders so #includes can find them
# even if they're not installed in /usr.
$(SILENT) $(MKDIRS) $(SYMROOT)
$(SILENT) $(REMOVE_RECUR) $(SYMROOT)/ProjectHeaders
$(SILENT) $(MKDIRS) $(SYMROOT)/ProjectHeaders
$(SILENT) $(ECHO) "Copying headers from $(SRCROOT) to $(SYMROOT)/ProjectHeaders..."
$(SILENT) $(COPY) $(addprefix $(SRCROOT)/, $(PRIVATE_HEADERS) ) $(SYMROOT)/ProjectHeaders
$(SILENT) $(MKDIRS) $(SYMROOT)/ProjectHeaders/objc
$(SILENT) $(COPY) $(addprefix $(SRCROOT)/, $(PUBLIC_HEADERS) ) $(SYMROOT)/ProjectHeaders/objc
$(SILENT) $(COPY) $(addprefix $(SRCROOT)/, $(OTHER_HEADERS) ) $(SYMROOT)/ProjectHeaders/objc
build-optimized: prebuild-optimized compile-optimized link-optimized
build-debug: prebuild-debug compile-debug link-debug
build-profile: prebuild-profile compile-profile link-profile
prebuild-optimized:
$(SILENT) $(ECHO) "Building (optimized) ..."
$(SILENT) $(MKDIRS) $(foreach S, $(SUBDIRS), $(OBJROOT)/$(S) )
prebuild-debug:
$(SILENT) $(ECHO) "Building (debug) ..."
$(SILENT) $(MKDIRS) $(foreach S, $(SUBDIRS), $(OBJROOT)/$(S) )
prebuild-profile:
$(SILENT) $(ECHO) "Building (profile) ..."
$(SILENT) $(MKDIRS) $(foreach S, $(SUBDIRS), $(OBJROOT)/$(S) )
compile-optimized: $(OBJECTS_OPTIMIZED)
compile-debug: $(OBJECTS_DEBUG)
compile-profile: $(OBJECTS_PROFILE)
# link lib-suffix, LDFLAGS, OBJECTS
# libsuffix should be "" or _debug or _profile
ifeq "$(PLATFORM)" "Darwin"
define link
$(foreach A, $(ARCH_LIST), \
$(SILENT) $(LD) -arch $A -r -o $(OBJROOT)/libobjc$1.$A.o $3 ; )
$(foreach A, $(ARCH_LIST), \
-$(SILENT) $(NMEDIT) -s $(SRCROOT)/objc-exports \
$(OBJROOT)/libobjc$1.$A.o ; )
$(SILENT) $(CC) $2 \
-Wl,-init,__objcInit \
-install_name /$(INSTALLDIR)/libobjc$1.$(VERSION_NAME)$(LIBRARY_EXT) \
-o $(SYMROOT)/libobjc$1.$(VERSION_NAME)$(LIBRARY_EXT) \
$(foreach A, $(ARCH_LIST), $(OBJROOT)/libobjc$1.$A.o )
endef
else
# PLATFORM != Darwin
define link
$(SILENT) $(ECHO) "Don't know how to link for platform '$(PLATFORM)'"
endef
endif
link-optimized:
$(SILENT) $(ECHO) "Linking (optimized)..."
$(call link,,$(LDFLAGS_OPTIMIZED),$(OBJECTS_OPTIMIZED) )
$(SILENT) $(STRIP) -x $(SYMROOT)/libobjc.$(VERSION_NAME)$(LIBRARY_EXT)
link-debug:
$(SILENT) $(ECHO) "Linking (debug)..."
$(call link,_debug,$(LDFLAGS_DEBUG),$(OBJECTS_DEBUG) )
link-profile:
$(SILENT) $(ECHO) "Linking (profile)..."
$(call link,_profile,$(LDFLAGS_PROFILE),$(OBJECTS_PROFILE))
postbuild:
$(SILENT) $(ECHO) "Done!"