]> git.saurik.com Git - apple/cf.git/blame - framework.make
CF-368.28.tar.gz
[apple/cf.git] / framework.make
CommitLineData
d8925383
A
1# Simple makefile for building a framework or library on platforms other than OS X.
2# the open source subset used in Darwin.
3#
4# These make variables (or environment variables) are used
5# if defined:
6# SRCROOT path location of root of source hierarchy;
7# defaults to ".", but must be set to a
8# destination path for installsrc target.
9# OBJROOT path location where .o files will be put;
10# defaults to "/tmp/CoreFoundation.obj".
11# SYMROOT path location where build products will be
12# put; defaults to "/tmp/CoreFoundation.sym".
13# DSTROOT path location where installed products will
14# be put; defaults to "/tmp/CoreFoundation.dst".
15#
16# Interesting variables to be set by the including Makefile:
17# NAME base name of the framework or library
18# CFILES .c to build
19# CPP_FILES .cpp to build
20# PUBLIC_HFILES .h files that will be installed for clients of API
21# PRIVATE_HFILES .h files that will be installed for clients of SPI
22# PROJECT_HFILES the rest of the .h files in the project
23# PUBLIC_IFILES .i with API
24# PRIVATE_IFILES .i files with SPI
25# IFILES_DIR directory holding all the .i files
26# MASTER_INTERFACE_DIR location of .i files we depend on
27#
28# We now follow the model of modern PB builds, which allow SYMROOT and OBJROOT to be shared
29# across projects during development. This provides the benefit that one set of build flags
30# (-F on Mach, -I and -L on Unix or Cygwin) can be used to share build products across projects.
31# For release builds, the directories are always separate per project.
32#
33# PLATFORM name of platform being built on
34# USER name of user building the project
35# ARCHS list of archs for which to build
36# RC_ARCHS more archs for which to build (build system)
37# OTHER_CFLAGS other flags to be passed to compiler
38# RC_CFLAGS more flags to be passed to compiler (build system)
39# OTHER_LFLAGS other flags to be passed to the link stage
40#
41# (Note: lame "#*/" tacked onto some lines is to get PB to stop syntax coloring the entire rest of the file as a comment.)
42
43# First figure out the platform if not specified, so we can use it in the
44# rest of this file. Currently defined values: Darwin, Linux, FreeBSD, variants of CYGWIN
45ifeq "$(PLATFORM)" ""
46PLATFORM := $(shell uname)
47endif
48
49ifeq "$(PLATFORM)" "Darwin"
50# Darwin platforms always define __MACH__
51else
52ifneq "" "$(findstring CYGWIN, $(PLATFORM))"
53# The windows platforms all define one cpp symbol or another, which CFBase.h funnels to __WIN32__.
54# Simplify later checks, since we don't care about different versions of CYGWIN.
55PLATFORM = CYGWIN
56else
57ifeq "$(PLATFORM)" "Linux"
58PLATFORM_CFLAGS = -D__LINUX__=1
59else
60ifeq "$(PLATFORM)" "FreeBSD"
61PLATFORM_CFLAGS = -D__FREEBSD__=1
62else
63$(error Platform could not be identified. Neither $$PLATFORM was set, nor the result of uname was recognized)
64endif
65endif
66endif
67endif
68
69#
70# Set up basic variables, commands we use
71#
72
73ifndef SRCROOT
74SRCROOT = .
75endif
76
77ifndef OBJROOT
78OBJROOT = /tmp/$(NAME).obj
79endif
80
81ifndef SYMROOT
82SYMROOT = /tmp/$(NAME).sym
83endif
84
85ifndef DSTROOT
86DSTROOT = /tmp/$(NAME).dst
87endif
88
89SILENT = @
90ifeq "$(PLATFORM)" "CYGWIN"
91CC = gcc
92CPLUSPLUS = g++
93ECHO = echo
94MKDIRS = mkdir -p
95COPY = cp
96COPY_RECUR = cp -r
97REMOVE = rm
98REMOVE_RECUR = rm -rf
99SYMLINK = ln -sfh
100CHMOD = chmod
101CHOWN = chown
102TAR = tar
103TOUCH = touch
104STRIP = strip
105DLLTOOL = dlltool
106INTERFACER = Interfacer
107else
108ifeq "$(PLATFORM)" "Darwin"
109CC = /usr/bin/cc
110else
111CC = /usr/bin/gcc
112endif
113CPLUSPLUS = /usr/bin/g++
114ECHO = /bin/echo
115MKDIRS = /bin/mkdir -p
116COPY = /bin/cp
117COPY_RECUR = /bin/cp -r
118REMOVE = /bin/rm
119REMOVE_RECUR = /bin/rm -rf
120SYMLINK = /bin/ln -sfh
121CHMOD = /bin/chmod
122CHOWN = /usr/sbin/chown
123TAR = /usr/bin/tar
124TOUCH = /usr/bin/touch
125STRIP = /usr/bin/strip
126INTERFACER = /AppleInternal/Developer/Tools/Interfacer
127endif
128
129#
130# Set up CC flags
131#
132
133ifeq "$(PLATFORM)" "Darwin"
0ae65c4b
A
134C_WARNING_FLAGS += -Wno-precomp -Wno-four-char-constants -Wall
135CPP_WARNING_FLAGS += -Wno-precomp -Wno-four-char-constants -Wall
d8925383
A
136endif
137
138ifeq "$(PLATFORM)" "CYGWIN"
139C_WARNING_FLAGS += -Wall
140CPP_WARNING_FLAGS += -Wall
141endif
142
143ifeq "$(PLATFORM)" "Darwin"
144ifneq "$(ARCHS)" ""
145ARCH_FLAGS = $(foreach A, $(ARCHS), $(addprefix -arch , $(A)))
146else
147ifneq "$(RC_ARCHS)" ""
148ARCH_FLAGS = $(foreach A, $(RC_ARCHS), $(addprefix -arch , $(A)))
149else
150ARCH_FLAGS = -arch ppc
151endif
152endif
153endif
154
155ifeq "$(PLATFORM)" "FreeBSD"
156ARCH_FLAGS = -march=i386
157endif
158
159ifeq "$(PLATFORM)" "Linux"
160ARCH_FLAGS =
161endif
162
163ifeq "$(USER)" ""
164USER = unknown
165endif
166
167CFLAGS = -fno-common -pipe $(PLATFORM_CFLAGS) $(C_WARNING_FLAGS) -I.
168CPPFLAGS = -fno-common -pipe $(PLATFORM_CFLAGS) $(CPP_WARNING_FLAGS) -I.
169
170ifeq "$(PLATFORM)" "Darwin"
171CFLAGS += $(ARCH_FLAGS) -F$(SYMROOT) -fconstant-cfstrings
172CPPFLAGS += $(ARCH_FLAGS) -F$(SYMROOT) -fconstant-cfstrings
173endif
174
175ifeq "$(PLATFORM)" "CYGWIN"
176# -mno-cygwin can be left out to build using the CYGWIN unix emulation libs
177CFLAGS += -mno-cygwin
178CPPFLAGS += -mno-cygwin
179endif
180
181
182
183#
184# Set style of building the library/framework, and the linker flags
185#
186
187ifeq "$(wildcard /System/Library/Frameworks)" ""
188LIBRARY_STYLE = Library
189LIBRARY_EXT = .so
190RELEASE_LIB = lib$(NAME)$(LIBRARY_EXT)
191DEBUG_LIB = lib$(NAME)_debug$(LIBRARY_EXT)
192PROFILE_LIB = lib$(NAME)_profile$(LIBRARY_EXT)
193ifeq "$(PLATFORM)" "Linux"
194LIBRARY_EXT = .a
195endif
196INSTALLDIR = /usr/local/lib
197ifeq "$(PLATFORM)" "CYGWIN"
198LIBRARY_EXT = .dll
199RELEASE_LIB = $(NAME)$(LIBRARY_EXT)
200DEBUG_LIB = $(NAME)_debug$(LIBRARY_EXT)
201PROFILE_LIB = $(NAME)_profile$(LIBRARY_EXT)
202RELEASE_IMPLIB = lib$(RELEASE_LIB:.dll=.a)
203DEBUG_IMPLIB = lib$(DEBUG_LIB:.dll=.a)
204PROFILE_IMPLIB = lib$(PROFILE_LIB:.dll=.a)
205INSTALLDIR = /usr/local/bin
206LIB_INSTALLDIR = /usr/local/lib
207endif
208HEADER_INSTALLDIR = /usr/local/include/$(NAME)
209INSTALLDIR = /usr/local/lib
210MASTER_INTERFACE_DIR = $(SYMROOT)/interfaces
211# Next four dirs are used at build time, but not install time
212PUBLIC_HEADER_DIR = $(SYMROOT)/Headers/$(NAME)
213PRIVATE_HEADER_DIR = $(SYMROOT)/PrivateHeaders/$(NAME)
214PROJECT_HEADER_DIR = $(OBJROOT)/$(NAME).build/ProjectHeaders/$(NAME)
215RESOURCE_DIR = $(SYMROOT)
216else
217LIBRARY_STYLE = Framework
218RELEASE_LIB = $(NAME)
219DEBUG_LIB = $(NAME)_debug
220PROFILE_LIB = $(NAME)_profile
221INSTALLDIR = /System/Library/Frameworks
222FRAMEWORK_DIR = /System/Library/Frameworks/$(NAME).framework
223MASTER_INTERFACE_DIR = /AppleInternal/Carbon/interfaces
224# Next three dirs are used at build time, but not install time
225PUBLIC_HEADER_DIR = $(SYMROOT)/$(NAME).framework/Versions/A/Headers
226PRIVATE_HEADER_DIR = $(SYMROOT)/$(NAME).framework/Versions/A/PrivateHeaders
227PROJECT_HEADER_DIR = $(OBJROOT)/$(NAME).build/ProjectHeaders
228endif
229
230ifeq "$(PLATFORM)" "Darwin"
231LFLAGS = $(ARCH_FLAGS) -dynamiclib -dynamic
232endif
233
234ifeq "$(PLATFORM)" "FreeBSD"
235LFLAGS = -shared
236endif
237
238ifeq "$(PLATFORM)" "CYGWIN"
239# -mno-cygwin can be left out to build using the CYGWIN unix emulation libs
240LFLAGS = -mno-cygwin -L$(SYMROOT)
241endif
242
243# other flags passed in from the make command line, and RC
244CFLAGS += $(OTHER_CFLAGS) $(RC_CFLAGS)
245CPPFLAGS += $(OTHER_CPPFLAGS) $(RC_CFLAGS)
246LFLAGS += $(OTHER_LFLAGS)
247
248
249# Needed to find Project Headers, which work in PB because of the fancy -header-mapfile feature.
250CFLAGS += -I$(PROJECT_HEADER_DIR)
251CPPFLAGS += -I$(PROJECT_HEADER_DIR)
252# Needed for cases when a private header is included as "Foo.h" instead of <CF/Foo.h>
253CFLAGS += -I$(PRIVATE_HEADER_DIR)
254CPPFLAGS += -I$(PRIVATE_HEADER_DIR)
255ifeq "$(LIBRARY_STYLE)" "Library"
256# Needed for headers included as <CF/Foo.h>, since there is no -FframeworkDir mechanism at work
257CFLAGS += -I$(PUBLIC_HEADER_DIR)/.. -I$(PRIVATE_HEADER_DIR)/..
258CPPFLAGS += -I$(PUBLIC_HEADER_DIR)/.. -I$(PRIVATE_HEADER_DIR)/..
259endif
260
261
262.PHONY: build all prebuild release debug profile debug-build release-build profile-build build-realwork test
263default: build
264all: build
265build: prebuild debug-build release-build profile-build
266release: prebuild release-build
267debug: prebuild debug-build
268profile: prebuild profile-build
269
270# These are the main targets:
271# build builds the library to OBJROOT and SYMROOT
272# installsrc copies the sources to SRCROOT
273# installhdrs install only the headers to DSTROOT
274# install build, then install the headers and library to DSTROOT
275# clean removes build products in OBJROOT and SYMROOT
276# test invoke items in Tests subdirectory
277
278#--------------------------------------------------------------------------------
279# INSTALL
280#--------------------------------------------------------------------------------
281
282installsrc:
283 $(SILENT) $(ECHO) "Installing source..."
284ifeq "$(SRCROOT)" "."
285 $(SILENT) $(ECHO) "SRCROOT must be defined to be the destination directory; it cannot be '.'"
286 exit 1
287endif
288 $(SILENT) $(MKDIRS) $(SRCROOT)
289 $(SILENT) $(MKDIRS) $(foreach S, $(SUBPROJECTS), $(SRCROOT)/$(S).subproj)
290 -$(SILENT) $(foreach S, $(SUBPROJECTS), $(COPY) $(foreach F, $($(S)_SOURCES), $(S).subproj/$(F)) $(SRCROOT)/$(S).subproj;)
291 -$(SILENT) $(foreach S, $(SUBPROJECTS), $(COPY) $(foreach F, $($(S)_PROJHEADERS), $(S).subproj/$(F)) $(SRCROOT)/$(S).subproj;)
292 -$(SILENT) $(foreach S, $(SUBPROJECTS), $(COPY) $(foreach F, $($(S)_PRIVHEADERS), $(S).subproj/$(F)) $(SRCROOT)/$(S).subproj;)
293 -$(SILENT) $(foreach S, $(SUBPROJECTS), $(COPY) $(foreach F, $($(S)_PUBHEADERS), $(S).subproj/$(F)) $(SRCROOT)/$(S).subproj;)
294 $(SILENT) $(COPY) $(OTHER_SOURCES) $(SRCROOT)
295 $(SILENT) $(COPY_RECUR) CharacterSets $(SRCROOT)
296 $(SILENT) $(REMOVE_RECUR) $(SRCROOT)/CharacterSets/CVS
297
298installhdrs:
299 $(SILENT) $(ECHO) "Installing headers..."
300ifeq "$(LIBRARY_STYLE)" "Framework"
301 $(SILENT) $(REMOVE) -f $(DSTROOT)/$(FRAMEWORK_DIR)/Headers
302 $(SILENT) $(REMOVE) -f $(DSTROOT)/$(FRAMEWORK_DIR)/PrivateHeaders
303 $(SILENT) $(REMOVE) -f $(DSTROOT)/$(FRAMEWORK_DIR)/Versions/Current
304 $(SILENT) $(MKDIRS) $(DSTROOT)/$(FRAMEWORK_DIR)/Versions/A/Headers
305 $(SILENT) $(MKDIRS) $(DSTROOT)/$(FRAMEWORK_DIR)/Versions/A/PrivateHeaders
306 $(SILENT) $(SYMLINK) A $(DSTROOT)/$(FRAMEWORK_DIR)/Versions/Current
307 $(SILENT) $(SYMLINK) Versions/Current/Headers $(DSTROOT)/$(FRAMEWORK_DIR)/Headers
308 $(SILENT) $(SYMLINK) Versions/Current/PrivateHeaders $(DSTROOT)/$(FRAMEWORK_DIR)/PrivateHeaders
309 -$(SILENT) $(CHMOD) +w $(DSTROOT)/$(FRAMEWORK_DIR)/Versions/A/Headers/*.h #*/
310 -$(SILENT) $(CHMOD) +w $(DSTROOT)/$(FRAMEWORK_DIR)/Versions/A/PrivateHeaders/*.h #*/
311 $(SILENT) $(COPY) $(PUBLIC_HFILES) $(DSTROOT)/$(FRAMEWORK_DIR)/Versions/A/Headers
312# Install two private headers for internal Apple projects' use
313 $(SILENT) $(COPY) Base.subproj/CFPriv.h Base.subproj/CFRuntime.h PlugIn.subproj/CFBundlePriv.h $(DSTROOT)/$(FRAMEWORK_DIR)/Versions/A/PrivateHeaders
314 $(SILENT) $(CHOWN) -R root:wheel $(DSTROOT)/$(FRAMEWORK_DIR)
315 -$(SILENT) $(CHMOD) -w $(DSTROOT)/$(FRAMEWORK_DIR)/Versions/A/Headers/*.h #*/
316 -$(SILENT) $(CHMOD) -w $(DSTROOT)/$(FRAMEWORK_DIR)/Versions/A/PrivateHeaders/*.h #*/
317endif
318ifeq "$(LIBRARY_STYLE)" "Library"
319 $(SILENT) $(MKDIRS) $(DSTROOT)/$(HEADER_INSTALLDIR)
320 -$(SILENT) $(CHMOD) +w $(DSTROOT)/$(HEADER_INSTALLDIR)/*.h #*/
321 $(SILENT) $(COPY) $(PUBLIC_HFILES) $(DSTROOT)/$(HEADER_INSTALLDIR)
322 $(SILENT) $(CHMOD) -w $(DSTROOT)/$(HEADER_INSTALLDIR)/*.h #*/
323endif
324
325install: build install_before install_builtin install_after
326install_before::
327install_after::
328
329install_builtin:
330 $(SILENT) $(ECHO) "Installing..."
331ifeq "$(LIBRARY_STYLE)" "Framework"
332 $(SILENT) $(REMOVE_RECUR) $(DSTROOT)/$(FRAMEWORK_DIR)
333 $(SILENT) $(MKDIRS) $(DSTROOT)/$(FRAMEWORK_DIR)
334 -$(SILENT) $(CHMOD) -R +w $(DSTROOT)/$(FRAMEWORK_DIR)
335 $(SILENT) (cd $(SYMROOT) && $(TAR) -cf - $(NAME).framework) | (cd $(DSTROOT)/$(INSTALLDIR) && $(TAR) -xf -)
336 $(SILENT) $(STRIP) -S $(DSTROOT)/$(FRAMEWORK_DIR)/Versions/A/$(RELEASE_LIB)
337 $(SILENT) $(STRIP) -S $(DSTROOT)/$(FRAMEWORK_DIR)/Versions/A/$(DEBUG_LIB)
338 $(SILENT) $(STRIP) -S $(DSTROOT)/$(FRAMEWORK_DIR)/Versions/A/$(PROFILE_LIB)
339 $(SILENT) $(CHMOD) -R ugo-w $(DSTROOT)/$(FRAMEWORK_DIR)
340 $(SILENT) $(CHMOD) -R o+rX $(DSTROOT)/$(FRAMEWORK_DIR)
341 $(SILENT) $(CHOWN) -R root:wheel $(DSTROOT)/$(FRAMEWORK_DIR)
342endif
343ifeq "$(LIBRARY_STYLE)" "Library"
344 $(SILENT) $(MKDIRS) $(DSTROOT)/$(INSTALLDIR)
345 -$(SILENT) $(CHMOD) +w $(DSTROOT)/$(INSTALLDIR)
346 $(SILENT) $(REMOVE) -f $(DSTROOT)/$(INSTALLDIR)/$(RELEASE_LIB)
347 $(SILENT) $(REMOVE) -f $(DSTROOT)/$(INSTALLDIR)/$(DEBUG_LIB)
348 $(SILENT) $(REMOVE) -f $(DSTROOT)/$(INSTALLDIR)/$(PROFILE_LIB)
349 $(SILENT) $(COPY) $(SYMROOT)/$(RELEASE_LIB) $(DSTROOT)/$(INSTALLDIR)/$(RELEASE_LIB)
350 $(SILENT) $(COPY) $(SYMROOT)/$(DEBUG_LIB) $(DSTROOT)/$(INSTALLDIR)/$(DEBUG_LIB)
351 $(SILENT) $(COPY) $(SYMROOT)/$(PROFILE_LIB) $(DSTROOT)/$(INSTALLDIR)/$(PROFILE_LIB)
352ifneq "$(PLATFORM)" "CYGWIN"
353 -$(SILENT) $(CHOWN) root:wheel $(DSTROOT)/$(INSTALLDIR)/$(RELEASE_LIB)
354 -$(SILENT) $(CHOWN) root:wheel $(DSTROOT)/$(INSTALLDIR)/$(DEBUG_LIB)
355 -$(SILENT) $(CHOWN) root:wheel $(DSTROOT)/$(INSTALLDIR)/$(PROFILE_LIB)
356endif
357 $(SILENT) $(CHMOD) 755 $(DSTROOT)/$(INSTALLDIR)/$(RELEASE_LIB)
358 $(SILENT) $(CHMOD) 755 $(DSTROOT)/$(INSTALLDIR)/$(DEBUG_LIB)
359 $(SILENT) $(CHMOD) 755 $(DSTROOT)/$(INSTALLDIR)/$(PROFILE_LIB)
360ifeq "$(PLATFORM)" "CYGWIN"
361 $(SILENT) $(MKDIRS) $(DSTROOT)/$(LIB_INSTALLDIR)
362 -$(SILENT) $(CHMOD) +w $(DSTROOT)/$(LIB_INSTALLDIR)
363 $(SILENT) $(REMOVE) -f $(DSTROOT)/$(LIB_INSTALLDIR)/$(RELEASE_IMPLIB)
364 $(SILENT) $(REMOVE) -f $(DSTROOT)/$(LIB_INSTALLDIR)/$(DEBUG_IMPLIB)
365 $(SILENT) $(REMOVE) -f $(DSTROOT)/$(LIB_INSTALLDIR)/$(PROFILE_IMPLIB)
366 $(SILENT) $(COPY) $(SYMROOT)/$(RELEASE_IMPLIB) $(DSTROOT)/$(LIB_INSTALLDIR)/$(RELEASE_IMPLIB)
367 $(SILENT) $(COPY) $(SYMROOT)/$(DEBUG_IMPLIB) $(DSTROOT)/$(LIB_INSTALLDIR)/$(DEBUG_IMPLIB)
368 $(SILENT) $(COPY) $(SYMROOT)/$(PROFILE_IMPLIB) $(DSTROOT)/$(LIB_INSTALLDIR)/$(PROFILE_IMPLIB)
369 $(SILENT) $(CHMOD) 755 $(DSTROOT)/$(LIB_INSTALLDIR)/$(RELEASE_IMPLIB)
370 $(SILENT) $(CHMOD) 755 $(DSTROOT)/$(LIB_INSTALLDIR)/$(DEBUG_IMPLIB)
371 $(SILENT) $(CHMOD) 755 $(DSTROOT)/$(LIB_INSTALLDIR)/$(PROFILE_IMPLIB)
372endif
373 $(SILENT) $(MKDIRS) $(DSTROOT)/$(HEADER_INSTALLDIR)
374 -$(SILENT) $(CHMOD) +w $(DSTROOT)/$(HEADER_INSTALLDIR)/*.h #*/
375 $(SILENT) $(COPY) $(PUBLIC_HFILES) $(DSTROOT)/$(HEADER_INSTALLDIR)
376 -$(SILENT) $(CHMOD) -w $(DSTROOT)/$(HEADER_INSTALLDIR)/*.h #*/
377endif
378
379#--------------------------------------------------------------------------------
380# CLEAN
381#--------------------------------------------------------------------------------
382
383clean: clean_before clean_builtin clean_after
384clean_before::
385clean_after::
386
387clean_builtin:
388 $(SILENT) $(ECHO) "Deleting build products..."
389 $(REMOVE_RECUR) $(OBJROOT)/$(NAME).build
390ifeq "$(LIBRARY_STYLE)" "Framework"
391 $(REMOVE_RECUR) $(SYMROOT)/$(NAME).framework
392endif
393ifeq "$(LIBRARY_STYLE)" "Library"
394 $(REMOVE) -f $(SYMROOT)/$(RELEASE_LIB)
395 $(REMOVE) -f $(SYMROOT)/$(DEBUG_LIB)
396 $(REMOVE) -f $(SYMROOT)/$(PROFILE_LIB)
397 $(REMOVE_RECUR) -f $(PUBLIC_HEADER_DIR) $(PRIVATE_HEADER_DIR)
398ifeq "$(PLATFORM)" "CYGWIN"
399 $(REMOVE) -f $(SYMROOT)/$(RELEASE_IMPLIB)
400 $(REMOVE) -f $(SYMROOT)/$(DEBUG_IMPLIB)
401 $(REMOVE) -f $(SYMROOT)/$(PROFILE_IMPLIB)
402 $(REMOVE) -f $(SYMROOT)/$(RELEASE_LIB:.dll=.lib)
403 $(REMOVE) -f $(SYMROOT)/$(DEBUG_LIB:.dll=.lib)
404 $(REMOVE) -f $(SYMROOT)/$(PROFILE_LIB:.dll=.lib)
405 $(REMOVE) -f $(SYMROOT)/$(RELEASE_LIB:.dll=.defs)
406 $(REMOVE) -f $(SYMROOT)/$(DEBUG_LIB:.dll=.defs)
407 $(REMOVE) -f $(SYMROOT)/$(PROFILE_LIB:.dll=.exp)
408 $(REMOVE) -f $(SYMROOT)/$(RELEASE_LIB:.dll=.exp)
409 $(REMOVE) -f $(SYMROOT)/$(DEBUG_LIB:.dll=.exp)
410 $(REMOVE) -f $(SYMROOT)/$(PROFILE_LIB:.dll=.defs)
411endif
412endif
413
414#--------------------------------------------------------------------------------
415# PREBUILD
416#--------------------------------------------------------------------------------
417
418prebuild: prebuild_before prebuild_setup prebuild_headers prebuild_after
419prebuild_before::
420prebuild_after::
421
422# build the framework, or other basic dir structure
423prebuild_setup::
424 $(SILENT) $(ECHO) "Prebuild-setup..."
425 $(SILENT) $(MKDIRS) $(SYMROOT)
426ifeq "$(LIBRARY_STYLE)" "Framework"
427prebuild_setup::
428 $(SILENT) $(MKDIRS) $(SYMROOT)/$(NAME).framework/Versions/A/Resources
429 $(SILENT) $(SYMLINK) A $(SYMROOT)/$(NAME).framework/Versions/Current
430 $(SILENT) $(SYMLINK) Versions/Current/Headers $(SYMROOT)/$(NAME).framework/Headers
431 $(SILENT) $(SYMLINK) Versions/Current/PrivateHeaders $(SYMROOT)/$(NAME).framework/PrivateHeaders
432 $(SILENT) $(SYMLINK) Versions/Current/Resources $(SYMROOT)/$(NAME).framework/Resources
433endif
434
435ifeq "$(LIBRARY_STYLE)" "Framework"
436PLATFORM_IFLAGS = -framework $(NAME) -frameworkInterfaces $(IFILES_DIR)
437ALL_IFILES = $(foreach F,$(PUBLIC_IFILES) $(PRIVATE_IFILES),$(IFILES_DIR)/$(F))
438
439# Since they share output directories, if either the ifiles or hfiles change we must redo both
440prebuild_headers: $(OBJROOT)/$(NAME).build/Headers.touch
441$(OBJROOT)/$(NAME).build/Headers.touch: $(PUBLIC_HFILES) $(PRIVATE_HFILES) $(PROJECT_HFILES) $(ALL_IFILES)
442 $(SILENT) $(REMOVE_RECUR) $(PUBLIC_HEADER_DIR)
443 $(SILENT) $(REMOVE_RECUR) $(PRIVATE_HEADER_DIR)
444 $(SILENT) $(REMOVE_RECUR) $(PROJECT_HEADER_DIR)
445 $(SILENT) $(MKDIRS) $(PUBLIC_HEADER_DIR)
446 $(SILENT) $(MKDIRS) $(PRIVATE_HEADER_DIR)
447 $(SILENT) $(MKDIRS) $(PROJECT_HEADER_DIR)
448 $(SILENT) $(MAKE) prebuild_copy_headers
449ifneq "$(ALL_IFILES)" ""
450 $(SILENT) $(MAKE) prebuild_gen_headers
451endif
452 $(SILENT) $(TOUCH) $(OBJROOT)/$(NAME).build/Headers.touch
453else
454
455ALL_IFILES = $(foreach F,$(PUBLIC_IFILES) $(PRIVATE_IFILES),$(IFILES_DIR)/$(F))
456
457# Since they share output directories, if either the ifiles or hfiles change we must redo both
458prebuild_headers: $(OBJROOT)/$(NAME).build/Headers.touch
459$(OBJROOT)/$(NAME).build/Headers.touch: $(PUBLIC_HFILES) $(PRIVATE_HFILES) $(PROJECT_HFILES) $(ALL_IFILES)
460 $(SILENT) $(REMOVE_RECUR) $(PUBLIC_HEADER_DIR)
461 $(SILENT) $(REMOVE_RECUR) $(PRIVATE_HEADER_DIR)
462 $(SILENT) $(REMOVE_RECUR) $(PROJECT_HEADER_DIR)
463 $(SILENT) $(MKDIRS) $(PUBLIC_HEADER_DIR)
464 $(SILENT) $(MKDIRS) $(PRIVATE_HEADER_DIR)
465 $(SILENT) $(MKDIRS) $(PROJECT_HEADER_DIR)
466 $(SILENT) $(MAKE) prebuild_copy_headers
467ifneq "$(ALL_IFILES)" ""
468 $(SILENT) $(MAKE) prebuild_gen_headers
469endif
470 $(SILENT) $(TOUCH) $(OBJROOT)/$(NAME).build/Headers.touch
471
472# First try was not using -framework, so we get EXTERN_API to leverage for __declspec trickery.
473# But that didn't help us for externed data, and the imports changed to omit the framework name.
474# As best I can tell, when not using -framework you need to cd into the IFILES_DIR for the
475# inter-file references to work.
476# -update and -deepUpdate don't seem to work on WIN32, so just use a touch file
477#ALL_IFILES = $(PUBLIC_IFILES) $(PRIVATE_IFILES)
478#PLATFORM_IFLAGS = $(foreach F, $(ALL_IFILES), `cygpath -w $(F)`)
479PLATFORM_IFLAGS = -framework $(NAME) -frameworkInterfaces `cygpath -w $(IFILES_DIR)/`
480endif
481prebuild_gen_headers:
482 $(SILENT) $(ECHO) "Processing interface files..."
483 $(SILENT) $(INTERFACER) $(PLATFORM_IFLAGS) -c -rez -update \
484 -masterInterfaces `cygpath -w $(MASTER_INTERFACE_DIR)/` \
485 -cacheFolder `cygpath -w $(OBJROOT)/$(NAME).build/InterfacerCache/` \
486 -generated c=`cygpath -w $(PUBLIC_HEADER_DIR)/` \
487 -generatedPriv c=`cygpath -w $(PRIVATE_HEADER_DIR)/` \
488 -generated rez=`cygpath -w $(PUBLIC_HEADER_DIR)/` \
489 -generatedPriv rez=`cygpath -w $(PRIVATE_HEADER_DIR)/`
490ifeq "$(PLATFORM)" "CYGWIN"
491# Replace externs with a symbol we can use for declspec purposes, except not extern "C"
492# Get rid of non-standard pragma
493 $(SILENT) perl -p -i \
494 -e 's/^extern ([^"].[^"])/$(NAME)_EXPORT $$1/ ;' \
495 -e 's/^(#pragma options)/\/\/$$1/' \
496 $(PUBLIC_HEADER_DIR)/*.h $(PRIVATE_HEADER_DIR)/*.h #*/
497 $(SILENT) $(REMOVE) -f $(PUBLIC_HEADER_DIR)/*.bak $(PRIVATE_HEADER_DIR)/*.bak #*/
498endif
499
500# This is the line from a CFNetwork build in PB
501# /AppleInternal/Developer/Tools/Interfacer -masterInterfaces "/AppleInternal/Carbon/interfaces/" -cacheFolder "/Volumes/Whopper/symroots/CFNetwork.build/CFNetwork.build/InterfacerCache/" -c -rez -framework "CFNetwork" -p -generated "c=/Volumes/Whopper/symroots/CFNetwork.framework/Versions/A/Headers/" -generatedPriv "c=/Volumes/Whopper/symroots/CFNetwork.framework/Versions/A/PrivateHeaders/" -generated "rez=/Volumes/Whopper/symroots/CFNetwork.framework/Versions/A/Headers/" -generatedPriv "rez=/Volumes/Whopper/symroots/CFNetwork.framework/Versions/A/PrivateHeaders/" -frameworkInterfaces /Volumes/Whale/trey/CFNetwork-Windows/Interfaces/ -installMasterInterfaces /tmp/CFNetwork.dst/AppleInternal/Carbon/interfaces/
502
503
504prebuild_copy_headers:
505 $(SILENT) $(ECHO) "Copying headers..."
506ifneq "$(strip $(PUBLIC_HFILES))" ""
507 $(SILENT) $(COPY) $(PUBLIC_HFILES) $(PUBLIC_HEADER_DIR)
508endif
509ifneq "$(strip $(PRIVATE_HFILES))" ""
510 $(SILENT) $(COPY) $(PRIVATE_HFILES) $(PRIVATE_HEADER_DIR)
511endif
512ifneq "$(strip $(PROJECT_HFILES))" ""
513 $(SILENT) $(COPY) $(PROJECT_HFILES) $(PROJECT_HEADER_DIR)
514endif
515
516
517#--------------------------------------------------------------------------------
518# BUILD
519#--------------------------------------------------------------------------------
520
521# ??? should use VPATH, should use generic rules
522# ??? should use cc -MM to generate dependencies
523# ??? should separate private from project headers, for proper installation
524
525# Set some parameters of the build-realwork target, then call it with a recursive make
526release-build:
527 $(SILENT) $(MAKE) \
528 BUILD_TYPE=release \
529 BUILD_PRODUCT=$(RELEASE_LIB) \
530 BUILD_IMPLIB=$(RELEASE_IMPLIB) \
531 OTHER_CFLAGS="-O $(OTHER_CFLAGS)" \
532 OTHER_CPPFLAGS="-O $(OTHER_CPPFLAGS)" \
533 OTHER_LFLAGS="-O $(OTHER_LFLAGS)" \
534 build-realwork
535debug-build:
536 $(SILENT) $(MAKE) \
537 BUILD_TYPE=debug \
538 BUILD_PRODUCT=$(DEBUG_LIB) \
539 BUILD_IMPLIB=$(DEBUG_IMPLIB) \
540 LIBRARY_SUFFIX=_debug \
541 OTHER_CFLAGS="-DDEBUG -g $(OTHER_CFLAGS)" \
542 OTHER_CPPFLAGS="-DDEBUG -g $(OTHER_CPPFLAGS)" \
543 OTHER_LFLAGS="-g $(OTHER_LFLAGS)" \
544 build-realwork
545profile-build:
546 $(SILENT) $(MAKE) \
547 BUILD_TYPE=profile \
548 BUILD_PRODUCT=$(PROFILE_LIB) \
549 BUILD_IMPLIB=$(PROFILE_IMPLIB) \
550 LIBRARY_SUFFIX=_profile \
551 OTHER_CFLAGS="-DPROFILE -pg -O $(OTHER_CFLAGS)" \
552 OTHER_CPPFLAGS="-DPROFILE -pg -O $(OTHER_CPPFLAGS)" \
553 OTHER_LFLAGS="-pg -O $(OTHER_LFLAGS)" \
554 build-realwork
555
556OFILE_DIR = $(OBJROOT)/$(NAME).build/$(BUILD_TYPE)_ofiles
557
558build-realwork: check-vars-defined compile-before build-compile compile-after build-link
559compile-before::
560compile-after::
561
562build-compile:
563 $(SILENT) $(ECHO) "Building $(BUILD_TYPE)..."
564 $(SILENT) $(MKDIRS) $(OFILE_DIR)
565 $(SILENT) cumulativeError=0; \
566 for x in $(CFILES) ; do \
567 ofile=$(OFILE_DIR)/`basename $$x .c`.o ; \
568 if [ ! $$ofile -nt $$x ] ; then \
569 $(ECHO) " ..." $$x " ($(BUILD_TYPE))" ; \
570 $(CC) $(CFLAGS) -c $$x -o $$ofile ; \
571 ccError=$$? ; \
572 if [ $$ccError != 0 ] ; then cumulativeError=$$ccError; fi;\
573 fi ; \
574 done; \
575 exit $$cumulativeError
576 $(SILENT) cumulativeError=0; \
577 for x in $(CPP_FILES) ; do \
578 ofile=$(OFILE_DIR)/`basename $$x .c`.o ; \
579 if [ ! $$ofile -nt $$x ] ; then \
580 $(ECHO) " ..." $$x " ($(BUILD_TYPE))" ; \
581 $(CPLUSPLUS) $(CPPFLAGS) -c $$x -o $$ofile ; \
582 ccError=$$? ; \
583 if [ $$ccError != 0 ] ; then cumulativeError=$$ccError; fi;\
584 fi ; \
585 done; \
586 exit $$cumulativeError
587
588ifeq "$(CPP_FILES)" ""
589LINKER_CMD = $(CC)
590else
591LINKER_CMD = $(CPLUSPLUS)
592endif
593
594build-link:
595 $(SILENT) $(ECHO) "Linking..."
596ifeq "$(PLATFORM)" "Darwin"
597 $(SILENT) $(LINKER_CMD) $(LFLAGS) -O -install_name $(FRAMEWORK_DIR)/Versions/A/$(BUILD_PRODUCT) $(LIBS) -o $(SYMROOT)/$(NAME).framework/Versions/A/$(BUILD_PRODUCT) $(OFILE_DIR)/*.o #*/
598 $(SILENT) $(SYMLINK) Versions/Current/$(BUILD_PRODUCT) $(SYMROOT)/$(NAME).framework/$(BUILD_PRODUCT)
599endif
600ifeq "$(PLATFORM)" "Linux"
601 $(SILENT) $(ECHO) "NOTE: Producing static libraries on Linux"
602 $(SILENT) ar cr $(SYMROOT)/$(BUILD_PRODUCT) $(OFILE_DIR)/*.o #*/
603endif
604ifeq "$(PLATFORM)" "FreeBSD"
605 $(SILENT) $(LINKER_CMD) $(LFLAGS) -O -o $(SYMROOT)/$(BUILD_PRODUCT) $(OFILE_DIR)/*.o $(LIBS) #*/
606endif
607ifeq "$(PLATFORM)" "CYGWIN"
608 $(SILENT) $(DLLTOOL) --no-export-all-symbols -z $(SYMROOT)/$(BUILD_PRODUCT:.dll=.defs) -e $(OFILE_DIR)/$(BUILD_PRODUCT:.dll=.exports.o) -l $(SYMROOT)/$(BUILD_IMPLIB) -D $(BUILD_PRODUCT) $(OFILE_DIR)/*.o #*/
609 $(SILENT) $(LINKER_CMD) $(LFLAGS) -mdll $(OFILE_DIR)/*.o $(OFILE_DIR)/$(BUILD_PRODUCT:.dll=.exports.o) $(LIBS) -o $(SYMROOT)/$(BUILD_PRODUCT) #*/
610# generate a MS VC compatible import library
611 $(SILENT) if [ "$$MSVCDIR" != "" ] ; then \
612 defFile=`cygpath -w $(SYMROOT)/$(BUILD_PRODUCT:.dll=.defs)`; \
613 outFile=`cygpath -w $(SYMROOT)/$(BUILD_PRODUCT:.dll=.lib)`; \
614 cmd /C "$$MSVCDIR\BIN\VCVARS32" "&&" lib /MACHINE:i386 "/DEF:$$defFile" "/OUT:$$outFile"; \
615 else \
616 $(ECHO) WARNING: \$$MSVCDIR is not set - no MS Visual C++ compatible import lib will be generated; \
617 fi
618endif
619 $(SILENT) $(ECHO) "Done!"
620
621# Make sure a couple variables are defined.
622check-vars-defined:
623 $(SILENT) if [ "" = "$(BUILD_TYPE)" ] || [ "" = "$(BUILD_PRODUCT)" ]; then \
624 echo ERROR: That target cannot be directly invoked. It is used only internally for recursive makes.; \
625 exit 1; \
626 fi