make: fix CPU reset in some conditions
[sip-router] / Makefile.defs
1 # $Id$
2 #
3 # makefile defs (CC, LD,a.s.o)
4 #
5 # Environment variables:
6 #   PREFIX, LOCALBASE, BASEDIR
7 #   INSTALL, TAR , CC, LEX, YACC,
8 #   CPU, CC_EXTRA_OPTS,
9 #   exclude_modules, skip_modules, include_modules
10 #   extra_defs
11 #
12 # History:
13 # --------
14 #              created by andrei
15 #  2003-02-24  added LOCALBASE, fixed doc_dir for freebsd - patch provided
16 #               by Maxim Sobolev <sobomax@FreeBSD.org>
17 #  2003-02-25  added -DDISABLE_NAGLE (andrei)
18 #  2003-03-02  added -DDIGEST_DOMAIN (janakj)
19 #  2003-03-10  added -xcode=pic32 for module compilation w/ sun cc
20 #               (too many symbols for pic13)  (andrei)
21 #  2003-04-16  added CC_EXTRA_OPTS, s/march/mcpu, added CPU (cpu to optimize 
22 #               for, used only with gcc-3.x) (andrei)
23 #  2003-05-23  check if this makefile was already included (andrei)
24 #              removed -DDIGEST_DOMAIN (andrei)
25 #  2003-05-30  added extra_defs (andrei)
26 #  2003-06-06  moved compiler detection before DEFS (andrei)
27 #  2003-06-10  removed -m32 for gcc 3.x/sparc64  -- it will use 
28 #              arch. default: -m32 on solaris, -m64 on *bsd (andrei)
29 #  2003-09-25  added -pthread into LIBS when compiling on FreeBSD/alpha
30 #              and other FreeBSD arches for which no fast locking assembly
31 #              code exists (sobomax)
32 #  2003-11-08  mips1 support introduced (andrei)
33 #  2003-11-24  openbsd 3.4 (elf) fixes (andrei)
34 #  2004-07-27  darwin (mac os x) port  (andrei)
35 #  2004-09-12  mips2 & cobalt support introduced (andrei)
36 #  2004-09-28  x86_64 support introduced (andrei)
37 #  2004-12-14  gcc-3.4 special case added (andrei)
38 #  2004-12-15  HAVE_ALLOCA_H added (andrei)
39 #  2004-12-19  amd64 transformed in x86_64 (andrei)
40 #  2005-04-27  alpha support added (andrei)
41 #  2005-06-01  use $(LOCALBASE) instead of /usr/{local,pkg} (andrei)
42 #  2005-06-26  numeric OSREL & HAVE_KQUEUE added to the *BSD (andrei)
43 #  2005-07-04  HAVE_DEVPOLL added to solaris (andrei)
44 #  2005-07-06  gcc 4.0 optimizations support (andrei)
45 #  2005-07-25  better solaris arch detection (andrei)
46 #  2005-09-12  -mallign-double removed (too many problems) (andrei)
47 #  2005-10-02  distcc get gcc version hack (andrei)
48 #  2006-03-30  64 bit mode compile by default on sparc64 (-m64), added
49 #              CC_GCC_LIKE_ASM and SPARC64_MODE (andrei)
50 #              sparc <= v8 support (andrei)
51 #  2006-03-31  armv6 & mips64 support added
52 #              mips and arm set to NOSMP by default (andrei)
53 #  2006-07-10  added -DPROFILING (hscholz)
54 #  2007-02-09  added TLS_HOOKS and CORE_TLS support, obsoleted TLS=1
55 #              added TLS_EXTRA_LIBS (andrei)
56 #  2007-03-16  added LIB building options: LIB_LDFLAGS, LIB_SONAME, LIB_RPATH,
57 #                INSTALL_LIB, libraries install paths (andrei)
58 #  2007-05-14  futex support if linux 2.5.70+ and 
59 #               use_futex=yes (default) (andrei)
60 #  2007-05-26  changed darwin module link flags (instead of -bundle_loader ser
61 #               -flat_namespace -undefined suppress) (andrei)
62 #  2007-07-07  use isainfo -n to detect cpu type on solaris (andrei)
63 #  2007-07-07  added HAVE_SCHED_SETSCHEDULER for linux (andrei)
64 #  2007-07-18  added DNS_WATCHDOG_SUPPORT (Miklos)
65 #  2007-07-30  added USE_DNS_CACHE_STATS and USE_DST_BLACKLIST_STATS (Gergo)
66 #  2008-06-26  support for make cfg / config.mak and hack to load 
67 #               automatically config.mak when included from a module, lib 
68 #               a.s.o (not from the main Makefile)  (andrei)
69 #  2009-03-10  replaced DEFS with C_DEFS and INCLUDES with C_INCLUDES (DEFS
70 #              and INCLUDES are now used only for "temporary" defines/includes
71 #              inside modules or libs) (andrei)
72 #  2009-09-29  for gcc 4.2+ use -fno-strict-overflow (andrei)
73 #  2009-09-30  find the target architecture from the compiler and not
74 #              from the host (andrei)
75 #  2009-10-01  use -fsigned-char for gcc on ppc, ppc64, arm and arm6
76 #              (on those archs char is unsigned by default) (andrei)
77 #  2010-03-10  added CC_MKDEP_OPTS, which contains to the list of options
78 #               needed to generate dependencies on-the-fly while compiling
79 #               or is empty if the compiler doesn't support it (andrei)
80
81 quiet?=$(if $(filter 1 yes on,$(Q)),silent,verbose)
82
83 # check if already included/exported
84
85 # used for sanity checks for Makefile.defs inclusion (!= makefile_defs which
86 # specifies if we have a set of valid defs)
87 override makefile_defs_included:=1
88 ifeq ($(makefile_defs),1)
89 ifeq ($(quiet),verbose)
90 $(info Makefile.defs defs skipped)
91 endif # verbose
92
93 else
94
95 ifeq (,$(main_makefile))
96 # hack to automatically use config.mak in all the modules, without 
97 # changing the current module makefiles (which all include Makefile.defs):
98 # if not called from the main makefile (module, lib or ut):
99 # include config.mak, but if not present or incomplete (makefile_defs!=1)
100 # don't export the vars)
101 COREPATH?= ../..
102 include $(COREPATH)/config.mak
103 ifeq ($(quiet),verbose)
104 $(info config.mak included)
105 endif # verbose
106 # config.mak should set makefile_defs if complete
107 export makefile_defs
108
109 else
110 override makefile_defs=1
111 export makefile_defs
112
113
114 ifeq ($(quiet),verbose)
115 $(info normal Makefile.defs exec)
116 endif # verbose
117
118 # usage: $(call set_if_empty,VAR,value)
119 set_if_empty=$(if $($(1)),,$(eval override $(1)=$(2)))
120
121 # flavour: sip-router, ser or kamailio
122 $(call  set_if_empty,FLAVOUR,sip-router)
123
124 #prefix for various configs and scripts
125 #config name/name-prefix for distributed configs
126 CFG_NAME=sip-router
127 #config name/name-prefix for distributed scripts
128 SCR_NAME=sip-router
129 #name in source tree
130 SRC_NAME=sip-router
131
132 ifeq ($(FLAVOUR),sip-router)
133 # main binary name
134 MAIN_NAME=ser
135 else ifeq ($(FLAVOUR),ser)
136 # main binary name
137 MAIN_NAME=ser
138 else ifeq ($(FLAVOUR),kamailio)
139 # main binary name
140 MAIN_NAME=kamailio
141 # use kamailio config
142 CFG_NAME=kamailio
143 # kamailio statistics on
144 KMSTATS ?= 1
145 # fast malloc statistics on
146 FMSTATS ?= 1
147 else # default:
148 # main binary name
149 MAIN_NAME=sip-router
150 endif
151
152 # what to install
153 INSTALL_FLAVOUR=$(FLAVOUR)
154
155 #version number
156 VERSION = 3
157 PATCHLEVEL = 0
158 SUBLEVEL =  99
159 EXTRAVERSION = -dev1
160
161 # memory debugger switcher
162 # 0 - off (release mode)
163 # 1 - on (devel mode)
164 MEMDBG ?= 1
165
166 SER_VER = $(shell expr $(VERSION) \* 1000000 + $(PATCHLEVEL) \* 1000 + \
167                         $(SUBLEVEL) )
168 RELEASE:=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
169 OS := $(shell uname -s | sed -e s/SunOS/solaris/ -e s/CYGWIN.*/cygwin/ \
170                  | tr "[A-Z]" "[a-z]")
171
172 ifeq ($(OS),solaris)
173         GETARCH=isainfo -n
174 ifeq ($(GETARCH),)
175         GETARCH=uname -p
176 endif
177 else
178         GETARCH=uname -m
179 endif
180
181 HOST_ARCH := $(shell $(GETARCH) |sed -e s/i.86/i386/ -e s/sun4[uv]/sparc64/  \
182                         -e s/armv[3-5].*/arm/  -e s/armv6.*/arm6/ \
183                         -e "s/Power Macintosh/ppc/" \
184                         -e "s/cobalt/mips2/" \
185                         -e s/amd64/x86_64/ -e s/sparcv9/sparc64/ )
186 # fix sparc -> sparc64
187 ifeq ($(HOST_ARCH),sparc)
188         ifeq ($(shell uname -m),sun4u)
189                 HOST_ARCH := sparc64
190         endif
191         ifeq ($(shell uname -m),sun4v)
192                 HOST_ARCH := sparc64
193         endif
194 endif
195
196 OSREL := $(shell uname -r)
197 # numerical version (good for comparisons: A.B.C => A*1000000+B*1000+C)
198 OSREL_N:= $(shell echo $(OSREL) | sed -e 's/^[^0-9]*//' \
199                 -e 's/^\([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*$$/\1/g' | \
200                 (IFS=. read A B C D; R=0; \
201                 [ -n "$$A" ] && R=`expr $$R \* 1000 + $$A` && \
202                 [ -n "$$B" ] && R=`expr $$R \* 1000 + $$B` && \
203                 [ -n "$$C" ] && R=`expr $$R \* 1000 + $$C`; echo $$R ) )
204
205
206 # TLS support
207 CORE_TLS ?= 
208 # by default compile with tls hooks support (so that no ser recompile is
209 #  needed before the tls module can be used)
210 TLS_HOOKS=1
211 ifeq ($(CORE_TLS), 1)
212         RELEASE:=$(RELEASE)-tls
213         TLS_HOOKS:=0
214 endif
215 ifeq ($(TLS_HOOKS), 1)
216 #       RELEASE:=$(RELEASE)-tls
217 endif
218
219 # extra CC command line options (e.g  -march=athlon-mp)
220 CC_EXTRA_OPTS ?=
221
222 # dirs 
223 cfg_dir = etc/$(MAIN_NAME)/
224 bin_dir = sbin/
225 share_dir = share/$(MAIN_NAME)/
226 # lib/$(MAIN_NAME)/modules , lib/$(MAIN_NAME)/modules-s, lib/$(MAIN_NAME)/modules-k
227 modules_dir = lib/$(MAIN_NAME)/
228 lib_dir = lib/$(MAIN_NAME)/
229 ifeq ($(OS), linux)
230         doc_dir = share/doc/$(MAIN_NAME)/
231         man_dir = share/man/
232         data_dir = share/$(MAIN_NAME)/
233         LOCALBASE ?= /usr/local
234 else
235 ifeq ($(OS), freebsd)
236         doc_dir = share/doc/$(MAIN_NAME)/
237         man_dir = man/
238         data_dir = share/$(MAIN_NAME)/
239         LOCALBASE ?= /usr/local
240 else
241 ifeq ($(OS), openbsd)
242         doc_dir = share/doc/$(MAIN_NAME)/
243         man_dir = man/
244         data_dir = share/$(MAIN_NAME)/
245         LOCALBASE ?= /usr/local
246 else
247 ifeq ($(OS), netbsd)
248         doc_dir = share/doc/$(MAIN_NAME)/
249         man_dir = man/
250         data_dir = share/$(MAIN_NAME)/
251         LOCALBASE ?= /usr/pkg
252 else
253 ifeq ($(OS), darwin)
254         doc_dir = share/doc/$(MAIN_NAME)/
255         man_dir = man/
256         data_dir = share/$(MAIN_NAME)/
257         LOCALBASE ?= /usr/local
258 else
259         doc_dir = doc/$(MAIN_NAME)/
260         man_dir = man/
261         data_dir = $(MAIN_NAME)/
262         LOCALBASE ?= /usr/local
263 endif
264 endif
265 endif
266 endif
267 endif
268
269 # Doxygen directory
270 doxygen_dir=doc/doxygen
271
272  # install location
273 DESTDIR ?= $(LOCALBASE)
274 PREFIX ?= $(DESTDIR)
275 prefix = $(PREFIX)
276 # install path is $(basedir) $(prefix) 
277 # example:
278 #  creating a bin. archive in /tmp, which unpacks in /usr/local
279 #  basedir=/tmp
280 #  prefix=/usr/local
281
282 BASEDIR ?=
283 basedir = $(BASEDIR)
284 # install prefixes for various stuff
285 cfg_prefix = $(basedir)$(prefix)
286 bin_prefix = $(basedir)$(prefix)
287 modules_prefix = $(basedir)$(prefix)
288 lib_prefix = $(basedir)$(prefix)
289 doc_prefix = $(basedir)$(prefix)
290 man_prefix = $(basedir)$(prefix)
291 ut_prefix = $(basedir)$(prefix)
292 share_prefix = $(basedir)$(prefix)
293 data_prefix = $(basedir)$(prefix)
294
295
296 # target dirs for various stuff
297 cfg_target = $(prefix)/$(cfg_dir)
298 bin_target = $(prefix)/$(bin_dir)
299 #modules_target = $(prefix)/$(modules_dir)
300 lib_target = $(prefix)/$(lib_dir)
301 doc_target = $(prefix)/$(doc_dir)
302 data_target = $(prefix)/$(data_dir)
303
304
305
306 ifeq ($(OS), solaris)
307 #use GNU versions
308 INSTALL ?= ginstall
309 TAR ?= gtar
310 else
311 INSTALL ?= install
312 TAR ?= tar
313 endif
314
315 INSTALL_TOUCH = touch          # used to create the file first (good to 
316                                #  make solaris install work)
317 INSTALL_CFG = $(INSTALL) -m 644
318 INSTALL_BIN = $(INSTALL) -m 755
319 INSTALL_SCRIPT = $(INSTALL) -m 755
320 INSTALL_MODULES = $(INSTALL) -m 755
321 INSTALL_LIB = $(INSTALL) -m 755
322 INSTALL_DOC = $(INSTALL) -m 644
323 INSTALL_MAN = $(INSTALL) -m 644
324 INSTALL_SHARE = $(INSTALL) -m 644
325
326 #set some vars from the environment (and not make builtins)
327 CC   := $(shell echo "$${CC}")
328 LEX  := $(shell echo "$${LEX}")
329 YACC := $(shell echo "$${YACC}")
330
331
332
333
334 # find compiler name & version
335 ifeq ($(CC),)
336         CC=gcc
337 endif
338 LD= $(CC)
339 CC_LONGVER:=$(shell if  $(CC) -v 2>/dev/null; then \
340                                                 $(CC) -v 2>&1 ;\
341                                         else \
342                                                 $(CC) -V 2>&1 ; \
343                                         fi )
344 MKTAGS=ctags -R .
345
346 #find-out the compiler's name
347
348 ifneq (,$(findstring gcc, $(CC_LONGVER)))
349         CC_NAME=gcc
350         RPAREN=)
351         CC_VER:=$(word 1,$(CC)) $(shell $(CC) - --version|head -n 1|\
352                                 sed  -e 's/([^$(RPAREN)]*)//g' \
353                                          -e 's/^.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/'\
354                                          -e 's/^[^0-9].*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/')
355 #       CC_VER:=$(word 1,$(CC)) $(shell $(CC) - --version|head -n 1|cut -d" " -f 3\
356 #                               |sed -e 's/^.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/'\
357 #                                        -e 's/^[^0-9].*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/')
358         # sed with POSIX.1 regex doesn't support |, + or ? 
359         # (darwin, solaris ...) => this complicated expression
360         MKDEP=$(CC) -MM -MG
361         #transform gcc version into 2.9x or 3.0
362         CC_SHORTVER:=$(shell echo "$(CC_VER)" | cut -d" " -f 2| \
363                                  sed -e 's/[^0-9]*-\(.*\)/\1/'| \
364                                  sed -e 's/2\.9.*/2.9x/' -e 's/3\.[0-3]\..*/3.0/' -e \
365                                         's/3\.[0-3]/3.0/' -e 's/3\.[4-9]\..*/3.4/' -e \
366                                         's/3\.[4-9]/3.4/' -e 's/4\.[0-1]\..*/4.x/' -e \
367                                         's/4\.[0-1]/4.x/' -e 's/4\.[2-9]\..*/4.2+/' -e \
368                                         's/4\.[2-9]$$/4.2+/')
369 ifeq (,$(strip $(filter-out 3.0 3.4 4.x 4.2+,$(CC_SHORTVER))))
370         # dependencies can be generated on-the-fly while compiling *.c
371         CC_MKDEP_OPTS=-MMD -MP
372 endif # 3.0 <= $(CC_SHORTVER) <= 4.x
373 endif # gcc
374
375 ifneq (, $(findstring Sun, $(CC_LONGVER)))
376         CC_NAME=suncc
377         CC_SHORTVER:=$(shell echo "$(CC_LONGVER)"|head -n 1| \
378                                         sed -e 's/.*\([0-9]\.[0-9]\).*/\1/g' )
379         CC_VER=$(CC) $(CC_SHORTVER)
380         MKDEP=$(CC) -xM1 
381 endif
382
383 ifneq (, $(findstring Intel(R) C++ Compiler, $(CC_LONGVER)))
384         # very nice: gcc compatible
385         CC_NAME=icc
386         CC_FULLVER:=$(shell echo "$(CC_LONGVER)"|head -n 1| \
387                                         sed -e 's/.*Version \([0-9]\.[0-9]\.[0-9]*\).*/\1/g' )
388         CC_SHORTVER:=$(shell echo "$(CC_FULLVER)" | cut -d. -f1,2 )
389         CC_VER=$(CC) $(CC_FULLVER)
390         MKDEP=$(CC) -MM 
391 endif
392
393
394 ifeq (,$(CC_NAME))
395 #not found
396         CC_NAME=$(CC)
397         CC_SHORTVER=unknown
398         CC_VER=unknown
399         MKDEP=gcc -MM 
400 $(warning       Unknown compiler $(CC)\; supported compilers: \
401                         gcc, sun cc, intel icc )
402 endif
403
404 # ARCH detection
405 # predefined compiler macros for different architectures
406 # (see http://predef.sourceforge.net/prearch.html for a more complete list)
407 i386_macros= i386 __i386__ __i486__ __i586__ __i686__ \
408                         __i386 _M_IX86 __X86__ _X86_
409 x86_64_macros= __amd64__ __amd64 __x86_64__ __x86_64 _M_X64
410
411 sparc_macros= __sparc__ __sparc __sparcv8
412 sparc64_macros= __sparcv9 __sparc_v9__
413
414 arm_macros= __arm__ __thumb__
415 arm6_macros= __ARM_ARCH_6__
416
417 ppc_macros= __powerpc __powerpc__ __POWERPC__ __ppc__ _ARCH_PPC
418 ppc64_macros= __ppc64__ _ARCH_PPC64
419
420 mips_macros= __mips__ __mips _MIPS_ARCH_MIPS1
421 mips2_macros= _MIPS_ISA_MIPS2 _MIPS_ISA_MIPS3 _MIPS_ISA_MIPS4 \
422                         _MIPS_ARCH_MIPS2 _MIPS_ARCH_MIPS3 _MIPS_ARCH_MIPS4
423 mips64_macros= _MIPS_ISA_MIPS64 _MIPS_ARCH_MIPS64
424
425 alpha_macros= __alpha__ __alpha _M_ALPHA_
426
427 ifeq ($(CC_NAME),gcc)
428 #if gcc use gcc arch
429 predef_macros:=$(shell $(CC) -dM -E -x c $(CC_EXTRA_OPTS) $(extra_defs) \
430                                         $(CFLAGS) /dev/null)
431
432 ifneq ($(strip $(filter $(i386_macros), $(predef_macros))),)
433 CC_ARCH=i386
434 else ifneq ($(strip $(filter $(x86_64_macros), $(predef_macros))),)
435 CC_ARCH=x86_64
436 else ifneq ($(strip $(filter $(sparc_macros), $(predef_macros))),)
437
438 ifneq ($(strip $(filter $(sparc64_macros), $(predef_macros))),)
439 CC_ARCH=sparc64
440 else # sparc64_macros
441 CC_ARCH=sparc
442 endif # sparc64_macros
443
444 else ifneq ($(strip $(filter $(arm_macros), $(predef_macros))),)
445
446 ifneq ($(strip $(filter $(arm6_macros), $(predef_macros))),)
447 CC_ARCH=arm6
448 else # arm6_macros
449 CC_ARCH=arm
450 endif # arm6_macros
451
452 else ifneq ($(strip $(filter $(ppc64_macros), $(predef_macros))),)
453 CC_ARCH=ppc64
454 else ifneq ($(strip $(filter $(ppc_macros), $(predef_macros))),)
455 CC_ARCH=ppc
456 else ifneq ($(strip $(filter $(mips_macros), $(predef_macros))),)
457
458 ifneq ($(strip $(filter $(mips64_macros), $(predef_macros))),)
459 CC_ARCH=mips64
460 else ifneq ($(strip $(filter $(mips2_macros), $(predef_macros))),)
461 CC_ARCH=mips2
462 else # mips2_macros
463 CC_ARCH=mips
464 endif # mips64_macros
465
466 else ifneq ($(strip $(filter $(alpha_macros), $(predef_macros))),)
467 CC_ARCH=alpha
468 else
469
470 $(warn "Unknown target compiler architecture")
471
472 endif # predefined macros tests (x86_macros, ...)
473
474 endif # gcc
475
476 ifdef CC_ARCH
477 ARCH:=$(CC_ARCH)
478 else
479 ARCH:=$(HOST_ARCH)
480 endif
481 $(info target architecture <$(ARCH)>, host architecture <$(HOST_ARCH)>)
482
483 # compile-time options
484 #
485 # -DSTATS
486 #               allows to print out number of packets processed on CTRL-C;
487 #               implementation still nasty and reports per-process
488 # -DNO_DEBUG
489 #               turns off some of the debug messages (DBG(...)).
490 # -DNO_LOG
491 #               completely turns of all the logging (and DBG(...))
492 # -DEXTRA_DEBUG
493 #               compiles in some extra debugging code
494 # -DDNS_IP_HACK
495 #               faster ip address resolver for ip strings (e.g "127.0.0.1")
496 # -DSHM_MEM
497 #               compiles in shared mem. support, needed by some modules and
498 #               by USE_SHM_MEM
499 # -DSHM_MMAP
500 #               use mmap instead of SYSV shared memory
501 # -DPKG_MALLOC
502 #               uses a faster malloc (exclusive w/ USE_SHM_MEM)
503 # -DUSE_SHM_MEM
504 #               all pkg_malloc => shm_malloc (most mallocs use a common sh.
505 #               mem. segment); don't define PKG_MALLOC if you want this!
506 # -DDBG_QM_MALLOC
507 #               qm_malloc debug code, will cause pkg_malloc and shm_malloc
508 #               to keep and display lot of debuging information: file name,
509 #               function, line number of malloc/free call for each block,
510 #               extra error checking (trying to free the same pointer
511 #               twice, trying to free a pointer alloc'ed with a different
512 #               malloc etc.)
513 # -DVQ_MALLOC
514 #               additional option to PKG_MALLOC which utilizes a fater then
515 #               qm version
516 #               (not true anymore, q_malloc performs approx. the same)
517 # -DF_MALLOC
518 #               an even faster malloc, not recommended for debugging
519 # -DDL_MALLOC
520 #               a malloc implementation based on Doug Lea's dl_malloc
521 # -DSF_MALLOC 
522 #               an experimental multi-CPU, pool based, multi-process safe version of 
523 #               F_MALLOC. Should give better performance on machines with lots of CPUs
524 #               after some tunning.
525 # -DLL_MALLOC
526 #               an experimental multi-CPU, pool based, multi-process safe, mostly
527 #               lockless version of SF_MALLOC/F_MALLOC. Not for production use for
528 #               now.
529 # -DDBG_MALLOC
530 #               issues additional debugging information if lock/unlock is called
531 # -DFAST_LOCK
532 #               uses fast arhitecture specific locking (see the arh. specific section)
533 # -DUSE_SYSV_SEM
534 #               uses sys v sems for locking (slower & limited number)
535 # -DUSE_PTHREAD_MUTEX
536 #               uses pthread mutexes, faster than sys v or posix sems, but do not 
537 #               work on all systems inter-processes (e.g. linux)
538 # -DUSE_POSIX_SEM
539 #               uses posix semaphores for locking (faster than sys v)
540 # -DUSE_FUTEX
541 #               uses futexes for locking (linux 2.6+)
542 # -DBUSY_WAIT
543 #               uses busy waiting on the lock (FAST_LOCK)
544 # -DADAPTIVE_WAIT
545 #               try busy waiting for a while and if the lock is still held go to
546 #               force reschedule (FAST_LOCK)
547 # -DADAPTIVE_WAIT_LOOPS=number
548 #               number of loops we busy wait, after "number" loops have elapsed we 
549 #               force a reschedule (FAST_LOCK)
550 # -DNOSMP
551 #               don't use smp compliant locking (faster but won't work on SMP machines)
552 #               (not yet enabled) (FAST_LOCK)
553 # -DNO_PINGTEL_TAG_HACK
554 #               if enabled, To-header-field will be less liberal and will not accept
555 #               'tag=' (tag parameter with equal sign and without value); it is called
556 #               this way because such message was sighted from a Pingtel phone
557 # -DUSE_TCP
558 #               compiles in tcp support
559 # -DDISABLE_NAGLE
560 #               disable the tcp Nagle algorithm (lower delay)
561 # -DUSE_TLS
562 #               compiles in tls support, requires -DUSE_TCP. Note: this is only 
563 #               generic support (parsing a.s.o.), it does not include the actual
564 #               "tls engine". If you really want tls you need also either
565 #               -DCORE_TLS and a tls/ subdir with the tls code or -DTLS_HOOKS and
566 #               the tls module loaded.
567 # -DCORE_TLS
568 #               compiles tls in-core support. Requires -DUSE_TLS, conflicts 
569 #               -DTLS_HOOKS. Please use make CORE_TLS=1 instead  (it will set all the
570 #               needed defines automatically and extra libraries needed for linking).
571 # -DTLS_HOOKS
572 #               compile tls module support (support for having the "tls engine" in a
573 #               module). Requires -DUSE_TLS, conflicts -DCORE_TLS.
574 #               Please use make TLS_HOOKS=1 (or TLS_HOOKS=0 to for disabling) instead
575 #               of setting -DTLS_HOOKS (it will set all the needed defines 
576 #               automatically)
577 # -DHAVE_RESOLV_RES
578 #               support for changing some of the resolver parameters present
579 #                (_res structure in <resolv.h>)
580 # -DUSE_COMP
581 #               compiles in comp=[sergz|sigcomp] support (parsing uri & via, 
582 #               adding it to via, lumps a.s.o). WARNING: right now this option
583 #               is useless since the compression code doesn't exist yet.
584 # -DHONOR_MADDR
585 #               compiles in checks and use for maddr parameter in uri.
586 #               Required to support Windows Messenger 5.x over TCP connection
587 #               which (mis)uses this parameter.
588 # -DUSE_DNS_CACHE
589 #               use an internal dns cache instead of making dns requests each time
590 # -DUSE_DNS_CACHE_STATS
591 #               turns on DNS cache measurements
592 # -DUSE_DNS_FAILOVER
593 #               if the destination resolves to multiple ips, on send error fall back
594 #               to the others
595 # -DUSE_DST_BLACKLIST
596 #               blacklist bad destination (timeout, failed to connect, error sending
597 #        a.s.o)
598 # -DUSE_DST_BLACKLIST_STATS
599 #               turns on blacklist bad destination measurements
600 # -DPROFILING
601 #               if enabled profiling will be enabled for child processes
602 #               Don't forget to set PROFILE (see below)
603 # -DUSE_STUN
604 #               compiles in stun support
605 # -DNO_SIG_DEBUG
606 #        turns off debugging messages in signal handlers (which might be 
607 #         unsafe)
608 # -DUSE_NAPTR
609 #                turns on naptr support (but must be also enabled from the config)
610 # -DDNS_WATCHDOG_SUPPORT
611 #               turns on DNS watchdog support which can be used to inform the
612 #               core that the DNS servers are down. No DNS query is performed
613 #               when the servers are unreachable, and even expired resource
614 #               records are used from the cache. (requires external watchdog)
615 # -DWITH_AS_SUPPORT
616 #               adds support for Application Server interface
617 # Sometimes is needes correct non-quoted $OS. HACK: gcc translates known OS to number ('linux'), so there is added underscore
618
619 C_DEFS= $(extra_defs) \
620          -DNAME='"$(MAIN_NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
621          -DOS='$(OS)_' -DOS_QUOTED='"$(OS)"' -DCOMPILER='"$(CC_VER)"'\
622          -D__CPU_$(ARCH) -D__OS_$(OS) \
623          -DSER_VER=$(SER_VER) \
624          -DCFG_DIR='"$(cfg_target)"'\
625          -DPKG_MALLOC \
626          -DSHM_MEM  -DSHM_MMAP \
627          -DDNS_IP_HACK \
628          -DUSE_IPV6 \
629          -DUSE_MCAST \
630          -DUSE_TCP \
631          -DDISABLE_NAGLE \
632          -DHAVE_RESOLV_RES \
633          -DUSE_DNS_CACHE \
634          -DUSE_DNS_FAILOVER \
635          -DUSE_DST_BLACKLIST \
636          -DUSE_NAPTR \
637          #-DUSE_DNS_CACHE_STATS \
638          #-DUSE_DST_BLACKLIST_STATS \
639          #-DDNS_WATCHDOG_SUPPORT \
640          #-DLL_MALLOC \
641          #-DSF_MALLOC \
642          #-DDL_MALLOC \
643          #-DDBG_F_MALLOC \
644          #-DNO_DEBUG \
645          #-DEXTRA_DEBUG \
646          #-DVQ_MALLOC  \
647          #-DDBG_LOCK \
648          #-DNOSMP \
649          #-DUSE_SHM_MEM \
650          #-DSTATS \
651          #-DNO_LOG \
652          #-DPROFILING \
653          #-DNO_SIG_DEBUG
654
655 #PROFILE=  -pg  # set this if you want profiling
656                                 # you may also want to set -DPROFILING
657
658 # WARNING: do not add mode=debug or mode=release anymore in the Makefile,
659 # use make mode=debug all instead. Anyway no by default ser is  compiled w/ 
660 # debugging symbols in all cases (-g). --andrei
661
662 ifeq ($(MEMDBG), 1)
663         C_DEFS+= -DDBG_QM_MALLOC
664 else
665         C_DEFS+= -DF_MALLOC
666 endif
667 ifeq ($(CORE_TLS), 1)
668         C_DEFS+= -DUSE_TLS -DCORE_TLS
669 endif
670 ifeq ($(TLS_HOOKS), 1)
671         C_DEFS+= -DUSE_TLS -DTLS_HOOKS
672 endif
673 ifeq ($(KMSTATS), 1)
674         C_DEFS+= -DUSE_CORE_STATS -DSTATISTICS
675 endif
676 ifeq ($(FMSTATS), 1)
677         C_DEFS+= -DMALLOC_STATS
678 endif
679
680 ifneq ($(STUN),)
681         C_DEFS+= -DUSE_STUN
682 endif
683
684 ifeq ($(mode),)
685         mode = release
686 endif
687
688 ifeq ($(mode),debug)
689         C_DEFS+= -DEXTRA_DEBUG
690 endif
691
692 # platform dependent settings
693
694 # find ld & as name (gnu or solaris)
695 ifeq ($(OS), solaris)
696 ifeq ($(CC_NAME), gcc)
697                 LDGCC:=$(shell $(CC) -v 2>&1 | grep with-ld| \
698                                    sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
699                 ASGCC:=$(shell $(CC) -v 2>&1 | grep with-as| \
700                                    sed -e 's/.*--with-as=\([^ ][^ ]*\).*/\1/' )
701                 LDPATH:=$(shell  if [ -z "$(LDGCC)" ] ; then echo "ld" ;\
702                                                 else \
703                                                 if $(LDGCC) -V 2>/dev/null 1>/dev/null; then \
704                                                         echo $(LDGCC); \
705                                                 else echo "ld" ; \
706                                                 fi\
707                                                 fi)
708                 ASPATH:=$(shell  if [ -z "$(ASGCC)" ] ; then echo "as" ;\
709                                                 else \
710                                                 if $(ASGCC) -V 2>/dev/null 1>/dev/null </dev/null; \
711                                                 then \
712                                                         echo $(ASGCC); \
713                                                 else echo "as" ; \
714                                                 fi\
715                                                 fi)
716                                                         
717                 LDTYPE:=$(shell if $(LDPATH) -V 1>/dev/null  2>/dev/null; then \
718                                                         if $(LDPATH) -V 2>&1|grep GNU >/dev/null; \
719                                                         then echo gnu; \
720                                                         else \
721                                                         if $(LDPATH) -V 2>&1|grep Solaris >/dev/null;\
722                                                         then echo solaris; \
723                                                         else \
724                                                                 echo unknown ; \
725                                                         fi \
726                                                         fi \
727                                                 fi)
728                 ASTYPE:=$(shell if $(ASPATH) -V 1>/dev/null  2>/dev/null </dev/null; \
729                                                 then \
730                                                         if $(ASPATH) -V 2>&1 </dev/null | \
731                                                                 grep GNU >/dev/null; then echo gnu; \
732                                                         else \
733                                                         if $(ASPATH) -V 2>&1 </dev/null | \
734                                                                 grep Sun >/dev/null; then echo solaris; \
735                                                         else \
736                                                                 echo unknown ; \
737                                                         fi \
738                                                         fi \
739                                                 fi)
740 #$(warning "using ld=$(LDPATH)/$(LDTYPE), as=$(ASPATH)/$(ASTYPE)")
741
742 endif
743 endif
744
745 # arch. specific definitions
746 ifeq ($(ARCH), i386)
747         use_fast_lock=yes
748 endif
749
750 ifeq ($(ARCH), x86_64)
751         use_fast_lock=yes
752 endif
753
754 ifeq ($(ARCH), sparc64)
755 ifeq    ($(CC_NAME), gcc)
756         use_fast_lock=yes
757 endif
758 endif
759
760 ifeq ($(ARCH), sparc)
761         use_fast_lock=yes
762 endif
763
764 ifeq ($(ARCH), arm)
765         use_fast_lock=yes
766         C_DEFS+=-DNOSMP # very unlikely to have an smp arm
767 endif
768
769 ifeq ($(ARCH), arm6)
770         use_fast_lock=yes
771 endif
772
773 ifeq ($(ARCH), ppc)
774         use_fast_lock=yes
775 endif
776
777 ifeq ($(ARCH), ppc64)
778         use_fast_lock=yes
779 endif
780
781 ifeq ($(ARCH), mips)
782 # mips1 arch. (e.g. R3000) - no hardware locking support
783         use_fast_lock=no
784         C_DEFS+=-DMIPS_HAS_LLSC # likely
785         C_DEFS+=-DNOSMP # very likely
786 endif
787
788 ifeq ($(ARCH), mips2)
789 # mips2 arch and newer (mips3=R4000, mips4=R5000 a.s.o)
790         use_fast_lock=yes
791 endif
792
793 ifeq ($(ARCH), mips64)
794 # mips2 arch and newer (mips3=R4000, mips4=R5000 a.s.o)
795         use_fast_lock=yes
796 endif
797
798 ifeq ($(ARCH), alpha)
799         use_fast_lock=yes
800         C_DEFS+=-DNOSMP # very likely
801 endif
802
803 ifeq ($(use_fast_lock), yes)
804         C_DEFS+= -DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 
805         found_lock_method=yes
806 endif
807
808 CFLAGS=
809 LDFLAGS=
810 C_INCLUDES=
811 # setting CFLAGS
812 ifeq ($(mode), release)
813         #if i386
814 ifeq    ($(ARCH), i386)
815                 # if gcc 
816 ifeq            ($(CC_NAME), gcc)
817                                 C_DEFS+=-DCC_GCC_LIKE_ASM
818                                 #common stuff
819                                 CFLAGS=-g -O9 -funroll-loops  -Wcast-align $(PROFILE)
820                         #if gcc 4.2+
821 ifeq                    ($(CC_SHORTVER), 4.2+)
822 $(call                          set_if_empty,CPU,athlon64)
823                                         CFLAGS+=-m32 -minline-all-stringops \
824                                                         -falign-loops \
825                                                         -ftree-vectorize \
826                                                         -fno-strict-overflow \
827                                                         -mtune=$(CPU)
828                                         LDFLAGS+=-m32
829 else
830                         #if gcc 4.0+
831 ifeq                    ($(CC_SHORTVER), 4.x)
832 $(call                          set_if_empty,CPU,athlon64)
833                                         CFLAGS+=-m32 -minline-all-stringops \
834                                                         -falign-loops \
835                                                         -ftree-vectorize \
836                                                         -mtune=$(CPU) 
837                                         LDFLAGS+=-m32
838 else
839                         #if gcc 3.4+
840 ifeq                    ($(CC_SHORTVER), 3.4)
841 $(call                          set_if_empty,CPU,athlon)
842                                         CFLAGS+=-m32 -minline-all-stringops \
843                                                         -falign-loops \
844                                                         -mtune=$(CPU) 
845                                         LDFLAGS+=-m32
846 else
847                         #if gcc 3.0+
848 ifeq                    ($(CC_SHORTVER), 3.0)
849 $(call                          set_if_empty,CPU,athlon)
850                                         CFLAGS+=-minline-all-stringops \
851                                                         -falign-loops \
852                                                         -mcpu=$(CPU)
853                                         # -m32 supported since gcc 3.2
854 else
855 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
856 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
857                                         for better results)
858                                         
859                                         CFLAGS+=-m486 \
860                                                         -malign-loops=4
861 else
862                                 #really old version
863 $(warning                       You are using an old and unsupported gcc \
864                                          version  ($(CC_SHORTVER)), compile at your own risk!)
865
866 endif                   # CC_SHORTVER, 2.9x
867 endif                   # CC_SHORTVER, 3.0
868 endif                   # CC_SHORTVER, 3.4
869 endif                   # CC_SHORTVER, 4.x
870 endif                   # CC_SHORTVER, 4.2+
871
872 else            # CC_NAME, gcc
873 ifeq            ($(CC_NAME), icc)
874                         C_DEFS+=-DCC_GCC_LIKE_ASM
875                         CFLAGS=-g -O3  -ipo -ipo_obj -unroll  $(PROFILE) \
876                                          -tpp6 -xK  #-openmp  #optimize for PIII 
877                                 # -prefetch doesn't seem to work
878                                 #( ty to inline acroos files, unroll loops,prefetch,
879                                 # optimize for PIII, use PIII instructions & vect.,
880                                 # mutlithread loops)
881 else
882                                 #other compilers
883 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
884 endif           #CC_NAME, icc
885 endif           #CC_NAME, gcc
886 endif   #ARCH, i386
887
888 #x86_64
889 ifeq    ($(ARCH), x86_64)
890                 # if gcc 
891 ifeq            ($(CC_NAME), gcc)
892                                 C_DEFS+=-DCC_GCC_LIKE_ASM
893                                 #common stuff
894                                 CFLAGS=-g -O9 -funroll-loops  -Wcast-align $(PROFILE)
895                         #if gcc 4.2+
896 ifeq                    ($(CC_SHORTVER), 4.2+)
897 $(call                          set_if_empty,CPU,opteron)
898                                         CFLAGS+=-m64 -minline-all-stringops \
899                                                         -falign-loops \
900                                                         -ftree-vectorize \
901                                                         -fno-strict-overflow \
902                                                         -mtune=$(CPU)
903                                         LDFLAGS+=-m64
904 else
905                         #if gcc 4.0+
906 ifeq                    ($(CC_SHORTVER), 4.x)
907 $(call                          set_if_empty,CPU,opteron)
908                                         CFLAGS+=-m64 -minline-all-stringops \
909                                                         -falign-loops \
910                                                         -ftree-vectorize \
911                                                         -mtune=$(CPU) 
912                                         LDFLAGS+=-m64
913 else
914                         #if gcc 3.4
915 ifeq                    ($(CC_SHORTVER), 3.4)
916 $(call                          set_if_empty,CPU,athlon64)
917                                         CFLAGS+=-m64 -minline-all-stringops \
918                                                         -falign-loops 
919                                         LDFLAGS+=-m64
920 else
921                         #if gcc 3.0
922 ifeq                    ($(CC_SHORTVER), 3.0)
923 $(call                          set_if_empty,CPU,athlon64)
924                                         CFLAGS+=-minline-all-stringops \
925                                                         -falign-loops 
926                                                         #-mcpu=$(CPU) \ # not working on all x86_64 gccs
927                                                         #-mcpu=athlon
928                                         #-m64 on x86_64/x86 works starting with gcc 3.2
929 else
930 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
931 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
932                                         for better results)
933                                         
934                                         CFLAGS+=-m486 \
935                                                         -malign-loops=4
936 else
937                                 #really old version
938 $(warning                       You are using an old and unsupported gcc \
939                                          version  ($(CC_SHORTVER)), compile at your own risk!)
940
941 endif                   # CC_SHORTVER, 2.9x
942 endif                   # CC_SHORTVER, 3.0
943 endif                   # CC_SHORTVER, 3.4
944 endif                   # CC_SHORTVER, 4.x
945 endif                   # CC_SHORTVER, 4.2+
946
947 else            # CC_NAME, gcc
948 ifeq            ($(CC_NAME), icc)
949                         C_DEFS+=-DCC_GCC_LIKE_ASM
950                         CFLAGS=-g -O3  -ipo -ipo_obj -unroll  $(PROFILE) \
951                                          -tpp6 -xK  #-openmp  #optimize for PIII 
952                                 # -prefetch doesn't seem to work
953                                 #( ty to inline acroos files, unroll loops,prefetch,
954                                 # optimize for PIII, use PIII instructions & vect.,
955                                 # mutlithread loops)
956 else
957                                 #other compilers
958 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
959 endif           #CC_NAME, icc
960 endif           #CC_NAME, gcc
961 endif   #ARCH, x86_64
962
963         #if sparc64
964 ifeq    ($(ARCH), sparc64)
965                         #if gcc
966 ifeq            ($(CC_NAME), gcc)
967                                 C_DEFS+=-DCC_GCC_LIKE_ASM -DSPARC64_MODE
968                                 #common stuff
969                                 CFLAGS=-g -O9 -funroll-loops  $(PROFILE) \
970                                         #-Wcast-align \
971                                         #-Wmissing-prototypes 
972                                 #if gcc 4.2+
973 ifeq                    ($(CC_SHORTVER), 4.2+)
974 $(call                          set_if_empty,CPU,ultrasparc)
975                                         #use 32bit for now
976                                         CFLAGS+=-m64 -mcpu=ultrasparc  \
977                                                         -mtune=$(CPU) \
978                                                         -fno-strict-overflow \
979                                                         -ftree-vectorize
980                                         # use -m64 to force 64 bit (but add it also to LDFLAGS and
981                                         #  don't forget to define SPARC64_MODE)
982                                         # -m32 for 32 bit (default on solaris),
983                                         # nothing for arch. default
984                                         LDFLAGS+=-m64
985 else
986                                 #if gcc 4.x
987 ifeq                    ($(CC_SHORTVER), 4.x)
988 $(call                          set_if_empty,CPU,ultrasparc)
989                                         #use 32bit for now
990                                         CFLAGS+=-m64 -mcpu=ultrasparc  \
991                                                         -mtune=$(CPU) \
992                                                         -ftree-vectorize
993                                         LDFLAGS+=-m64
994 else
995                                 #if gcc 3.4
996 ifeq                    ($(CC_SHORTVER), 3.4)
997 $(call                          set_if_empty,CPU,ultrasparc)
998                                         #use 32bit for now
999                                         CFLAGS+=-m64 -mcpu=ultrasparc -mtune=$(CPU)
1000                                         LDFLAGS+=-m64
1001 else
1002                                 #if gcc 3.0
1003 ifeq                    ($(CC_SHORTVER), 3.0)
1004 $(call                          set_if_empty,CPU,ultrasparc)
1005                                         #use 32bit for now
1006                                         CFLAGS+=-m64 -mcpu=ultrasparc -mtune=$(CPU)   \
1007                                         # -mcpu=v9 or ultrasparc? # -mtune implied by -mcpu
1008                                         #-mno-epilogue #try to inline function exit code
1009                                         #-mflat # omit save/restore
1010                                         #-,faster-structs #faster non Sparc ABI structure copy ops
1011                                         LDFLAGS+=-m64
1012 else                    # CC_SHORTVER, 3.0
1013 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1014 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
1015                                         for better results)
1016 ifneq                           ($(OS), netbsd)
1017                                                 # on netbsd/sparc64,  gcc 2.95.3 does not compile
1018                                                 # ser with -mv8
1019                                                 CFLAGS+= -mv9 
1020                                                 # -m64/-m32 on sparc works starting with gcc 3.0
1021 endif
1022 ifeq                                    ($(ASTYPE), solaris)
1023                                                         CFLAGS+= -Wa,-xarch=v8plus
1024 endif                                   
1025 else                    #CC_SHORTVER, 2.9x
1026                                 #really old version
1027 $(warning                       You are using an old and unsupported gcc \
1028                                          version ($(CC_SHORTVER)), compile at your own risk!)
1029                                         
1030                                         CFLAGS+= -mv9 
1031 ifeq                                    ($(ASTYPE), solaris)
1032                                                         CFLAGS+= -Wa,-xarch=v8plus
1033 endif                                   
1034         
1035 endif                   #CC_SHORTVER, 2.9x
1036 endif                   #CC_SHORTVER, 3.0
1037 endif                   #CC_SHORTVER, 3.4
1038 endif                   #CC_SHORTVER, 4.x
1039 endif                   #CC_SHORTVER, 4.2+
1040         
1041 else            #CC_NAME, gcc
1042 ifeq            ($(CC_NAME), suncc)
1043                         C_DEFS+=-DSPARC64_MODE
1044                         CFLAGS+= -m64 -g -xO5 -fast -native -xarch=v9 -xCC \
1045                                         -xc99 # C99 support
1046                         # -Dinline="" # add this if cc < 5.3 (define inline as null)
1047 else
1048                                 #other compilers
1049 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1050 endif           #CC_NAME, suncc
1051 endif           #CC_NAME, gcc
1052 endif   #ARCH, sparc64
1053
1054         #if sparc
1055 ifeq    ($(ARCH), sparc)
1056                         #if gcc
1057 ifeq            ($(CC_NAME), gcc)
1058                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1059                                 #common stuff
1060                                 CFLAGS=-g -O9 -funroll-loops  $(PROFILE) \
1061                                         #-Wcast-align \
1062                                         #-Wmissing-prototypes 
1063                                 #if gcc 4.2+
1064 ifeq                    ($(CC_SHORTVER), 4.2+)
1065 $(call                          set_if_empty,CPU,v8)
1066                                         #use 32bit for now
1067                                         CFLAGS+= -mtune=$(CPU) \
1068                                                         -fno-strict-overflow \
1069                                                         -ftree-vectorize
1070 else
1071                                 #if gcc 4.x
1072 ifeq                    ($(CC_SHORTVER), 4.x)
1073 $(call                          set_if_empty,CPU,v8)
1074                                         #use 32bit for now
1075                                         CFLAGS+= -mtune=$(CPU) \
1076                                                         -ftree-vectorize
1077 else
1078                                 #if gcc 3.4
1079 ifeq                    ($(CC_SHORTVER), 3.4)
1080 $(call                          set_if_empty,CPU,v8)
1081                                         #use 32bit for now
1082                                         CFLAGS+= -mtune=$(CPU)
1083 else
1084                                 #if gcc 3.0
1085 ifeq                    ($(CC_SHORTVER), 3.0)
1086 $(call                          set_if_empty,CPU,v8)
1087                                         #use 32bit for now
1088                                         CFLAGS+= -mtune=$(CPU)   \
1089                                         #-mno-epilogue #try to inline function exit code
1090                                         #-mflat # omit save/restore
1091                                         #-,faster-structs #faster non Sparc ABI structure copy ops
1092 else                    # CC_SHORTVER, 3.0
1093 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1094 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
1095                                         for better results)
1096 else                    #CC_SHORTVER, 2.9x
1097                                 #really old version
1098 $(warning                       You are using an old and unsupported gcc \
1099                                          version ($(CC_SHORTVER)), compile at your own risk!)
1100                                         
1101 endif                   #CC_SHORTVER, 2.9x
1102 endif                   #CC_SHORTVER, 3.0
1103 endif                   #CC_SHORTVER, 3.4
1104 endif                   #CC_SHORTVER, 4.x
1105 endif                   #CC_SHORTVER, 4.2+
1106         
1107 else            #CC_NAME, gcc
1108 ifeq            ($(CC_NAME), suncc)
1109                         CFLAGS+= -g -xO5 -fast -native -xCC \
1110                                         -xc99 # C99 support
1111                         # -Dinline="" # add this if cc < 5.3 (define inline as null)
1112 else
1113                                 #other compilers
1114 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1115 endif           #CC_NAME, suncc
1116 endif           #CC_NAME, gcc
1117 endif   #ARCH, sparc
1118
1119         #if ipaq/netwinder
1120 ifeq    ($(ARCH), arm)
1121                 # if gcc 
1122 ifeq            ($(CC_NAME), gcc)
1123                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1124                                 #common stuff
1125                                 CFLAGS=-O9 -funroll-loops -fsigned-char $(PROFILE)
1126                         #if gcc 4.2+
1127 ifeq                    ($(CC_SHORTVER), 4.2+)
1128                                         CFLAGS+= -ftree-vectorize -fno-strict-overflow
1129                                         # not supported on arm: -minline-all-stringops 
1130 else
1131                         #if gcc 4.x+
1132 ifeq                    ($(CC_SHORTVER), 4.x)
1133                                         CFLAGS+= -ftree-vectorize
1134                                         # not supported on arm: -minline-all-stringops 
1135 else
1136                         #if gcc 3.4+
1137 ifeq                    ($(CC_SHORTVER), 3.4)
1138                                         CFLAGS+=
1139 else
1140                         #if gcc 3.0
1141 ifeq                    ($(CC_SHORTVER), 3.0)
1142                                         CFLAGS+= 
1143                                                         #-mcpu=athlon
1144 else
1145 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1146 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1147                                         for better results)
1148                                         
1149                                         CFLAGS+=
1150 else
1151                                 #really old version
1152 $(warning                       You are using an old and unsupported gcc \
1153                                          version ($(CC_SHORTVER)), compile at your own risk!)
1154         
1155 endif                   # CC_SHORTVER, 2.9x
1156 endif                   # CC_SHORTVER, 3.0
1157 endif                   # CC_SHORTVER, 3.4
1158 endif                   # CC_SHORTVER, 4.x
1159 endif                   # CC_SHORTVER, 4.2+
1160         
1161 else            # CC_NAME, gcc
1162                                 #other compilers
1163 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1164 endif           #CC_NAME, gcc
1165 endif   #ARCH, arm 
1166
1167         #if armv6 cpu 
1168 ifeq    ($(ARCH), arm6)
1169                 # if gcc 
1170 ifeq            ($(CC_NAME), gcc)
1171                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1172                                 #common stuff
1173                                 CFLAGS=-march=armv6 -O9 -funroll-loops -fsigned-char \
1174                                                 $(PROFILE)
1175                         #if gcc 4.2+
1176 ifeq                    ($(CC_SHORTVER), 4.2+)
1177                                         CFLAGS+= -ftree-vectorize -fno-strict-overflow
1178 else
1179                         #if gcc 4.x+
1180 ifeq                    ($(CC_SHORTVER), 4.x)
1181                                         CFLAGS+= -ftree-vectorize
1182 else
1183                         #if gcc 3.4+
1184 ifeq                    ($(CC_SHORTVER), 3.4)
1185                                         CFLAGS+=
1186 else
1187                         #if gcc 3.0
1188 ifeq                    ($(CC_SHORTVER), 3.0)
1189                                         CFLAGS+= 
1190                                                         #-mcpu=athlon
1191 else
1192 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1193 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1194                                         for better results)
1195                                         
1196                                         CFLAGS+=
1197 else
1198                                 #really old version
1199 $(warning                       You are using an old and unsupported gcc \
1200                                          version ($(CC_SHORTVER)), compile at your own risk!)
1201         
1202 endif                   # CC_SHORTVER, 2.9x
1203 endif                   # CC_SHORTVER, 3.0
1204 endif                   # CC_SHORTVER, 3.4
1205 endif                   # CC_SHORTVER, 4.x
1206 endif                   # CC_SHORTVER, 4.2+
1207         
1208 else            # CC_NAME, gcc
1209                                 #other compilers
1210 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1211 endif           #CC_NAME, gcc
1212 endif   #ARCH, arm6
1213
1214         #if  mips (R3000)
1215 ifeq    ($(ARCH), mips)
1216                 # if gcc 
1217 ifeq            ($(CC_NAME), gcc)
1218                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1219                                 #common stuff
1220                                 CFLAGS=-O9 -funroll-loops  $(PROFILE)
1221                         #if gcc 4.2+
1222 ifeq                    ($(CC_SHORTVER), 4.2+)
1223                                         CFLAGS+=-march=r3000 -minline-all-stringops \
1224                                                         -ftree-vectorize -fno-strict-overflow
1225 else
1226                         #if gcc 4.0+
1227 ifeq                    ($(CC_SHORTVER), 4.x)
1228                                         CFLAGS+=-march=r3000 -minline-all-stringops \
1229                                                         -ftree-vectorize
1230 else
1231                         #if gcc 3.4+
1232 ifeq                    ($(CC_SHORTVER), 3.4)
1233                                         CFLAGS+= -march=r3000
1234 else
1235                         #if gcc 3.0
1236 ifeq                    ($(CC_SHORTVER), 3.0)
1237                                         CFLAGS+= -march=r3000
1238 else
1239 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1240 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1241                                         for better results)
1242                                         
1243                                         CFLAGS+=-march=r3000
1244 else
1245                                 #really old version
1246 $(warning                       You are using an old and unsupported gcc \
1247                                          version ($(CC_SHORTVER)), compile at your own risk!)
1248         
1249 endif                   # CC_SHORTVER, 2.9x
1250 endif                   # CC_SHORTVER, 3.0
1251 endif                   # CC_SHORTVER, 3.4
1252 endif                   # CC_SHORTVER, 4.x
1253 endif                   # CC_SHORTVER, 4.2+
1254         
1255 else            # CC_NAME, gcc
1256                                 #other compilers
1257 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1258 endif           #CC_NAME, gcc
1259 endif   #ARCH, mips
1260
1261         #if  >=mips2 (R4000, R5000, R6000 ....)
1262 ifeq    ($(ARCH), mips2)
1263                 # if gcc 
1264 ifeq            ($(CC_NAME), gcc)
1265                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1266                                 #common stuff
1267                                 CFLAGS= -mips2 -O9 -funroll-loops $(PROFILE)
1268                         #if gcc 4.2+
1269 ifeq                    ($(CC_SHORTVER), 4.2+)
1270                                         CFLAGS+=-minline-all-stringops -ftree-vectorize \
1271                                                         -fno-strict-overflow
1272 else
1273                         #if gcc 4.0+
1274 ifeq                    ($(CC_SHORTVER), 4.x)
1275                                         CFLAGS+=-minline-all-stringops -ftree-vectorize
1276 else
1277                         #if gcc 3.4+
1278 ifeq                    ($(CC_SHORTVER), 3.4)
1279                                         CFLAGS+=
1280 else
1281                         #if gcc 3.0
1282 ifeq                    ($(CC_SHORTVER), 3.0)
1283                                         CFLAGS+=
1284 else
1285 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1286 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1287                                         for better results)
1288                                         CFLAGS+=
1289 else
1290                                 #really old version
1291 $(warning                       You are using an old and unsupported gcc \
1292                                          version ($(CC_SHORTVER)), compile at your own risk!)
1293         
1294 endif                   # CC_SHORTVER, 2.9x
1295 endif                   # CC_SHORTVER, 3.0
1296 endif                   # CC_SHORTVER, 3.4
1297 endif                   # CC_SHORTVER, 4.x
1298 endif                   # CC_SHORTVER, 4.2+
1299         
1300 else            # CC_NAME, gcc
1301                                 #other compilers
1302 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1303 endif           #CC_NAME, gcc
1304 endif   #ARCH, mips2
1305
1306 #if  >=mips64
1307 ifeq    ($(ARCH), mips64)
1308                 # if gcc 
1309 ifeq            ($(CC_NAME), gcc)
1310                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1311                                 #common stuff
1312                                 CFLAGS= -mips64 -O9 -funroll-loops $(PROFILE)
1313                         #if gcc 4.2+
1314 ifeq                    ($(CC_SHORTVER), 4.2+)
1315                                         CFLAGS+=-minline-all-stringops -ftree-vectorize \
1316                                                         -fno-strict-overflow
1317 else
1318                         #if gcc 4.0+
1319 ifeq                    ($(CC_SHORTVER), 4.x)
1320                                         CFLAGS+=-minline-all-stringops -ftree-vectorize
1321 else
1322                         #if gcc 3.4+
1323 ifeq                    ($(CC_SHORTVER), 3.4)
1324                                         CFLAGS+=
1325 else
1326                         #if gcc 3.0
1327 ifeq                    ($(CC_SHORTVER), 3.0)
1328                                         CFLAGS+=
1329 else
1330 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1331 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1332                                         for better results)
1333                                         CFLAGS+=
1334 else
1335                                 #really old version
1336 $(warning                       You are using an old and unsupported gcc \
1337                                          version ($(CC_SHORTVER)), compile at your own risk!)
1338         
1339 endif                   # CC_SHORTVER, 2.9x
1340 endif                   # CC_SHORTVER, 3.0
1341 endif                   # CC_SHORTVER, 3.4
1342 endif                   # CC_SHORTVER, 4.x
1343 endif                   # CC_SHORTVER, 4.2+
1344         
1345 else            # CC_NAME, gcc
1346                                 #other compilers
1347 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1348 endif           #CC_NAME, gcc
1349 endif   #ARCH, mips64
1350
1351 #if  alpha
1352 ifeq    ($(ARCH), alpha)
1353                 # if gcc 
1354 ifeq            ($(CC_NAME), gcc)
1355                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1356                                 #common stuff
1357                                 CFLAGS= -O9 -funroll-loops $(PROFILE)
1358                         #if gcc 4.2+
1359 ifeq                    ($(CC_SHORTVER), 4.2+)
1360                                         CFLAGS+= -fno-strict-overflow
1361                                         # not supported: -minline-all-stringops
1362 else
1363                         #if gcc 4.0+
1364 ifeq                    ($(CC_SHORTVER), 4.x)
1365                                         CFLAGS+= 
1366                                         # not supported: -minline-all-stringops
1367 else
1368                         #if gcc 3.4+
1369 ifeq                    ($(CC_SHORTVER), 3.4)
1370                                         CFLAGS+=
1371 else
1372                         #if gcc 3.0
1373 ifeq                    ($(CC_SHORTVER), 3.0)
1374                                         CFLAGS+=
1375 else
1376 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1377 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1378                                         for better results)
1379                                         CFLAGS+=
1380 else
1381                                 #really old version
1382 $(warning                       You are using an old and unsupported gcc \
1383                                          version ($(CC_SHORTVER)), compile at your own risk!)
1384         
1385 endif                   # CC_SHORTVER, 2.9x
1386 endif                   # CC_SHORTVER, 3.0
1387 endif                   # CC_SHORTVER, 3.4
1388 endif                   # CC_SHORTVER, 4.x
1389 endif                   # CC_SHORTVER, 4.2+
1390         
1391 else            # CC_NAME, gcc
1392                                 #other compilers
1393 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1394 endif           #CC_NAME, gcc
1395 endif   #ARCH, alpha 
1396
1397 #if  ppc
1398 ifeq    ($(ARCH), ppc)
1399                 # if gcc 
1400 ifeq            ($(CC_NAME), gcc)
1401                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1402                                 #common stuff
1403                                 CFLAGS= -O9 -funroll-loops -fsigned-char $(PROFILE)
1404                         #if gcc 4.2+
1405 ifeq                    ($(CC_SHORTVER), 4.2+)
1406 $(call                          set_if_empty,CPU,powerpc)
1407                                         CFLAGS+=-ftree-vectorize \
1408                                                         -fno-strict-overflow \
1409                                                         -mtune=$(CPU) -maltivec
1410 else
1411                         #if gcc 4.0+
1412 ifeq                    ($(CC_SHORTVER), 4.x)
1413 $(call                          set_if_empty,CPU,powerpc)
1414                                         CFLAGS+=-ftree-vectorize \
1415                                                         -mtune=$(CPU) -maltivec
1416 else
1417                         #if gcc 3.4+
1418 ifeq                    ($(CC_SHORTVER), 3.4)
1419                                         CFLAGS+=
1420 else
1421                         #if gcc 3.0
1422 ifeq                    ($(CC_SHORTVER), 3.0)
1423                                         CFLAGS+=
1424 else
1425 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1426 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1427                                         for better results)
1428                                         CFLAGS+=
1429 else
1430                                 #really old version
1431 $(warning                       You are using an old and unsupported gcc \
1432                                          version ($(CC_SHORTVER)), compile at your own risk!)
1433         
1434 endif                   # CC_SHORTVER, 2.9x
1435 endif                   # CC_SHORTVER, 3.0
1436 endif                   # CC_SHORTVER, 3.4
1437 endif                   # CC_SHORTVER, 4.x
1438 endif                   # CC_SHORTVER, 4.2+
1439         
1440 else            # CC_NAME, gcc
1441                                 #other compilers
1442 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1443 endif           #CC_NAME, gcc
1444 endif   #ARCH, ppc 
1445
1446 #if  ppc64
1447 ifeq    ($(ARCH), ppc64)
1448                 # if gcc 
1449 ifeq            ($(CC_NAME), gcc)
1450                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1451                                 #common stuff
1452                                 CFLAGS= -O9 -funroll-loops -fsigned-char $(PROFILE)
1453                         #if gcc 4.2+
1454 ifeq                    ($(CC_SHORTVER), 4.2+)
1455 $(call                          set_if_empty,CPU,powerpc64)
1456                                         CFLAGS+=-ftree-vectorize \
1457                                                         -fno-strict-overflow \
1458                                                         -mtune=$(CPU) -maltivec
1459 else
1460                         #if gcc 4.0+
1461 ifeq                    ($(CC_SHORTVER), 4.x)
1462 $(call                          set_if_empty,CPU,powerpc64)
1463                                         CFLAGS+=-ftree-vectorize \
1464                                                         -mtune=$(CPU) -maltivec
1465 else
1466                         #if gcc 3.4+
1467 ifeq                    ($(CC_SHORTVER), 3.4)
1468                                         CFLAGS+=
1469 else
1470                         #if gcc 3.0
1471 ifeq                    ($(CC_SHORTVER), 3.0)
1472                                         CFLAGS+=
1473 else
1474 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1475 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1476                                         for better results)
1477                                         CFLAGS+=
1478 else
1479                                 #really old version
1480 $(warning                       You are using an old and unsupported gcc \
1481                                          version ($(CC_SHORTVER)), compile at your own risk!)
1482         
1483 endif                   # CC_SHORTVER, 2.9x
1484 endif                   # CC_SHORTVER, 3.0
1485 endif                   # CC_SHORTVER, 3.4
1486 endif                   # CC_SHORTVER, 4.x
1487 endif                   # CC_SHORTVER, 4.2+
1488         
1489 else            # CC_NAME, gcc
1490                                 #other compilers
1491 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1492 endif           #CC_NAME, gcc
1493 endif   #ARCH, ppc 
1494
1495 CFLAGS+= $(CC_EXTRA_OPTS)
1496
1497
1498 # setting LDFLAGS
1499 ifeq    ($(CC_NAME), gcc)
1500 ifeq            ($(LDTYPE), solaris)
1501                 # solaris ld
1502                 LDFLAGS+=-O2 $(PROFILE)
1503                 MOD_LDFLAGS:=-G $(LDFLAGS)
1504                 LIB_LDFLAGS:=-G $(LDFLAGS)
1505                 LIB_SONAME=-Wl,-h,
1506                 LD_RPATH=-Wl,-R,
1507 else            
1508                 #gcc and maybe others, => gnu ld
1509                 LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
1510                 MOD_LDFLAGS:=-shared $(LDFLAGS)
1511                 LIB_LDFLAGS:=-shared $(LDFLAGS)
1512                 LIB_SONAME=-Wl,-soname,
1513                 LD_RPATH=-Wl,-rpath,
1514 endif
1515 endif
1516 ifeq    ($(CC_NAME), icc)
1517         #gcc and maybe others
1518         LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
1519         MOD_LDFLAGS:=-shared $(LDFLAGS)
1520         LIB_LDFLAGS:=-shared $(LDFLAGS)
1521         LIB_SONAME=-Wl,-soname,
1522         LD_RPATH=-Wl,-rpath,
1523 endif
1524 ifeq    ($(CC_NAME), suncc)
1525         # -dy?
1526         LDFLAGS+=-xO5 $(PROFILE)
1527         MOD_LDFLAGS:=-G $(LDFLAGS)
1528         LIB_LDFLAGS:=-G $(LDFLAGS)
1529         LIB_SONAME="-h "
1530         LD_RPATH=-"-R "
1531 endif
1532         # we need -fPIC -DPIC only for shared objects, we don't need them for
1533         # the executable file, because it's always loaded at a fixed address
1534         # -andrei
1535 else    #mode,release
1536 ifeq    ($(CC_NAME), gcc)
1537                 CFLAGS=-g -Wcast-align $(PROFILE)
1538                 C_DEFS+=-DCC_GCC_LIKE_ASM
1539 ifeq            ($(ARCH), sparc64)
1540                         C_DEFS+=SPARC64_MODE
1541                         CFLAGS+= -mcpu=ultrasparc -m64
1542                         LDFLAGS+=-m64
1543 endif
1544 ifeq            ($(LDTYPE), solaris)
1545                         #solaris ld
1546                         LDFLAGS+=-g $(PROFILE)
1547                         MOD_LDFLAGS:=-G $(LDFLAGS)
1548                         LIB_LDFLAGS:=-G $(LDFLAGS)
1549                         LIB_SONAME=-Wl,-h,
1550                         LD_RPATH=-Wl,-R,
1551 else
1552                         #gnu or other ld type
1553                         LDFLAGS+=-g -Wl,-E $(PROFILE)
1554                         MOD_LDFLAGS:=-shared $(LDFLAGS)
1555                         LIB_LDFLAGS:=-shared $(LDFLAGS)
1556                         LIB_SONAME=-Wl,-soname,
1557                         LD_RPATH=-Wl,-rpath,
1558 endif
1559 endif
1560 ifeq    ($(CC_NAME), icc)
1561                 C_DEFS+=-DCC_GCC_LIKE_ASM
1562                 CFLAGS=-g  $(PROFILE)
1563                 LDFLAGS+=-g -Wl,-E $(PROFILE)
1564                 MOD_LDFLAGS:=-shared $(LDFLAGS)
1565                 LIB_LDFLAGS:=-shared $(LDFLAGS)
1566                 LIB_SONAME=-Wl,-soname,
1567                 LD_RPATH=-Wl,-rpath,
1568 endif
1569 ifeq    ($(CC_NAME), suncc)
1570                 CFLAGS= -g $(PROFILE)
1571                 LDFLAGS+=-g $(PROFILE)
1572                 MOD_LDFLAGS:=-G $(LDFLAGS)
1573                 LIB_LDFLAGS:=-G $(LDFLAGS)
1574                 LIB_SONAME="-h "
1575                 LD_RPATH=-"-R "
1576 endif
1577
1578 endif #mode=release
1579
1580
1581 # set pedantic compiler options
1582 ifeq ($(CC_NAME), gcc)
1583                 CFLAGS+= -Wall
1584 else # no gcc
1585 ifeq ($(CC_NAME), icc)
1586                 CFLAGS+= -Wall
1587 else # no icc
1588 ifeq ($(CC_NAME), suncc)
1589                 # FIXME: is the default (-Xa ?) enough?
1590 endif # CC_NAME=suncc
1591 endif # CC_NAME=icc
1592 endif # CC_NAME=gcc
1593
1594 #CFLAGS used for compiling the modules, libraries and utils
1595 ifeq    ($(CC_NAME), gcc)
1596 MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
1597 LIB_CFLAGS=-fPIC -DPIC $(CFLAGS)
1598 endif
1599 ifeq    ($(CC_NAME), icc)
1600 MOD_CFLAGS=-Kpic $(CFLAGS)
1601 LIB_CFLAGS=-Kpic $(CFLAGS)
1602 endif
1603 ifeq    ($(CC_NAME), suncc)
1604 # FIMXE: use -KPIC instead -xcode ?
1605 MOD_CFLAGS=-xcode=pic32  $(CFLAGS)
1606 LIB_CFLAGS=-xcode=pic32  $(CFLAGS)
1607 endif
1608 UTILS_CFLAGS=$(CFLAGS)
1609 # LDFLAGS uses for compiling the utils
1610 UTILS_LDFLAGS=$(LDFLAGS)
1611
1612 ifeq ($(LEX),)
1613         LEX=flex
1614 endif
1615 ifeq ($(YACC),)
1616         YACC=bison
1617 endif
1618 YACC_FLAGS=-d -b cfg
1619 # on solaris add -lxnet (e.g. LIBS= -lxnet)
1620 LIBS= -ldl -lresolv
1621 LIB_PREFIX:=lib
1622 LIB_SUFFIX:=.so
1623
1624
1625 #os specific stuff
1626 ifeq ($(OS), linux)
1627 # by default use futexes if available
1628         use_futex= yes
1629         C_DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
1630                         -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
1631                         -DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER
1632         ifneq ($(found_lock_method), yes)
1633                 #C_DEFS+= -DUSE_POSIX_SEM
1634                 C_DEFS+=-DUSE_PTHREAD_MUTEX
1635                 LIBS+= -lpthread
1636                 #C_DEFS+= -DUSE_SYSV_SEM  # try posix sems
1637                 found_lock_method=yes
1638         else
1639                 ifneq (,$(findstring -DUSE_POSIX_SEM, $(C_DEFS)))
1640                         LIBS+=-lpthread
1641                 endif
1642                 ifneq (,$(findstring -DUSE_PTHREAD_MUTEX, $(C_DEFS)))
1643                         LIBS+=-lpthread
1644                 endif
1645         endif
1646         # check for >= 2.5.44
1647         ifeq ($(shell [ $(OSREL_N) -ge 2005044 ] && echo has_epoll), has_epoll)
1648                 ifeq ($(NO_EPOLL),)
1649                         C_DEFS+=-DHAVE_EPOLL
1650                         # linux + gcc >= 3.0 + -malign-double + epoll => problems
1651                         CFLAGS_RM+=-malign-double
1652                         #CFLAGS:=$(filter-out -malign-double, $(CFLAGS))
1653                 endif
1654         endif
1655         # check for >= 2.2.0
1656         ifeq ($(shell [ $(OSREL_N) -ge 2002000 ] && echo has_sigio), has_sigio)
1657                 ifeq ($(NO_SIGIO),)
1658                         C_DEFS+=-DHAVE_SIGIO_RT -DSIGINFO64_WORKARROUND
1659                 endif
1660         endif
1661         # check for >= 2.5.70
1662         ifeq ($(shell [ $(OSREL_N) -ge 2005070 ] && echo has_futex), has_futex)
1663                 ifeq ($(use_futex), yes)
1664                         C_DEFS+=-DUSE_FUTEX
1665                 endif
1666         endif
1667         ifeq ($(NO_SELECT),)
1668                 C_DEFS+=-DHAVE_SELECT
1669         endif
1670         # sctp support
1671         ifeq ($(SCTP),1)
1672                 # test to see if the devfiles and lib are installed
1673                 sctp_dev_locations := /usr/include/netinet/sctp.h \
1674                                                                 $(LOCALBASE)/include/netinet/sctp.h
1675                 sctp_lib_locations := /usr/lib/libsctp.so \
1676                                                                 $(LOCALBASE)/usr/local/lib/libsctp.so
1677                 sctp_dev_path := $(wildcard $(sctp_dev_locations))
1678                 sctp_lib_path := $(wildcard $(sctp_lib_locations))
1679                 ifeq ($(sctp_dev_path),)
1680 $(info "sctp development files not installed -- sctp disabled")
1681                         override SCTP := 
1682                 endif
1683                 ifeq ($(sctp_lib_path),)
1684 $(info "sctp libraries not installed -- sctp disabled")
1685                         override SCTP := 
1686                 endif
1687                 
1688                 ifeq ($(SCTP),1)
1689                         # use lksctp
1690                         C_DEFS+=-DUSE_SCTP
1691                         LIBS+=-lsctp
1692                 endif
1693         endif # SCTP
1694 endif
1695
1696 ifeq  ($(OS), solaris)
1697         C_DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD \
1698                         -DHAVE_ALLOCA_H -DUSE_SIGACTION
1699         ifneq ($(found_lock_method), yes)
1700                 C_DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1701                 found_lock_method=yes
1702         endif
1703         # check for ver >= 5.7
1704         ifeq ($(shell [ $(OSREL_N) -gt 5007 ] && echo has_devpoll), has_devpoll)
1705                 ifeq ($(NO_DEVPOLL),)
1706                         C_DEFS+=-DHAVE_DEVPOLL
1707                 endif
1708         endif
1709         ifeq ($(NO_SELECT),)
1710                 C_DEFS+=-DHAVE_SELECT
1711         endif
1712         # check for filio.h
1713         filio_h_locations= /usr/include/sys/filio.h \
1714                                                 $(LOCALBASE)/include/sys/filio.h
1715         has_filio_h=$(shell for r in $(filio_h_locations); do \
1716                                                 if  [ -r "$$r" ] ; then echo yes; exit; fi \
1717                                                 done;\
1718                                 )
1719         ifeq ($(has_filio_h), yes)
1720                 C_DEFS+=-DHAVE_FILIO_H
1721         endif
1722         ifeq ($(mode), release)
1723                 #use these only if you're using gcc with Solaris ld
1724                 #LDFLAGS=-O2 $(PROFILE)
1725                 #MOD_LDFLAGS=-O2 -G
1726         else
1727                 #LDFLAGS=-g $(PROFILE)
1728                 #MOD_LDFLAGS=-g -G
1729         endif
1730         YACC=yacc
1731
1732 ifeq ($(CC_NAME), suncc)
1733         LIBS= -lfast -ldl -lresolv
1734 endif
1735         OLD_SOLARIS= $(shell echo "$(OSREL)" | \
1736                                 sed -e 's/^5\.[0-6][^0-9]*$$/yes/' )
1737         LIBS+= -L$(LOCALBASE)/lib -lxnet -lnsl 
1738 ifeq    ($(OLD_SOLARIS), yes)
1739                 LIBS+=-lposix4
1740 else
1741                 LIBS+=-lrt
1742 endif
1743         # -lrt needed for sched_yield
1744 endif
1745
1746 ifeq ($(OS), freebsd)
1747         C_DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1748                 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1749                 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1750                 -DHAVE_NETINET_IN_SYSTM
1751         ifneq ($(found_lock_method), yes)
1752                 C_DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1753                 found_lock_method=yes
1754                 LIBS+= -pthread   #dlopen is in libc
1755         else
1756                 LIBS=   #dlopen is in libc
1757         endif
1758         # check for ver >= 4.1
1759         ifeq ($(shell [ $(OSREL_N) -gt 4001 ] && echo has_kqueue), has_kqueue)
1760                 ifeq ($(NO_KQUEUE),)
1761                         C_DEFS+=-DHAVE_KQUEUE
1762                 endif
1763         endif
1764         ifeq ($(NO_SELECT),)
1765                 C_DEFS+=-DHAVE_SELECT
1766         endif
1767         YACC=yacc
1768         # sctp support
1769         ifeq ($(SCTP),1)
1770                 # test to see if the devfiles and lib are installed
1771                 sctp_dev_locations := /usr/include/netinet/sctp.h \
1772                                                                 $(LOCALBASE)/include/netinet/sctp.h
1773                 sctp_dev_path := $(wildcard $(sctp_dev_locations))
1774                 ifeq ($(sctp_dev_path),)
1775 $(info "sctp development files not installed -- sctp disabled")
1776                         override SCTP := 
1777                 endif
1778                 ifeq ($(shell [ $(OSREL_N) -lt 7000 ] && echo sctp), sctp)
1779 $(info "old freebsd version (>= 7.0 needed) -- sctp disabled")
1780                         override SCTP := 
1781                 endif
1782                 
1783                 ifeq ($(SCTP),1)
1784                         C_DEFS+=-DUSE_SCTP
1785                         LIBS+=  # no extra libs needed on freebsd
1786                 endif
1787         endif # SCTP
1788 endif
1789
1790 ifeq ($(OS), openbsd)
1791         C_DEFS+=-DHAVE_SOCKADDR_SA_LEN  -DHAVE_GETHOSTBYNAME2 \
1792                 -DHAVE_UNION_SEMUN -DHAVE_MSGHDR_MSG_CONTROL \
1793                 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1794                 -DHAVE_NETINET_IN_SYSTM -DUSE_SIGWAIT
1795         ifneq ($(found_lock_method), yes)
1796                 C_DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1797                 found_lock_method=yes
1798         endif
1799         # check for ver >=2 9
1800         ifeq ($(shell [ $(OSREL_N) -ge 2009 ] && echo has_kqueue), has_kqueue)
1801                 ifeq ($(NO_KQUEUE),)
1802                         C_DEFS+=-DHAVE_KQUEUE
1803                 endif
1804         endif
1805         ifeq ($(NO_SELECT),)
1806                 C_DEFS+=-DHAVE_SELECT
1807         endif
1808         # (symbols on openbsd are prefixed by "_")
1809         YACC=yacc
1810         # no sched_yield on openbsd unless linking with c_r (not recommended)
1811         # unfortunately pthread is needed for sigwait
1812         LIBS= -lpthread
1813         OPENBSD_IS_AOUT:= $(shell echo "$(OSREL)" | \
1814                                 sed -e 's/^3\.[0-3][^0-9]*$$/yes/' |sed -e 's/^[0-2]\..*/yes/')
1815 # exception: on sparc openbsd 3.2 is elf and not aout
1816 ifeq ($(OSREL), 3.2)
1817 ifeq    ($(ARCH), sparc)
1818                 OPENBSD_IS_AOUT:=no
1819 endif
1820 ifeq    ($(ARCH), sparc64)
1821                 OPENBSD_IS_AOUT:=no
1822 endif
1823 endif
1824         
1825 ifeq ($(OPENBSD_IS_AOUT), yes)
1826                 C_DEFS+=-DDLSYM_PREFIX='"_"'
1827                 LDFLAGS=        # openbsd ld doesn't like -O2 or -E
1828 endif
1829 endif   # if opensd
1830         
1831 ifeq ($(OS), netbsd)
1832         C_DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 \
1833                 -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM
1834         ifneq ($(found_lock_method), yes)
1835                 C_DEFS+= -DUSE_SYSV_SEM  # try pthread sems
1836                 found_lock_method=yes
1837         endif
1838         # check for ver >= 2.0.0
1839         ifeq ($(shell [ $(OSREL_N) -ge 2000000 ] && echo has_kqueue), has_kqueue)
1840                 ifeq ($(NO_KQUEUE),)
1841                         C_DEFS+=-DHAVE_KQUEUE
1842                         # netbsd + kqueue and -malign-double don't work
1843                         CFLAGS_RM+=-malign-double
1844                         #CFLAGS:=$(filter-out -malign-double, $(CFLAGS))
1845                 endif
1846         endif
1847         ifeq ($(NO_SELECT),)
1848                 C_DEFS+=-DHAVE_SELECT
1849         endif
1850         YACC=yacc
1851         LIBS=  
1852 endif
1853
1854 # OS X support, same as freebsd
1855 ifeq ($(OS), darwin)
1856         C_DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1857                 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1858                 -DUSE_ANON_MMAP \
1859                 -DNDEBUG -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1860                 -DUSE_SIGWAIT
1861         # -DNDEBUG used to turn off assert (assert wants to call
1862         # eprintf which doesn't seem to be defined in any shared lib
1863         ifneq ($(found_lock_method), yes)
1864                 C_DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1865                 found_lock_method=yes
1866                 C_DEFS+= -DUSE_SYSV_SEM  # try sys v sems (pthread don't work for
1867                                        # processes and unnamed posix sems are not
1868                                        # supported)
1869         endif
1870         LIBS= -lresolv  #dlopen is in libc
1871         ifeq ($(NO_KQUEUE),)
1872                 C_DEFS+=-DHAVE_KQUEUE
1873         endif
1874         ifeq ($(NO_SELECT),)
1875                 C_DEFS+=-DHAVE_SELECT
1876         endif
1877         LDFLAGS=        # darwin doesn't like -O2 or -E
1878         # the modules uses symbols from ser => either 
1879         # -flat_namespace -undefined_suppress or -bundle_loader ../../$(MAIN_NAME)
1880         MOD_LDFLAGS:= -bundle -flat_namespace -undefined suppress
1881         # for libs using symbols from ser (e.g srdb2, kcore a.s.o) we
1882         # need -flat_namespace -undefined suppress
1883         LIB_LDFLAGS:= -dynamiclib -flat_namespace -undefined suppress
1884         LIB_SUFFIX:=.dylib
1885         # on darwin soname should include the full path
1886         # (it kind of combines rpath & soname)
1887         LIB_SONAME=
1888         # no equiv. for rpath on darwin
1889         LD_RPATH=
1890         YACC=yacc
1891 endif
1892
1893 ifneq (,$(findstring cygwin, $(OS)))
1894         # cygwin doesn't support IPV6 and doesn't support fd passing so no TCP
1895         #C_DEFS:=$(filter-out -DUSE_IPV6 -DUSE_TCP, $(C_DEFS))
1896         DEFS_RM+=-DUSE_IPV6 -DUSE_TCP
1897         C_DEFS+=-DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
1898                         -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
1899                         -DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER
1900         ifneq ($(found_lock_method), yes)
1901                 C_DEFS+= -DUSE_POSIX_SEM
1902                 #C_DEFS+= -DUSE_SYSV_SEM  # try posix sems
1903                 # PTHREAD_MUTEX do not work for processes (try test/pthread_test.c)
1904                 #LIBS+= -lpthread
1905                 found_lock_method=yes
1906         else
1907                 ifneq (,$(findstring -DUSE_POSIX_SEM, $(C_DEFS)))
1908                         #LIBS+=-lpthread
1909                 endif
1910                 ifneq (,$(findstring -DUSE_PTHREAD_MUTEX, $(C_DEFS)))
1911 $(error PTHREAD_MUTEX do not work for processes on Windows/CYGWIN)
1912                 endif
1913         endif
1914         # check for >= 2.5.70
1915         ifeq ($(NO_SELECT),)
1916                 C_DEFS+=-DHAVE_SELECT
1917         endif
1918 endif
1919
1920 #add libssl if needed
1921 ifeq ($(CORE_TLS), 1)
1922 C_INCLUDES+= -I$(LOCALBASE)/ssl/include
1923 LIBS+= -L$(LOCALBASE)/lib -L$(LOCALBASE)/ssl/lib -lssl -lcrypto \
1924                 $(TLS_EXTRA_LIBS)
1925 # NOTE: depending on the way in which libssl was compiled you might
1926 #       have to add -lz -lkrb5   (zlib and kerberos5).
1927 #       E.g.: make CORE_TLS=1 EXTRA_TLS_LIBS="-lz -lkrb5"
1928 endif
1929
1930 ifneq ($(STUN),)
1931 C_INCLUDES+= -I$(LOCALBASE)/ssl/include
1932 LIBS+= -L$(LOCALBASE)/lib -L$(LOCALBASE)/ssl/lib -lcrypto
1933 endif
1934
1935 ifneq ($(found_lock_method), yes)
1936 $(warning       No locking method found so far, trying SYS V sems)
1937                 C_DEFS+= -DUSE_SYSV_SEM  # try sys v sems
1938                 found_lock_method=yes
1939 endif
1940
1941
1942 endif # ifeq (,$(main_makefile))
1943 endif  # ifeq ($(makefile_defs), 1)
1944
1945 # if incomplete or missing config.mak, or already exported vars, don't
1946 # try to export/re-export
1947 ifeq ($(makefile_defs),1) 
1948 ifneq ($(exported_vars),1)
1949
1950
1951 override exported_vars:=1
1952 export exported_vars
1953
1954 # variable changeable only at configure time (once saved in config.mak they
1955 #  cannot be overwritten from environment or command line, unless make cfg
1956 #  is run)
1957 saved_fixed_vars:=      MAIN_NAME  CFG_NAME SCR_NAME FLAVOUR INSTALL_FLAVOUR \
1958                 SRC_NAME RELEASE OS ARCH \
1959                 C_DEFS DEFS_RM PROFILE CC LD MKDEP MKTAGS LDFLAGS C_INCLUDES \
1960                 CC_MKDEP_OPTS \
1961                 MOD_LDFLAGS LIB_LDFLAGS UTILS_LDFLAGS LIB_SONAME LD_RPATH \
1962                 LIB_SUFFIX LIB_PREFIX \
1963                 LIBS \
1964                 LEX YACC YACC_FLAGS \
1965                 PREFIX LOCALBASE \
1966                 TAR \
1967                 INSTALL INSTALL_CFG INSTALL_BIN INSTALL_MODULES INSTALL_DOC \
1968                 INSTALL_MAN INSTALL_LIB INSTALL_TOUCH INSTALL_SHARE \
1969                 Q
1970
1971 # variable changeable at compile time
1972 # extra: prefix DESTDIR BASEDIR basedirt
1973 saved_chg_vars:=\
1974                 CC_EXTRA_OPTS CPU CFLAGS_RM CFLAGS MOD_CFLAGS LIB_CFLAGS UTILS_CFLAGS \
1975                 BASEDIR basedir DESTDIR \
1976                 PREFIX prefix\
1977                 cfg_prefix cfg_dir bin_prefix bin_dir modules_prefix modules_dir \
1978                 doc_prefix doc_dir man_prefix man_dir ut_prefix ut_dir \
1979                 share_prefix share_dir lib_prefix lib_dir data_prefix data_dir \
1980                 cfg_target lib_target data_target
1981
1982
1983 #export relevant variables to the sub-makes
1984 export $(saved_fixed_vars)
1985 export $(saved_chg_vars)
1986
1987
1988 endif # ifneq ($(exported_vars),1)
1989 endif # ifeq ($(makefile_defs),1)
1990