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