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