4 # Common make rules included in ptlib.mak and pwlib.mak
6 # Portable Windows Library
8 # Copyright (c) 1993-1998 Equivalence Pty. Ltd.
10 # The contents of this file are subject to the Mozilla Public License
11 # Version 1.0 (the "License"); you may not use this file except in
12 # compliance with the License. You may obtain a copy of the License at
13 # http://www.mozilla.org/MPL/
15 # Software distributed under the License is distributed on an "AS IS"
16 # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 # the License for the specific language governing rights and limitations
20 # The Original Code is Portable Windows Library.
22 # The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 # Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 # All Rights Reserved.
27 # Contributor(s): ______________________________________.
29 # $Log: common.mak,v $
30 # Revision 1.95 2006/01/08 14:49:08 dsandras
31 # Several fixes to allow compilation on Open Solaris thanks to Brian Lu <brian.lu _AT_____ sun.com>. Many thanks!
33 # Revision 1.94 2004/06/10 01:36:44 csoutheren
34 # Fixed problems with static links
36 # Revision 1.93 2004/04/29 14:07:07 csoutheren
37 # Changed install target to use $(INSTALL)
38 # Various makefile cleanups and verified install and uninstall targets
39 # Removed some vestiges of old GUI code
41 # Revision 1.92 2004/04/24 06:26:03 rjongbloed
42 # Fixed very bizarre problem with GNU GCC 3.4.0 and generating dependencies,
43 # cannot have -g and -M on the command line at the same time!
45 # Revision 1.91 2004/04/21 12:05:04 csoutheren
46 # Added target to create gcc compiled header for ptlib.h, but not used
47 # because it does not seem to be able to compile some files
49 # Revision 1.90 2004/04/14 10:21:15 csoutheren
50 # Grrr...more changes for CXX flags
52 # Revision 1.89 2004/04/14 10:07:00 csoutheren
55 # Revision 1.88 2003/12/29 07:15:31 csoutheren
56 # Fixed problem with creating statically linked executables
58 # Revision 1.87 2003/11/02 15:57:56 shawn
59 # remove -static for Mac OS X
61 # Revision 1.86 2003/10/03 00:36:59 dereksmithies
62 # Fix generation of dependencies. Thanks to Vyacheslav Frolov
64 # Revision 1.85 2003/07/29 11:25:23 csoutheren
65 # Added support for system swab function
67 # Revision 1.84 2003/07/24 22:01:42 dereksmithies
68 # Add fixes from Peter Nixon for fixing install problems. Thanks.
70 # Revision 1.83 2003/06/17 12:05:01 csoutheren
71 # Changed compiler flags for optimised build
73 # Revision 1.82 2003/02/03 06:08:52 robertj
74 # Changed tagbuild so leaves a cvs sticky version of sources to that tag.
76 # Revision 1.81 2002/11/15 06:36:59 robertj
77 # Changed so library build only occurs if source is present.
79 # Revision 1.80 2002/10/10 04:43:44 robertj
80 # VxWorks port, thanks Martijn Roest
82 # Revision 1.79 2002/08/30 11:41:33 robertj
83 # Added guarantee that version numbers exist.
85 # Revision 1.78 2002/08/30 02:23:13 craigs
86 # Added changes for correct creation of debug libraries
87 # thanks to Martin Froehlich
89 # Revision 1.77 2002/06/25 04:13:07 robertj
90 # Added symbol NODEPS so dependency files are not included, very useful for
91 # when they get corrupted so don;t have to manually delete them.
93 # Revision 1.76 2002/04/08 00:41:50 robertj
94 # Added dependency build to "make libs" target.
96 # Revision 1.75 2002/04/01 09:14:09 rogerh
97 # Add noshared build targets
99 # Revision 1.74 2002/02/25 16:23:16 rogerh
100 # Test for GCC 3 in unix.mak and not it common.mak so -DGCC3 can be set
102 # Revision 1.73 2002/02/19 06:26:29 rogerh
103 # Move $$BLD outside quotes so it gets expanded correctly
105 # Revision 1.72 2002/02/18 07:39:04 robertj
106 # Changed version number increment to more portable expr function.
108 # Revision 1.71 2002/01/28 10:33:20 rogerh
109 # use CPLUS instead of gcc. Makes it work on Mac OS X
111 # Revision 1.70 2002/01/28 00:19:59 craigs
112 # Made gcc 3 changes dependent on having gcc 3.0 installed
114 # Revision 1.69 2001/12/17 23:33:50 robertj
115 # Solaris 8 porting changes, thanks James Dugal
117 # Revision 1.68 2001/11/29 07:50:42 robertj
118 # Removed static, it doesn't work either
120 # Revision 1.67 2001/11/29 03:16:49 robertj
121 # Made make noshared completely static
123 # Revision 1.66 2001/11/28 02:44:14 robertj
124 # Fixed attempt to do static link on debug version, causes crashes.
126 # Revision 1.65 2001/11/27 22:42:13 robertj
127 # Changed to make system to better support non-shared library building.
129 # Revision 1.64 2001/10/31 00:45:20 robertj
130 # Added debuglibs, optlibs and bothlibs targets, moving help to where these
131 # targets are in teh make file system.
133 # Revision 1.63 2001/10/12 07:25:33 robertj
134 # Removed diff test, cvs commit already does compare
136 # Revision 1.62 2001/10/12 06:18:41 robertj
137 # Fixed check of change of version file for tagbuild
139 # Revision 1.61 2001/10/09 08:53:26 robertj
140 # Added LIBDIRS variable so can go "make libs" and make all libraries.
141 # Added "make version" target to display version of project.
142 # Added inclusion of library versions into "make tagbuild" check in.
144 # Revision 1.60 2001/08/07 08:24:42 robertj
145 # Fixed bug in tagbuild if have more than one BUILD_NUMBER in file.
147 # Revision 1.59 2001/07/30 07:45:54 robertj
148 # Added "all" target with double colon.
150 # Revision 1.58 2001/07/27 14:39:12 robertj
151 # Allowed libs target to have multiple definitions
153 # Revision 1.57 2001/06/30 06:59:06 yurik
154 # Jac Goudsmit from Be submit these changes 6/28. Implemented by Yuri Kiryanov
156 # Revision 1.56 2001/06/29 06:47:30 robertj
157 # Added missing dollar sign
159 # Revision 1.55 2001/06/29 06:41:03 robertj
160 # Fixed make tagbuild for different #defines
162 # Revision 1.54 2001/05/29 03:31:48 craigs
163 # Removed BROKEN_GCC symbol, now that pwlib is totally gcc friendly
165 # Revision 1.53 2001/03/29 04:48:45 robertj
166 # Added tagbuild target to do CVS tag and autoincrement BUILD_NUMBER
167 # Changed order so version.h is used before custom.cxx
169 # Revision 1.52 2001/03/23 19:59:48 craigs
170 # Added detection of broken gcc versions
172 # Revision 1.51 2001/03/22 01:14:16 robertj
173 # Allowed for the version file #defines to configured by calling makefile.
175 # Revision 1.50 2000/11/02 04:46:42 craigs
176 # Added support for buildnum.h file for version numbers
178 # Revision 1.49 2000/10/01 01:08:10 craigs
179 # Fixed problems with Motif build
181 # Revision 1.48 2000/09/20 23:59:35 craigs
182 # Fixed problem with bothnoshared target
184 # Revision 1.47 2000/04/26 00:40:48 robertj
185 # Redesigned version number system to have single file to change on releases.
187 # Revision 1.46 2000/04/06 20:12:33 craigs
188 # Added install targets
190 # Revision 1.45 2000/03/20 23:08:31 craigs
191 # Added showgui target to allow displaying the GUI settings
193 # Revision 1.44 2000/03/20 22:43:09 craigs
194 # Added totally new mechanism for detecting GUI
196 # Revision 1.43 2000/03/03 00:37:42 robertj
197 # Fixed problem for when have GUI environment variable set, always builds GUI!
199 # Revision 1.42 2000/02/24 11:02:11 craigs
200 # Fixed problems with PW make
202 # Revision 1.41 2000/02/16 11:30:25 craigs
203 # Added rule to force library build for applications
205 # Revision 1.40 2000/02/04 19:33:25 craigs
206 # Added ability to create non-shared versions of programs
208 # Revision 1.39 2000/01/22 00:51:18 craigs
209 # Added ability to compile in any directory, and to create shared libs
211 # Revision 1.38 1999/07/10 03:32:02 robertj
212 # Improved release version detection code.
214 # Revision 1.37 1999/07/03 04:31:53 robertj
215 # Fixed problems with not including oss.cxx in library if OSTYPE not "linux"
217 # Revision 1.36 1999/07/02 05:10:33 robertj
218 # Fixed bug in changing from debug default to opt build
220 # Revision 1.35 1999/06/28 09:12:01 robertj
221 # Fixed problems with the order in which macros are defined especially on BeOS & Solaris
223 # Revision 1.34 1999/06/27 02:42:10 robertj
224 # Fixed BeOS compatability.
225 # Fixed error of platform name not supported, needed :: on main targets.
227 # Revision 1.33 1999/06/09 15:41:18 robertj
228 # Added better UI to make files.
230 # Revision 1.32 1999/04/18 09:36:31 robertj
231 # Get date grammar build.
233 # Revision 1.31 1999/02/19 11:32:10 robertj
234 # Improved the "release" target to build release tar files.
236 # Revision 1.30 1999/01/16 09:56:24 robertj
237 # Changed some macros to more informative names.
239 # Revision 1.29 1999/01/16 04:00:05 robertj
240 # Added bothclean target
242 # Revision 1.28 1998/12/02 02:36:57 robertj
243 # New directory structure.
245 # Revision 1.27 1998/11/26 12:48:20 robertj
246 # Support for .c files.
248 # Revision 1.26 1998/11/26 11:40:03 craigs
249 # Added checking for resource compilation
251 # Revision 1.25 1998/11/26 07:29:19 craigs
252 # Yet another bash at a GUI build environment
254 # Revision 1.24 1998/11/24 03:41:32 robertj
255 # Fixed problem where failed make depend leaves bad .dep files behind
257 # Revision 1.23 1998/11/22 10:41:02 craigs
258 # New GUI build system - for sure!
260 # Revision 1.22 1998/11/22 08:11:31 craigs
261 # *** empty log message ***
263 # Revision 1.21 1998/09/24 04:20:49 robertj
264 # Added open software license.
267 ######################################################################
271 ######################################################################
273 # Submodules built with make lib
274 LIBDIRS += $(PWLIBDIR)
278 OBJDIR = ./$(PT_OBJBASE)
281 vpath %.cxx $(VPATH_CXX)
284 vpath %.dep $(DEPDIR)
285 vpath %.gch $(PWLIBDIR)/include
288 # add common directory to include path - must be after PW and PT directories
290 STDCCFLAGS += -I$(PWLIBDIR)/include
292 ifneq ($(P_SHAREDLIB),1)
294 #ifneq ($(OSTYPE),Darwin) # Mac OS X does not really support -static
298 ifneq ($(P_STATIC_LDFLAGS),)
299 LDFLAGS += $(P_STATIC_LDFLAGS)
302 ifneq ($(P_STATIC_ENDLDLIBS),)
303 ENDLDLIBS += $(P_STATIC_ENDLDLIBS)
308 # clean whitespace out of source file list
309 SOURCES := $(strip $(SOURCES))
312 # define rule for .cxx and .c files
314 $(OBJDIR)/%.o : %.cxx
315 @if [ ! -d $(OBJDIR) ] ; then mkdir -p $(OBJDIR) ; fi
316 $(CPLUS) $(STDCCFLAGS) $(OPTCCFLAGS) $(CFLAGS) $(STDCXXFLAGS) -c $< -o $@
319 @if [ ! -d $(OBJDIR) ] ; then mkdir -p $(OBJDIR) ; fi
320 $(CC) $(STDCCFLAGS) $(OPTCCFLAGS) $(CFLAGS) -c $< -o $@
323 # create list of object files
325 SRC_OBJS := $(SOURCES:.c=.o)
326 SRC_OBJS := $(SRC_OBJS:.cxx=.o)
327 OBJS := $(EXTERNALOBJS) $(patsubst %.o, $(OBJDIR)/%.o, $(notdir $(SRC_OBJS) $(OBJS)))
330 # create list of dependency files
333 SRC_DEPS := $(SOURCES:.c=.dep)
334 SRC_DEPS := $(SRC_DEPS:.cxx=.dep)
335 DEPS := $(patsubst %.dep, $(DEPDIR)/%.dep, $(notdir $(SRC_DEPS) $(DEPS)))
338 # define rule for .dep files
340 $(DEPDIR)/%.dep : %.cxx
341 @if [ ! -d $(DEPDIR) ] ; then mkdir -p $(DEPDIR) ; fi
342 @printf %s $(OBJDIR)/ > $@
343 $(CPLUS) $(STDCCFLAGS:-g=) -M $< >> $@
345 $(DEPDIR)/%.dep : %.c
346 @if [ ! -d $(DEPDIR) ] ; then mkdir -p $(DEPDIR) ; fi
347 @printf %s $(OBJDIR)/ > $@
348 $(CC) $(STDCCFLAGS:-g=) -M $< >> $@
351 # add in good files to delete
353 CLEAN_FILES += $(OBJS) $(DEPS) core
355 ######################################################################
357 # rules for application
359 ######################################################################
364 TARGET = $(OBJDIR)/$(PROG)
368 OBJS += $(OBJDIR)/buildnum.o
371 TARGET_LIBS = $(PWLIBDIR)/lib/$(PTLIB_FILE)
373 # distinguish betweek building and using pwlib
374 ifeq (,$(wildcard $(PWLIBDIR)/src))
375 TARGET_LIBS = $(SYSLIBDIR)/$(PTLIB_FILE)
378 $(TARGET): $(OBJS) $(TARGET_LIBS)
379 ifeq ($(OSTYPE),beos)
380 # BeOS won't find dynamic libraries unless they are in one of the system
381 # library directories or in the lib directory under the application's
383 @if [ ! -L $(OBJDIR)/lib ] ; then cd $(OBJDIR); ln -s $(PW_LIBDIR) lib; fi
385 $(CPLUS) -o $@ $(CFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) $(ENDLDLIBS) $(ENDLDFLAGS)
386 ifeq ($(OSTYPE),VxWorks)
387 $(LD) --split-by-reloc 65535 -r $(OBJS) -o $@
392 ifneq (,$(wildcard $(PWLIBDIR)/src/ptlib/unix))
393 $(PW_LIBDIR)/$(PTLIB_FILE):
394 $(MAKE) -C $(PWLIBDIR)/src/ptlib/unix debug
399 ifneq (,$(wildcard $(PWLIBDIR)/src/ptlib/unix))
400 $(PW_LIBDIR)/$(PTLIB_FILE):
401 $(MAKE) -C $(PWLIBDIR)/src/ptlib/unix opt
406 CLEAN_FILES += $(TARGET)
408 ifndef INSTALL_OVERRIDE
411 $(INSTALL) $(TARGET) $(INSTALLBIN_DIR)
417 $(PWLIBDIR)/include/ptlib.h.gch: $(PWLIBDIR)/include/ptlib.h
418 @if [ ! -d $(OBJDIR) ] ; then mkdir -p $(OBJDIR) ; fi
419 $(CPLUS) $(STDCCFLAGS) $(OPTCCFLAGS) $(CFLAGS) $(STDCXXFLAGS) -x c++ -c $< -o $@
421 PCH := $(PWLIBDIR)/include/ptlib.h.gch
423 ######################################################################
425 # Main targets for build management
427 ######################################################################
429 all :: debuglibs debugdepend debug optlibs optdepend opt
432 @echo "The following targets are available:"
433 @echo " make debug Make debug version of application"
434 @echo " make opt Make optimised version of application"
435 @echo " make both Make both versions of application"
437 @echo " make debugnoshared Make static debug version of application"
438 @echo " make optnoshared Make static optimised version of application"
439 @echo " make bothnoshared Make static both versions of application"
441 @echo " make debugclean Remove debug files"
442 @echo " make optclean Remove optimised files"
443 @echo " make clean Remove both debug and optimised files"
445 @echo " make debugdepend Create debug dependency files"
446 @echo " make optdepend Create optimised dependency files"
447 @echo " make bothdepend Create both debug and optimised dependency files"
449 @echo " make debuglibs Make debug libraries project depends on"
450 @echo " make optlibs Make optimised libraries project depends on"
451 @echo " make bothlibs Make both debug and optimised libraries project depends on"
453 @echo " make all Create debug & optimised dependencies & libraries"
455 @echo " make version Display version for project"
456 @echo " make tagbuild Do a CVS tag of the source, and bump build number"
457 @echo " make release Package up optimised version int tar.gz file"
468 rm -rf $(CLEAN_FILES)
471 @$(MAKE) DEBUG= optclean
473 .DELETE_ON_ERROR : debugdepend
475 debugdepend :: $(DEPS)
476 @echo Created dependencies.
479 @$(MAKE) DEBUG= optdepend
487 set -e; for i in $(LIBDIRS); do $(MAKE) -C $$i debugdepend debug; done
492 @$(MAKE) DEBUG=1 debug
497 @$(MAKE) DEBUG=1 debugclean
500 rm -rf $(CLEAN_FILES)
502 .DELETE_ON_ERROR : optdepend
505 @$(MAKE) DEBUG=1 debugdepend
508 @echo Created dependencies.
511 @$(MAKE) DEBUG=1 libs
516 set -e; for i in $(LIBDIRS); do $(MAKE) -C $$i optdepend opt; done
521 clean :: optclean debugclean
522 bothdepend :: optdepend debugdepend
523 bothlibs :: optlibs debuglibs
526 $(MAKE) P_SHAREDLIB=1 opt
529 $(MAKE) P_SHAREDLIB=1 debug
532 $(MAKE) optshared debugshared
535 $(MAKE) P_SHAREDLIB=0 opt
538 $(MAKE) P_SHAREDLIB=0 debug
541 $(MAKE) optnoshared debugnoshared
545 ######################################################################
547 # common rule to make a release of the program
549 ######################################################################
551 # if have not explictly defined VERSION_FILE, locate a default
554 ifneq (,$(wildcard buildnum.h))
555 VERSION_FILE := buildnum.h
557 ifneq (,$(wildcard version.h))
558 VERSION_FILE := version.h
560 ifneq (,$(wildcard custom.cxx))
561 VERSION_FILE := custom.cxx
570 # Set default strings to search in VERSION_FILE
571 ifndef MAJOR_VERSION_DEFINE
572 MAJOR_VERSION_DEFINE:=MAJOR_VERSION
574 ifndef MINOR_VERSION_DEFINE
575 MINOR_VERSION_DEFINE:=MINOR_VERSION
577 ifndef BUILD_NUMBER_DEFINE
578 BUILD_NUMBER_DEFINE:=BUILD_NUMBER
582 # If not specified, find the various version components in the VERSION_FILE
585 MAJOR_VERSION:=$(strip $(subst \#define,, $(subst $(MAJOR_VERSION_DEFINE),,\
586 $(shell grep "define *$(MAJOR_VERSION_DEFINE) *" $(VERSION_FILE)))))
589 MINOR_VERSION:=$(strip $(subst \#define,, $(subst $(MINOR_VERSION_DEFINE),,\
590 $(shell grep "define *$(MINOR_VERSION_DEFINE)" $(VERSION_FILE)))))
593 BUILD_TYPE:=$(strip $(subst \#define,,$(subst BUILD_TYPE,,\
594 $(subst AlphaCode,alpha,$(subst BetaCode,beta,$(subst ReleaseCode,.,\
595 $(shell grep "define *BUILD_TYPE" $(VERSION_FILE))))))))
598 BUILD_NUMBER:=$(strip $(subst \#define,,$(subst $(BUILD_NUMBER_DEFINE),,\
599 $(shell grep "define *$(BUILD_NUMBER_DEFINE)" $(VERSION_FILE)))))
602 # Finally check that version numbers are not empty
604 ifeq (,$(MAJOR_VERSION))
605 override MAJOR_VERSION:=1
607 ifeq (,$(MINOR_VERSION))
608 override MINOR_VERSION:=0
610 ifeq (,$(BUILD_TYPE))
611 override BUILD_TYPE:=alpha
613 ifeq (,$(BUILD_NUMBER))
614 override BUILD_NUMBER:=0
617 # Check for VERSION either predefined or defined by previous section from VERSION_FILE
619 VERSION:=$(MAJOR_VERSION).$(MINOR_VERSION)$(BUILD_TYPE)$(BUILD_NUMBER)
620 endif # ifndef VERSION
621 endif # ifdef VERSION_FILE
623 # Build the CVS_TAG string from the components
625 CVS_TAG := v$(MAJOR_VERSION)_$(MINOR_VERSION)$(subst .,_,$(BUILD_TYPE))$(BUILD_NUMBER)
630 # Cannot do this in DEBUG mode, so do it without DEBUG
633 $(MAKE) DEBUG= release
641 @echo Must define VERSION macro or have version.h/custom.cxx file.
644 @echo Must define VERSION macro or have version.h/custom.cxx file.
648 # "make release" definition
654 ifndef RELEASEBASEDIR
655 RELEASEBASEDIR=$(PROG)
658 RELEASEPROGDIR=$(RELEASEDIR)/$(RELEASEBASEDIR)
660 release :: $(TARGET) releasefiles
661 cp $(TARGET) $(RELEASEPROGDIR)/$(PROG)
662 cd $(RELEASEDIR) ; tar chf - $(RELEASEBASEDIR) | gzip > $(PROG)_$(VERSION)_$(PLATFORM_TYPE).tar.gz
663 rm -r $(RELEASEPROGDIR)
666 -mkdir -p $(RELEASEPROGDIR)
670 @echo v$(VERSION) " CVS tag:" `cvs status Makefile | grep "Sticky Tag" | sed -e "s/(none)/HEAD/" -e "s/(.*)//" -e "s/^.*://"`
676 @echo Must define VERSION_FILE macro or have version.h/custom.cxx file.
678 else # ifndef VERSION_FILE
683 @echo Must define CVS_TAG macro or have version.h/custom.cxx file.
685 else # ifndef CVS_TAG
688 sed $(foreach dir,$(LIBDIRS), -e "s/ $(notdir $(dir)):.*/ $(notdir $(dir)): $(shell $(MAKE) -s -C $(dir) version)/") $(VERSION_FILE) > $(VERSION_FILE).new
689 mv -f $(VERSION_FILE).new $(VERSION_FILE)
690 cvs commit -m "Pre-tagging check in for $(CVS_TAG)." $(VERSION_FILE)
691 cvs tag -c $(CVS_TAG)
692 BLD=`expr $(BUILD_NUMBER) + 1` ; \
693 echo "Incrementing to build number " $$BLD; \
694 sed "s/$(BUILD_NUMBER_DEFINE)[ ]*[0-9][0-9]*/$(BUILD_NUMBER_DEFINE) $$BLD/" $(VERSION_FILE) > $(VERSION_FILE).new
695 mv -f $(VERSION_FILE).new $(VERSION_FILE)
696 cvs commit -m "Incremented build number after tagging to $(CVS_TAG)." $(VERSION_FILE)
697 cvs -q update -r $(CVS_TAG)
699 endif # else ifndef CVS_TAG
701 endif # else ifndef VERSION_FILE
703 endif # else ifdef VERSION
705 endif # else ifdef DEBUG
708 ######################################################################
710 # rules for creating build number files
712 ######################################################################
715 $(OBJDIR)/buildnum.o: buildnum.c
716 cc -o $(OBJDIR)/buildnum.o -c buildnum.c
719 #buildnum.c: $(SOURCES) $(BUILDFILES)
720 # buildinc buildnum.c
727 ######################################################################
729 # Include all of the dependencies
731 ######################################################################
734 -include $(DEPDIR)/*.dep