]>
Commit | Line | Data |
---|---|---|
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 | |
45 | ifeq "$(PLATFORM)" "" | |
46 | PLATFORM := $(shell uname) | |
47 | endif | |
48 | ||
49 | ifeq "$(PLATFORM)" "Darwin" | |
50 | # Darwin platforms always define __MACH__ | |
51 | else | |
52 | ifneq "" "$(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. | |
55 | PLATFORM = CYGWIN | |
56 | else | |
57 | ifeq "$(PLATFORM)" "Linux" | |
58 | PLATFORM_CFLAGS = -D__LINUX__=1 | |
59 | else | |
60 | ifeq "$(PLATFORM)" "FreeBSD" | |
61 | PLATFORM_CFLAGS = -D__FREEBSD__=1 | |
62 | else | |
63 | $(error Platform could not be identified. Neither $$PLATFORM was set, nor the result of uname was recognized) | |
64 | endif | |
65 | endif | |
66 | endif | |
67 | endif | |
68 | ||
69 | # | |
70 | # Set up basic variables, commands we use | |
71 | # | |
72 | ||
73 | ifndef SRCROOT | |
74 | SRCROOT = . | |
75 | endif | |
76 | ||
77 | ifndef OBJROOT | |
78 | OBJROOT = /tmp/$(NAME).obj | |
79 | endif | |
80 | ||
81 | ifndef SYMROOT | |
82 | SYMROOT = /tmp/$(NAME).sym | |
83 | endif | |
84 | ||
85 | ifndef DSTROOT | |
86 | DSTROOT = /tmp/$(NAME).dst | |
87 | endif | |
88 | ||
89 | SILENT = @ | |
90 | ifeq "$(PLATFORM)" "CYGWIN" | |
91 | CC = gcc | |
92 | CPLUSPLUS = g++ | |
93 | ECHO = echo | |
94 | MKDIRS = mkdir -p | |
95 | COPY = cp | |
96 | COPY_RECUR = cp -r | |
97 | REMOVE = rm | |
98 | REMOVE_RECUR = rm -rf | |
99 | SYMLINK = ln -sfh | |
100 | CHMOD = chmod | |
101 | CHOWN = chown | |
102 | TAR = tar | |
103 | TOUCH = touch | |
104 | STRIP = strip | |
105 | DLLTOOL = dlltool | |
106 | INTERFACER = Interfacer | |
107 | else | |
108 | ifeq "$(PLATFORM)" "Darwin" | |
109 | CC = /usr/bin/cc | |
110 | else | |
111 | CC = /usr/bin/gcc | |
112 | endif | |
113 | CPLUSPLUS = /usr/bin/g++ | |
114 | ECHO = /bin/echo | |
115 | MKDIRS = /bin/mkdir -p | |
116 | COPY = /bin/cp | |
117 | COPY_RECUR = /bin/cp -r | |
118 | REMOVE = /bin/rm | |
119 | REMOVE_RECUR = /bin/rm -rf | |
120 | SYMLINK = /bin/ln -sfh | |
121 | CHMOD = /bin/chmod | |
122 | CHOWN = /usr/sbin/chown | |
123 | TAR = /usr/bin/tar | |
124 | TOUCH = /usr/bin/touch | |
125 | STRIP = /usr/bin/strip | |
126 | INTERFACER = /AppleInternal/Developer/Tools/Interfacer | |
127 | endif | |
128 | ||
129 | # | |
130 | # Set up CC flags | |
131 | # | |
132 | ||
133 | ifeq "$(PLATFORM)" "Darwin" | |
0ae65c4b A |
134 | C_WARNING_FLAGS += -Wno-precomp -Wno-four-char-constants -Wall |
135 | CPP_WARNING_FLAGS += -Wno-precomp -Wno-four-char-constants -Wall | |
d8925383 A |
136 | endif |
137 | ||
138 | ifeq "$(PLATFORM)" "CYGWIN" | |
139 | C_WARNING_FLAGS += -Wall | |
140 | CPP_WARNING_FLAGS += -Wall | |
141 | endif | |
142 | ||
143 | ifeq "$(PLATFORM)" "Darwin" | |
144 | ifneq "$(ARCHS)" "" | |
145 | ARCH_FLAGS = $(foreach A, $(ARCHS), $(addprefix -arch , $(A))) | |
146 | else | |
147 | ifneq "$(RC_ARCHS)" "" | |
148 | ARCH_FLAGS = $(foreach A, $(RC_ARCHS), $(addprefix -arch , $(A))) | |
149 | else | |
150 | ARCH_FLAGS = -arch ppc | |
151 | endif | |
152 | endif | |
153 | endif | |
154 | ||
155 | ifeq "$(PLATFORM)" "FreeBSD" | |
156 | ARCH_FLAGS = -march=i386 | |
157 | endif | |
158 | ||
159 | ifeq "$(PLATFORM)" "Linux" | |
160 | ARCH_FLAGS = | |
161 | endif | |
162 | ||
163 | ifeq "$(USER)" "" | |
164 | USER = unknown | |
165 | endif | |
166 | ||
167 | CFLAGS = -fno-common -pipe $(PLATFORM_CFLAGS) $(C_WARNING_FLAGS) -I. | |
168 | CPPFLAGS = -fno-common -pipe $(PLATFORM_CFLAGS) $(CPP_WARNING_FLAGS) -I. | |
169 | ||
170 | ifeq "$(PLATFORM)" "Darwin" | |
171 | CFLAGS += $(ARCH_FLAGS) -F$(SYMROOT) -fconstant-cfstrings | |
172 | CPPFLAGS += $(ARCH_FLAGS) -F$(SYMROOT) -fconstant-cfstrings | |
173 | endif | |
174 | ||
175 | ifeq "$(PLATFORM)" "CYGWIN" | |
176 | # -mno-cygwin can be left out to build using the CYGWIN unix emulation libs | |
177 | CFLAGS += -mno-cygwin | |
178 | CPPFLAGS += -mno-cygwin | |
179 | endif | |
180 | ||
181 | ||
182 | ||
183 | # | |
184 | # Set style of building the library/framework, and the linker flags | |
185 | # | |
186 | ||
187 | ifeq "$(wildcard /System/Library/Frameworks)" "" | |
188 | LIBRARY_STYLE = Library | |
189 | LIBRARY_EXT = .so | |
190 | RELEASE_LIB = lib$(NAME)$(LIBRARY_EXT) | |
191 | DEBUG_LIB = lib$(NAME)_debug$(LIBRARY_EXT) | |
192 | PROFILE_LIB = lib$(NAME)_profile$(LIBRARY_EXT) | |
193 | ifeq "$(PLATFORM)" "Linux" | |
194 | LIBRARY_EXT = .a | |
195 | endif | |
196 | INSTALLDIR = /usr/local/lib | |
197 | ifeq "$(PLATFORM)" "CYGWIN" | |
198 | LIBRARY_EXT = .dll | |
199 | RELEASE_LIB = $(NAME)$(LIBRARY_EXT) | |
200 | DEBUG_LIB = $(NAME)_debug$(LIBRARY_EXT) | |
201 | PROFILE_LIB = $(NAME)_profile$(LIBRARY_EXT) | |
202 | RELEASE_IMPLIB = lib$(RELEASE_LIB:.dll=.a) | |
203 | DEBUG_IMPLIB = lib$(DEBUG_LIB:.dll=.a) | |
204 | PROFILE_IMPLIB = lib$(PROFILE_LIB:.dll=.a) | |
205 | INSTALLDIR = /usr/local/bin | |
206 | LIB_INSTALLDIR = /usr/local/lib | |
207 | endif | |
208 | HEADER_INSTALLDIR = /usr/local/include/$(NAME) | |
209 | INSTALLDIR = /usr/local/lib | |
210 | MASTER_INTERFACE_DIR = $(SYMROOT)/interfaces | |
211 | # Next four dirs are used at build time, but not install time | |
212 | PUBLIC_HEADER_DIR = $(SYMROOT)/Headers/$(NAME) | |
213 | PRIVATE_HEADER_DIR = $(SYMROOT)/PrivateHeaders/$(NAME) | |
214 | PROJECT_HEADER_DIR = $(OBJROOT)/$(NAME).build/ProjectHeaders/$(NAME) | |
215 | RESOURCE_DIR = $(SYMROOT) | |
216 | else | |
217 | LIBRARY_STYLE = Framework | |
218 | RELEASE_LIB = $(NAME) | |
219 | DEBUG_LIB = $(NAME)_debug | |
220 | PROFILE_LIB = $(NAME)_profile | |
221 | INSTALLDIR = /System/Library/Frameworks | |
222 | FRAMEWORK_DIR = /System/Library/Frameworks/$(NAME).framework | |
223 | MASTER_INTERFACE_DIR = /AppleInternal/Carbon/interfaces | |
224 | # Next three dirs are used at build time, but not install time | |
225 | PUBLIC_HEADER_DIR = $(SYMROOT)/$(NAME).framework/Versions/A/Headers | |
226 | PRIVATE_HEADER_DIR = $(SYMROOT)/$(NAME).framework/Versions/A/PrivateHeaders | |
227 | PROJECT_HEADER_DIR = $(OBJROOT)/$(NAME).build/ProjectHeaders | |
228 | endif | |
229 | ||
230 | ifeq "$(PLATFORM)" "Darwin" | |
231 | LFLAGS = $(ARCH_FLAGS) -dynamiclib -dynamic | |
232 | endif | |
233 | ||
234 | ifeq "$(PLATFORM)" "FreeBSD" | |
235 | LFLAGS = -shared | |
236 | endif | |
237 | ||
238 | ifeq "$(PLATFORM)" "CYGWIN" | |
239 | # -mno-cygwin can be left out to build using the CYGWIN unix emulation libs | |
240 | LFLAGS = -mno-cygwin -L$(SYMROOT) | |
241 | endif | |
242 | ||
243 | # other flags passed in from the make command line, and RC | |
244 | CFLAGS += $(OTHER_CFLAGS) $(RC_CFLAGS) | |
245 | CPPFLAGS += $(OTHER_CPPFLAGS) $(RC_CFLAGS) | |
246 | LFLAGS += $(OTHER_LFLAGS) | |
247 | ||
248 | ||
249 | # Needed to find Project Headers, which work in PB because of the fancy -header-mapfile feature. | |
250 | CFLAGS += -I$(PROJECT_HEADER_DIR) | |
251 | CPPFLAGS += -I$(PROJECT_HEADER_DIR) | |
252 | # Needed for cases when a private header is included as "Foo.h" instead of <CF/Foo.h> | |
253 | CFLAGS += -I$(PRIVATE_HEADER_DIR) | |
254 | CPPFLAGS += -I$(PRIVATE_HEADER_DIR) | |
255 | ifeq "$(LIBRARY_STYLE)" "Library" | |
256 | # Needed for headers included as <CF/Foo.h>, since there is no -FframeworkDir mechanism at work | |
257 | CFLAGS += -I$(PUBLIC_HEADER_DIR)/.. -I$(PRIVATE_HEADER_DIR)/.. | |
258 | CPPFLAGS += -I$(PUBLIC_HEADER_DIR)/.. -I$(PRIVATE_HEADER_DIR)/.. | |
259 | endif | |
260 | ||
261 | ||
262 | .PHONY: build all prebuild release debug profile debug-build release-build profile-build build-realwork test | |
263 | default: build | |
264 | all: build | |
265 | build: prebuild debug-build release-build profile-build | |
266 | release: prebuild release-build | |
267 | debug: prebuild debug-build | |
268 | profile: 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 | ||
282 | installsrc: | |
283 | $(SILENT) $(ECHO) "Installing source..." | |
284 | ifeq "$(SRCROOT)" "." | |
285 | $(SILENT) $(ECHO) "SRCROOT must be defined to be the destination directory; it cannot be '.'" | |
286 | exit 1 | |
287 | endif | |
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 | ||
298 | installhdrs: | |
299 | $(SILENT) $(ECHO) "Installing headers..." | |
300 | ifeq "$(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 #*/ | |
317 | endif | |
318 | ifeq "$(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 #*/ | |
323 | endif | |
324 | ||
325 | install: build install_before install_builtin install_after | |
326 | install_before:: | |
327 | install_after:: | |
328 | ||
329 | install_builtin: | |
330 | $(SILENT) $(ECHO) "Installing..." | |
331 | ifeq "$(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) | |
342 | endif | |
343 | ifeq "$(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) | |
352 | ifneq "$(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) | |
356 | endif | |
357 | $(SILENT) $(CHMOD) 755 $(DSTROOT)/$(INSTALLDIR)/$(RELEASE_LIB) | |
358 | $(SILENT) $(CHMOD) 755 $(DSTROOT)/$(INSTALLDIR)/$(DEBUG_LIB) | |
359 | $(SILENT) $(CHMOD) 755 $(DSTROOT)/$(INSTALLDIR)/$(PROFILE_LIB) | |
360 | ifeq "$(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) | |
372 | endif | |
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 #*/ | |
377 | endif | |
378 | ||
379 | #-------------------------------------------------------------------------------- | |
380 | # CLEAN | |
381 | #-------------------------------------------------------------------------------- | |
382 | ||
383 | clean: clean_before clean_builtin clean_after | |
384 | clean_before:: | |
385 | clean_after:: | |
386 | ||
387 | clean_builtin: | |
388 | $(SILENT) $(ECHO) "Deleting build products..." | |
389 | $(REMOVE_RECUR) $(OBJROOT)/$(NAME).build | |
390 | ifeq "$(LIBRARY_STYLE)" "Framework" | |
391 | $(REMOVE_RECUR) $(SYMROOT)/$(NAME).framework | |
392 | endif | |
393 | ifeq "$(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) | |
398 | ifeq "$(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) | |
411 | endif | |
412 | endif | |
413 | ||
414 | #-------------------------------------------------------------------------------- | |
415 | # PREBUILD | |
416 | #-------------------------------------------------------------------------------- | |
417 | ||
418 | prebuild: prebuild_before prebuild_setup prebuild_headers prebuild_after | |
419 | prebuild_before:: | |
420 | prebuild_after:: | |
421 | ||
422 | # build the framework, or other basic dir structure | |
423 | prebuild_setup:: | |
424 | $(SILENT) $(ECHO) "Prebuild-setup..." | |
425 | $(SILENT) $(MKDIRS) $(SYMROOT) | |
426 | ifeq "$(LIBRARY_STYLE)" "Framework" | |
427 | prebuild_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 | |
433 | endif | |
434 | ||
435 | ifeq "$(LIBRARY_STYLE)" "Framework" | |
436 | PLATFORM_IFLAGS = -framework $(NAME) -frameworkInterfaces $(IFILES_DIR) | |
437 | ALL_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 | |
440 | prebuild_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 | |
449 | ifneq "$(ALL_IFILES)" "" | |
450 | $(SILENT) $(MAKE) prebuild_gen_headers | |
451 | endif | |
452 | $(SILENT) $(TOUCH) $(OBJROOT)/$(NAME).build/Headers.touch | |
453 | else | |
454 | ||
455 | ALL_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 | |
458 | prebuild_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 | |
467 | ifneq "$(ALL_IFILES)" "" | |
468 | $(SILENT) $(MAKE) prebuild_gen_headers | |
469 | endif | |
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)`) | |
479 | PLATFORM_IFLAGS = -framework $(NAME) -frameworkInterfaces `cygpath -w $(IFILES_DIR)/` | |
480 | endif | |
481 | prebuild_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)/` | |
490 | ifeq "$(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 #*/ | |
498 | endif | |
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 | ||
504 | prebuild_copy_headers: | |
505 | $(SILENT) $(ECHO) "Copying headers..." | |
506 | ifneq "$(strip $(PUBLIC_HFILES))" "" | |
507 | $(SILENT) $(COPY) $(PUBLIC_HFILES) $(PUBLIC_HEADER_DIR) | |
508 | endif | |
509 | ifneq "$(strip $(PRIVATE_HFILES))" "" | |
510 | $(SILENT) $(COPY) $(PRIVATE_HFILES) $(PRIVATE_HEADER_DIR) | |
511 | endif | |
512 | ifneq "$(strip $(PROJECT_HFILES))" "" | |
513 | $(SILENT) $(COPY) $(PROJECT_HFILES) $(PROJECT_HEADER_DIR) | |
514 | endif | |
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 | |
526 | release-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 | |
535 | debug-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 | |
545 | profile-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 | ||
556 | OFILE_DIR = $(OBJROOT)/$(NAME).build/$(BUILD_TYPE)_ofiles | |
557 | ||
558 | build-realwork: check-vars-defined compile-before build-compile compile-after build-link | |
559 | compile-before:: | |
560 | compile-after:: | |
561 | ||
562 | build-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 | ||
588 | ifeq "$(CPP_FILES)" "" | |
589 | LINKER_CMD = $(CC) | |
590 | else | |
591 | LINKER_CMD = $(CPLUSPLUS) | |
592 | endif | |
593 | ||
594 | build-link: | |
595 | $(SILENT) $(ECHO) "Linking..." | |
596 | ifeq "$(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) | |
599 | endif | |
600 | ifeq "$(PLATFORM)" "Linux" | |
601 | $(SILENT) $(ECHO) "NOTE: Producing static libraries on Linux" | |
602 | $(SILENT) ar cr $(SYMROOT)/$(BUILD_PRODUCT) $(OFILE_DIR)/*.o #*/ | |
603 | endif | |
604 | ifeq "$(PLATFORM)" "FreeBSD" | |
605 | $(SILENT) $(LINKER_CMD) $(LFLAGS) -O -o $(SYMROOT)/$(BUILD_PRODUCT) $(OFILE_DIR)/*.o $(LIBS) #*/ | |
606 | endif | |
607 | ifeq "$(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 | |
618 | endif | |
619 | $(SILENT) $(ECHO) "Done!" | |
620 | ||
621 | # Make sure a couple variables are defined. | |
622 | check-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 |