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