aca251e9101dd341c4faab46565b1683cf28956e
[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
49
50 # check if already included/exported
51
52 ifeq ($(makefile_defs), 1)
53 else
54 makefile_defs=1
55 export makefile_defs
56
57 # main binary name
58 MAIN_NAME=ser
59
60 #version number
61 VERSION = 0
62 PATCHLEVEL = 10
63 SUBLEVEL =   99
64 EXTRAVERSION = -dev29-tm-timers
65
66 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
67 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
68
69 ifeq ($(OS),solaris)
70         GETARCH=uname -p
71 else
72         GETARCH=uname -m
73 endif
74
75 ARCH := $(shell $(GETARCH) |sed -e s/i.86/i386/ -e s/sun4u/sparc64/  \
76                         -e s/armv4l/arm/ -e "s/Power Macintosh/ppc/" \
77                         -e "s/cobalt/mips2/" \
78                         -e s/amd64/x86_64/ )
79 # fix sparc -> sparc64
80 ifeq ($(ARCH),sparc)
81         ifeq ($(shell uname -m),sun4u)
82                 ARCH := sparc64
83         endif
84 endif
85
86 OSREL = $(shell uname -r)
87 # numerical version (good for comparisons: A.B.C => A*1000000+B*1000+C)
88 OSREL_N= $(shell echo $(OSREL) | sed -e 's/^[^0-9]*//' \
89                 -e 's/^\([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*$$/\1/g' | \
90                 (IFS=. read A B C D; R=0; \
91                 [ -n "$$A" ] && R=`expr $$R \* 1000 + $$A` && \
92                 [ -n "$$B" ] && R=`expr $$R \* 1000 + $$B` && \
93                 [ -n "$$C" ] && R=`expr $$R \* 1000 + $$C`; echo $$R ) )
94
95 # TLS support
96 TLS ?= 
97 ifneq ($(TLS),)
98         RELEASE:=$(RELEASE)-tls
99 endif
100 # extra CC command line options (e.g  -march=athlon-mp)
101 CC_EXTRA_OPTS ?=
102
103 # dirs 
104 cfg-dir = etc/ser/
105 bin-dir = sbin/
106 modules-dir = lib/ser/modules/
107 ifeq ($(OS), linux)
108         doc-dir = share/doc/ser/
109         man-dir = share/man/
110         LOCALBASE ?= /usr/local
111 else
112 ifeq ($(OS), freebsd)
113         doc-dir = share/doc/ser/
114         man-dir = man/
115         LOCALBASE ?= /usr/local
116 else
117 ifeq ($(OS), openbsd)
118         doc-dir = share/doc/ser/
119         man-dir = man/
120         LOCALBASE ?= /usr/local
121 else
122 ifeq ($(OS), netbsd)
123         doc-dir = share/doc/ser
124         man-dir = man/
125         LOCALBASE ?= /usr/pkg
126 else
127 ifeq ($(OS), darwin)
128         doc-dir = share/doc/ser/
129         man-dir = man/
130         LOCALBASE ?= /usr/local
131 else
132         doc-dir = doc/ser/
133         man-dir = man/
134         LOCALBASE ?= /usr/local
135 endif
136 endif
137 endif
138 endif
139 endif
140
141  # install location
142 DESTDIR ?= $(LOCALBASE)
143 PREFIX ?= $(DESTDIR)
144 prefix = $(PREFIX)
145 # install path is $(basedir) $(prefix) 
146 # example:
147 #  creating a bin. archive in /tmp, which unpacks in /usr/local
148 #  basedir=/tmp
149 #  prefix=/usr/local
150
151 BASEDIR ?=
152 basedir = $(BASEDIR)
153 # install prefixes for various stuff
154 cfg-prefix = $(basedir)$(prefix)
155 bin-prefix = $(basedir)$(prefix)
156 modules-prefix = $(basedir)$(prefix)
157 doc-prefix = $(basedir)$(prefix)
158 man-prefix = $(basedir)$(prefix)
159 ut-prefix = $(basedir)$(prefix)
160
161
162 # target dirs for various stuff
163 cfg-target = $(prefix)/$(cfg-dir)
164 bin-target = $(prefix)/$(bin-dir)
165 modules-target = $(prefix)/$(modules-dir)
166 doc-target = $(prefix)/$(doc-dir)
167
168
169 ifeq ($(OS), solaris)
170 #use GNU versions
171 INSTALL ?= ginstall
172 TAR ?= gtar
173 else
174 INSTALL ?= install 
175 TAR ?= tar
176 endif
177
178 INSTALL-TOUCH = touch          # used to create the file first (good to 
179                                #  make solaris install work)
180 INSTALL-CFG = $(INSTALL) -m 644
181 INSTALL-BIN = $(INSTALL) -m 755
182 INSTALL-MODULES = $(INSTALL) -m 755
183 INSTALL-DOC = $(INSTALL) -m 644
184 INSTALL-MAN = $(INSTALL) -m 644
185
186 #set some vars from the environment (and not make builtins)
187 CC   := $(shell echo "$${CC}")
188 LEX  := $(shell echo "$${LEX}")
189 YACC := $(shell echo "$${YACC}")
190
191
192
193
194 # find compiler name & version
195 ifeq ($(CC),)
196         CC=gcc
197 endif
198 LD= $(CC)
199 CC_LONGVER=$(shell if  $(CC) -v 2>/dev/null; then \
200                                                 $(CC) -v 2>&1 ;\
201                                         else \
202                                                 $(CC) -V 2>&1 ; \
203                                         fi )
204 MKTAGS=ctags -R .
205
206 #find-out the compiler's name
207
208 ifneq (,$(findstring gcc, $(CC_LONGVER)))
209         CC_NAME=gcc
210         CC_VER=$(word 1,$(CC)) $(shell $(CC) - --version|head -n 1|cut -d" " -f 3|\
211                                  sed -e 's/^.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/'\
212                                          -e 's/^[^0-9].*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/')
213         # sun sed is a little brain damaged => this complicated expression
214         MKDEP=$(CC) -MM 
215         #transform gcc version into 2.9x or 3.0
216         CC_SHORTVER=$(shell echo "$(CC_VER)" | cut -d" " -f 2| \
217                                  sed -e 's/[^0-9]*-\(.*\)/\1/'| \
218                                  sed -e 's/2\.9.*/2.9x/' -e 's/3\.[0-3]\..*/3.0/' -e \
219                                         's/3\.[0-3]/3.0/' -e 's/3\.[4-9]\..*/3.4/' -e \
220                                         's/3\.[4-9]/3.4/' -e 's/4\.[0-9]\..*/4.x/' -e \
221                                         's/4\.[0-9]/4.x/' )
222 endif
223
224 ifneq (, $(findstring Sun, $(CC_LONGVER)))
225         CC_NAME=suncc
226         CC_SHORTVER=$(shell echo "$(CC_LONGVER)"|head -n 1| \
227                                         sed -e 's/.*\([0-9]\.[0-9]\).*/\1/g' )
228         CC_VER=$(CC) $(CC_SHORTVER)
229         MKDEP=$(CC) -xM1 
230 endif
231
232 ifneq (, $(findstring Intel(R) C++ Compiler, $(CC_LONGVER)))
233         # very nice: gcc compatible
234         CC_NAME=icc
235         CC_FULLVER=$(shell echo "$(CC_LONGVER)"|head -n 1| \
236                                         sed -e 's/.*Version \([0-9]\.[0-9]\.[0-9]*\).*/\1/g' )
237         CC_SHORTVER=$(shell echo "$(CC_FULLVER)" | cut -d. -f1,2 )
238         CC_VER=$(CC) $(CC_FULLVER)
239         MKDEP=$(CC) -MM 
240 endif
241
242
243 ifeq (,$(CC_NAME))
244 #not found
245         CC_NAME=$(CC)
246         CC_SHORTVER=unknown
247         CC_VER=unknown
248         MKDEP=gcc -MM 
249 $(warning       Unknown compiler $(CC)\; supported compilers: \
250                         gcc, sun cc, intel icc )
251 endif
252
253
254 # compile-time options
255 #
256 # -DSTATS
257 #               allows to print out number of packets processed on CTRL-C;
258 #               implementation still nasty and reports per-process
259 # -DNO_DEBUG
260 #               turns off some of the debug messages (DBG(...)).
261 # -DNO_LOG
262 #               completely turns of all the logging (and DBG(...))
263 # -DEXTRA_DEBUG
264 #               compiles in some extra debugging code
265 # -DDNS_IP_HACK
266 #               faster ip address resolver for ip strings (e.g "127.0.0.1")
267 # -DSHM_MEM
268 #               compiles in shared mem. support, needed by some modules and
269 #               by USE_SHM_MEM
270 # -DSHM_MMAP
271 #               use mmap instead of SYSV shared memory
272 # -DPKG_MALLOC
273 #               uses a faster malloc (exclusive w/ USE_SHM_MEM)
274 # -DUSE_SHM_MEM
275 #               all pkg_malloc => shm_malloc (most mallocs use a common sh.
276 #               mem. segment); don't define PKG_MALLOC if you want this!
277 # -DDBG_QM_MALLOC
278 #               qm_malloc debug code, will cause pkg_malloc and shm_malloc
279 #               to keep and display lot of debuging information: file name,
280 #               function, line number of malloc/free call for each block,
281 #               extra error checking (trying to free the same pointer
282 #               twice, trying to free a pointer alloc'ed with a different
283 #               malloc etc.)
284 # -DVQ_MALLOC
285 #               additional option to PKG_MALLOC which utilizes a fater then
286 #               qm version
287 #               (not true anymore, q_malloc performs approx. the same)
288 # -DF_MALLOC
289 #               an even faster malloc, not recommended for debugging
290 # -DDBG_MALLOC
291 #               issues additional debugging information if lock/unlock is called
292 # -DFAST_LOCK
293 #               uses fast arhitecture specific locking (see the arh. specific section)
294 # -DUSE_SYSV_SEM
295 #               uses sys v sems for locking (slower & limited number)
296 # -DUSE_PTHREAD_MUTEX
297 #               uses pthread mutexes, faster than sys v or posix sems, but do not 
298 #               work on all systems inter-processes (e.g. linux)
299 # -DUSE_POSIX_SEM
300 #               uses posix semaphores for locking (faster than sys v)
301 # -DBUSY_WAIT
302 #               uses busy waiting on the lock (FAST_LOCK)
303 # -DADAPTIVE_WAIT
304 #               try busy waiting for a while and if the lock is still held go to
305 #               force reschedule (FAST_LOCK)
306 # -DADAPTIVE_WAIT_LOOPS=number
307 #               number of loops we busy wait, after "number" loops have elapsed we 
308 #               force a reschedule (FAST_LOCK)
309 # -DNOSMP
310 #               don't use smp compliant locking (faster but won't work on SMP machines)
311 #               (not yet enabled) (FAST_LOCK)
312 # -DNO_PINGTEL_TAG_HACK
313 #               if enabled, To-header-field will be less liberal and will not accept
314 #               'tag=' (tag parameter with equal sign and without value); it is called
315 #               this way because such message was sighted from a Pingtel phone
316 # -DWITH_SNMP_MOD
317 #               if enabled, allows forking of the snmp agent just before child
318 #               forking (done at the top of main_loop). Needed if you want
319 #               to use the snmp module.
320 # -DUSE_TCP
321 #               compiles in tcp support
322 # -DDISABLE_NAGLE
323 #               disable the tcp Nagle algorithm (lower delay)
324 # -DUSE_TLS
325 #               compiles in tls support, requires -DUSE_TCP. Please use
326 #               make TLS=1 instead. (tls support is highly experimental for now)
327 # -DHAVE_RESOLV_RES
328 #               support for changing some of the resolver parameters present
329 #                (_res structure in <resolv.h>)
330
331
332 DEFS+= $(extra_defs) \
333          -DNAME='"$(MAIN_NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
334          -DOS='"$(OS)"' -DCOMPILER='"$(CC_VER)"' -D__CPU_$(ARCH) -D__OS_$(OS) \
335          -DCFG_DIR='"$(cfg-target)"'\
336          -DPKG_MALLOC \
337          -DSHM_MEM  -DSHM_MMAP \
338          -DDNS_IP_HACK \
339          -DUSE_IPV6 \
340          -DUSE_MCAST \
341          -DUSE_TCP \
342          -DDISABLE_NAGLE \
343          -DHAVE_RESOLV_RES \
344          -DDBG_QM_MALLOC \
345          #-DF_MALLOC \
346          #-DDBG_F_MALLOC \
347          #-DNO_DEBUG \
348          #-DNO_LOG \
349          #-DEXTRA_DEBUG \
350          #-DVQ_MALLOC  \
351          #-DCONTACT_BUG \
352          #-DDBG_LOCK \
353          #-DNOSMP \
354          #-DUSE_SHM_MEM \
355          #-DSTATS \
356          #-DNO_LOG
357
358 #PROFILE=  -pg #set this if you want profiling
359
360 # WARNING: do not add mode=debug or mode=release anymore in the Makefile,
361 # use make mode=debug all instead. Anyway no by default ser is  compiled w/ 
362 # debugging symbols in all cases (-g). --andrei
363
364 ifneq ($(TLS),)
365         DEFS+= -DUSE_TLS
366 endif
367
368 ifeq ($(mode),)
369         mode = release
370 endif
371
372 ifeq ($(mode),debug)
373         DEFS+= -DEXTRA_DEBUG
374 endif
375
376 # platform dependent settings
377
378 # find ld & as name (gnu or solaris)
379 ifeq ($(OS), solaris)
380 ifeq ($(CC_NAME), gcc)
381                 LDGCC=$(shell $(CC) -v 2>&1 | grep with-ld| \
382                                    sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
383                 ASGCC=$(shell $(CC) -v 2>&1 | grep with-as| \
384                                    sed -e 's/.*--with-as=\([^ ][^ ]*\).*/\1/' )
385                 LDPATH=$(shell  if [ -z "$(LDGCC)" ] ; then echo "ld" ;\
386                                                 else \
387                                                 if $(LDGCC) -V 2>/dev/null 1>/dev/null; then \
388                                                         echo $(LDGCC); \
389                                                 else echo "ld" ; \
390                                                 fi\
391                                                 fi)
392                 ASPATH=$(shell  if [ -z "$(ASGCC)" ] ; then echo "as" ;\
393                                                 else \
394                                                 if $(ASGCC) -V 2>/dev/null 1>/dev/null; then \
395                                                         echo $(ASGCC); \
396                                                 else echo "as" ; \
397                                                 fi\
398                                                 fi)
399                                                         
400                 LDTYPE=$(shell if $(LDPATH) -V 1>/dev/null  2>/dev/null; then \
401                                                         if $(LDPATH) -V 2>&1|grep GNU >/dev/null; \
402                                                         then echo gnu; \
403                                                         else \
404                                                         if $(LDPATH) -V 2>&1|grep Solaris >/dev/null;\
405                                                         then echo solaris; \
406                                                         else \
407                                                                 echo unknown ; \
408                                                         fi \
409                                                         fi \
410                                                 fi)
411                 ASTYPE=$(shell if $(ASPATH) -V 1>/dev/null  2>/dev/null </dev/null; \
412                                                 then \
413                                                         if $(ASPATH) -V 2>&1 </dev/null |grep GNU >/dev/null; \
414                                                         then echo gnu; \
415                                                         else \
416                                                         if $(ASPATH) -V 2>&1 </dev/null |grep Sun >/dev/null;\
417                                                         then echo solaris; \
418                                                         else \
419                                                                 echo unknown ; \
420                                                         fi \
421                                                         fi \
422                                                 fi)
423 #$(warning "using ld=$(LDPATH)/$(LDTYPE), as=$(ASPATH)/$(ASTYPE)")
424
425 endif
426 endif
427
428 # arh. specific definitions
429 ifeq ($(ARCH), i386)
430         use_fast_lock=yes
431 endif
432
433 ifeq ($(ARCH), x86_64)
434         use_fast_lock=yes
435 endif
436
437 ifeq ($(ARCH), sparc64)
438 ifeq    ($(CC_NAME), gcc)
439         use_fast_lock=yes
440 endif
441 endif
442
443 ifeq ($(ARCH), sparc)
444         # smp no supported on sparc32
445         DEFS+= -DNOSMP 
446         use_fast_lock=yes
447 endif
448
449 ifeq ($(ARCH), arm)
450         use_fast_lock=yes
451 endif
452
453 ifeq ($(ARCH), ppc)
454         use_fast_lock=yes
455 endif
456
457 ifeq ($(ARCH), ppc64)
458         use_fast_lock=yes
459 endif
460
461 ifeq ($(ARCH), mips)
462 # mips1 arch. (e.g. R3000) - no hardware locking support
463         use_fast_lock=no
464 endif
465
466 ifeq ($(ARCH), mips2)
467 # mips2 arch and newer (mips3=R4000, mips4=R5000 a.s.o)
468         use_fast_lock=yes
469 endif
470
471 ifeq ($(ARCH), alpha)
472         use_fast_lock=yes
473 endif
474
475 ifeq ($(use_fast_lock), yes)
476         DEFS+= -DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 
477         found_lock_method=yes
478 endif
479
480 CFLAGS=
481 LDFLAGS=
482 # setting CFLAGS
483 ifeq ($(mode), release)
484         #if i386
485 ifeq    ($(ARCH), i386)
486                 # if gcc 
487 ifeq            ($(CC_NAME), gcc)
488                                 #common stuff
489                                 CFLAGS=-g -O9 -funroll-loops  -Wcast-align $(PROFILE) \
490                                         -Wall  
491                         #if gcc 4.0+
492 ifeq                    ($(CC_SHORTVER), 4.x)
493                                         CPU ?= athlon64
494                                         CFLAGS+=-minline-all-stringops \
495                                                         -falign-loops \
496                                                         -ftree-vectorize \
497                                                         -mtune=$(CPU) 
498 else
499                         #if gcc 3.4+
500 ifeq                    ($(CC_SHORTVER), 3.4)
501                                         CPU ?= athlon
502                                         CFLAGS+=-minline-all-stringops \
503                                                         -falign-loops \
504                                                         -mtune=$(CPU) 
505 else
506                         #if gcc 3.0+
507 ifeq                    ($(CC_SHORTVER), 3.0)
508                                         CPU ?= athlon
509                                         CFLAGS+=-minline-all-stringops \
510                                                         -falign-loops \
511                                                         -mcpu=$(CPU) 
512 else
513 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
514 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
515                                         for better results)
516                                         
517                                         CFLAGS+=-m486 \
518                                                         -malign-loops=4
519 else
520                                 #really old version
521 $(warning                       You are using an old and unsupported gcc \
522                                          version  ($(CC_SHORTVER)), compile at your own risk!)
523
524 endif                   # CC_SHORTVER, 2.9x
525 endif                   # CC_SHORTVER, 3.0
526 endif                   # CC_SHORTVER, 3.4
527 endif                   # CC_SHORTVER, 4.x
528
529 else            # CC_NAME, gcc
530 ifeq            ($(CC_NAME), icc)
531                         CFLAGS=-g -O3  -ipo -ipo_obj -unroll  $(PROFILE) \
532                                          -tpp6 -xK  #-openmp  #optimize for PIII 
533                                 # -prefetch doesn't seem to work
534                                 #( ty to inline acroos files, unroll loops,prefetch,
535                                 # optimize for PIII, use PIII instructions & vect.,
536                                 # mutlithread loops)
537 else
538                                 #other compilers
539 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
540 endif           #CC_NAME, icc
541 endif           #CC_NAME, gcc
542 endif   #ARCH, i386
543
544 #x86_64
545 ifeq    ($(ARCH), x86_64)
546                 # if gcc 
547 ifeq            ($(CC_NAME), gcc)
548                                 #common stuff
549                                 CFLAGS=-g -O9 -funroll-loops  -Wcast-align $(PROFILE) \
550                                         -Wall 
551                         #if gcc 4.0+
552 ifeq                    ($(CC_SHORTVER), 4.x)
553                                         CPU ?= opteron
554                                         CFLAGS+=-minline-all-stringops \
555                                                         -falign-loops \
556                                                         -ftree-vectorize \
557                                                         -mtune=$(CPU) 
558 else
559                         #if gcc 3.4
560 ifeq                    ($(CC_SHORTVER), 3.4)
561                                         CPU ?= athlon64
562                                         CFLAGS+=-minline-all-stringops \
563                                                         -falign-loops 
564 else
565                         #if gcc 3.0
566 ifeq                    ($(CC_SHORTVER), 3.0)
567                                         CPU ?= athlon64
568                                         CFLAGS+=-minline-all-stringops \
569                                                         -falign-loops 
570                                                         #-mcpu=$(CPU) \ # not working on all x86_64 gccs
571                                                         #-mcpu=athlon
572 else
573 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
574 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
575                                         for better results)
576                                         
577                                         CFLAGS+=-m486 \
578                                                         -malign-loops=4
579 else
580                                 #really old version
581 $(warning                       You are using an old and unsupported gcc \
582                                          version  ($(CC_SHORTVER)), compile at your own risk!)
583
584 endif                   # CC_SHORTVER, 2.9x
585 endif                   # CC_SHORTVER, 3.0
586 endif                   # CC_SHORTVER, 3.4
587 endif                   # CC_SHORTVER, 4.x
588
589 else            # CC_NAME, gcc
590 ifeq            ($(CC_NAME), icc)
591                         CFLAGS=-g -O3  -ipo -ipo_obj -unroll  $(PROFILE) \
592                                          -tpp6 -xK  #-openmp  #optimize for PIII 
593                                 # -prefetch doesn't seem to work
594                                 #( ty to inline acroos files, unroll loops,prefetch,
595                                 # optimize for PIII, use PIII instructions & vect.,
596                                 # mutlithread loops)
597 else
598                                 #other compilers
599 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
600 endif           #CC_NAME, icc
601 endif           #CC_NAME, gcc
602 endif   #ARCH, x86_64
603
604         #if sparc
605 ifeq    ($(ARCH), sparc64)
606                         #if gcc
607 ifeq            ($(CC_NAME), gcc)
608                                 #common stuff
609                                 CFLAGS=-g -O9 -funroll-loops  $(PROFILE) \
610                                         -Wall\
611                                         #-Wcast-align \
612                                         #-Wmissing-prototypes 
613                                 #if gcc 4.x
614 ifeq                    ($(CC_SHORTVER), 4.x)
615                                         CPU ?= ultrasparc
616                                         #use 32bit for now
617                                         CFLAGS+=-mcpu=ultrasparc -minline-all-stringops \
618                                                         -mtune=$(CPU) \
619                                                         -ftree-vectorize
620 else
621                                 #if gcc 3.4
622 ifeq                    ($(CC_SHORTVER), 3.4)
623                                         CPU ?= ultrasparc
624                                         #use 32bit for now
625                                         CFLAGS+= -mcpu=ultrasparc -mtune=$(CPU)
626 else
627                                 #if gcc 3.0
628 ifeq                    ($(CC_SHORTVER), 3.0)
629                                         CPU ?= ultrasparc
630                                         #use 32bit for now
631                                         CFLAGS+= -mcpu=ultrasparc -mtune=$(CPU)   \
632                                         # use -m64 to force 64 bit (but add it also to LDFLAGS), 
633                                         # -m32 for 32 bit (default on solaris),
634                                         # nothing for arch. default
635                                         # -mcpu=v9 or ultrasparc? # -mtune implied by -mcpu
636                                         #-mno-epilogue #try to inline function exit code
637                                         #-mflat # omit save/restore
638                                         #-,faster-structs #faster non Sparc ABI structure copy ops
639 else                    # CC_SHORTVER, 3.0
640 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
641 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
642                                         for better results)
643 ifneq                           ($(OS), netbsd)
644                                                 # on netbsd/sparc64,  gcc 2.95.3 does not compile
645                                                 # ser with -mv8
646                                                 CFLAGS+= -mv8 
647 endif
648 ifeq                                    ($(ASTYPE), solaris)
649                                                         CFLAGS+= -Wa,-xarch=v8plus
650 endif                                   
651 else                    #CC_SHORTVER, 2.9x
652                                 #really old version
653 $(warning                       You are using an old and unsupported gcc \
654                                          version ($(CC_SHORTVER)), compile at your own risk!)
655                                         
656                                         CFLAGS+= -mv8 
657 ifeq                                    ($(ASTYPE), solaris)
658                                                         CFLAGS+= -Wa,-xarch=v8plus
659 endif                                   
660         
661 endif                   #CC_SHORTVER, 2.9x
662 endif                   #CC_SHORTVER, 3.0
663 endif                   #CC_SHORTVER, 3.4
664 endif                   #CC_SHORTVER, 4.x
665
666 else            #CC_NAME, gcc
667 ifeq            ($(CC_NAME), suncc)
668                         CFLAGS+=-g -xO5 -fast -native -xarch=v8plusa -xCC \
669                                         -xc99 # C99 support
670                         # -Dinline="" # add this if cc < 5.3 (define inline as null)
671 else
672                                 #other compilers
673 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
674 endif           #CC_NAME, suncc
675 endif           #CC_NAME, gcc
676 endif   #ARCH, sparc64
677
678         #if ipaq/netwinder
679 ifeq    ($(ARCH), arm)
680                 # if gcc 
681 ifeq            ($(CC_NAME), gcc)
682                                 #common stuff
683                                 CFLAGS=-O9 -funroll-loops  -Wcast-align $(PROFILE) \
684                                         -Wall   
685                         #if gcc 4.x+
686 ifeq                    ($(CC_SHORTVER), 4.x)
687                                         CFLAGS+=-mcpu=strongarm1100 -minline-all-stringops \
688                                                         -ftree-vectorize
689 else
690                         #if gcc 3.4+
691 ifeq                    ($(CC_SHORTVER), 3.4)
692                                         CFLAGS+= -mcpu=strongarm1100
693 else
694                         #if gcc 3.0
695 ifeq                    ($(CC_SHORTVER), 3.0)
696                                         CFLAGS+= -mcpu=strongarm1100
697                                                         #-mcpu=athlon
698 else
699 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
700 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
701                                         for better results)
702                                         
703                                         CFLAGS+=
704 else
705                                 #really old version
706 $(warning                       You are using an old and unsupported gcc \
707                                          version ($(CC_SHORTVER)), compile at your own risk!)
708         
709 endif                   # CC_SHORTVER, 2.9x
710 endif                   # CC_SHORTVER, 3.0
711 endif                   # CC_SHORTVER, 3.4
712 endif                   # CC_SHORTVER, 4.0
713         
714 else            # CC_NAME, gcc
715                                 #other compilers
716 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
717 endif           #CC_NAME, gcc
718 endif   #ARCH, arm 
719
720         #if  mips (R3000)
721 ifeq    ($(ARCH), mips)
722                 # if gcc 
723 ifeq            ($(CC_NAME), gcc)
724                                 #common stuff
725                                 CFLAGS=-O9 -funroll-loops  -Wcast-align $(PROFILE) \
726                                         -Wall 
727                         #if gcc 4.0+
728 ifeq                    ($(CC_SHORTVER), 4.x)
729                                         CFLAGS+=-mcpu=r3000 -minline-all-stringops \
730                                                         -ftree-vectorize
731 else
732                         #if gcc 3.4+
733 ifeq                    ($(CC_SHORTVER), 3.4)
734                                         CFLAGS+= -mcpu=r3000
735 else
736                         #if gcc 3.0
737 ifeq                    ($(CC_SHORTVER), 3.0)
738                                         CFLAGS+= -mcpu=r3000
739                                                         #-mcpu=athlon
740 else
741 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
742 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
743                                         for better results)
744                                         
745                                         CFLAGS+=-mcpu=r3000
746 else
747                                 #really old version
748 $(warning                       You are using an old and unsupported gcc \
749                                          version ($(CC_SHORTVER)), compile at your own risk!)
750         
751 endif                   # CC_SHORTVER, 2.9x
752 endif                   # CC_SHORTVER, 3.0
753 endif                   # CC_SHORTVER, 3.4
754 endif                   # CC_SHORTVER, 4.x
755         
756 else            # CC_NAME, gcc
757                                 #other compilers
758 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
759 endif           #CC_NAME, gcc
760 endif   #ARCH, mips
761
762         #if  >=mips2 (R4000, R5000, R6000 ....)
763 ifeq    ($(ARCH), mips2)
764                 # if gcc 
765 ifeq            ($(CC_NAME), gcc)
766                                 #common stuff
767                                 CFLAGS= -mips2 -O9 -funroll-loops $(PROFILE) \
768                                         -Wall 
769                         #if gcc 4.0+
770 ifeq                    ($(CC_SHORTVER), 4.x)
771                                         CFLAGS+=-minline-all-stringops -ftree-vectorize
772 else
773                         #if gcc 3.4+
774 ifeq                    ($(CC_SHORTVER), 3.4)
775                                         CFLAGS+=
776 else
777                         #if gcc 3.0
778 ifeq                    ($(CC_SHORTVER), 3.0)
779                                         CFLAGS+=
780 else
781 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
782 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
783                                         for better results)
784                                         CFLAGS+=
785 else
786                                 #really old version
787 $(warning                       You are using an old and unsupported gcc \
788                                          version ($(CC_SHORTVER)), compile at your own risk!)
789         
790 endif                   # CC_SHORTVER, 2.9x
791 endif                   # CC_SHORTVER, 3.0
792 endif                   # CC_SHORTVER, 3.4
793 endif                   # CC_SHORTVER, 4.x
794         
795 else            # CC_NAME, gcc
796                                 #other compilers
797 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
798 endif           #CC_NAME, gcc
799 endif   #ARCH, mips2
800
801
802 #if  alpha
803 ifeq    ($(ARCH), alpha)
804                 # if gcc 
805 ifeq            ($(CC_NAME), gcc)
806                                 #common stuff
807                                 CFLAGS= -O9 -funroll-loops $(PROFILE)  -Wall 
808                         #if gcc 4.0+
809 ifeq                    ($(CC_SHORTVER), 4.x)
810                                         CFLAGS+=-minline-all-stringops
811 else
812                         #if gcc 3.4+
813 ifeq                    ($(CC_SHORTVER), 3.4)
814                                         CFLAGS+=
815 else
816                         #if gcc 3.0
817 ifeq                    ($(CC_SHORTVER), 3.0)
818                                         CFLAGS+=
819 else
820 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
821 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
822                                         for better results)
823                                         CFLAGS+=
824 else
825                                 #really old version
826 $(warning                       You are using an old and unsupported gcc \
827                                          version ($(CC_SHORTVER)), compile at your own risk!)
828         
829 endif                   # CC_SHORTVER, 2.9x
830 endif                   # CC_SHORTVER, 3.0
831 endif                   # CC_SHORTVER, 3.4
832 endif                   # CC_SHORTVER, 4.x
833         
834 else            # CC_NAME, gcc
835                                 #other compilers
836 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
837 endif           #CC_NAME, gcc
838 endif   #ARCH, alpha 
839
840 #if  ppc
841 ifeq    ($(ARCH), ppc)
842                 # if gcc 
843 ifeq            ($(CC_NAME), gcc)
844                                 #common stuff
845                                 CFLAGS= -O9 -funroll-loops $(PROFILE)  -Wall 
846                         #if gcc 4.0+
847 ifeq                    ($(CC_SHORTVER), 4.x)
848                                         CPU ?= powerpc
849                                         CFLAGS+=-ftree-vectorize \
850                                                         -mtune=$(CPU) -maltivec
851 else
852                         #if gcc 3.4+
853 ifeq                    ($(CC_SHORTVER), 3.4)
854                                         CFLAGS+=
855 else
856                         #if gcc 3.0
857 ifeq                    ($(CC_SHORTVER), 3.0)
858                                         CFLAGS+=
859 else
860 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
861 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
862                                         for better results)
863                                         CFLAGS+=
864 else
865                                 #really old version
866 $(warning                       You are using an old and unsupported gcc \
867                                          version ($(CC_SHORTVER)), compile at your own risk!)
868         
869 endif                   # CC_SHORTVER, 2.9x
870 endif                   # CC_SHORTVER, 3.0
871 endif                   # CC_SHORTVER, 3.4
872 endif                   # CC_SHORTVER, 4.x
873         
874 else            # CC_NAME, gcc
875                                 #other compilers
876 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
877 endif           #CC_NAME, gcc
878 endif   #ARCH, ppc 
879
880 #if  ppc64
881 ifeq    ($(ARCH), ppc64)
882                 # if gcc 
883 ifeq            ($(CC_NAME), gcc)
884                                 #common stuff
885                                 CFLAGS= -O9 -funroll-loops $(PROFILE)  -Wall 
886 ifeq                    ($(CC_SHORTVER), 4.x)
887                                         CPU ?= powerpc64
888                                         CFLAGS+=-ftree-vectorize \
889                                                         -mtune=$(CPU) -maltivec
890 else
891                         #if gcc 3.4+
892 ifeq                    ($(CC_SHORTVER), 3.4)
893                                         CFLAGS+=
894 else
895                         #if gcc 3.0
896 ifeq                    ($(CC_SHORTVER), 3.0)
897                                         CFLAGS+=
898 else
899 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
900 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
901                                         for better results)
902                                         CFLAGS+=
903 else
904                                 #really old version
905 $(warning                       You are using an old and unsupported gcc \
906                                          version ($(CC_SHORTVER)), compile at your own risk!)
907         
908 endif                   # CC_SHORTVER, 2.9x
909 endif                   # CC_SHORTVER, 3.0
910 endif                   # CC_SHORTVER, 3.4
911 endif                   # CC_SHORTVER, 4.x
912         
913 else            # CC_NAME, gcc
914                                 #other compilers
915 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
916 endif           #CC_NAME, gcc
917 endif   #ARCH, ppc 
918
919 CFLAGS+= $(CC_EXTRA_OPTS)
920
921
922 # setting LDFLAGS
923 ifeq    ($(CC_NAME), gcc)
924 ifeq            ($(LDTYPE), solaris)
925                 # solaris ld
926                 LDFLAGS+=-O2 $(PROFILE)
927                 MOD_LDFLAGS=-G $(LDFLAGS)
928 else            
929                 #gcc and maybe others, => gnu ld
930                 LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
931                 MOD_LDFLAGS=-shared $(LDFLAGS)
932 endif
933 endif
934 ifeq    ($(CC_NAME), icc)
935         #gcc and maybe others
936         LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
937         MOD_LDFLAGS=-shared $(LDFLAGS)
938 endif
939 ifeq    ($(CC_NAME), suncc)
940         LDFLAGS+=-xO5 $(PROFILE)
941         MOD_LDFLAGS=-G $(LDFLAGS)
942 endif
943         # we need -fPIC -DPIC only for shared objects, we don't need them for
944         # the executable file, because it's always loaded at a fixed address
945         # -andrei
946 else    #mode,release
947 ifeq    ($(CC_NAME), gcc)
948                 CFLAGS=-g -Wcast-align $(PROFILE)
949 ifeq            ($(ARCH), sparc64)
950                         CFLAGS+= -mcpu=ultrasparc 
951 endif
952 ifeq            ($(LDTYPE), solaris)
953                         #solaris ld
954                         LDFLAGS+=-g $(PROFILE)
955                         MOD_LDFLAGS=-G $(LDFLAGS)
956 else
957                         #gnu or other ld type
958                         LDFLAGS+=-g -Wl,-E $(PROFILE)
959                         MOD_LDFLAGS=-shared $(LDFLAGS)
960 endif
961 endif
962 ifeq    ($(CC_NAME), icc)
963                 CFLAGS=-g  $(PROFILE)
964                 LDFLAGS+=-g -Wl,-E $(PROFILE)
965                 MOD_LDFLAGS=-shared $(LDFLAGS)
966 endif
967 ifeq    ($(CC_NAME), suncc)
968                 CFLAGS= -g $(PROFILE)
969                 LDFLAGS+=-g $(PROFILE)
970                 MOD_LDFLAGS=-G $(LDFLAGS)
971 endif
972
973 endif #mode=release
974
975
976 #*FLAGS used for compiling the modules
977 ifeq    ($(CC_NAME), gcc)
978 MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
979 endif
980 ifeq    ($(CC_NAME), icc)
981 MOD_CFLAGS=-Kpic $(CFLAGS)
982 endif
983 ifeq    ($(CC_NAME), suncc)
984 MOD_CFLAGS=-xcode=pic32  $(CFLAGS)
985 endif
986
987 ifeq ($(LEX),)
988         LEX=flex
989 endif
990 ifeq ($(YACC),)
991         YACC=bison
992 endif
993 YACC_FLAGS=-d -b cfg
994 # on solaris add -lxnet (e.g. LIBS= -lxnet)
995 LIBS= -lfl -ldl -lresolv
996
997
998 #os specific stuff
999 ifeq ($(OS), linux)
1000         DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
1001                         -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
1002                         -DHAVE_TIMEGM
1003         ifneq ($(found_lock_method), yes)
1004                 DEFS+= -DUSE_SYSV_SEM  # try posix sems
1005                 found_lock_method=yes
1006         endif
1007         # check for >= 2.5.44
1008         ifeq ($(shell [ $(OSREL_N) -ge 2005044 ] && echo has_epoll), has_epoll)
1009                 ifeq ($(NO_EPOLL),)
1010                         DEFS+=-DHAVE_EPOLL
1011                         # linux + gcc >= 3.0 + -malign-double + epoll => problems
1012                         CFLAGS:=$(filter-out -malign-double, $(CFLAGS))
1013                 endif
1014         endif
1015         # check for >= 2.2.0
1016         ifeq ($(shell [ $(OSREL_N) -ge 2002000 ] && echo has_sigio), has_sigio)
1017                 ifeq ($(NO_SIGIO),)
1018                         DEFS+=-DHAVE_SIGIO_RT
1019                 endif
1020         endif
1021         ifeq ($(NO_SELECT),)
1022                 DEFS+=-DHAVE_SELECT
1023         endif
1024 endif
1025
1026 ifeq  ($(OS), solaris)
1027         DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD \
1028                         -DHAVE_ALLOCA_H -DUSE_SIGACTION
1029         ifneq ($(found_lock_method), yes)
1030                 DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1031                 found_lock_method=yes
1032         endif
1033         # check for ver >= 5.7
1034         ifeq ($(shell [ $(OSREL_N) -gt 5007 ] && echo has_devpoll), has_devpoll)
1035                 ifeq ($(NO_DEVPOLL),)
1036                         DEFS+=-DHAVE_DEVPOLL
1037                 endif
1038         endif
1039         ifeq ($(NO_SELECT),)
1040                 DEFS+=-DHAVE_SELECT
1041         endif
1042         ifeq ($(mode), release)
1043                 #use these only if you're using gcc with Solaris ld
1044                 #LDFLAGS=-O2 $(PROFILE)
1045                 #MOD_LDFLAGS=-O2 -G
1046         else
1047                 #LDFLAGS=-g $(PROFILE)
1048                 #MOD_LDFLAGS=-g -G
1049         endif
1050         YACC=yacc
1051
1052 ifeq ($(CC_NAME), suncc)
1053         LIBS= -lfast -ldl -lresolv
1054 endif
1055         OLD_SOLARIS= $(shell echo "$(OSREL)" | \
1056                                 sed -e 's/^5\.[0-6][^0-9]*$$/yes/' )
1057         LIBS+= -L$(LOCALBASE)/lib -lfl -lxnet -lnsl 
1058 ifeq    ($(OLD_SOLARIS), yes)
1059                 LIBS+=-lposix4
1060 else
1061                 LIBS+=-lrt
1062 endif
1063         # -lrt needed for sched_yield
1064 endif
1065
1066 ifeq ($(OS), freebsd)
1067         DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1068                 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1069                 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1070                 -DHAVE_NETINET_IN_SYSTM
1071         ifneq ($(found_lock_method), yes)
1072                 DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1073                 found_lock_method=yes
1074                 LIBS= -pthread -lfl  #dlopen is in libc
1075         else
1076                 LIBS= -lfl  #dlopen is in libc
1077         endif
1078         # check for ver >= 4.1
1079         ifeq ($(shell [ $(OSREL_N) -gt 4001 ] && echo has_kqueue), has_kqueue)
1080                 ifeq ($(NO_KQUEUE),)
1081                         DEFS+=-DHAVE_KQUEUE
1082                 endif
1083         endif
1084         ifeq ($(NO_SELECT),)
1085                 DEFS+=-DHAVE_SELECT
1086         endif
1087         YACC=yacc
1088 endif
1089
1090 ifeq ($(OS), openbsd)
1091         DEFS+=-DHAVE_SOCKADDR_SA_LEN  -DHAVE_GETHOSTBYNAME2 \
1092                 -DHAVE_UNION_SEMUN -DHAVE_MSGHDR_MSG_CONTROL \
1093                 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM
1094         ifneq ($(found_lock_method), yes)
1095                 DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1096                 found_lock_method=yes
1097         endif
1098         # check for ver >=2 9
1099         ifeq ($(shell [ $(OSREL_N) -ge 2009 ] && echo has_kqueue), has_kqueue)
1100                 ifeq ($(NO_KQUEUE),)
1101                         DEFS+=-DHAVE_KQUEUE
1102                 endif
1103         endif
1104         ifeq ($(NO_SELECT),)
1105                 DEFS+=-DHAVE_SELECT
1106         endif
1107         # (symbols on openbsd are prefixed by "_")
1108         YACC=yacc
1109         # no sched_yield on openbsd unless linking with c_r (not recommended)
1110         LIBS= -lfl 
1111         OPENBSD_IS_AOUT= $(shell echo "$(OSREL)" | \
1112                                 sed -e 's/^3\.[0-3][^0-9]*$$/yes/' |sed -e 's/^[0-2]\..*/yes/')
1113 # exception: on sparc openbsd 3.2 is elf and not aout
1114 ifeq ($(OSREL), 3.2)
1115 ifeq    ($(ARCH), sparc)
1116                 OPENBSD_IS_AOUT:=no
1117 endif
1118 ifeq    ($(ARCH), sparc64)
1119                 OPENBSD_IS_AOUT:=no
1120 endif
1121 endif
1122         
1123 ifeq ($(OPENBSD_IS_AOUT), yes)
1124                 DEFS+=-DDLSYM_PREFIX='"_"'
1125                 LDFLAGS=        # openbsd ld doesn't like -O2 or -E
1126 endif
1127 endif   # if opensd
1128         
1129 ifeq ($(OS), netbsd)
1130         DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 \
1131                 -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM
1132         ifneq ($(found_lock_method), yes)
1133                 DEFS+= -DUSE_SYSV_SEM  # try pthread sems
1134                 found_lock_method=yes
1135         endif
1136         # check for ver >= 2.0.0
1137         ifeq ($(shell [ $(OSREL_N) -ge 2000000 ] && echo has_kqueue), has_kqueue)
1138                 ifeq ($(NO_KQUEUE),)
1139                         DEFS+=-DHAVE_KQUEUE
1140                         # netbsd + kqueue and -malign-double don't work
1141                         CFLAGS:=$(filter-out -malign-double, $(CFLAGS))
1142                 endif
1143         endif
1144         ifeq ($(NO_SELECT),)
1145                 DEFS+=-DHAVE_SELECT
1146         endif
1147         YACC=yacc
1148         LIBS= -lfl 
1149 endif
1150
1151 # OS X support, same as freebsd
1152 ifeq ($(OS), darwin)
1153         DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1154                 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1155                 -DUSE_ANON_MMAP \
1156                 -DNDEBUG -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM
1157         # -DNDEBUG used to turn off assert (assert wants to call
1158         # eprintf which doesn't seem to be defined in any shared lib
1159         ifneq ($(found_lock_method), yes)
1160                 DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1161                 found_lock_method=yes
1162                 LIBS= -pthread -lfl -lresolv  #dlopen is in libc
1163         else
1164                 LIBS= -lfl -lresolv  #dlopen is in libc
1165         endif
1166         ifeq ($(NO_KQUEUE),)
1167                 DEFS+=-DHAVE_KQUEUE
1168         endif
1169         ifeq ($(NO_SELECT),)
1170                 DEFS+=-DHAVE_SELECT
1171         endif
1172         LDFLAGS=        # darwin doesn't like -O2 or -E
1173         MOD_LDFLAGS= -bundle -bundle_loader ../../$(MAIN_NAME)
1174         YACC=yacc
1175 endif
1176
1177 ifneq (,$(findstring CYGWIN, $(OS)))
1178         #cygwin is the same as common
1179         ifneq ($(found_lock_method), yes)
1180                 DEFS+= -DUSE_SYSV_SEM  # try sys v sems
1181                 found_lock_method=yes
1182         endif
1183 endif
1184
1185 #add libssl if needed
1186 ifneq ($(TLS),)
1187 DEFS+= -I$(LOCALBASE)/ssl/include
1188 LIBS+= -L$(LOCALBASE)/lib -L$(LOCALBASE)/ssl/lib -lssl  -lcrypto
1189 endif
1190
1191 ifneq ($(found_lock_method), yes)
1192 $(warning       No locking method found so far, trying SYS V sems)
1193                 DEFS+= -DUSE_SYSV_SEM  # try sys v sems
1194                 found_lock_method=yes
1195 endif
1196
1197
1198
1199
1200
1201 endif  # ifeq ($(makefile_defs, 1)