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