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