Makefile.defs: version set to 5.0.0-dev1
[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 # enable f_malloc
668 C_DEFS+= -DF_MALLOC
669 # enable q_malloc
670 C_DEFS+= -DQ_MALLOC
671 # enable TLSF malloc
672 C_DEFS+= -DTLSF_MALLOC
673 ifeq    ($(MEMDBG), 1)
674         C_DEFS+= -DDBG_SR_MEMORY
675 endif
676
677 ifneq ($(PKG_MEM_SIZE),)
678         C_DEFS+= -DPKG_MEM_SIZE=$(PKG_MEM_SIZE)
679 endif
680 ifeq ($(CORE_TLS), 1)
681         C_DEFS+= -DUSE_TLS -DCORE_TLS
682 endif
683 ifeq ($(TLS_HOOKS), 1)
684         C_DEFS+= -DUSE_TLS -DTLS_HOOKS
685 endif
686 ifeq ($(KMSTATS), 1)
687         C_DEFS+= -DUSE_CORE_STATS -DSTATISTICS
688 endif
689 ifeq ($(FMSTATS), 1)
690         C_DEFS+= -DMALLOC_STATS
691 endif
692 ifeq ($(WITHAS), 1)
693         C_DEFS+= -DWITH_AS_SUPPORT
694 endif
695
696 ifeq ($(SCTP), 1)
697         C_DEFS+= -DUSE_SCTP
698 endif
699
700 ifeq ($(mode),)
701         mode = release
702 endif
703
704 ifeq ($(mode),debug)
705         C_DEFS+= -DEXTRA_DEBUG
706 endif
707
708 # platform dependent settings
709
710 # find ld & as name (gnu or solaris)
711 ifeq ($(OS), solaris)
712 ifeq ($(CC_NAME), gcc)
713                 LDGCC:=$(shell $(CC) -v 2>&1 | grep with-ld| \
714                                    sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
715                 ASGCC:=$(shell $(CC) -v 2>&1 | grep with-as| \
716                                    sed -e 's/.*--with-as=\([^ ][^ ]*\).*/\1/' )
717                 LDPATH:=$(shell  if [ -z "$(LDGCC)" ] ; then echo "ld" ;\
718                                                 else \
719                                                 if $(LDGCC) -V 2>/dev/null 1>/dev/null; then \
720                                                         echo $(LDGCC); \
721                                                 else echo "ld" ; \
722                                                 fi\
723                                                 fi)
724                 ASPATH:=$(shell  if [ -z "$(ASGCC)" ] ; then echo "as" ;\
725                                                 else \
726                                                 if $(ASGCC) -V 2>/dev/null 1>/dev/null </dev/null; \
727                                                 then \
728                                                         echo $(ASGCC); \
729                                                 else echo "as" ; \
730                                                 fi\
731                                                 fi)
732                                                         
733                 LDTYPE:=$(shell if $(LDPATH) -V 1>/dev/null  2>/dev/null; then \
734                                                         if $(LDPATH) -V 2>&1|grep GNU >/dev/null; \
735                                                         then echo gnu; \
736                                                         else \
737                                                         if $(LDPATH) -V 2>&1|grep Solaris >/dev/null;\
738                                                         then echo solaris; \
739                                                         else \
740                                                                 echo unknown ; \
741                                                         fi \
742                                                         fi \
743                                                 fi)
744                 ASTYPE:=$(shell if $(ASPATH) -V 1>/dev/null  2>/dev/null </dev/null; \
745                                                 then \
746                                                         if $(ASPATH) -V 2>&1 </dev/null | \
747                                                                 grep GNU >/dev/null; then echo gnu; \
748                                                         else \
749                                                         if $(ASPATH) -V 2>&1 </dev/null | \
750                                                                 grep Sun >/dev/null; then echo solaris; \
751                                                         else \
752                                                                 echo unknown ; \
753                                                         fi \
754                                                         fi \
755                                                 fi)
756 #$(warning "using ld=$(LDPATH)/$(LDTYPE), as=$(ASPATH)/$(ASTYPE)")
757
758 endif
759 endif
760
761 # arch. specific definitions
762 ifeq ($(ARCH), i386)
763         use_fast_lock=yes
764 endif
765
766 ifeq ($(ARCH), x86_64)
767         use_fast_lock=yes
768 endif
769
770 ifeq ($(ARCH), sparc64)
771 ifeq    ($(CC_NAME), gcc)
772         use_fast_lock=yes
773 endif
774 endif
775
776 ifeq ($(ARCH), sparc)
777         use_fast_lock=yes
778 endif
779
780 ifeq ($(ARCH), arm)
781         use_fast_lock=yes
782         C_DEFS+=-DNOSMP # very unlikely to have an smp arm
783 endif
784
785 ifeq ($(ARCH), arm6)
786         use_fast_lock=yes
787         C_DEFS+=-DNOSMP # very unlikely to have an smp arm
788 endif
789
790 ifeq ($(ARCH), ppc)
791         use_fast_lock=yes
792 endif
793
794 ifeq ($(ARCH), ppc64)
795         use_fast_lock=yes
796 endif
797
798 ifeq ($(ARCH), mips)
799 # mips1 arch. (e.g. R3000) - no hardware locking support
800         use_fast_lock=no
801         C_DEFS+=-DMIPS_HAS_LLSC # likely
802         C_DEFS+=-DNOSMP # very likely
803 endif
804
805 ifeq ($(ARCH), mips2)
806 # mips2 arch and newer (mips3=R4000, mips4=R5000 a.s.o)
807         use_fast_lock=yes
808 endif
809
810 ifeq ($(ARCH), mips64)
811 # mips2 arch and newer (mips3=R4000, mips4=R5000 a.s.o)
812         use_fast_lock=yes
813 endif
814
815 ifeq ($(ARCH), alpha)
816         use_fast_lock=yes
817         C_DEFS+=-DNOSMP # very likely
818 endif
819
820 ifeq ($(use_fast_lock), yes)
821         C_DEFS+= -DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 
822         found_lock_method=yes
823 endif
824
825 CFLAGS=
826 LDFLAGS=
827 C_INCLUDES=
828 # setting CFLAGS
829 ifeq ($(mode), release)
830         #if i386
831 ifeq    ($(ARCH), i386)
832                 # if gcc 
833 ifeq            ($(CC_NAME), gcc) 
834                                 C_DEFS+=-DCC_GCC_LIKE_ASM
835                                 #common stuff
836                                 CFLAGS=-g $(CC_OPT) -funroll-loops  -Wcast-align $(PROFILE)
837                         #if gcc 5.0+, 4.5+ or 4.2+
838 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+,$(CC_SHORTVER))))
839 $(call                          set_if_empty,CPUTYPE,athlon64)
840                                         CFLAGS+=-m32 -minline-all-stringops \
841                                                         -falign-loops \
842                                                         -ftree-vectorize \
843                                                         -fno-strict-overflow \
844                                                         -mtune=$(CPUTYPE)
845                                         LDFLAGS+=-m32
846 else
847                         #if gcc 4.0+
848 ifeq                    ($(CC_SHORTVER), 4.x)
849 $(call                          set_if_empty,CPUTYPE,athlon64)
850                                         CFLAGS+=-m32 -minline-all-stringops \
851                                                         -falign-loops \
852                                                         -ftree-vectorize \
853                                                         -mtune=$(CPUTYPE) 
854                                         LDFLAGS+=-m32
855 else
856                         #if gcc 3.4+
857 ifeq                    ($(CC_SHORTVER), 3.4)
858 $(call                          set_if_empty,CPUTYPE,athlon)
859                                         CFLAGS+=-m32 -minline-all-stringops \
860                                                         -falign-loops \
861                                                         -mtune=$(CPUTYPE) 
862                                         LDFLAGS+=-m32
863 else
864                         #if gcc 3.0+
865 ifeq                    ($(CC_SHORTVER), 3.0)
866 $(call                          set_if_empty,CPUTYPE,athlon)
867                                         CFLAGS+=-minline-all-stringops \
868                                                         -falign-loops \
869                                                         -mcpu=$(CPUTYPE)
870                                         # -m32 supported since gcc 3.2
871 else
872 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
873 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
874                                         for better results)
875                                         
876                                         CFLAGS+=-m486 \
877                                                         -malign-loops=4
878 else
879                                 #really old version
880 $(warning                       You are using an old and unsupported gcc \
881                                          version  ($(CC_SHORTVER)), compile at your own risk!)
882
883 endif                   # CC_SHORTVER, 2.9x
884 endif                   # CC_SHORTVER, 3.0
885 endif                   # CC_SHORTVER, 3.4
886 endif                   # CC_SHORTVER, 4.x
887 endif                   # CC_SHORTVER, 5.0+, 4.5+ or 4.2+
888
889 else            # CC_NAME, gcc
890 ifeq            ($(CC_NAME), clang)
891 $(call                          set_if_empty,CPUTYPE,athlon64)
892                                         C_DEFS+=-DCC_GCC_LIKE_ASM
893                                         CFLAGS+=-g -m32 $(CC_OPT) -mtune=$(CPUTYPE)
894                                         LDFLAGS+=-m32
895 else                    # CC_NAME, clang
896 ifeq            ($(CC_NAME), icc)
897                         C_DEFS+=-DCC_GCC_LIKE_ASM
898                         CFLAGS=-g -O3  -ipo -ipo_obj -unroll  $(PROFILE) \
899                                          -tpp6 -xK  #-openmp  #optimize for PIII 
900                                 # -prefetch doesn't seem to work
901                                 #( ty to inline acroos files, unroll loops,prefetch,
902                                 # optimize for PIII, use PIII instructions & vect.,
903                                 # mutlithread loops)
904 else
905                                 #other compilers
906 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
907 endif           #CC_NAME, icc
908 endif           #CC_NAME, clang
909 endif           #CC_NAME, gcc
910 endif   #ARCH, i386
911
912 #x86_64
913 ifeq    ($(ARCH), x86_64)
914                 # if gcc 
915 ifeq            ($(CC_NAME), gcc)
916                                 C_DEFS+=-DCC_GCC_LIKE_ASM
917                                 #common stuff
918                                 CFLAGS=-g $(CC_OPT) -funroll-loops  -Wcast-align $(PROFILE)
919                         #if gcc 4.5+
920                         # don't add '-mtune=$(CPUTYPE)' - gcc failure
921 ifeq                    ($(CC_SHORTVER),$(filter $(CC_SHORTVER),4.5+ 5.0+))
922 $(call                          set_if_empty,CPUTYPE,opteron)
923                                         CFLAGS+=-m64 -minline-all-stringops \
924                                                         -falign-loops \
925                                                         -ftree-vectorize \
926                                                         -fno-strict-overflow
927                                         LDFLAGS+=-m64
928 else
929                         #if gcc 4.2+
930 ifeq                    ($(CC_SHORTVER), 4.2+)
931 $(call                          set_if_empty,CPUTYPE,opteron)
932                                         CFLAGS+=-m64 -minline-all-stringops \
933                                                         -falign-loops \
934                                                         -ftree-vectorize \
935                                                         -fno-strict-overflow \
936                                                         -mtune=$(CPUTYPE)
937                                         LDFLAGS+=-m64
938 else
939                         #if gcc 4.0+
940 ifeq                    ($(CC_SHORTVER), 4.x)
941 $(call                          set_if_empty,CPUTYPE,opteron)
942                                         CFLAGS+=-m64 -minline-all-stringops \
943                                                         -falign-loops \
944                                                         -ftree-vectorize \
945                                                         -mtune=$(CPUTYPE) 
946                                         LDFLAGS+=-m64
947 else
948                         #if gcc 3.4
949 ifeq                    ($(CC_SHORTVER), 3.4)
950 $(call                          set_if_empty,CPUTYPE,athlon64)
951                                         CFLAGS+=-m64 -minline-all-stringops \
952                                                         -falign-loops 
953                                         LDFLAGS+=-m64
954 else
955                         #if gcc 3.0
956 ifeq                    ($(CC_SHORTVER), 3.0)
957 $(call                          set_if_empty,CPUTYPE,athlon64)
958                                         CFLAGS+=-minline-all-stringops \
959                                                         -falign-loops 
960                                                         #-mcpu=$(CPUTYPE) \ # not working on all x86_64 gccs
961                                                         #-mcpu=athlon
962                                         #-m64 on x86_64/x86 works starting with gcc 3.2
963 else
964 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
965 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
966                                         for better results)
967                                         
968                                         CFLAGS+=-m486 \
969                                                         -malign-loops=4
970 else
971                                 #really old version
972 $(warning                       You are using an old and unsupported gcc \
973                                          version  ($(CC_SHORTVER)), compile at your own risk!)
974
975 endif                   # CC_SHORTVER, 2.9x
976 endif                   # CC_SHORTVER, 3.0
977 endif                   # CC_SHORTVER, 3.4
978 endif                   # CC_SHORTVER, 4.x
979 endif                   # CC_SHORTVER, 4.2+
980 endif                   # CC_SHORTVER, 5.0+, 4.5+
981
982 else            # CC_NAME, gcc
983 ifeq            ($(CC_NAME), clang)
984 $(call                          set_if_empty,CPUTYPE,opteron)
985                                         C_DEFS+=-DCC_GCC_LIKE_ASM
986                                         CFLAGS+=-g -m64 \
987                                                 $(CC_OPT)        
988                                         LDFLAGS+=-m64
989 else            # CC_NAME, clang
990 ifeq            ($(CC_NAME), icc)
991                         C_DEFS+=-DCC_GCC_LIKE_ASM
992                         CFLAGS=-g -O3  -ipo -ipo_obj -unroll  $(PROFILE) \
993                                          -tpp6 -xK  #-openmp  #optimize for PIII 
994                                 # -prefetch doesn't seem to work
995                                 #( ty to inline acroos files, unroll loops,prefetch,
996                                 # optimize for PIII, use PIII instructions & vect.,
997                                 # mutlithread loops)
998 else
999                                 #other compilers
1000 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1001 endif           #CC_NAME, icc
1002 endif           #CC_NAME, clang
1003 endif           #CC_NAME, gcc
1004 endif   #ARCH, x86_64
1005
1006         #if sparc64
1007 ifeq    ($(ARCH), sparc64)
1008                         #if gcc
1009 ifeq            ($(CC_NAME), gcc)
1010                                 C_DEFS+=-DCC_GCC_LIKE_ASM -DSPARC64_MODE
1011                                 #common stuff
1012                                 CFLAGS=-g $(CC_OPT) -funroll-loops  $(PROFILE) \
1013                                         #-Wcast-align \
1014                                         #-Wmissing-prototypes 
1015                                 #if gcc 5.0+, 4.5+ or 4.2+
1016 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+,$(CC_SHORTVER))))
1017 $(call                          set_if_empty,CPUTYPE,ultrasparc)
1018                                         #use 32bit for now
1019                                         CFLAGS+=-m64 -mcpu=ultrasparc  \
1020                                                         -mtune=$(CPUTYPE) \
1021                                                         -fno-strict-overflow \
1022                                                         -ftree-vectorize
1023                                         # use -m64 to force 64 bit (but add it also to LDFLAGS and
1024                                         #  don't forget to define SPARC64_MODE)
1025                                         # -m32 for 32 bit (default on solaris),
1026                                         # nothing for arch. default
1027                                         LDFLAGS+=-m64
1028 else
1029                                 #if gcc 4.x
1030 ifeq                    ($(CC_SHORTVER), 4.x)
1031 $(call                          set_if_empty,CPUTYPE,ultrasparc)
1032                                         #use 32bit for now
1033                                         CFLAGS+=-m64 -mcpu=ultrasparc  \
1034                                                         -mtune=$(CPUTYPE) \
1035                                                         -ftree-vectorize
1036                                         LDFLAGS+=-m64
1037 else
1038                                 #if gcc 3.4
1039 ifeq                    ($(CC_SHORTVER), 3.4)
1040 $(call                          set_if_empty,CPUTYPE,ultrasparc)
1041                                         #use 32bit for now
1042                                         CFLAGS+=-m64 -mcpu=ultrasparc -mtune=$(CPUTYPE)
1043                                         LDFLAGS+=-m64
1044 else
1045                                 #if gcc 3.0
1046 ifeq                    ($(CC_SHORTVER), 3.0)
1047 $(call                          set_if_empty,CPUTYPE,ultrasparc)
1048                                         #use 32bit for now
1049                                         CFLAGS+=-m64 -mcpu=ultrasparc -mtune=$(CPUTYPE)   \
1050                                         # -mcpu=v9 or ultrasparc? # -mtune implied by -mcpu
1051                                         #-mno-epilogue #try to inline function exit code
1052                                         #-mflat # omit save/restore
1053                                         #-,faster-structs #faster non Sparc ABI structure copy ops
1054                                         LDFLAGS+=-m64
1055 else                    # CC_SHORTVER, 3.0
1056 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1057 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
1058                                         for better results)
1059 ifneq                           ($(OS), netbsd)
1060                                                 # on netbsd/sparc64,  gcc 2.95.3 does not compile
1061                                                 # ser with -mv8
1062                                                 CFLAGS+= -mv9 
1063                                                 # -m64/-m32 on sparc works starting with gcc 3.0
1064 endif
1065 ifeq                                    ($(ASTYPE), solaris)
1066                                                         CFLAGS+= -Wa,-xarch=v8plus
1067 endif                                   
1068 else                    #CC_SHORTVER, 2.9x
1069                                 #really old version
1070 $(warning                       You are using an old and unsupported gcc \
1071                                          version ($(CC_SHORTVER)), compile at your own risk!)
1072                                         
1073                                         CFLAGS+= -mv9 
1074 ifeq                                    ($(ASTYPE), solaris)
1075                                                         CFLAGS+= -Wa,-xarch=v8plus
1076 endif                                   
1077         
1078 endif                   #CC_SHORTVER, 2.9x
1079 endif                   #CC_SHORTVER, 3.0
1080 endif                   #CC_SHORTVER, 3.4
1081 endif                   #CC_SHORTVER, 4.x
1082 endif                   #CC_SHORTVER, 5.0+, 4.5+ or 4.2+
1083         
1084 else            #CC_NAME, gcc
1085 ifeq            ($(CC_NAME), suncc)
1086                         C_DEFS+=-DSPARC64_MODE
1087                         CFLAGS+= -m64 -g -xO5 -fast -native -xarch=v9 -xCC \
1088                                         -xc99 # C99 support
1089                         # -Dinline="" # add this if cc < 5.3 (define inline as null)
1090 else
1091                                 #other compilers
1092 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1093 endif           #CC_NAME, suncc
1094 endif           #CC_NAME, gcc
1095 endif   #ARCH, sparc64
1096
1097         #if sparc
1098 ifeq    ($(ARCH), sparc)
1099                         #if gcc
1100 ifeq            ($(CC_NAME), gcc)
1101                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1102                                 #common stuff
1103                                 CFLAGS=-g $(CC_OPT) -funroll-loops  $(PROFILE) \
1104                                         #-Wcast-align \
1105                                         #-Wmissing-prototypes 
1106                                 #if gcc 5.0+, 4.5+ or 4.2+
1107 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+,$(CC_SHORTVER))))
1108 $(call                          set_if_empty,CPUTYPE,v8)
1109                                         #use 32bit for now
1110                                         CFLAGS+= -mtune=$(CPUTYPE) \
1111                                                         -fno-strict-overflow \
1112                                                         -ftree-vectorize
1113 else
1114                                 #if gcc 4.x
1115 ifeq                    ($(CC_SHORTVER), 4.x)
1116 $(call                          set_if_empty,CPUTYPE,v8)
1117                                         #use 32bit for now
1118                                         CFLAGS+= -mtune=$(CPUTYPE) \
1119                                                         -ftree-vectorize
1120 else
1121                                 #if gcc 3.4
1122 ifeq                    ($(CC_SHORTVER), 3.4)
1123 $(call                          set_if_empty,CPUTYPE,v8)
1124                                         #use 32bit for now
1125                                         CFLAGS+= -mtune=$(CPUTYPE)
1126 else
1127                                 #if gcc 3.0
1128 ifeq                    ($(CC_SHORTVER), 3.0)
1129 $(call                          set_if_empty,CPUTYPE,v8)
1130                                         #use 32bit for now
1131                                         CFLAGS+= -mtune=$(CPUTYPE)   \
1132                                         #-mno-epilogue #try to inline function exit code
1133                                         #-mflat # omit save/restore
1134                                         #-,faster-structs #faster non Sparc ABI structure copy ops
1135 else                    # CC_SHORTVER, 3.0
1136 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1137 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
1138                                         for better results)
1139 else                    #CC_SHORTVER, 2.9x
1140                                 #really old version
1141 $(warning                       You are using an old and unsupported gcc \
1142                                          version ($(CC_SHORTVER)), compile at your own risk!)
1143                                         
1144 endif                   #CC_SHORTVER, 2.9x
1145 endif                   #CC_SHORTVER, 3.0
1146 endif                   #CC_SHORTVER, 3.4
1147 endif                   #CC_SHORTVER, 4.x
1148 endif                   #CC_SHORTVER, 5.0+, 4.5+ or 4.2+
1149         
1150 else            #CC_NAME, gcc
1151 ifeq            ($(CC_NAME), suncc)
1152                         CFLAGS+= -g -xO5 -fast -native -xCC \
1153                                         -xc99 # C99 support
1154                         # -Dinline="" # add this if cc < 5.3 (define inline as null)
1155 else
1156                                 #other compilers
1157 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1158 endif           #CC_NAME, suncc
1159 endif           #CC_NAME, gcc
1160 endif   #ARCH, sparc
1161
1162         #if ipaq/netwinder
1163 ifeq    ($(ARCH), arm)
1164                 # if gcc 
1165 ifeq            ($(CC_NAME), gcc)
1166                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1167                                 #common stuff
1168                                 CFLAGS=-marm -march=armv5t $(CC_OPT) -funroll-loops -fsigned-char $(PROFILE)
1169                         #if gcc 4.5+ or 4.2+
1170 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+,$(CC_SHORTVER))))
1171                                         CFLAGS+= -ftree-vectorize -fno-strict-overflow
1172                                         # not supported on arm: -minline-all-stringops 
1173 else
1174                         #if gcc 4.x+
1175 ifeq                    ($(CC_SHORTVER), 4.x)
1176                                         CFLAGS+= -ftree-vectorize
1177                                         # not supported on arm: -minline-all-stringops 
1178 else
1179                         #if gcc 3.4+
1180 ifeq                    ($(CC_SHORTVER), 3.4)
1181                                         CFLAGS+=
1182 else
1183                         #if gcc 3.0
1184 ifeq                    ($(CC_SHORTVER), 3.0)
1185                                         CFLAGS+= 
1186                                                         #-mcpu=athlon
1187 else
1188 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1189 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1190                                         for better results)
1191                                         
1192                                         CFLAGS+=
1193 else
1194                                 #really old version
1195 $(warning                       You are using an old and unsupported gcc \
1196                                          version ($(CC_SHORTVER)), compile at your own risk!)
1197         
1198 endif                   # CC_SHORTVER, 2.9x
1199 endif                   # CC_SHORTVER, 3.0
1200 endif                   # CC_SHORTVER, 3.4
1201 endif                   # CC_SHORTVER, 4.x
1202 endif                   # CC_SHORTVER, 5.0+, 4.5+ or 4.2+
1203         
1204 else            # CC_NAME, gcc
1205                                 #other compilers
1206 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1207 endif           #CC_NAME, gcc
1208 endif   #ARCH, arm 
1209
1210         #if armv6 cpu 
1211 ifeq    ($(ARCH), arm6)
1212                 # if gcc 
1213 ifeq            ($(CC_NAME), gcc)
1214                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1215                                 #common stuff
1216                                 CFLAGS=-march=armv6 $(CC_OPT) -funroll-loops -fsigned-char \
1217                                                 $(PROFILE)
1218                         #if gcc 5.0+, 4.5+ or 4.2+
1219 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+,$(CC_SHORTVER))))
1220                                         CFLAGS+= -ftree-vectorize -fno-strict-overflow
1221 else
1222                         #if gcc 4.x+
1223 ifeq                    ($(CC_SHORTVER), 4.x)
1224                                         CFLAGS+= -ftree-vectorize
1225 else
1226                         #if gcc 3.4+
1227 ifeq                    ($(CC_SHORTVER), 3.4)
1228                                         CFLAGS+=
1229 else
1230                         #if gcc 3.0
1231 ifeq                    ($(CC_SHORTVER), 3.0)
1232                                         CFLAGS+= 
1233                                                         #-mcpu=athlon
1234 else
1235 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1236 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1237                                         for better results)
1238                                         
1239                                         CFLAGS+=
1240 else
1241                                 #really old version
1242 $(warning                       You are using an old and unsupported gcc \
1243                                          version ($(CC_SHORTVER)), compile at your own risk!)
1244         
1245 endif                   # CC_SHORTVER, 2.9x
1246 endif                   # CC_SHORTVER, 3.0
1247 endif                   # CC_SHORTVER, 3.4
1248 endif                   # CC_SHORTVER, 4.x
1249 endif                   # CC_SHORTVER, 5.0+, 4.5+ or 4.2+
1250         
1251 else            # CC_NAME, gcc
1252                                 #other compilers
1253 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1254 endif           #CC_NAME, gcc
1255 endif   #ARCH, arm6
1256
1257         #if  mips (R3000)
1258 ifeq    ($(ARCH), mips)
1259                 # if gcc 
1260 ifeq            ($(CC_NAME), gcc)
1261                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1262                                 #common stuff
1263                                 CFLAGS=$(CC_OPT) -funroll-loops  $(PROFILE)
1264                         #if gcc 5.0+, 4.5+ or 4.2+
1265 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+,$(CC_SHORTVER))))
1266                                         CFLAGS+=-mfp32 -march=r3000 \
1267                                                         -ftree-vectorize -fno-strict-overflow
1268                         # not supported on mips: -minline-all-stringops
1269 else
1270                         #if gcc 4.0+
1271 ifeq                    ($(CC_SHORTVER), 4.x)
1272                                         CFLAGS+=-march=r3000 \
1273                                                         -ftree-vectorize
1274                         # not supported on mips: -minline-all-stringops
1275 else
1276                         #if gcc 3.4+
1277 ifeq                    ($(CC_SHORTVER), 3.4)
1278                                         CFLAGS+= -march=r3000
1279 else
1280                         #if gcc 3.0
1281 ifeq                    ($(CC_SHORTVER), 3.0)
1282                                         CFLAGS+= -march=r3000
1283 else
1284 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1285 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1286                                         for better results)
1287                                         
1288                                         CFLAGS+=-march=r3000
1289 else
1290                                 #really old version
1291 $(warning                       You are using an old and unsupported gcc \
1292                                          version ($(CC_SHORTVER)), compile at your own risk!)
1293         
1294 endif                   # CC_SHORTVER, 2.9x
1295 endif                   # CC_SHORTVER, 3.0
1296 endif                   # CC_SHORTVER, 3.4
1297 endif                   # CC_SHORTVER, 4.x
1298 endif                   # CC_SHORTVER, 5.0+, 4.5+ or 4.2+
1299         
1300 else            # CC_NAME, gcc
1301                                 #other compilers
1302 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1303 endif           #CC_NAME, gcc
1304 endif   #ARCH, mips
1305
1306         #if  >=mips2 (R4000, R5000, R6000 ....)
1307 ifeq    ($(ARCH), mips2)
1308                 # if gcc 
1309 ifeq            ($(CC_NAME), gcc)
1310                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1311                                 #common stuff
1312                                 CFLAGS= -mips2 $(CC_OPT) -funroll-loops $(PROFILE)
1313                         #if gcc 5.0+, 4.5+ or 4.2+
1314 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+,$(CC_SHORTVER))))
1315                                         CFLAGS+=-ftree-vectorize -fno-strict-overflow
1316                         # not supported on mips: -minline-all-stringops
1317 else
1318                         #if gcc 4.0+
1319 ifeq                    ($(CC_SHORTVER), 4.x)
1320                                         CFLAGS+=-ftree-vectorize
1321                         # not supported on mips: -minline-all-stringops
1322 else
1323                         #if gcc 3.4+
1324 ifeq                    ($(CC_SHORTVER), 3.4)
1325                                         CFLAGS+=
1326 else
1327                         #if gcc 3.0
1328 ifeq                    ($(CC_SHORTVER), 3.0)
1329                                         CFLAGS+=
1330 else
1331 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1332 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1333                                         for better results)
1334                                         CFLAGS+=
1335 else
1336                                 #really old version
1337 $(warning                       You are using an old and unsupported gcc \
1338                                          version ($(CC_SHORTVER)), compile at your own risk!)
1339         
1340 endif                   # CC_SHORTVER, 2.9x
1341 endif                   # CC_SHORTVER, 3.0
1342 endif                   # CC_SHORTVER, 3.4
1343 endif                   # CC_SHORTVER, 4.x
1344 endif                   # CC_SHORTVER, 5.0+, 4.5+ or 4.2+
1345         
1346 else            # CC_NAME, gcc
1347                                 #other compilers
1348 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1349 endif           #CC_NAME, gcc
1350 endif   #ARCH, mips2
1351
1352 #if  >=mips64
1353 ifeq    ($(ARCH), mips64)
1354                 # if gcc 
1355 ifeq            ($(CC_NAME), gcc)
1356                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1357                                 #common stuff
1358                                 CFLAGS= -mips64 $(CC_OPT) -funroll-loops $(PROFILE)
1359                         #if gcc 5.0+, 4.5+ or 4.2+
1360 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+,$(CC_SHORTVER))))
1361                                         CFLAGS+=-ftree-vectorize -fno-strict-overflow
1362                         # not supported on mips: -minline-all-stringops
1363
1364 else
1365                         #if gcc 4.0+
1366 ifeq                    ($(CC_SHORTVER), 4.x)
1367                                         CFLAGS+=-ftree-vectorize
1368                         # not supported on mips: -minline-all-stringops
1369 else
1370                         #if gcc 3.4+
1371 ifeq                    ($(CC_SHORTVER), 3.4)
1372                                         CFLAGS+=
1373 else
1374                         #if gcc 3.0
1375 ifeq                    ($(CC_SHORTVER), 3.0)
1376                                         CFLAGS+=
1377 else
1378 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1379 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1380                                         for better results)
1381                                         CFLAGS+=
1382 else
1383                                 #really old version
1384 $(warning                       You are using an old and unsupported gcc \
1385                                          version ($(CC_SHORTVER)), compile at your own risk!)
1386         
1387 endif                   # CC_SHORTVER, 2.9x
1388 endif                   # CC_SHORTVER, 3.0
1389 endif                   # CC_SHORTVER, 3.4
1390 endif                   # CC_SHORTVER, 4.x
1391 endif                   # CC_SHORTVER, 5.0+, 4.5+ or 4.2+
1392         
1393 else            # CC_NAME, gcc
1394                                 #other compilers
1395 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1396 endif           #CC_NAME, gcc
1397 endif   #ARCH, mips64
1398
1399 #if  alpha
1400 ifeq    ($(ARCH), alpha)
1401                 # if gcc 
1402 ifeq            ($(CC_NAME), gcc)
1403                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1404                                 #common stuff
1405                                 CFLAGS= $(CC_OPT) -funroll-loops $(PROFILE)
1406                         #if gcc 5.0+, 4.5 or 4.2+
1407 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+,$(CC_SHORTVER))))
1408                                         CFLAGS+= -fno-strict-overflow
1409                                         # not supported: -minline-all-stringops
1410 else
1411                         #if gcc 4.0+
1412 ifeq                    ($(CC_SHORTVER), 4.x)
1413                                         CFLAGS+= 
1414                                         # not supported: -minline-all-stringops
1415 else
1416                         #if gcc 3.4+
1417 ifeq                    ($(CC_SHORTVER), 3.4)
1418                                         CFLAGS+=
1419 else
1420                         #if gcc 3.0
1421 ifeq                    ($(CC_SHORTVER), 3.0)
1422                                         CFLAGS+=
1423 else
1424 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1425 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1426                                         for better results)
1427                                         CFLAGS+=
1428 else
1429                                 #really old version
1430 $(warning                       You are using an old and unsupported gcc \
1431                                          version ($(CC_SHORTVER)), compile at your own risk!)
1432         
1433 endif                   # CC_SHORTVER, 2.9x
1434 endif                   # CC_SHORTVER, 3.0
1435 endif                   # CC_SHORTVER, 3.4
1436 endif                   # CC_SHORTVER, 4.x
1437 endif                   # CC_SHORTVER, 5.0+, 4.5+ or 4.2+
1438         
1439 else            # CC_NAME, gcc
1440                                 #other compilers
1441 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1442 endif           #CC_NAME, gcc
1443 endif   #ARCH, alpha 
1444
1445 #if  ppc
1446 ifeq    ($(ARCH), ppc)
1447                 # if gcc 
1448 ifeq            ($(CC_NAME), gcc)
1449                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1450                                 #common stuff
1451                                 CFLAGS=
1452                         #if gcc 5.0+, 4.5+ or 4.2+
1453 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+,$(CC_SHORTVER))))
1454 $(call                          set_if_empty,CPUTYPE,powerpc)
1455 ifeq                            ($(NOALTIVEC),)
1456                                                 CFLAGS += $(CC_OPT) -funroll-loops -fsigned-char $(PROFILE)
1457                                                 CFLAGS += -ftree-vectorize
1458                                                 CFLAGS += -maltivec
1459                                                 CFLAGS += -fno-strict-overflow
1460                                                 CFLAGS += -mtune=$(CPUTYPE)
1461 endif
1462 else
1463                         #if gcc 4.0+
1464 ifeq                    ($(CC_SHORTVER), 4.x)
1465 $(call                          set_if_empty,CPUTYPE,powerpc)
1466 ifeq                            ($(NOALTIVEC),)
1467                                                 CFLAGS += $(CC_OPT) -funroll-loops -fsigned-char $(PROFILE)
1468                                                 CFLAGS += -ftree-vectorize
1469                                                 CFLAGS += -maltivec
1470                                                 CFLAGS += -mtune=$(CPUTYPE)
1471 endif
1472 else
1473                         #if gcc 3.4+
1474 ifeq                    ($(CC_SHORTVER), 3.4)
1475                                         CFLAGS+=
1476 else
1477                         #if gcc 3.0
1478 ifeq                    ($(CC_SHORTVER), 3.0)
1479                                         CFLAGS+=
1480 else
1481 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1482 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1483                                         for better results)
1484                                         CFLAGS+=
1485 else
1486                                 #really old version
1487 $(warning                       You are using an old and unsupported gcc \
1488                                          version ($(CC_SHORTVER)), compile at your own risk!)
1489         
1490 endif                   # CC_SHORTVER, 2.9x
1491 endif                   # CC_SHORTVER, 3.0
1492 endif                   # CC_SHORTVER, 3.4
1493 endif                   # CC_SHORTVER, 4.x
1494 endif                   # CC_SHORTVER, 5.0+, 4.5+ or 4.2+
1495         
1496 else            # CC_NAME, gcc
1497                                 #other compilers
1498 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1499 endif           #CC_NAME, gcc
1500 endif   #ARCH, ppc 
1501
1502 #if  ppc64
1503 ifeq    ($(ARCH), ppc64)
1504                 # if gcc 
1505 ifeq            ($(CC_NAME), gcc)
1506                                 C_DEFS+=-DCC_GCC_LIKE_ASM
1507                                 #common stuff
1508                                 CFLAGS= $(CC_OPT) -funroll-loops -fsigned-char $(PROFILE)
1509                         #if gcc 5.0+, 4.5+ or 4.2+
1510 ifeq (,$(strip $(filter-out 4.2+ 4.5+ 5.0+,$(CC_SHORTVER))))
1511 $(call                          set_if_empty,CPUTYPE,powerpc64)
1512                                         CFLAGS+=-ftree-vectorize \
1513                                                         -fno-strict-overflow \
1514                                                         -mtune=$(CPUTYPE) -maltivec
1515 else
1516                         #if gcc 4.0+
1517 ifeq                    ($(CC_SHORTVER), 4.x)
1518 $(call                          set_if_empty,CPUTYPE,powerpc64)
1519                                         CFLAGS+=-ftree-vectorize \
1520                                                         -mtune=$(CPUTYPE) -maltivec
1521 else
1522                         #if gcc 3.4+
1523 ifeq                    ($(CC_SHORTVER), 3.4)
1524                                         CFLAGS+=
1525 else
1526                         #if gcc 3.0
1527 ifeq                    ($(CC_SHORTVER), 3.0)
1528                                         CFLAGS+=
1529 else
1530 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1531 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1532                                         for better results)
1533                                         CFLAGS+=
1534 else
1535                                 #really old version
1536 $(warning                       You are using an old and unsupported gcc \
1537                                          version ($(CC_SHORTVER)), compile at your own risk!)
1538         
1539 endif                   # CC_SHORTVER, 2.9x
1540 endif                   # CC_SHORTVER, 3.0
1541 endif                   # CC_SHORTVER, 3.4
1542 endif                   # CC_SHORTVER, 4.x
1543 endif                   # CC_SHORTVER, 5.0+, 4.5+ or 4.2+
1544         
1545 else            # CC_NAME, gcc
1546                                 #other compilers
1547 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1548 endif           #CC_NAME, gcc
1549 endif   #ARCH, ppc 
1550
1551 CFLAGS+= $(CC_EXTRA_OPTS)
1552
1553
1554 # setting LDFLAGS
1555 ifeq    ($(CC_NAME), gcc)
1556 ifeq            ($(LDTYPE), solaris)
1557                 # solaris ld
1558                 LDFLAGS+=-O2 $(PROFILE)
1559                 MOD_LDFLAGS:=-G $(LDFLAGS)
1560                 LIB_LDFLAGS:=-G $(LDFLAGS)
1561                 LIB_SONAME=-Wl,-h,
1562                 LD_RPATH=-Wl,-R,
1563 else            
1564                 #gcc and maybe others, => gnu ld
1565                 LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
1566                 MOD_LDFLAGS:=-shared $(LDFLAGS)
1567                 LIB_LDFLAGS:=-shared $(LDFLAGS)
1568                 LIB_SONAME=-Wl,-soname,
1569                 LD_RPATH=-Wl,-rpath,
1570 endif
1571 endif
1572 ifeq    ($(CC_NAME), icc)
1573         #gcc and maybe others
1574         LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
1575         MOD_LDFLAGS:=-shared $(LDFLAGS)
1576         LIB_LDFLAGS:=-shared $(LDFLAGS)
1577         LIB_SONAME=-Wl,-soname,
1578         LD_RPATH=-Wl,-rpath,
1579 endif
1580 ifeq    ($(CC_NAME), suncc)
1581         # -dy?
1582         LDFLAGS+=-xO5 $(PROFILE)
1583         MOD_LDFLAGS:=-G $(LDFLAGS)
1584         LIB_LDFLAGS:=-G $(LDFLAGS)
1585         LIB_SONAME="-h "
1586         LD_RPATH=-"-R "
1587 endif
1588         # we need -fPIC -DPIC only for shared objects, we don't need them for
1589         # the executable file, because it's always loaded at a fixed address
1590         # -andrei
1591
1592 ifeq ($(CC_NAME), clang)
1593         LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE)
1594         MOD_LDFLAGS:=-shared $(LDFLAGS)
1595         LIB_LDFLAGS:=-shared $(LDFLAGS)
1596         LIB_SONAME=-Wl,-soname,
1597         LD_RPATH=-Wl,-rpath,
1598 endif
1599
1600 LDFLAGS+= $(LD_EXTRA_OPTS)
1601 MOD_LDFLAGS+= $(LD_EXTRA_OPTS)
1602 LIB_LDFLAGS+= $(LD_EXTRA_OPTS)
1603
1604 else    #mode,release
1605 ifeq    ($(CC_NAME), gcc)
1606                 CFLAGS=-g -Wcast-align $(PROFILE)
1607                 C_DEFS+=-DCC_GCC_LIKE_ASM
1608 ifeq            ($(ARCH), sparc64)
1609                         C_DEFS+=SPARC64_MODE
1610                         CFLAGS+= -mcpu=ultrasparc -m64
1611                         LDFLAGS+=-m64
1612 endif
1613 ifeq            ($(LDTYPE), solaris)
1614                         #solaris ld
1615                         LDFLAGS+=-g $(PROFILE)
1616                         MOD_LDFLAGS:=-G $(LDFLAGS)
1617                         LIB_LDFLAGS:=-G $(LDFLAGS)
1618                         LIB_SONAME=-Wl,-h,
1619                         LD_RPATH=-Wl,-R,
1620 else
1621                         #gnu or other ld type
1622                         LDFLAGS+=-g -Wl,-E $(PROFILE)
1623                         MOD_LDFLAGS:=-shared $(LDFLAGS)
1624                         LIB_LDFLAGS:=-shared $(LDFLAGS)
1625                         LIB_SONAME=-Wl,-soname,
1626                         LD_RPATH=-Wl,-rpath,
1627 endif
1628 endif
1629 ifeq    ($(CC_NAME), icc)
1630                 C_DEFS+=-DCC_GCC_LIKE_ASM
1631                 CFLAGS=-g  $(PROFILE)
1632                 LDFLAGS+=-g -Wl,-E $(PROFILE)
1633                 MOD_LDFLAGS:=-shared $(LDFLAGS)
1634                 LIB_LDFLAGS:=-shared $(LDFLAGS)
1635                 LIB_SONAME=-Wl,-soname,
1636                 LD_RPATH=-Wl,-rpath,
1637 endif
1638 ifeq    ($(CC_NAME), suncc)
1639                 CFLAGS= -g $(PROFILE)
1640                 LDFLAGS+=-g $(PROFILE)
1641                 MOD_LDFLAGS:=-G $(LDFLAGS)
1642                 LIB_LDFLAGS:=-G $(LDFLAGS)
1643                 LIB_SONAME="-h "
1644                 LD_RPATH=-"-R "
1645 endif
1646
1647 endif #mode=release
1648
1649
1650 # set pedantic compiler options
1651 ifeq ($(CC_NAME), gcc)
1652                 CFLAGS+= -Wall
1653 else # no gcc
1654 ifeq ($(CC_NAME), icc)
1655                 CFLAGS+= -Wall
1656 else # no icc
1657 ifeq ($(CC_NAME), suncc)
1658                 # FIXME: is the default (-Xa ?) enough?
1659 endif # CC_NAME=suncc
1660 endif # CC_NAME=icc
1661 endif # CC_NAME=gcc
1662
1663 #CFLAGS used for compiling the modules, libraries and utils
1664 ifeq    ($(CC_NAME), gcc)
1665 MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
1666 LIB_CFLAGS=-fPIC -DPIC $(CFLAGS)
1667 endif
1668 ifeq    ($(CC_NAME), icc)
1669 MOD_CFLAGS=-Kpic $(CFLAGS)
1670 LIB_CFLAGS=-Kpic $(CFLAGS)
1671 endif
1672 ifeq    ($(CC_NAME), suncc)
1673 # FIMXE: use -KPIC instead -xcode ?
1674 MOD_CFLAGS=-xcode=pic32  $(CFLAGS)
1675 LIB_CFLAGS=-xcode=pic32  $(CFLAGS)
1676 endif
1677 ifeq    ($(CC_NAME), clang)
1678 MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
1679 LIB_CFLAGS=-fPIC -DPIC $(CFLAGS)
1680 endif
1681
1682 UTILS_CFLAGS=$(CFLAGS)
1683 # LDFLAGS uses for compiling the utils
1684 UTILS_LDFLAGS=$(LDFLAGS)
1685
1686 ifeq ($(LEX),)
1687         LEX=flex
1688 endif
1689 ifeq ($(YACC),)
1690         YACC=bison
1691 endif
1692 YACC_FLAGS=-d -b cfg
1693 # on solaris add -lxnet (e.g. LIBS= -lxnet)
1694 LIBS= -ldl -lresolv
1695 LIB_PREFIX:=lib
1696 LIB_SUFFIX:=.so
1697
1698
1699 #os specific stuff
1700 ifeq ($(OS), linux)
1701 # by default use futexes if available
1702         use_futex= yes
1703         C_DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
1704                         -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
1705                         -DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER -DUSE_RAW_SOCKS
1706         ifneq ($(found_lock_method), yes)
1707                 #C_DEFS+= -DUSE_POSIX_SEM
1708                 C_DEFS+=-DUSE_PTHREAD_MUTEX
1709                 LIBS+= -lpthread
1710                 #C_DEFS+= -DUSE_SYSV_SEM  # try posix sems
1711                 found_lock_method=yes
1712         else
1713                 ifneq (,$(findstring -DUSE_POSIX_SEM, $(C_DEFS)))
1714                         LIBS+=-lpthread
1715                 endif
1716                 ifneq (,$(findstring -DUSE_PTHREAD_MUTEX, $(C_DEFS)))
1717                         LIBS+=-lpthread
1718                 endif
1719         endif
1720         # check for >= 2.5.44
1721
1722         ifeq ($(shell [ $(OSREL_N) -ge 2005044 ] && echo has_epoll), has_epoll)
1723                 ifeq ($(NO_EPOLL),)
1724                         C_DEFS+=-DHAVE_EPOLL
1725                         # linux + gcc >= 3.0 + -malign-double + epoll => problems
1726                         CFLAGS_RM+=-malign-double
1727                         #CFLAGS:=$(filter-out -malign-double, $(CFLAGS))
1728                 endif
1729         endif
1730         # check for >= 2.2.0
1731         ifeq ($(shell [ $(OSREL_N) -ge 2002000 ] && echo has_sigio), has_sigio)
1732                 ifeq ($(NO_SIGIO),)
1733                         C_DEFS+=-DHAVE_SIGIO_RT -DSIGINFO64_WORKARROUND
1734                 endif
1735         endif
1736         # check for >= 2.5.70
1737         ifeq ($(shell [ $(OSREL_N) -ge 2005070 ] && echo has_futex), has_futex)
1738                 ifeq ($(use_futex), yes)
1739                         C_DEFS+=-DUSE_FUTEX
1740                 endif
1741         endif
1742         ifeq ($(NO_SELECT),)
1743                 C_DEFS+=-DHAVE_SELECT
1744         endif
1745 endif
1746
1747 ifeq  ($(OS), solaris)
1748         C_DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD \
1749                         -DHAVE_ALLOCA_H -DUSE_SIGACTION
1750         ifneq ($(found_lock_method), yes)
1751                 C_DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1752                 found_lock_method=yes
1753         endif
1754         # check for ver >= 5.7
1755         ifeq ($(shell [ $(OSREL_N) -gt 5007 ] && echo has_devpoll), has_devpoll)
1756                 ifeq ($(NO_DEVPOLL),)
1757                         C_DEFS+=-DHAVE_DEVPOLL
1758                 endif
1759         endif
1760         ifeq ($(NO_SELECT),)
1761                 C_DEFS+=-DHAVE_SELECT
1762         endif
1763         # check for filio.h
1764         filio_h_locations= /usr/include/sys/filio.h \
1765                                                 $(LOCALBASE)/include/sys/filio.h
1766         has_filio_h=$(shell for r in $(filio_h_locations); do \
1767                                                 if  [ -r "$$r" ] ; then echo yes; exit; fi \
1768                                                 done;\
1769                                 )
1770         ifeq ($(has_filio_h), yes)
1771                 C_DEFS+=-DHAVE_FILIO_H
1772         endif
1773         ifeq ($(mode), release)
1774                 #use these only if you're using gcc with Solaris ld
1775                 #LDFLAGS=-O2 $(PROFILE)
1776                 #MOD_LDFLAGS=-O2 -G
1777         else
1778                 #LDFLAGS=-g $(PROFILE)
1779                 #MOD_LDFLAGS=-g -G
1780         endif
1781         YACC=yacc
1782
1783 ifeq ($(CC_NAME), suncc)
1784         LIBS= -lfast -ldl -lresolv
1785 endif
1786         OLD_SOLARIS= $(shell echo "$(OSREL)" | \
1787                                 sed -e 's/^5\.[0-6][^0-9]*$$/yes/' )
1788         LIBS+= -L$(LOCALBASE)/lib -lxnet -lsocket -lnsl 
1789 ifeq    ($(OLD_SOLARIS), yes)
1790                 LIBS+=-lposix4
1791 else
1792                 LIBS+=-lrt
1793 endif
1794         # -lrt needed for sched_yield
1795 endif
1796
1797 ifeq ($(OS), freebsd)
1798         C_DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1799                 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1800                 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1801                 -DHAVE_NETINET_IN_SYSTM -DUSE_RAW_SOCKS
1802         ifneq ($(found_lock_method), yes)
1803                 C_DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1804                 found_lock_method=yes
1805                 LIBS+= -pthread   #dlopen is in libc
1806         else
1807                 LIBS=   #dlopen is in libc
1808         endif
1809         # check for ver >= 4.1
1810         ifeq ($(shell [ $(OSREL_N) -gt 4001 ] && echo has_kqueue), has_kqueue)
1811                 ifeq ($(NO_KQUEUE),)
1812                         C_DEFS+=-DHAVE_KQUEUE
1813                 endif
1814         endif
1815         ifeq ($(NO_SELECT),)
1816                 C_DEFS+=-DHAVE_SELECT
1817         endif
1818         YACC=yacc
1819 endif
1820
1821 ifeq ($(OS), dragonfly)
1822         C_DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1823                 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1824                 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1825                 -DHAVE_NETINET_IN_SYSTM
1826         ifneq ($(found_lock_method), yes)
1827                 C_DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1828                 found_lock_method=yes
1829                 LIBS+= -pthread   #dlopen is in libc
1830         else
1831                 LIBS=   #dlopen is in libc
1832         endif
1833         # dragonfly was forked from freebsd 4.8 => all version have kqueue
1834         ifeq ($(NO_KQUEUE),)
1835                 C_DEFS+=-DHAVE_KQUEUE
1836         endif
1837         ifeq ($(NO_SELECT),)
1838                 C_DEFS+=-DHAVE_SELECT
1839         endif
1840         YACC=yacc
1841 endif
1842
1843 ifeq ($(OS), openbsd)
1844         C_DEFS+=-DHAVE_SOCKADDR_SA_LEN  -DHAVE_GETHOSTBYNAME2 \
1845                 -DHAVE_UNION_SEMUN -DHAVE_MSGHDR_MSG_CONTROL \
1846                 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1847                 -DHAVE_NETINET_IN_SYSTM -DUSE_SIGWAIT \
1848                 -DHAVE_SCHED_YIELD
1849         ifneq ($(found_lock_method), yes)
1850                 C_DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1851                 found_lock_method=yes
1852         endif
1853         # check for ver >=2 9
1854         ifeq ($(shell [ $(OSREL_N) -ge 2009 ] && echo has_kqueue), has_kqueue)
1855                 ifeq ($(NO_KQUEUE),)
1856                         C_DEFS+=-DHAVE_KQUEUE
1857                 endif
1858         endif
1859         ifeq ($(NO_SELECT),)
1860                 C_DEFS+=-DHAVE_SELECT
1861         endif
1862         # (symbols on openbsd are prefixed by "_")
1863         YACC=yacc
1864         # unfortunately pthread is needed for sigwait
1865         LIBS= -lpthread
1866 endif   # if opensd
1867         
1868 ifeq ($(OS), netbsd)
1869         C_DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 \
1870                 -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM
1871         ifneq ($(found_lock_method), yes)
1872                 C_DEFS+= -DUSE_SYSV_SEM  # try pthread sems
1873                 found_lock_method=yes
1874         endif
1875         # check for ver >= 2.0.0
1876         ifeq ($(shell [ $(OSREL_N) -ge 2000000 ] && echo has_kqueue), has_kqueue)
1877                 ifeq ($(NO_KQUEUE),)
1878                         C_DEFS+=-DHAVE_KQUEUE
1879                         # netbsd + kqueue and -malign-double don't work
1880                         CFLAGS_RM+=-malign-double
1881                         #CFLAGS:=$(filter-out -malign-double, $(CFLAGS))
1882                 endif
1883         endif
1884         ifeq ($(NO_SELECT),)
1885                 C_DEFS+=-DHAVE_SELECT
1886         endif
1887         YACC=yacc
1888         LIBS=  
1889 endif
1890
1891 # OS X support, same as freebsd
1892 ifeq ($(OS), darwin)
1893         C_DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1894                 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1895                 -DUSE_ANON_MMAP \
1896                 -DNDEBUG -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1897                 -DUSE_SIGWAIT
1898         # -DNDEBUG used to turn off assert (assert wants to call
1899         # eprintf which doesn't seem to be defined in any shared lib
1900         ifneq ($(found_lock_method), yes)
1901                 C_DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1902                 found_lock_method=yes
1903                 C_DEFS+= -DUSE_SYSV_SEM  # try sys v sems (pthread don't work for
1904                                        # processes and unnamed posix sems are not
1905                                        # supported)
1906         endif
1907         LIBS= -lresolv  #dlopen is in libc
1908         ifeq ($(NO_KQUEUE),)
1909                 C_DEFS+=-DHAVE_KQUEUE
1910         endif
1911         ifeq ($(NO_SELECT),)
1912                 C_DEFS+=-DHAVE_SELECT
1913         endif
1914         LDFLAGS=        # darwin doesn't like -O2 or -E
1915         # the modules uses symbols from ser => either 
1916         # -flat_namespace -undefined_suppress or -bundle_loader ../../$(MAIN_NAME)
1917         MOD_LDFLAGS:= -bundle -flat_namespace -undefined suppress
1918         # for libs using symbols from ser (e.g srdb2, kcore a.s.o) we
1919         # need -flat_namespace -undefined suppress
1920         LIB_LDFLAGS:= -dynamiclib -flat_namespace -undefined suppress
1921         LIB_SUFFIX:=.dylib
1922         # on darwin soname should include the full path
1923         # (it kind of combines rpath & soname)
1924         LIB_SONAME=
1925         # no equiv. for rpath on darwin
1926         LD_RPATH=
1927         YACC=yacc
1928 endif
1929
1930 ifneq (,$(findstring cygwin, $(OS)))
1931         # cygwin does support IPV6 starting from version 1.7, but (still?) doesn't support fd passing so no TCP
1932         #C_DEFS:=$(filter-out -DUSE_TCP, $(C_DEFS))
1933         DEFS_RM+=-DUSE_TCP
1934         C_DEFS+=-DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
1935                         -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
1936                         -DHAVE_TIMEGM -DHAVE_SCHED_SETSCHEDULER
1937         ifneq ($(found_lock_method), yes)
1938                 C_DEFS+= -DUSE_POSIX_SEM
1939                 #C_DEFS+= -DUSE_SYSV_SEM  # try posix sems
1940                 # PTHREAD_MUTEX do not work for processes (try test/pthread_test.c)
1941                 #LIBS+= -lpthread
1942                 found_lock_method=yes
1943         else
1944                 ifneq (,$(findstring -DUSE_POSIX_SEM, $(C_DEFS)))
1945                         #LIBS+=-lpthread
1946                 endif
1947                 ifneq (,$(findstring -DUSE_PTHREAD_MUTEX, $(C_DEFS)))
1948 $(error PTHREAD_MUTEX do not work for processes on Windows/CYGWIN)
1949                 endif
1950         endif
1951         # check for >= 2.5.70
1952         ifeq ($(NO_SELECT),)
1953                 C_DEFS+=-DHAVE_SELECT
1954         endif
1955 endif
1956
1957 #add libssl if needed
1958 ifeq ($(CORE_TLS), 1)
1959 C_INCLUDES+= -I$(LOCALBASE)/ssl/include
1960 LIBS+= -L$(LOCALBASE)/lib -L$(LOCALBASE)/ssl/lib -lssl -lcrypto \
1961                 $(TLS_EXTRA_LIBS)
1962 # NOTE: depending on the way in which libssl was compiled you might
1963 #       have to add -lz -lkrb5   (zlib and kerberos5).
1964 #       E.g.: make CORE_TLS=1 EXTRA_TLS_LIBS="-lz -lkrb5"
1965 endif
1966
1967 ifneq ($(found_lock_method), yes)
1968 $(warning       No locking method found so far, trying SYS V sems)
1969                 C_DEFS+= -DUSE_SYSV_SEM  # try sys v sems
1970                 found_lock_method=yes
1971 endif
1972
1973
1974 endif # ifeq (,$(main_makefile))
1975 endif  # ifeq ($(makefile_defs), 1)
1976
1977 # if incomplete or missing config.mak, or already exported vars, don't
1978 # try to export/re-export
1979 ifeq ($(makefile_defs),1) 
1980 ifneq ($(exported_vars),1)
1981
1982
1983 override exported_vars:=1
1984 export exported_vars
1985
1986 # variable changeable only at configure time (once saved in config.mak they
1987 #  cannot be overwritten from environment or command line, unless make cfg
1988 #  is run)
1989 saved_fixed_vars:=      MAIN_NAME  CFG_NAME SCR_NAME FLAVOUR INSTALL_FLAVOUR \
1990                 SRC_NAME RELEASE OS ARCH \
1991                 C_DEFS DEFS_RM PROFILE CC LD MKDEP MKTAGS LDFLAGS C_INCLUDES \
1992                 CC_MKDEP_OPTS \
1993                 MOD_LDFLAGS LIB_LDFLAGS UTILS_LDFLAGS LIB_SONAME LD_RPATH \
1994                 LIB_SUFFIX LIB_PREFIX \
1995                 LIBS \
1996                 LEX YACC YACC_FLAGS \
1997                 PREFIX LOCALBASE \
1998                 TAR \
1999                 INSTALL INSTALL_CFG INSTALL_BIN INSTALL_MODULES INSTALL_DOC \
2000                 INSTALL_MAN INSTALL_LIB INSTALL_TOUCH INSTALL_SHARE \
2001                 Q
2002
2003 # variable changeable at compile time
2004 # extra: prefix DESTDIR BASEDIR basedirt
2005 saved_chg_vars:=\
2006                 CC_EXTRA_OPTS CPUTYPE CFLAGS_RM CFLAGS MOD_CFLAGS LIB_CFLAGS UTILS_CFLAGS \
2007                 BASEDIR basedir DESTDIR LIBDIR RUNBASEDIR runbasedir \
2008                 PREFIX prefix \
2009                 cfg_prefix cfg_dir bin_prefix bin_dir modules_prefix modules_dir \
2010                 doc_prefix doc_dir man_prefix man_dir ut_prefix ut_dir \
2011                 share_prefix share_dir lib_prefix lib_dir data_prefix data_dir \
2012                 cfg_target lib_target data_target run_prefix run_dir run_target
2013
2014
2015 #export relevant variables to the sub-makes
2016 export $(saved_fixed_vars)
2017 export $(saved_chg_vars)
2018
2019
2020 endif # ifneq ($(exported_vars),1)
2021 endif # ifeq ($(makefile_defs),1)
2022