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