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