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