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): ______________________________________.
30 # Revision 1.93 2004/04/29 14:07:07 csoutheren
31 # Changed install target to use $(INSTALL)
32 # Various makefile cleanups and verified install and uninstall targets
33 # Removed some vestiges of old GUI code
35 # Revision 1.92 2004/04/24 06:26:03 rjongbloed
36 # Fixed very bizarre problem with GNU GCC 3.4.0 and generating dependencies,
37 # cannot have -g and -M on the command line at the same time!
39 # Revision 1.91 2004/04/21 12:05:04 csoutheren
40 # Added target to create gcc compiled header for ptlib.h, but not used
41 # because it does not seem to be able to compile some files
43 # Revision 1.90 2004/04/14 10:21:15 csoutheren
44 # Grrr...more changes for CXX flags
46 # Revision 1.89 2004/04/14 10:07:00 csoutheren
49 # Revision 1.88 2003/12/29 07:15:31 csoutheren
50 # Fixed problem with creating statically linked executables
52 # Revision 1.87 2003/11/02 15:57:56 shawn
53 # remove -static for Mac OS X
55 # Revision 1.86 2003/10/03 00:36:59 dereksmithies
56 # Fix generation of dependencies. Thanks to Vyacheslav Frolov
58 # Revision 1.85 2003/07/29 11:25:23 csoutheren
59 # Added support for system swab function
61 # Revision 1.84 2003/07/24 22:01:42 dereksmithies
62 # Add fixes from Peter Nixon for fixing install problems. Thanks.
64 # Revision 1.83 2003/06/17 12:05:01 csoutheren
65 # Changed compiler flags for optimised build
67 # Revision 1.82 2003/02/03 06:08:52 robertj
68 # Changed tagbuild so leaves a cvs sticky version of sources to that tag.
70 # Revision 1.81 2002/11/15 06:36:59 robertj
71 # Changed so library build only occurs if source is present.
73 # Revision 1.80 2002/10/10 04:43:44 robertj
74 # VxWorks port, thanks Martijn Roest
76 # Revision 1.79 2002/08/30 11:41:33 robertj
77 # Added guarantee that version numbers exist.
79 # Revision 1.78 2002/08/30 02:23:13 craigs
80 # Added changes for correct creation of debug libraries
81 # thanks to Martin Froehlich
83 # Revision 1.77 2002/06/25 04:13:07 robertj
84 # Added symbol NODEPS so dependency files are not included, very useful for
85 # when they get corrupted so don;t have to manually delete them.
87 # Revision 1.76 2002/04/08 00:41:50 robertj
88 # Added dependency build to "make libs" target.
90 # Revision 1.75 2002/04/01 09:14:09 rogerh
91 # Add noshared build targets
93 # Revision 1.74 2002/02/25 16:23:16 rogerh
94 # Test for GCC 3 in unix.mak and not it common.mak so -DGCC3 can be set
96 # Revision 1.73 2002/02/19 06:26:29 rogerh
97 # Move $$BLD outside quotes so it gets expanded correctly
99 # Revision 1.72 2002/02/18 07:39:04 robertj
100 # Changed version number increment to more portable expr function.
102 # Revision 1.71 2002/01/28 10:33:20 rogerh
103 # use CPLUS instead of gcc. Makes it work on Mac OS X
105 # Revision 1.70 2002/01/28 00:19:59 craigs
106 # Made gcc 3 changes dependent on having gcc 3.0 installed
108 # Revision 1.69 2001/12/17 23:33:50 robertj
109 # Solaris 8 porting changes, thanks James Dugal
111 # Revision 1.68 2001/11/29 07:50:42 robertj
112 # Removed static, it doesn't work either
114 # Revision 1.67 2001/11/29 03:16:49 robertj
115 # Made make noshared completely static
117 # Revision 1.66 2001/11/28 02:44:14 robertj
118 # Fixed attempt to do static link on debug version, causes crashes.
120 # Revision 1.65 2001/11/27 22:42:13 robertj
121 # Changed to make system to better support non-shared library building.
123 # Revision 1.64 2001/10/31 00:45:20 robertj
124 # Added debuglibs, optlibs and bothlibs targets, moving help to where these
125 # targets are in teh make file system.
127 # Revision 1.63 2001/10/12 07:25:33 robertj
128 # Removed diff test, cvs commit already does compare
130 # Revision 1.62 2001/10/12 06:18:41 robertj
131 # Fixed check of change of version file for tagbuild
133 # Revision 1.61 2001/10/09 08:53:26 robertj
134 # Added LIBDIRS variable so can go "make libs" and make all libraries.
135 # Added "make version" target to display version of project.
136 # Added inclusion of library versions into "make tagbuild" check in.
138 # Revision 1.60 2001/08/07 08:24:42 robertj
139 # Fixed bug in tagbuild if have more than one BUILD_NUMBER in file.
141 # Revision 1.59 2001/07/30 07:45:54 robertj
142 # Added "all" target with double colon.
144 # Revision 1.58 2001/07/27 14:39:12 robertj
145 # Allowed libs target to have multiple definitions
147 # Revision 1.57 2001/06/30 06:59:06 yurik
148 # Jac Goudsmit from Be submit these changes 6/28. Implemented by Yuri Kiryanov
150 # Revision 1.56 2001/06/29 06:47:30 robertj
151 # Added missing dollar sign
153 # Revision 1.55 2001/06/29 06:41:03 robertj
154 # Fixed make tagbuild for different #defines
156 # Revision 1.54 2001/05/29 03:31:48 craigs
157 # Removed BROKEN_GCC symbol, now that pwlib is totally gcc friendly
159 # Revision 1.53 2001/03/29 04:48:45 robertj
160 # Added tagbuild target to do CVS tag and autoincrement BUILD_NUMBER
161 # Changed order so version.h is used before custom.cxx
163 # Revision 1.52 2001/03/23 19:59:48 craigs
164 # Added detection of broken gcc versions
166 # Revision 1.51 2001/03/22 01:14:16 robertj
167 # Allowed for the version file #defines to configured by calling makefile.
169 # Revision 1.50 2000/11/02 04:46:42 craigs
170 # Added support for buildnum.h file for version numbers
172 # Revision 1.49 2000/10/01 01:08:10 craigs
173 # Fixed problems with Motif build
175 # Revision 1.48 2000/09/20 23:59:35 craigs
176 # Fixed problem with bothnoshared target
178 # Revision 1.47 2000/04/26 00:40:48 robertj
179 # Redesigned version number system to have single file to change on releases.
181 # Revision 1.46 2000/04/06 20:12:33 craigs
182 # Added install targets
184 # Revision 1.45 2000/03/20 23:08:31 craigs
185 # Added showgui target to allow displaying the GUI settings
187 # Revision 1.44 2000/03/20 22:43:09 craigs
188 # Added totally new mechanism for detecting GUI
190 # Revision 1.43 2000/03/03 00:37:42 robertj
191 # Fixed problem for when have GUI environment variable set, always builds GUI!
193 # Revision 1.42 2000/02/24 11:02:11 craigs
194 # Fixed problems with PW make
196 # Revision 1.41 2000/02/16 11:30:25 craigs
197 # Added rule to force library build for applications
199 # Revision 1.40 2000/02/04 19:33:25 craigs
200 # Added ability to create non-shared versions of programs
202 # Revision 1.39 2000/01/22 00:51:18 craigs
203 # Added ability to compile in any directory, and to create shared libs
205 # Revision 1.38 1999/07/10 03:32:02 robertj
206 # Improved release version detection code.
208 # Revision 1.37 1999/07/03 04:31:53 robertj
209 # Fixed problems with not including oss.cxx in library if OSTYPE not "linux"
211 # Revision 1.36 1999/07/02 05:10:33 robertj
212 # Fixed bug in changing from debug default to opt build
214 # Revision 1.35 1999/06/28 09:12:01 robertj
215 # Fixed problems with the order in which macros are defined especially on BeOS & Solaris
217 # Revision 1.34 1999/06/27 02:42:10 robertj
218 # Fixed BeOS compatability.
219 # Fixed error of platform name not supported, needed :: on main targets.
221 # Revision 1.33 1999/06/09 15:41:18 robertj
222 # Added better UI to make files.
224 # Revision 1.32 1999/04/18 09:36:31 robertj
225 # Get date grammar build.
227 # Revision 1.31 1999/02/19 11:32:10 robertj
228 # Improved the "release" target to build release tar files.
230 # Revision 1.30 1999/01/16 09:56:24 robertj
231 # Changed some macros to more informative names.
233 # Revision 1.29 1999/01/16 04:00:05 robertj
234 # Added bothclean target
236 # Revision 1.28 1998/12/02 02:36:57 robertj
237 # New directory structure.
239 # Revision 1.27 1998/11/26 12:48:20 robertj
240 # Support for .c files.
242 # Revision 1.26 1998/11/26 11:40:03 craigs
243 # Added checking for resource compilation
245 # Revision 1.25 1998/11/26 07:29:19 craigs
246 # Yet another bash at a GUI build environment
248 # Revision 1.24 1998/11/24 03:41:32 robertj
249 # Fixed problem where failed make depend leaves bad .dep files behind
251 # Revision 1.23 1998/11/22 10:41:02 craigs
252 # New GUI build system - for sure!
254 # Revision 1.22 1998/11/22 08:11:31 craigs
255 # *** empty log message ***
257 # Revision 1.21 1998/09/24 04:20:49 robertj
258 # Added open software license.
261 ######################################################################
265 ######################################################################
267 # Submodules built with make lib
268 LIBDIRS
+= $(PWLIBDIR
)
272 OBJDIR
= .
/$(PT_OBJBASE
)
275 vpath
%.
cxx $(VPATH_CXX
)
278 vpath
%.dep
$(DEPDIR
)
279 vpath
%.gch
$(PWLIBDIR
)/include
282 # add common directory to include path - must be after PW and PT directories
284 STDCCFLAGS
+= -I
$(PWLIBDIR
)/include
286 ifneq ($(P_SHAREDLIB
),1)
288 ifneq ($(OSTYPE
),Darwin
) # Mac OS X does not really support -static
292 ifneq ($(P_STATIC_LDFLAGS
),)
293 LDFLAGS
+= $(P_STATIC_LDFLAGS
)
296 ifneq ($(P_STATIC_ENDLDLIBS
),)
297 ENDLDLIBS
+= $(P_STATIC_ENDLDLIBS
)
302 # clean whitespace out of source file list
303 SOURCES
:= $(strip $(SOURCES
))
306 # define rule for .cxx and .c files
308 $(OBJDIR
)/%.o
: %.
cxx
309 @if
[ ! -d
$(OBJDIR
) ] ; then mkdir
-p
$(OBJDIR
) ; fi
310 $(CPLUS
) $(STDCCFLAGS
) $(OPTCCFLAGS
) $(CFLAGS
) $(STDCXXFLAGS
) -x c
++ -c
$< -o
$@
313 @if
[ ! -d
$(OBJDIR
) ] ; then mkdir
-p
$(OBJDIR
) ; fi
314 $(CC
) $(STDCCFLAGS
) $(OPTCCFLAGS
) $(CFLAGS
) -x c
-c
$< -o
$@
317 # create list of object files
319 SRC_OBJS
:= $(SOURCES
:.c
=.o
)
320 SRC_OBJS
:= $(SRC_OBJS
:.
cxx=.o
)
321 OBJS
:= $(EXTERNALOBJS
) $(patsubst %.o
, $(OBJDIR
)/%.o
, $(notdir $(SRC_OBJS
) $(OBJS
)))
324 # create list of dependency files
327 SRC_DEPS
:= $(SOURCES
:.c
=.dep
)
328 SRC_DEPS
:= $(SRC_DEPS
:.
cxx=.dep
)
329 DEPS
:= $(patsubst %.dep
, $(DEPDIR
)/%.dep
, $(notdir $(SRC_DEPS
) $(DEPS
)))
332 # define rule for .dep files
334 $(DEPDIR
)/%.dep
: %.
cxx
335 @if
[ ! -d
$(DEPDIR
) ] ; then mkdir
-p
$(DEPDIR
) ; fi
336 @printf
%s
$(OBJDIR
)/ > $@
337 $(CPLUS
) $(STDCCFLAGS
:-g
=) -M
$< >> $@
339 $(DEPDIR
)/%.dep
: %.c
340 @if
[ ! -d
$(DEPDIR
) ] ; then mkdir
-p
$(DEPDIR
) ; fi
341 @printf
%s
$(OBJDIR
)/ > $@
342 $(CC
) $(STDCCFLAGS
:-g
=) -M
$< >> $@
345 # add in good files to delete
347 CLEAN_FILES
+= $(OBJS
) $(DEPS
) core
349 ######################################################################
351 # rules for application
353 ######################################################################
358 TARGET
= $(OBJDIR
)/$(PROG
)
362 OBJS
+= $(OBJDIR
)/buildnum.o
365 TARGET_LIBS
= $(PWLIBDIR
)/lib
/$(PTLIB_FILE
)
367 # distinguish betweek building and using pwlib
368 ifeq (,$(wildcard $(PWLIBDIR
)/src
))
369 TARGET_LIBS
= $(SYSLIBDIR
)/$(PTLIB_FILE
)
372 $(TARGET
): $(OBJS
) $(TARGET_LIBS
)
373 ifeq ($(OSTYPE
),beos
)
374 # BeOS won't find dynamic libraries unless they are in one of the system
375 # library directories or in the lib directory under the application's
377 @if
[ ! -L
$(OBJDIR
)/lib
] ; then cd
$(OBJDIR
); ln
-s
$(PW_LIBDIR
) lib
; fi
379 $(CPLUS
) -o
$@
$(CFLAGS
) $(LDFLAGS
) $(OBJS
) $(LDLIBS
) $(ENDLDLIBS
) $(ENDLDFLAGS
)
380 ifeq ($(OSTYPE
),VxWorks
)
381 $(LD
) --split-by-reloc
65535 -r
$(OBJS
) -o
$@
386 ifneq (,$(wildcard $(PWLIBDIR
)/src
/ptlib
/unix
))
387 $(PW_LIBDIR
)/$(PTLIB_FILE
):
388 $(MAKE
) -C
$(PWLIBDIR
)/src
/ptlib
/unix debug
393 ifneq (,$(wildcard $(PWLIBDIR
)/src
/ptlib
/unix
))
394 $(PW_LIBDIR
)/$(PTLIB_FILE
):
395 $(MAKE
) -C
$(PWLIBDIR
)/src
/ptlib
/unix opt
400 CLEAN_FILES
+= $(TARGET
)
402 ifndef INSTALL_OVERRIDE
405 $(INSTALL
) $(TARGET
) $(INSTALLBIN_DIR
)
411 $(PWLIBDIR
)/include/ptlib.h.gch
: $(PWLIBDIR
)/include/ptlib.h
412 @if
[ ! -d
$(OBJDIR
) ] ; then mkdir
-p
$(OBJDIR
) ; fi
413 $(CPLUS
) $(STDCCFLAGS
) $(OPTCCFLAGS
) $(CFLAGS
) $(STDCXXFLAGS
) -x c
++ -c
$< -o
$@
415 PCH
:= $(PWLIBDIR
)/include/ptlib.h.gch
417 ######################################################################
419 # Main targets for build management
421 ######################################################################
423 all :: debuglibs debugdepend debug optlibs optdepend opt
426 @echo
"The following targets are available:"
427 @echo
" make debug Make debug version of application"
428 @echo
" make opt Make optimised version of application"
429 @echo
" make both Make both versions of application"
431 @echo
" make debugnoshared Make static debug version of application"
432 @echo
" make optnoshared Make static optimised version of application"
433 @echo
" make bothnoshared Make static both versions of application"
435 @echo
" make debugclean Remove debug files"
436 @echo
" make optclean Remove optimised files"
437 @echo
" make clean Remove both debug and optimised files"
439 @echo
" make debugdepend Create debug dependency files"
440 @echo
" make optdepend Create optimised dependency files"
441 @echo
" make bothdepend Create both debug and optimised dependency files"
443 @echo
" make debuglibs Make debug libraries project depends on"
444 @echo
" make optlibs Make optimised libraries project depends on"
445 @echo
" make bothlibs Make both debug and optimised libraries project depends on"
447 @echo
" make all Create debug & optimised dependencies & libraries"
449 @echo
" make version Display version for project"
450 @echo
" make tagbuild Do a CVS tag of the source, and bump build number"
451 @echo
" make release Package up optimised version int tar.gz file"
462 rm -rf
$(CLEAN_FILES
)
465 @
$(MAKE
) DEBUG
= optclean
467 .DELETE_ON_ERROR
: debugdepend
469 debugdepend
:: $(DEPS
)
470 @echo Created dependencies.
473 @
$(MAKE
) DEBUG
= optdepend
481 set
-e
; for i in
$(LIBDIRS
); do
$(MAKE
) -C
$$i debugdepend debug
; done
486 @
$(MAKE
) DEBUG
=1 debug
491 @
$(MAKE
) DEBUG
=1 debugclean
494 rm -rf
$(CLEAN_FILES
)
496 .DELETE_ON_ERROR
: optdepend
499 @
$(MAKE
) DEBUG
=1 debugdepend
502 @echo Created dependencies.
505 @
$(MAKE
) DEBUG
=1 libs
510 set
-e
; for i in
$(LIBDIRS
); do
$(MAKE
) -C
$$i optdepend opt
; done
515 clean :: optclean debugclean
516 bothdepend
:: optdepend debugdepend
517 bothlibs
:: optlibs debuglibs
520 $(MAKE
) P_SHAREDLIB
=1 opt
523 $(MAKE
) P_SHAREDLIB
=1 debug
526 $(MAKE
) optshared debugshared
529 $(MAKE
) P_SHAREDLIB
=0 opt
532 $(MAKE
) P_SHAREDLIB
=0 debug
535 $(MAKE
) optnoshared debugnoshared
539 ######################################################################
541 # common rule to make a release of the program
543 ######################################################################
545 # if have not explictly defined VERSION_FILE, locate a default
548 ifneq (,$(wildcard buildnum.h
))
549 VERSION_FILE
:= buildnum.h
551 ifneq (,$(wildcard version.h
))
552 VERSION_FILE
:= version.h
554 ifneq (,$(wildcard custom.
cxx))
555 VERSION_FILE
:= custom.
cxx
564 # Set default strings to search in VERSION_FILE
565 ifndef MAJOR_VERSION_DEFINE
566 MAJOR_VERSION_DEFINE
:=MAJOR_VERSION
568 ifndef MINOR_VERSION_DEFINE
569 MINOR_VERSION_DEFINE
:=MINOR_VERSION
571 ifndef BUILD_NUMBER_DEFINE
572 BUILD_NUMBER_DEFINE
:=BUILD_NUMBER
576 # If not specified, find the various version components in the VERSION_FILE
579 MAJOR_VERSION
:=$(strip $(subst \
#define,, $(subst $(MAJOR_VERSION_DEFINE),,\
580 $(shell grep
"define *$(MAJOR_VERSION_DEFINE) *" $(VERSION_FILE
)))))
583 MINOR_VERSION
:=$(strip $(subst \
#define,, $(subst $(MINOR_VERSION_DEFINE),,\
584 $(shell grep
"define *$(MINOR_VERSION_DEFINE)" $(VERSION_FILE
)))))
587 BUILD_TYPE
:=$(strip $(subst \
#define,,$(subst BUILD_TYPE,,\
588 $(subst AlphaCode
,alpha
,$(subst BetaCode
,beta
,$(subst ReleaseCode
,.
,\
589 $(shell grep
"define *BUILD_TYPE" $(VERSION_FILE
))))))))
592 BUILD_NUMBER
:=$(strip $(subst \
#define,,$(subst $(BUILD_NUMBER_DEFINE),,\
593 $(shell grep
"define *$(BUILD_NUMBER_DEFINE)" $(VERSION_FILE
)))))
596 # Finally check that version numbers are not empty
598 ifeq (,$(MAJOR_VERSION
))
599 override MAJOR_VERSION
:=1
601 ifeq (,$(MINOR_VERSION
))
602 override MINOR_VERSION
:=0
604 ifeq (,$(BUILD_TYPE
))
605 override BUILD_TYPE
:=alpha
607 ifeq (,$(BUILD_NUMBER
))
608 override BUILD_NUMBER
:=0
611 # Check for VERSION either predefined or defined by previous section from VERSION_FILE
613 VERSION
:=$(MAJOR_VERSION
).
$(MINOR_VERSION
)$(BUILD_TYPE
)$(BUILD_NUMBER
)
614 endif # ifndef VERSION
615 endif # ifdef VERSION_FILE
617 # Build the CVS_TAG string from the components
619 CVS_TAG
:= v
$(MAJOR_VERSION
)_
$(MINOR_VERSION
)$(subst .
,_
,$(BUILD_TYPE
))$(BUILD_NUMBER
)
624 # Cannot do this in DEBUG mode, so do it without DEBUG
627 $(MAKE
) DEBUG
= release
635 @echo Must
define VERSION macro or have version.h
/custom.
cxx file.
638 @echo Must
define VERSION macro or have version.h
/custom.
cxx file.
642 # "make release" definition
648 ifndef RELEASEBASEDIR
649 RELEASEBASEDIR
=$(PROG
)
652 RELEASEPROGDIR
=$(RELEASEDIR
)/$(RELEASEBASEDIR
)
654 release
:: $(TARGET
) releasefiles
655 cp
$(TARGET
) $(RELEASEPROGDIR
)/$(PROG
)
656 cd
$(RELEASEDIR
) ; tar chf
- $(RELEASEBASEDIR
) | gzip
> $(PROG
)_
$(VERSION
)_
$(PLATFORM_TYPE
).
tar.gz
657 rm -r
$(RELEASEPROGDIR
)
660 -mkdir
-p
$(RELEASEPROGDIR
)
664 @echo v
$(VERSION
) " CVS tag:" `cvs status Makefile | grep "Sticky Tag" | sed -e "s/(none)/HEAD/" -e "s/(.*)//" -e "s/^.*://"`
670 @echo Must
define VERSION_FILE macro or have version.h
/custom.
cxx file.
672 else # ifndef VERSION_FILE
677 @echo Must
define CVS_TAG macro or have version.h
/custom.
cxx file.
679 else # ifndef CVS_TAG
682 sed
$(foreach dir,$(LIBDIRS
), -e
"s/ $(notdir $(dir)):.*/ $(notdir $(dir)): $(shell $(MAKE) -s -C $(dir) version)/") $(VERSION_FILE
) > $(VERSION_FILE
).new
683 mv
-f
$(VERSION_FILE
).new
$(VERSION_FILE
)
684 cvs commit
-m
"Pre-tagging check in for $(CVS_TAG)." $(VERSION_FILE
)
685 cvs tag
-c
$(CVS_TAG
)
686 BLD
=`expr $(BUILD_NUMBER) + 1` ; \
687 echo
"Incrementing to build number " $$BLD; \
688 sed
"s/$(BUILD_NUMBER_DEFINE)[ ]*[0-9][0-9]*/$(BUILD_NUMBER_DEFINE) $$BLD/" $(VERSION_FILE
) > $(VERSION_FILE
).new
689 mv
-f
$(VERSION_FILE
).new
$(VERSION_FILE
)
690 cvs commit
-m
"Incremented build number after tagging to $(CVS_TAG)." $(VERSION_FILE
)
691 cvs
-q update
-r
$(CVS_TAG
)
693 endif # else ifndef CVS_TAG
695 endif # else ifndef VERSION_FILE
697 endif # else ifdef VERSION
699 endif # else ifdef DEBUG
702 ######################################################################
704 # rules for creating build number files
706 ######################################################################
709 $(OBJDIR
)/buildnum.o
: buildnum.c
710 cc -o
$(OBJDIR
)/buildnum.o
-c buildnum.c
713 #buildnum.c: $(SOURCES) $(BUILDFILES)
714 # buildinc buildnum.c
721 ######################################################################
723 # Include all of the dependencies
725 ######################################################################
728 -include $(DEPDIR
)/*.dep