1 # use LDFLAGS not LFLAGS
2 # seg-addr-table, sect-order
4 # Simple makefile for building objc4 on Darwin
6 # These make variables (or environment variables) are used
8 # SRCROOT path location of root of source hierarchy;
9 # defaults to ".", but must be set to a
10 # destination path for installsrc target.
11 # OBJROOT path location where .o files will be put;
12 # defaults to SRCROOT.
13 # SYMROOT path location where build products will be
14 # put; defaults to SRCROOT.
15 # DSTROOT path location where installed products will
16 # be put; defaults to / .
17 # OBJROOT and SYMROOT should not be directories shared with other
19 # PLATFORM name of platform being built on
20 # USER name of user building the project
21 # ARCHS list of archs for which to build
22 # RC_ARCHS more archs for which to build (build system)
23 # OTHER_CFLAGS other flags to be passed to compiler
24 # RC_CFLAGS more flags to be passed to compiler (build system)
25 # OTHER_LDFLAGS other flags to be passed to the link stage
33 .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
35 CURRENT_PROJECT_VERSION = 218
39 # First figure out the platform if not specified, so we can use it in the
40 # rest of this file. Currently defined values: Darwin
42 PLATFORM := $(shell uname)
61 ifeq "$(PLATFORM)" "Darwin"
68 MKDIRS = /bin/mkdir -p
71 COPY_RECUR = /bin/cp -r
73 REMOVE_RECUR = /bin/rm -rf
76 CHOWN = /usr/sbin/chown
78 STRIP = /usr/bin/strip
79 NMEDIT = /usr/bin/nmedit
81 ifeq "$(PLATFORM)" "Darwin"
82 WARNING_FLAGS = -Wmost -Wno-precomp -Wno-four-char-constants
86 ifeq "$(PLATFORM)" "Darwin"
91 ifneq "$(RC_ARCHS)" ""
92 ARCH_LIST += $(RC_ARCHS)
98 ARCH_FLAGS = $(foreach A, $(ARCH_LIST), $(addprefix -arch , $(A)))
108 CFLAGS = -g -fno-common -pipe $(PLATFORM_CFLAGS) $(WARNING_FLAGS) -I$(SYMROOT) -I. -I$(SYMROOT)/ProjectHeaders
109 LDFLAGS = -framework CoreFoundation
113 PUBLIC_HEADER_INSTALLDIR = usr/include/objc
114 OTHER_HEADER_INSTALLDIR = usr/local/include/objc
117 ifeq "$(PLATFORM)" "Darwin"
118 CFLAGS += $(ARCH_FLAGS)
119 LDFLAGS += $(ARCH_FLAGS) -dynamiclib -dynamic -compatibility_version 1 -current_version $(CURRENT_PROJECT_VERSION)
122 CFLAGS += $(OTHER_CFLAGS) $(RC_CFLAGS)
123 LDFLAGS += $(OTHER_LDFLAGS)
125 ifndef OPTIMIZATION_CFLAGS
126 OPTIMIZATION_CFLAGS = -Os
129 DEBUG_CFLAGS = -DDEBUG
131 ifndef PROFILE_CFLAGS
132 PROFILE_CFLAGS = -DPROFILE -pg -Os
135 CFLAGS_OPTIMIZED = $(CFLAGS) $(OPTIMIZATION_CFLAGS)
136 CFLAGS_DEBUG = $(CFLAGS) $(DEBUG_CFLAGS)
137 CFLAGS_PROFILE = $(CFLAGS) $(PROFILE_CFLAGS)
139 LDFLAGS_OPTIMIZED = $(LDFLAGS)
140 LDFLAGS_DEBUG = $(LDFLAGS) -g
141 LDFLAGS_PROFILE = $(LDFLAGS) -g -pg
143 SUBDIRS = . runtime runtime/OldClasses.subproj runtime/Messengers.subproj
147 # files to not compile
149 # headers to install in /usr/include/objc
151 # headers that don't get installed
153 # headers to install in /usr/local/include/objc
157 SOURCES += $(addprefix runtime/, \
158 Object.m Protocol.m hashtable2.m maptable.m objc-class.m objc-errors.m \
159 objc-file.m objc-load.m objc-moninit.c objc-runtime.m objc-sel.m \
161 PUBLIC_HEADERS += $(addprefix runtime/, \
162 objc-class.h objc-api.h objc-load.h objc-runtime.h objc.h Object.h \
163 Protocol.h error.h hashtable2.h \
165 PRIVATE_HEADERS += runtime/objc-private.h runtime/objc-config.h
166 OTHER_HEADERS += runtime/maptable.h
169 SOURCES += runtime/OldClasses.subproj/List.m
170 PUBLIC_HEADERS += runtime/OldClasses.subproj/List.h
173 SOURCES += runtime/Messengers.subproj/objc-msg.s
174 OTHER_SOURCES += runtime/Messengers.subproj/objc-msg-ppc.s runtime/Messengers.subproj/objc-msg-i386.s
177 OTHER_SOURCES += Makefile APPLE_LICENSE objc-exports
179 OBJECTS = $(addprefix $(OBJROOT)/, $(addsuffix .o, $(basename $(SOURCES) ) ) )
180 OBJECTS_OPTIMIZED = $(OBJECTS:.o=.opt.o)
181 OBJECTS_DEBUG = $(OBJECTS:.o=.debug.o)
182 OBJECTS_PROFILE = $(OBJECTS:.o=.profile.o)
184 # For simplicity, each object target depends on all objc headers. Most of
185 # them come close to requiring this anyway, and rebuild from scratch is fast.
186 DEPEND_HEADERS = $(addprefix $(SRCROOT)/, \
187 $(PUBLIC_HEADERS) $(PRIVATE_HEADERS) $(OTHER_HEADERS) )
189 $(OBJROOT)/%.opt.o : $(SRCROOT)/%.m $(DEPEND_HEADERS)
190 $(SILENT) $(ECHO) " ... $<"
191 $(SILENT) $(CC) $(CFLAGS_OPTIMIZED) "$<" -c -o "$@"
193 $(OBJROOT)/%.debug.o : $(SRCROOT)/%.m $(DEPEND_HEADERS)
194 $(SILENT) $(ECHO) " ... $<"
195 $(SILENT) $(CC) $(CFLAGS_DEBUG) "$<" -c -o "$@"
197 $(OBJROOT)/%.profile.o : $(SRCROOT)/%.m $(DEPEND_HEADERS)
198 $(SILENT) $(ECHO) " ... $<"
199 $(SILENT) $(CC) $(CFLAGS_PROFILE) "$<" -c -o "$@"
201 $(OBJROOT)/%.opt.o : $(SRCROOT)/%.c $(DEPEND_HEADERS)
202 $(SILENT) $(ECHO) " ... $<"
203 $(SILENT) $(CC) $(CFLAGS_OPTIMIZED) "$<" -c -o "$@"
205 $(OBJROOT)/%.debug.o : $(SRCROOT)/%.c $(DEPEND_HEADERS)
206 $(SILENT) $(ECHO) " ... $<"
207 $(SILENT) $(CC) $(CFLAGS_DEBUG) "$<" -c -o "$@"
209 $(OBJROOT)/%.profile.o : $(SRCROOT)/%.c $(DEPEND_HEADERS)
210 $(SILENT) $(ECHO) " ... $<"
211 $(SILENT) $(CC) $(CFLAGS_PROFILE) "$<" -c -o "$@"
213 $(OBJROOT)/%.opt.o : $(SRCROOT)/%.s $(DEPEND_HEADERS)
214 $(SILENT) $(ECHO) " ... $<"
215 $(SILENT) $(CC) $(CFLAGS_OPTIMIZED) "$<" -c -o "$@"
217 $(OBJROOT)/%.debug.o : $(SRCROOT)/%.s $(DEPEND_HEADERS)
218 $(SILENT) $(ECHO) " ... $<"
219 $(SILENT) $(CC) $(CFLAGS_DEBUG) "$<" -c -o "$@"
221 $(OBJROOT)/%.profile.o : $(SRCROOT)/%.s $(DEPEND_HEADERS)
222 $(SILENT) $(ECHO) " ... $<"
223 $(SILENT) $(CC) $(CFLAGS_PROFILE) "$<" -c -o "$@"
225 # Additional dependency: objc-msg.s depends on objc-msg-ppc.s and
226 # objc-msg-i386.s, which it includes.
227 $(OBJROOT)/runtime/Messengers.subproj/objc-msg.opt.o \
228 $(OBJROOT)/runtime/Messengers.subproj/objc-msg.debug.o \
229 $(OBJROOT)/runtime/Messengers.subproj/objc-msg.profile.o : \
230 $(SRCROOT)/runtime/Messengers.subproj/objc-msg-ppc.s \
231 $(SRCROOT)/runtime/Messengers.subproj/objc-msg-i386.s
234 # These are the main targets:
235 # build builds the library to OBJROOT and SYMROOT
236 # installsrc copies the sources to SRCROOT
237 # installhdrs install only the headers to DSTROOT
238 # install build, then install the headers and library to DSTROOT
239 # clean removes build products in OBJROOT and SYMROOT
241 # optimized same as 'build' but builds optimized library only
242 # debug same as 'build' but builds debug library only
243 # profile same as 'build' but builds profile library only
245 # Default build doesn't currently build the debug library.
246 build: prebuild build-optimized build-profile postbuild
248 optimized: prebuild build-optimized postbuild
249 debug: prebuild build-debug postbuild
250 profile: prebuild build-profile postbuild
253 $(SILENT) $(ECHO) "Installing source from . to $(SRCROOT)..."
254 ifeq "$(SRCROOT)" "."
255 $(SILENT) $(ECHO) "SRCROOT must be defined to be the destination directory; it cannot be '.'"
258 $(SILENT) $(TAR) -cf $(SRCROOT)/objc4.sources.tar $(SOURCES) $(PUBLIC_HEADERS) $(PRIVATE_HEADERS) $(OTHER_HEADERS) $(OTHER_SOURCES)
259 $(SILENT) $(CD) $(SRCROOT) && $(TAR) -xf $(SRCROOT)/objc4.sources.tar
260 $(SILENT) $(REMOVE) -f $(SRCROOT)/objc4.sources.tar
263 $(SILENT) $(ECHO) "Installing headers from $(SRCROOT) to $(DSTROOT)/$(HEADER_INSTALLDIR)..."
265 $(SILENT) $(MKDIRS) $(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)
266 -$(SILENT) $(CHMOD) +w $(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)/*.h
267 $(SILENT) $(COPY) $(addprefix $(SRCROOT)/, $(PUBLIC_HEADERS) ) \
268 $(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)
269 # duplicate hashtable2.h to hashtable.h
270 $(SILENT) $(COPY) $(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)/hashtable2.h \
271 $(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)/hashtable.h
272 $(SILENT) $(CHMOD) -w $(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)/*.h
273 $(SILENT) $(CHMOD) a+r $(DSTROOT)/$(PUBLIC_HEADER_INSTALLDIR)/*.h
275 $(SILENT) $(MKDIRS) $(DSTROOT)/$(OTHER_HEADER_INSTALLDIR)
276 -$(SILENT) $(CHMOD) +w $(DSTROOT)/$(OTHER_HEADER_INSTALLDIR)/*.h
277 $(SILENT) $(COPY) $(addprefix $(SRCROOT)/, $(OTHER_HEADERS) ) \
278 $(DSTROOT)/$(OTHER_HEADER_INSTALLDIR)
279 $(SILENT) $(CHMOD) -w $(DSTROOT)/$(OTHER_HEADER_INSTALLDIR)/*.h
280 $(SILENT) $(CHMOD) a+r $(DSTROOT)/$(OTHER_HEADER_INSTALLDIR)/*.h
283 $(SILENT) $(RM) -f $(DSTROOT)$(PUBLIC_HEADER_DIR)$(PUBLIC_HEADER_DIR_SUFFIX)/hashtable.h
286 install: build installhdrs
287 $(SILENT) $(ECHO) "Installing products from $(SYMROOT) to $(DSTROOT)..."
289 $(SILENT) $(MKDIRS) $(DSTROOT)/$(INSTALLDIR)
290 -$(SILENT) $(CHMOD) +w $(DSTROOT)/$(INSTALLDIR)
292 $(SILENT) $(REMOVE) -f $(DSTROOT)/$(INSTALLDIR)/libobjc.$(VERSION_NAME)$(LIBRARY_EXT)
293 $(SILENT) $(REMOVE) -f $(DSTROOT)/$(INSTALLDIR)/libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT)
294 $(SILENT) $(REMOVE) -f $(DSTROOT)/$(INSTALLDIR)/libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT)
297 $(SILENT) $(COPY) $(SYMROOT)/libobjc.$(VERSION_NAME)$(LIBRARY_EXT) $(DSTROOT)/$(INSTALLDIR)
298 -$(SILENT) $(CHOWN) root:wheel $(DSTROOT)/$(INSTALLDIR)/libobjc.$(VERSION_NAME)$(LIBRARY_EXT)
299 $(SILENT) $(CHMOD) 755 $(DSTROOT)/$(INSTALLDIR)/libobjc.$(VERSION_NAME)$(LIBRARY_EXT)
300 $(SILENT) $(CD) $(DSTROOT)/$(INSTALLDIR) && \
301 $(SYMLINK) libobjc.$(VERSION_NAME)$(LIBRARY_EXT) libobjc$(LIBRARY_EXT)
303 # debug (allowed not to exist)
304 -$(SILENT) $(COPY) $(SYMROOT)/libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT) $(DSTROOT)/$(INSTALLDIR)
305 -$(SILENT) $(CHOWN) root:wheel $(DSTROOT)/$(INSTALLDIR)/libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT)
306 -$(SILENT) $(CHMOD) 755 $(DSTROOT)/$(INSTALLDIR)/libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT)
307 -$(SILENT) $(CD) $(DSTROOT)/$(INSTALLDIR) && \
308 test -e libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT) && \
309 $(SYMLINK) libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT) libobjc_debug$(LIBRARY_EXT) && \
310 $(SYMLINK) libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT) libobjc.$(VERSION_NAME)_debug$(LIBRARY_EXT)
313 # profile (allowed not to exist)
314 -$(SILENT) $(COPY) $(SYMROOT)/libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT) $(DSTROOT)/$(INSTALLDIR)
315 -$(SILENT) $(CHOWN) root:wheel $(DSTROOT)/$(INSTALLDIR)/libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT)
316 -$(SILENT) $(CHMOD) 755 $(DSTROOT)/$(INSTALLDIR)/libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT)
317 -$(SILENT) $(CD) $(DSTROOT)/$(INSTALLDIR) && \
318 test -e libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT) && \
319 $(SYMLINK) libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT) libobjc_profile$(LIBRARY_EXT) && \
320 $(SYMLINK) libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT) libobjc.$(VERSION_NAME)_profile$(LIBRARY_EXT)
324 $(SILENT) $(ECHO) "Deleting build products..."
325 $(foreach A, $(ARCH_LIST), \
326 $(SILENT) $(REMOVE) -f $(OBJROOT)/libobjc_debug.$A.o $(OBJROOT)/libobjc_profile.$A.o $(OBJROOT)/libobjc.$A.o ; )
328 $(SILENT) $(REMOVE) -f $(SYMROOT)/libobjc.optimized.o
329 $(SILENT) $(REMOVE) -f $(SYMROOT)/libobjc.debug.o
330 $(SILENT) $(REMOVE) -f $(SYMROOT)/libobjc.profile.o
332 $(SILENT) $(REMOVE) -f $(SYMROOT)/libobjc.$(VERSION_NAME)$(LIBRARY_EXT)
333 $(SILENT) $(REMOVE) -f $(SYMROOT)/libobjc_debug.$(VERSION_NAME)$(LIBRARY_EXT)
334 $(SILENT) $(REMOVE) -f $(SYMROOT)/libobjc_profile.$(VERSION_NAME)$(LIBRARY_EXT)
336 $(SILENT) $(REMOVE) -f $(OBJECTS_OPTIMIZED)
337 $(SILENT) $(REMOVE) -f $(OBJECTS_DEBUG)
338 $(SILENT) $(REMOVE) -f $(OBJECTS_PROFILE)
340 $(SILENT) $(REMOVE) -rf $(SYMROOT)/ProjectHeaders
343 $(SILENT) $(ECHO) "Prebuild-setup..."
345 # Install headers into $(SYMROOT)/ProjectHeaders so #includes can find them
346 # even if they're not installed in /usr.
347 $(SILENT) $(MKDIRS) $(SYMROOT)
348 $(SILENT) $(REMOVE_RECUR) $(SYMROOT)/ProjectHeaders
349 $(SILENT) $(MKDIRS) $(SYMROOT)/ProjectHeaders
350 $(SILENT) $(ECHO) "Copying headers from $(SRCROOT) to $(SYMROOT)/ProjectHeaders..."
351 $(SILENT) $(COPY) $(addprefix $(SRCROOT)/, $(PRIVATE_HEADERS) ) $(SYMROOT)/ProjectHeaders
352 $(SILENT) $(MKDIRS) $(SYMROOT)/ProjectHeaders/objc
353 $(SILENT) $(COPY) $(addprefix $(SRCROOT)/, $(PUBLIC_HEADERS) ) $(SYMROOT)/ProjectHeaders/objc
354 $(SILENT) $(COPY) $(addprefix $(SRCROOT)/, $(OTHER_HEADERS) ) $(SYMROOT)/ProjectHeaders/objc
358 build-optimized: prebuild-optimized compile-optimized link-optimized
359 build-debug: prebuild-debug compile-debug link-debug
360 build-profile: prebuild-profile compile-profile link-profile
364 $(SILENT) $(ECHO) "Building (optimized) ..."
365 $(SILENT) $(MKDIRS) $(foreach S, $(SUBDIRS), $(OBJROOT)/$(S) )
368 $(SILENT) $(ECHO) "Building (debug) ..."
369 $(SILENT) $(MKDIRS) $(foreach S, $(SUBDIRS), $(OBJROOT)/$(S) )
372 $(SILENT) $(ECHO) "Building (profile) ..."
373 $(SILENT) $(MKDIRS) $(foreach S, $(SUBDIRS), $(OBJROOT)/$(S) )
376 compile-optimized: $(OBJECTS_OPTIMIZED)
377 compile-debug: $(OBJECTS_DEBUG)
378 compile-profile: $(OBJECTS_PROFILE)
381 # link lib-suffix, LDFLAGS, OBJECTS
382 # libsuffix should be "" or _debug or _profile
383 ifeq "$(PLATFORM)" "Darwin"
386 $(foreach A, $(ARCH_LIST), \
387 $(SILENT) $(LD) -arch $A -r -o $(OBJROOT)/libobjc$1.$A.o $3 ; )
388 $(foreach A, $(ARCH_LIST), \
389 -$(SILENT) $(NMEDIT) -s $(SRCROOT)/objc-exports \
390 $(OBJROOT)/libobjc$1.$A.o ; )
392 -Wl,-init,__objcInit \
393 -install_name /$(INSTALLDIR)/libobjc$1.$(VERSION_NAME)$(LIBRARY_EXT) \
394 -o $(SYMROOT)/libobjc$1.$(VERSION_NAME)$(LIBRARY_EXT) \
395 $(foreach A, $(ARCH_LIST), $(OBJROOT)/libobjc$1.$A.o )
401 $(SILENT) $(ECHO) "Don't know how to link for platform '$(PLATFORM)'"
408 $(SILENT) $(ECHO) "Linking (optimized)..."
409 $(call link,,$(LDFLAGS_OPTIMIZED),$(OBJECTS_OPTIMIZED) )
410 $(SILENT) $(STRIP) -x $(SYMROOT)/libobjc.$(VERSION_NAME)$(LIBRARY_EXT)
413 $(SILENT) $(ECHO) "Linking (debug)..."
414 $(call link,_debug,$(LDFLAGS_DEBUG),$(OBJECTS_DEBUG) )
417 $(SILENT) $(ECHO) "Linking (profile)..."
418 $(call link,_profile,$(LDFLAGS_PROFILE),$(OBJECTS_PROFILE))
422 $(SILENT) $(ECHO) "Done!"