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