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