|
|
1.1 root 1: # build/Common.gmake
2: #
3: # Global build system setup file
4: #
5: # $Id: Common.gmake,v 1.60 2006/12/29 02:54:32 rswindell Exp $
6: #
7: #############################################################################
8: # @format.tab-size 4 (Plain Text/Source Code File Header) #
9: # @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) #
10: # #
11: # Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html #
12: # #
13: # This program is free software; you can redistribute it and/or #
14: # modify it under the terms of the GNU General Public License #
15: # as published by the Free Software Foundation; either version 2 #
16: # of the License, or (at your option) any later version. #
17: # See the GNU General Public License for more details: gpl.txt or #
18: # http://www.fsf.org/copyleft/gpl.html #
19: # #
20: # Anonymous FTP access to the most recent released source is available at #
21: # ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net #
22: # #
23: # Anonymous CVS access to the development source and modification history #
24: # is available at cvs.synchro.net:/cvsroot/sbbs, example: #
25: # cvs -d :pserver:[email protected]:/cvsroot/sbbs login #
26: # (just hit return, no password is necessary) #
27: # cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src #
28: # #
29: # For Synchronet coding style and modification guidelines, see #
30: # http://www.synchro.net/source.html #
31: # #
32: # You are encouraged to submit any modifications (preferably in Unix diff #
33: # format) via e-mail to [email protected] #
34: # #
35: # Note: If this box doesn't appear square, then you need to fix your tabs. #
36: #############################################################################
37: # #
38: #############################################################################
39: # #
40: # Common macro setup for GNU make #
41: # #
42: # Common Build Macros REQUIRED: #
43: # SRC_ROOT - *MUST* be set to the src dir #
44: # #
45: # Common Build Macros Used: #
46: # DEBUG - Create a debug build #
47: # PROFILE - Generates binaries which generate gprof details #
48: # (GCC/DEBUG only) #
49: # UPROFILE - Generates binaries which generate profile-driven #
50: # optimization data #
51: # (GCC/DEBUG only) #
52: # GCOV - Generates binaries that produce gcov data #
53: # (GCC/DEBUG only) #
54: # RELEASE - Create a release build #
55: # (Mutually exclusive, if both are set, RELEASE #
56: # is cleared) #
57: # USE_UPROFILE - Builds using information generated by UPROFILE. #
58: # (RELEASE builds only) #
59: # DONT_CLOBBER_CC - Do not change the default setting of CC #
60: # OBJPATH_SUFFIX - Suffix appended to OBJPATH usefull for compiling #
61: # different options of the same source file #
62: # STATIC - Create a statically linked build if possible #
63: # #
64: # Common Build Macros Defined: #
65: # DELETE - Delete files (Preferrably verbose) #
66: # MTOBJODIR - Object output dir #
67: # OBJODIR - Object output dir #
68: # LIBODIR - Library output dir #
69: # EXEODIR - Executable output dir #
70: # DEBUG - Set for debug builds #
71: # RELEASE - Set for release builds #
72: # One of DEBUG or RELEASE is always set! #
73: # QUIET - Target command prefix to show/not show commands #
74: # (Toggled off by setting VERBOSE) #
75: # CFLAGS - Common C and C++ compiler flags #
76: # CCFLAGS - C specific compiler flags #
77: # CXXFLAGS - C++ specific compiler flags #
78: # LDFLAGS - Linker flags #
79: # CC - C compiler #
80: # CXX - C++ compiler #
81: # EXEFILE - Executable file extension (Includes .) #
82: # OFILE - Object file extension (Includes .) #
83: # SOFILE - Shared object (DLL) file extension (Includes .) #
84: # LIBFILE - Static library file extension (Include .) #
85: # LIBPREFIX - Prefix to library filename #
86: # LIBS - Library names (Appropriate for dependencies) #
87: # LIB_LDFLAGS - Libraries appropriate for link command-line usage #
88: # COMPILE_MSG - Message saying a target is being compiled #
89: # DIRSEP - The directory seperator this system likes most #
90: # VERSION - Synchronet version number in MAJOR.MINOR format #
91: # (Numeric ONLY) #
92: # OUTPUT - Compiler flag specifying output filename #
93: # LOUTPUT - Linker flag specifying output filename #
94: # XPDEV_SRC - Path to xpdev #
95: # UIFC_SRC - Path to uifc #
96: # CIOLIB_SRC - Path to ciolib #
97: # SMBLIB_SRC - Path to smblib #
98: # MT_CFLAGS - CFLAGS for building MT objects #
99: # MT_LDFLAGS - LDFLAGS for linking MT targets #
100: # UL_PRE - Use Library prefix (*nix is -l) #
101: # UL_SUF - Use Library siffix (bcc is .lib) #
102: # #
103: # Common Targets Defined: #
104: # Implicit C and C++ targets #
105: # "clean" target #
106: # Output directory targets #
107: # #
108: #############################################################################
109:
110: # Set VERSION
111: ifndef VERSION
112: VERSION := 3.14
113: endif
114:
115: # Put local (optional) macro definitions in localdefs.mk
116: -include localdefs.mk
117: -include $(SRC_ROOT)/build/localdefs.mk
118:
119: # Set DEBUG
120: ifdef DEBUG
121: ifdef RELEASE
122: $(error Both DEBUG and RELEASE are defined)
123: endif
124: endif
125:
126: ifndef DEBUG
127: ifndef RELEASE
128: DEBUG := 1
129: endif
130: endif
131:
132: ifdef DEBUG
133: ifdef PROFILE
134: CFLAGS += -pg
135: LDFLAGS += -pg
136: endif
137: ifdef UPROFILE
138: CFLAGS += -fprofile-generate
139: LDFLAGS += -fprofile-generate
140: endif
141: ifdef GCOV
142: CFLAGS += -fprofile-arcs -ftest-coverage
143: LDFLAGS += -fprofile-arcs -ftest-coverage
144: endif
145: else
146: ifdef USE_UPROFILE
147: CFLAGS += -fprofile-use
148: LDFLAGS += -fprofile-use
149: endif
150: endif
151:
152: # VERBOSE/QUIET
153: ifndef VERBOSE
154: QUIET := @
155: endif
156:
157: # Compiler-specific options
158: CFLAGS += -MMD
159: ifdef BUILD_DEPENDS
160: ifdef DONT_CLOBBER_CC
161: CC ?= gcc
162: else
163: CC := gcc
164: endif
165: CCPRE := $(CC)
166: CC := $(SRC_ROOT)/build/mkdep -a
167: CXX := $(SRC_ROOT)/build/mkdep -a
168: LD := echo
169: COMPILE_MSG := Depending
170: AR := echo
171: RANLIB := echo
172: else
173: ifdef DONT_CLOBBER_CC
174: CC ?= gcc
175: else
176: CC := gcc
177: endif
178: CCPRE := $(CC)
179: CXX ?= g++
180: LD ?= ld
181: COMPILE_MSG := Compiling
182: AR ?= ar
183: RANLIB ?= ranlib
184: endif
185:
186: ifdef DEBUG
187: BUILD = debug
188: else
189: BUILD = release
190: endif
191: BUILDPATH ?= $(BUILD)
192:
193: # Get OS
194: ifndef os
195: os := $(shell uname)
196: endif
197: os := $(shell echo $(os) | tr '[A-Z]' '[a-z]' | tr ' ' '_')
198:
199: machine := $(shell if uname -m | egrep -v "(i[3456789]*|x)86" > /dev/null; then uname -m | tr "[A-Z]" "[a-z]" | tr " " "_" ; fi)
200: ifeq ($(machine),sparc64)
201: CFLAGS += -D__BIG_ENDIAN__
202: endif
203: ifeq ($(machine),sun4u)
204: CFLAGS += -D__BIG_ENDIAN__
205: endif
206: ifeq ($(machine),power_macintosh)
207: CFLAGS += -D__BIG_ENDIAN__
208: endif
209: ifeq ($(machine),mac68k)
210: CFLAGS += -D__BIG_ENDIAN__
211: endif
212: ifeq ($(machine),)
213: machine := $(os)
214: else
215: machine := $(os).$(machine)
216: endif
217:
218: LIBODIR := $(CCPRE).$(machine).lib.$(BUILDPATH)
219: OBJODIR := $(CCPRE).$(machine).obj.$(BUILDPATH)
220: MTOBJODIR := $(CCPRE).$(machine).obj.$(BUILDPATH)-mt
221: EXEODIR := $(CCPRE).$(machine).exe.$(BUILDPATH)
222: LDFLAGS += -L$(LIBODIR)
223:
224: ifeq ($(os),openbsd)
225: DELETE := rm -f
226: else
227: ifeq ($(os),sunos)
228: DELETE := rm -f
229: else
230: DELETE = rm -fv
231: endif
232: endif
233:
234: LIBPREFIX := lib
235: DIRSEP := /
236: OFILE := .o
237: EXEFILE :=
238: SOFILE := .so
239: LIBFILE := .a
240: UL_PRE := -l
241: UL_SUF :=
242:
243: OUTPUT := -o
244: LOUTPUT := -o
245:
246: ifdef STATIC
247: LDFLAGS += -static
248: CFLAGS += -DSTATIC_LINK
249: endif
250:
251: ifeq ($(os),openbsd)
252: SOFILE := $(SOFILE).$(VERSION)
253: else
254: ifeq ($(os),darwin)
255: SOFILE = .dylib
256: CFLAGS += -Wno-long-double
257: RANLIB += -s
258: endif
259: endif
260:
261: # OS Specific Flags
262: ifeq ($(os),sunos) # Solaris
263: CFLAGS += -D__solaris__ -DNEEDS_DAEMON -DNEEDS_FORKPTY -DNEEDS_CFMAKERAW
264: # Solaris 10 provides setenv()
265: ifeq ($(shell if [ `uname -r | sed 's/\.//'` -lt 510 ] ; then echo "Yes" ; else echo "No" ; fi),Yes)
266: CFLAGS += -DNEEDS_SETENV
267: endif
268: LDFLAGS += -L/opt/sfw/lib
269: endif
270: ifeq ($(os),netbsd) # NetBSD
271: CFLAGS += -D__unix__ -I/usr/pkg/include
272: endif
273: ifeq ($(os),darwin)
274: CFLAGS += -D__unix__ -fno-common -D__DARWIN__
275: endif
276:
277: # PThread-specific flags
278: ifeq ($(os),linux) # Linux
279: ifndef THREADS_ACTUALLY_WORK
280: CFLAGS += -D_THREAD_SUID_BROKEN
281: endif
282: endif
283: MT_CFLAGS += -D_THREAD_SAFE -D_REENTRANT
284: CFLAGS += -D_THREAD_SAFE -D_REENTRANT -D__EXTENSIONS__
285: ifeq ($(os),freebsd) # FreeBSD
286: MT_CFLAGS += -DUSE_XP_SEMAPHORES
287: MT_LDFLAGS += -pthread
288: LDFLAGS += -pthread
289: XP_SEM := 1
290: else
291: ifeq ($(os),openbsd) # OpenBSD
292: MT_CFLAGS += -DUSE_XP_SEMAPHORES
293: MT_LDFLAGS += -pthread
294: LDFLAGS += -pthread
295: XP_SEM := 1
296: else
297: ifeq ($(os),netbsd) # NetBSD
298: MT_CFLAGS += -DUSE_XP_SEMAPHORES
299: MT_LDFLAGS += -L/usr/pkg/lib
300: XP_SEM := 1
301: else
302: ifeq ($(os),qnx) # QNX
303: else
304: ifeq ($(os),darwin) # Darwin/Mac OS X
305: CFLAGS += -D__unix__
306: MT_CFLAGS += -DUSE_XP_SEMAPHORES -D__DARWIN__
307: XP_SEM := 1
308: else
309: ifeq ($(os),sunos) # Solaris
310: XP_SEM := 1
311: MT_CFLAGS += -D_POSIX_PTHREAD_SEMANTICS
312: MT_CFLAGS += -DUSE_XP_SEMAPHORES
313: # This makes ctime_r() be the correct one.
314: CFLAGS += -D_POSIX_PTHREAD_SEMANTICS
315: else # Linux / Other UNIX
316: XP_SEM := 1
317: MT_CFLAGS += -DUSE_XP_SEMAPHORES
318: endif
319: endif
320: endif
321: endif
322: endif
323: endif
324:
325: SHLIBOPTS := -shared
326: ifeq ($(os),darwin)
327: MKSHLIB := libtool -dynamic -framework System -lcc_dynamic
328: MKSHPPLIB := libtool -dynamic -framework System -lcc_dynamic -lstdc++
329: SHLIBOPTS :=
330: else
331: ifeq ($(os),sunos)
332: MKSHLIB := /usr/ccs/bin/ld -G
333: MKSHPPLIB := /usr/ccs/bin/ld -G
334: SHLIBOPTS :=
335: else
336: MKSHLIB := $(CC)
337: MKSHPPLIB := $(CXX)
338: endif
339: endif
340:
341: # Paths
342: XPDEV_SRC := $(SRC_ROOT)$(DIRSEP)xpdev
343: CIOLIB_SRC := $(SRC_ROOT)$(DIRSEP)conio
344: SMBLIB_SRC := $(SRC_ROOT)$(DIRSEP)smblib
345: UIFC_SRC := $(SRC_ROOT)$(DIRSEP)uifc
346:
347: # SDL disabled by default for the moment.
348: ifndef USE_SDL
349: WITHOUT_SDL := 1
350: endif
351:
352: # Pull in lib-specific flags
353: -include $(XPDEV_SRC)$(DIRSEP)Common.make
354: -include $(XPDEV_SRC)$(DIRSEP)Common.gmake
355: -include $(SMBLIB_SRC)$(DIRSEP)Common.make
356: -include $(SMBLIB_SRC)$(DIRSEP)Common.gmake
357: -include $(CIOLIB_SRC)$(DIRSEP)Common.make
358: -include $(CIOLIB_SRC)$(DIRSEP)Common.gmake
359: -include $(UIFC_SRC)$(DIRSEP)Common.make
360: -include $(UIFC_SRC)$(DIRSEP)Common.gmake
361:
362: ifdef DEBUG
363: CFLAGS += -ggdb
364: CFLAGS += -D_DEBUG
365: else # RELEASE
366: # -finline functions breaks the baja build badly.
367: # This also means that -O3 won't work either.
368: CFLAGS := -O2 -fomit-frame-pointer -ffast-math -funroll-loops $(CFLAGS)
369: endif
370:
371: -include targets.mk
372: -include $(SRC_ROOT)/build/rules.mk
373: -include objects.mk # defines $(OBJS)
374:
375: # Implicit C Compile Rule
376: $(OBJODIR)/%$(OFILE) : %.c $(BUILD_DEPENDS)
377: @echo $(COMPILE_MSG) $<
378: $(QUIET)$(CC) $(CFLAGS) $(CCFLAGS) -o $@ -c $<
379:
380: # Implicit C++ Compile Rule
381: $(OBJODIR)/%$(OFILE) : %.cpp $(BUILD_DEPENDS)
382: @echo $(COMPILE_MSG) $<
383: $(QUIET)$(CXX) $(CFLAGS) $(CXXFLAGS) -o $@ -c $<
384:
385: # Implicit MT C Compile Rule
386: $(MTOBJODIR)/%$(OFILE) : %.c $(BUILD_DEPENDS)
387: @echo $(COMPILE_MSG) $<
388: $(QUIET)$(CC) $(CFLAGS) $(CCFLAGS) $(MT_CFLAGS) -o $@ -c $<
389:
390: # Implicit MT C++ Compile Rule
391: $(MTOBJODIR)/%$(OFILE) : %.cpp $(BUILD_DEPENDS)
392: @echo $(COMPILE_MSG) $<
393: $(QUIET)$(CXX) $(CFLAGS) $(CXXFLAGS) $(MT_CFLAGS) -o $@ -c $<
394:
395: depend:
396: $(QUIET)$(DELETE) $(OBJODIR)/.depend
397: $(QUIET)$(DELETE) $(MTOBJODIR)/.depend
398: $(QUIET)$(DELETE) $(LIBODIR)/.depend
399: $(QUIET)$(DELETE) $(EXEODIR)/.depend
400: $(QUIET)$(MAKE) BUILD_DEPENDS=FORCE
401:
402: FORCE:
403:
404: -include $(MTOBJODIR)/.depend
405: -include $(OBJODIR)/.depend
406: -include $(LIBODIR)/.depend
407: -include $(EXEODIR)/.depend
408: -include $(MTOBJODIR)/*.d
409: -include $(OBJODIR)/*.d
410: -include $(LIBODIR)/*.d
411: -include $(EXEODIR)/*.d
412:
413: $(XPDEV_LIB): xpdev
414: xpdev:
415: $(MAKE) -C $(XPDEV_SRC) lib
416:
417: $(XPDEV-MT_LIB): xpdev-mt
418: xpdev-mt:
419: $(MAKE) -C $(XPDEV_SRC) mtlib
420:
421: $(SMBLIB): smblib
422: smblib:
423: $(MAKE) -C $(SMBLIB_SRC) lib
424:
425: $(CIOLIB-MT): ciolib-mt
426: ciolib-mt:
427: $(MAKE) -C $(CIOLIB_SRC) mtlib
428:
429: $(UIFCLIB): uifc
430: uifc:
431: $(MAKE) -C $(UIFC_SRC) lib
432:
433: $(UIFCLIB-MT): uifc-mt
434: uifc-mt:
435: $(MAKE) -C $(UIFC_SRC) mtlib
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.