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