- support for apart modules taken from svn, fixed bug for dependency files *.d
[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 INCLUDES=
486 # setting CFLAGS
487 ifeq ($(mode), release)
488         #if i386
489 ifeq    ($(ARCH), i386)
490                 # if gcc 
491 ifeq            ($(CC_NAME), gcc)
492                                 #common stuff
493                                 CFLAGS=-g -O9 -funroll-loops  -Wcast-align $(PROFILE) \
494                                         -Wall  
495                         #if gcc 4.0+
496 ifeq                    ($(CC_SHORTVER), 4.x)
497                                         CPU ?= athlon64
498                                         CFLAGS+=-minline-all-stringops \
499                                                         -falign-loops \
500                                                         -ftree-vectorize \
501                                                         -mtune=$(CPU) 
502 else
503                         #if gcc 3.4+
504 ifeq                    ($(CC_SHORTVER), 3.4)
505                                         CPU ?= athlon
506                                         CFLAGS+=-minline-all-stringops \
507                                                         -falign-loops \
508                                                         -mtune=$(CPU) 
509 else
510                         #if gcc 3.0+
511 ifeq                    ($(CC_SHORTVER), 3.0)
512                                         CPU ?= athlon
513                                         CFLAGS+=-minline-all-stringops \
514                                                         -falign-loops \
515                                                         -mcpu=$(CPU) 
516 else
517 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
518 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
519                                         for better results)
520                                         
521                                         CFLAGS+=-m486 \
522                                                         -malign-loops=4
523 else
524                                 #really old version
525 $(warning                       You are using an old and unsupported gcc \
526                                          version  ($(CC_SHORTVER)), compile at your own risk!)
527
528 endif                   # CC_SHORTVER, 2.9x
529 endif                   # CC_SHORTVER, 3.0
530 endif                   # CC_SHORTVER, 3.4
531 endif                   # CC_SHORTVER, 4.x
532
533 else            # CC_NAME, gcc
534 ifeq            ($(CC_NAME), icc)
535                         CFLAGS=-g -O3  -ipo -ipo_obj -unroll  $(PROFILE) \
536                                          -tpp6 -xK  #-openmp  #optimize for PIII 
537                                 # -prefetch doesn't seem to work
538                                 #( ty to inline acroos files, unroll loops,prefetch,
539                                 # optimize for PIII, use PIII instructions & vect.,
540                                 # mutlithread loops)
541 else
542                                 #other compilers
543 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
544 endif           #CC_NAME, icc
545 endif           #CC_NAME, gcc
546 endif   #ARCH, i386
547
548 #x86_64
549 ifeq    ($(ARCH), x86_64)
550                 # if gcc 
551 ifeq            ($(CC_NAME), gcc)
552                                 #common stuff
553                                 CFLAGS=-g -O9 -funroll-loops  -Wcast-align $(PROFILE) \
554                                         -Wall 
555                         #if gcc 4.0+
556 ifeq                    ($(CC_SHORTVER), 4.x)
557                                         CPU ?= opteron
558                                         CFLAGS+=-minline-all-stringops \
559                                                         -falign-loops \
560                                                         -ftree-vectorize \
561                                                         -mtune=$(CPU) 
562 else
563                         #if gcc 3.4
564 ifeq                    ($(CC_SHORTVER), 3.4)
565                                         CPU ?= athlon64
566                                         CFLAGS+=-minline-all-stringops \
567                                                         -falign-loops 
568 else
569                         #if gcc 3.0
570 ifeq                    ($(CC_SHORTVER), 3.0)
571                                         CPU ?= athlon64
572                                         CFLAGS+=-minline-all-stringops \
573                                                         -falign-loops 
574                                                         #-mcpu=$(CPU) \ # not working on all x86_64 gccs
575                                                         #-mcpu=athlon
576 else
577 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
578 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
579                                         for better results)
580                                         
581                                         CFLAGS+=-m486 \
582                                                         -malign-loops=4
583 else
584                                 #really old version
585 $(warning                       You are using an old and unsupported gcc \
586                                          version  ($(CC_SHORTVER)), compile at your own risk!)
587
588 endif                   # CC_SHORTVER, 2.9x
589 endif                   # CC_SHORTVER, 3.0
590 endif                   # CC_SHORTVER, 3.4
591 endif                   # CC_SHORTVER, 4.x
592
593 else            # CC_NAME, gcc
594 ifeq            ($(CC_NAME), icc)
595                         CFLAGS=-g -O3  -ipo -ipo_obj -unroll  $(PROFILE) \
596                                          -tpp6 -xK  #-openmp  #optimize for PIII 
597                                 # -prefetch doesn't seem to work
598                                 #( ty to inline acroos files, unroll loops,prefetch,
599                                 # optimize for PIII, use PIII instructions & vect.,
600                                 # mutlithread loops)
601 else
602                                 #other compilers
603 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
604 endif           #CC_NAME, icc
605 endif           #CC_NAME, gcc
606 endif   #ARCH, x86_64
607
608         #if sparc
609 ifeq    ($(ARCH), sparc64)
610                         #if gcc
611 ifeq            ($(CC_NAME), gcc)
612                                 #common stuff
613                                 CFLAGS=-g -O9 -funroll-loops  $(PROFILE) \
614                                         -Wall\
615                                         #-Wcast-align \
616                                         #-Wmissing-prototypes 
617                                 #if gcc 4.x
618 ifeq                    ($(CC_SHORTVER), 4.x)
619                                         CPU ?= ultrasparc
620                                         #use 32bit for now
621                                         CFLAGS+=-mcpu=ultrasparc -minline-all-stringops \
622                                                         -mtune=$(CPU) \
623                                                         -ftree-vectorize
624 else
625                                 #if gcc 3.4
626 ifeq                    ($(CC_SHORTVER), 3.4)
627                                         CPU ?= ultrasparc
628                                         #use 32bit for now
629                                         CFLAGS+= -mcpu=ultrasparc -mtune=$(CPU)
630 else
631                                 #if gcc 3.0
632 ifeq                    ($(CC_SHORTVER), 3.0)
633                                         CPU ?= ultrasparc
634                                         #use 32bit for now
635                                         CFLAGS+= -mcpu=ultrasparc -mtune=$(CPU)   \
636                                         # use -m64 to force 64 bit (but add it also to LDFLAGS), 
637                                         # -m32 for 32 bit (default on solaris),
638                                         # nothing for arch. default
639                                         # -mcpu=v9 or ultrasparc? # -mtune implied by -mcpu
640                                         #-mno-epilogue #try to inline function exit code
641                                         #-mflat # omit save/restore
642                                         #-,faster-structs #faster non Sparc ABI structure copy ops
643 else                    # CC_SHORTVER, 3.0
644 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
645 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
646                                         for better results)
647 ifneq                           ($(OS), netbsd)
648                                                 # on netbsd/sparc64,  gcc 2.95.3 does not compile
649                                                 # ser with -mv8
650                                                 CFLAGS+= -mv8 
651 endif
652 ifeq                                    ($(ASTYPE), solaris)
653                                                         CFLAGS+= -Wa,-xarch=v8plus
654 endif                                   
655 else                    #CC_SHORTVER, 2.9x
656                                 #really old version
657 $(warning                       You are using an old and unsupported gcc \
658                                          version ($(CC_SHORTVER)), compile at your own risk!)
659                                         
660                                         CFLAGS+= -mv8 
661 ifeq                                    ($(ASTYPE), solaris)
662                                                         CFLAGS+= -Wa,-xarch=v8plus
663 endif                                   
664         
665 endif                   #CC_SHORTVER, 2.9x
666 endif                   #CC_SHORTVER, 3.0
667 endif                   #CC_SHORTVER, 3.4
668 endif                   #CC_SHORTVER, 4.x
669
670 else            #CC_NAME, gcc
671 ifeq            ($(CC_NAME), suncc)
672                         CFLAGS+=-g -xO5 -fast -native -xarch=v8plusa -xCC \
673                                         -xc99 # C99 support
674                         # -Dinline="" # add this if cc < 5.3 (define inline as null)
675 else
676                                 #other compilers
677 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
678 endif           #CC_NAME, suncc
679 endif           #CC_NAME, gcc
680 endif   #ARCH, sparc64
681
682         #if ipaq/netwinder
683 ifeq    ($(ARCH), arm)
684                 # if gcc 
685 ifeq            ($(CC_NAME), gcc)
686                                 #common stuff
687                                 CFLAGS=-O9 -funroll-loops  -Wcast-align $(PROFILE) \
688                                         -Wall   
689                         #if gcc 4.x+
690 ifeq                    ($(CC_SHORTVER), 4.x)
691                                         CFLAGS+=-mcpu=strongarm1100 -minline-all-stringops \
692                                                         -ftree-vectorize
693 else
694                         #if gcc 3.4+
695 ifeq                    ($(CC_SHORTVER), 3.4)
696                                         CFLAGS+= -mcpu=strongarm1100
697 else
698                         #if gcc 3.0
699 ifeq                    ($(CC_SHORTVER), 3.0)
700                                         CFLAGS+= -mcpu=strongarm1100
701                                                         #-mcpu=athlon
702 else
703 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
704 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
705                                         for better results)
706                                         
707                                         CFLAGS+=
708 else
709                                 #really old version
710 $(warning                       You are using an old and unsupported gcc \
711                                          version ($(CC_SHORTVER)), compile at your own risk!)
712         
713 endif                   # CC_SHORTVER, 2.9x
714 endif                   # CC_SHORTVER, 3.0
715 endif                   # CC_SHORTVER, 3.4
716 endif                   # CC_SHORTVER, 4.0
717         
718 else            # CC_NAME, gcc
719                                 #other compilers
720 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
721 endif           #CC_NAME, gcc
722 endif   #ARCH, arm 
723
724         #if  mips (R3000)
725 ifeq    ($(ARCH), mips)
726                 # if gcc 
727 ifeq            ($(CC_NAME), gcc)
728                                 #common stuff
729                                 CFLAGS=-O9 -funroll-loops  -Wcast-align $(PROFILE) \
730                                         -Wall 
731                         #if gcc 4.0+
732 ifeq                    ($(CC_SHORTVER), 4.x)
733                                         CFLAGS+=-mcpu=r3000 -minline-all-stringops \
734                                                         -ftree-vectorize
735 else
736                         #if gcc 3.4+
737 ifeq                    ($(CC_SHORTVER), 3.4)
738                                         CFLAGS+= -mcpu=r3000
739 else
740                         #if gcc 3.0
741 ifeq                    ($(CC_SHORTVER), 3.0)
742                                         CFLAGS+= -mcpu=r3000
743                                                         #-mcpu=athlon
744 else
745 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
746 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
747                                         for better results)
748                                         
749                                         CFLAGS+=-mcpu=r3000
750 else
751                                 #really old version
752 $(warning                       You are using an old and unsupported gcc \
753                                          version ($(CC_SHORTVER)), compile at your own risk!)
754         
755 endif                   # CC_SHORTVER, 2.9x
756 endif                   # CC_SHORTVER, 3.0
757 endif                   # CC_SHORTVER, 3.4
758 endif                   # CC_SHORTVER, 4.x
759         
760 else            # CC_NAME, gcc
761                                 #other compilers
762 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
763 endif           #CC_NAME, gcc
764 endif   #ARCH, mips
765
766         #if  >=mips2 (R4000, R5000, R6000 ....)
767 ifeq    ($(ARCH), mips2)
768                 # if gcc 
769 ifeq            ($(CC_NAME), gcc)
770                                 #common stuff
771                                 CFLAGS= -mips2 -O9 -funroll-loops $(PROFILE) \
772                                         -Wall 
773                         #if gcc 4.0+
774 ifeq                    ($(CC_SHORTVER), 4.x)
775                                         CFLAGS+=-minline-all-stringops -ftree-vectorize
776 else
777                         #if gcc 3.4+
778 ifeq                    ($(CC_SHORTVER), 3.4)
779                                         CFLAGS+=
780 else
781                         #if gcc 3.0
782 ifeq                    ($(CC_SHORTVER), 3.0)
783                                         CFLAGS+=
784 else
785 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
786 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
787                                         for better results)
788                                         CFLAGS+=
789 else
790                                 #really old version
791 $(warning                       You are using an old and unsupported gcc \
792                                          version ($(CC_SHORTVER)), compile at your own risk!)
793         
794 endif                   # CC_SHORTVER, 2.9x
795 endif                   # CC_SHORTVER, 3.0
796 endif                   # CC_SHORTVER, 3.4
797 endif                   # CC_SHORTVER, 4.x
798         
799 else            # CC_NAME, gcc
800                                 #other compilers
801 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
802 endif           #CC_NAME, gcc
803 endif   #ARCH, mips2
804
805
806 #if  alpha
807 ifeq    ($(ARCH), alpha)
808                 # if gcc 
809 ifeq            ($(CC_NAME), gcc)
810                                 #common stuff
811                                 CFLAGS= -O9 -funroll-loops $(PROFILE)  -Wall 
812                         #if gcc 4.0+
813 ifeq                    ($(CC_SHORTVER), 4.x)
814                                         CFLAGS+=-minline-all-stringops
815 else
816                         #if gcc 3.4+
817 ifeq                    ($(CC_SHORTVER), 3.4)
818                                         CFLAGS+=
819 else
820                         #if gcc 3.0
821 ifeq                    ($(CC_SHORTVER), 3.0)
822                                         CFLAGS+=
823 else
824 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
825 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
826                                         for better results)
827                                         CFLAGS+=
828 else
829                                 #really old version
830 $(warning                       You are using an old and unsupported gcc \
831                                          version ($(CC_SHORTVER)), compile at your own risk!)
832         
833 endif                   # CC_SHORTVER, 2.9x
834 endif                   # CC_SHORTVER, 3.0
835 endif                   # CC_SHORTVER, 3.4
836 endif                   # CC_SHORTVER, 4.x
837         
838 else            # CC_NAME, gcc
839                                 #other compilers
840 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
841 endif           #CC_NAME, gcc
842 endif   #ARCH, alpha 
843
844 #if  ppc
845 ifeq    ($(ARCH), ppc)
846                 # if gcc 
847 ifeq            ($(CC_NAME), gcc)
848                                 #common stuff
849                                 CFLAGS= -O9 -funroll-loops $(PROFILE)  -Wall 
850                         #if gcc 4.0+
851 ifeq                    ($(CC_SHORTVER), 4.x)
852                                         CPU ?= powerpc
853                                         CFLAGS+=-ftree-vectorize \
854                                                         -mtune=$(CPU) -maltivec
855 else
856                         #if gcc 3.4+
857 ifeq                    ($(CC_SHORTVER), 3.4)
858                                         CFLAGS+=
859 else
860                         #if gcc 3.0
861 ifeq                    ($(CC_SHORTVER), 3.0)
862                                         CFLAGS+=
863 else
864 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
865 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
866                                         for better results)
867                                         CFLAGS+=
868 else
869                                 #really old version
870 $(warning                       You are using an old and unsupported gcc \
871                                          version ($(CC_SHORTVER)), compile at your own risk!)
872         
873 endif                   # CC_SHORTVER, 2.9x
874 endif                   # CC_SHORTVER, 3.0
875 endif                   # CC_SHORTVER, 3.4
876 endif                   # CC_SHORTVER, 4.x
877         
878 else            # CC_NAME, gcc
879                                 #other compilers
880 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
881 endif           #CC_NAME, gcc
882 endif   #ARCH, ppc 
883
884 #if  ppc64
885 ifeq    ($(ARCH), ppc64)
886                 # if gcc 
887 ifeq            ($(CC_NAME), gcc)
888                                 #common stuff
889                                 CFLAGS= -O9 -funroll-loops $(PROFILE)  -Wall 
890 ifeq                    ($(CC_SHORTVER), 4.x)
891                                         CPU ?= powerpc64
892                                         CFLAGS+=-ftree-vectorize \
893                                                         -mtune=$(CPU) -maltivec
894 else
895                         #if gcc 3.4+
896 ifeq                    ($(CC_SHORTVER), 3.4)
897                                         CFLAGS+=
898 else
899                         #if gcc 3.0
900 ifeq                    ($(CC_SHORTVER), 3.0)
901                                         CFLAGS+=
902 else
903 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
904 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
905                                         for better results)
906                                         CFLAGS+=
907 else
908                                 #really old version
909 $(warning                       You are using an old and unsupported gcc \
910                                          version ($(CC_SHORTVER)), compile at your own risk!)
911         
912 endif                   # CC_SHORTVER, 2.9x
913 endif                   # CC_SHORTVER, 3.0
914 endif                   # CC_SHORTVER, 3.4
915 endif                   # CC_SHORTVER, 4.x
916         
917 else            # CC_NAME, gcc
918                                 #other compilers
919 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
920 endif           #CC_NAME, gcc
921 endif   #ARCH, ppc 
922
923 CFLAGS+= $(CC_EXTRA_OPTS)
924
925
926 # setting LDFLAGS
927 ifeq    ($(CC_NAME), gcc)
928 ifeq            ($(LDTYPE), solaris)
929                 # solaris ld
930                 LDFLAGS+=-O2 $(PROFILE)
931                 MOD_LDFLAGS=-G $(LDFLAGS)
932 else            
933                 #gcc and maybe others, => gnu ld
934                 LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
935                 MOD_LDFLAGS=-shared $(LDFLAGS)
936 endif
937 endif
938 ifeq    ($(CC_NAME), icc)
939         #gcc and maybe others
940         LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
941         MOD_LDFLAGS=-shared $(LDFLAGS)
942 endif
943 ifeq    ($(CC_NAME), suncc)
944         LDFLAGS+=-xO5 $(PROFILE)
945         MOD_LDFLAGS=-G $(LDFLAGS)
946 endif
947         # we need -fPIC -DPIC only for shared objects, we don't need them for
948         # the executable file, because it's always loaded at a fixed address
949         # -andrei
950 else    #mode,release
951 ifeq    ($(CC_NAME), gcc)
952                 CFLAGS=-g -Wcast-align $(PROFILE)
953 ifeq            ($(ARCH), sparc64)
954                         CFLAGS+= -mcpu=ultrasparc 
955 endif
956 ifeq            ($(LDTYPE), solaris)
957                         #solaris ld
958                         LDFLAGS+=-g $(PROFILE)
959                         MOD_LDFLAGS=-G $(LDFLAGS)
960 else
961                         #gnu or other ld type
962                         LDFLAGS+=-g -Wl,-E $(PROFILE)
963                         MOD_LDFLAGS=-shared $(LDFLAGS)
964 endif
965 endif
966 ifeq    ($(CC_NAME), icc)
967                 CFLAGS=-g  $(PROFILE)
968                 LDFLAGS+=-g -Wl,-E $(PROFILE)
969                 MOD_LDFLAGS=-shared $(LDFLAGS)
970 endif
971 ifeq    ($(CC_NAME), suncc)
972                 CFLAGS= -g $(PROFILE)
973                 LDFLAGS+=-g $(PROFILE)
974                 MOD_LDFLAGS=-G $(LDFLAGS)
975 endif
976
977 endif #mode=release
978
979
980 #*FLAGS used for compiling the modules
981 ifeq    ($(CC_NAME), gcc)
982 MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
983 endif
984 ifeq    ($(CC_NAME), icc)
985 MOD_CFLAGS=-Kpic $(CFLAGS)
986 endif
987 ifeq    ($(CC_NAME), suncc)
988 MOD_CFLAGS=-xcode=pic32  $(CFLAGS)
989 endif
990
991 ifeq ($(LEX),)
992         LEX=flex
993 endif
994 ifeq ($(YACC),)
995         YACC=bison
996 endif
997 YACC_FLAGS=-d -b cfg
998 # on solaris add -lxnet (e.g. LIBS= -lxnet)
999 LIBS= -lfl -ldl -lresolv
1000
1001
1002 #os specific stuff
1003 ifeq ($(OS), linux)
1004         DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
1005                         -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
1006                         -DHAVE_TIMEGM
1007         ifneq ($(found_lock_method), yes)
1008                 DEFS+= -DUSE_SYSV_SEM  # try posix sems
1009                 found_lock_method=yes
1010         endif
1011         # check for >= 2.5.44
1012         ifeq ($(shell [ $(OSREL_N) -ge 2005044 ] && echo has_epoll), has_epoll)
1013                 ifeq ($(NO_EPOLL),)
1014                         DEFS+=-DHAVE_EPOLL
1015                         # linux + gcc >= 3.0 + -malign-double + epoll => problems
1016                         CFLAGS:=$(filter-out -malign-double, $(CFLAGS))
1017                 endif
1018         endif
1019         # check for >= 2.2.0
1020         ifeq ($(shell [ $(OSREL_N) -ge 2002000 ] && echo has_sigio), has_sigio)
1021                 ifeq ($(NO_SIGIO),)
1022                         DEFS+=-DHAVE_SIGIO_RT
1023                 endif
1024         endif
1025         ifeq ($(NO_SELECT),)
1026                 DEFS+=-DHAVE_SELECT
1027         endif
1028 endif
1029
1030 ifeq  ($(OS), solaris)
1031         DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD \
1032                         -DHAVE_ALLOCA_H -DUSE_SIGACTION
1033         ifneq ($(found_lock_method), yes)
1034                 DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1035                 found_lock_method=yes
1036         endif
1037         # check for ver >= 5.7
1038         ifeq ($(shell [ $(OSREL_N) -gt 5007 ] && echo has_devpoll), has_devpoll)
1039                 ifeq ($(NO_DEVPOLL),)
1040                         DEFS+=-DHAVE_DEVPOLL
1041                 endif
1042         endif
1043         ifeq ($(NO_SELECT),)
1044                 DEFS+=-DHAVE_SELECT
1045         endif
1046         ifeq ($(mode), release)
1047                 #use these only if you're using gcc with Solaris ld
1048                 #LDFLAGS=-O2 $(PROFILE)
1049                 #MOD_LDFLAGS=-O2 -G
1050         else
1051                 #LDFLAGS=-g $(PROFILE)
1052                 #MOD_LDFLAGS=-g -G
1053         endif
1054         YACC=yacc
1055
1056 ifeq ($(CC_NAME), suncc)
1057         LIBS= -lfast -ldl -lresolv
1058 endif
1059         OLD_SOLARIS= $(shell echo "$(OSREL)" | \
1060                                 sed -e 's/^5\.[0-6][^0-9]*$$/yes/' )
1061         LIBS+= -L$(LOCALBASE)/lib -lfl -lxnet -lnsl 
1062 ifeq    ($(OLD_SOLARIS), yes)
1063                 LIBS+=-lposix4
1064 else
1065                 LIBS+=-lrt
1066 endif
1067         # -lrt needed for sched_yield
1068 endif
1069
1070 ifeq ($(OS), freebsd)
1071         DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1072                 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1073                 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1074                 -DHAVE_NETINET_IN_SYSTM
1075         ifneq ($(found_lock_method), yes)
1076                 DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1077                 found_lock_method=yes
1078                 LIBS= -pthread -lfl  #dlopen is in libc
1079         else
1080                 LIBS= -lfl  #dlopen is in libc
1081         endif
1082         # check for ver >= 4.1
1083         ifeq ($(shell [ $(OSREL_N) -gt 4001 ] && echo has_kqueue), has_kqueue)
1084                 ifeq ($(NO_KQUEUE),)
1085                         DEFS+=-DHAVE_KQUEUE
1086                 endif
1087         endif
1088         ifeq ($(NO_SELECT),)
1089                 DEFS+=-DHAVE_SELECT
1090         endif
1091         YACC=yacc
1092 endif
1093
1094 ifeq ($(OS), openbsd)
1095         DEFS+=-DHAVE_SOCKADDR_SA_LEN  -DHAVE_GETHOSTBYNAME2 \
1096                 -DHAVE_UNION_SEMUN -DHAVE_MSGHDR_MSG_CONTROL \
1097                 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM
1098         ifneq ($(found_lock_method), yes)
1099                 DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1100                 found_lock_method=yes
1101         endif
1102         # check for ver >=2 9
1103         ifeq ($(shell [ $(OSREL_N) -ge 2009 ] && echo has_kqueue), has_kqueue)
1104                 ifeq ($(NO_KQUEUE),)
1105                         DEFS+=-DHAVE_KQUEUE
1106                 endif
1107         endif
1108         ifeq ($(NO_SELECT),)
1109                 DEFS+=-DHAVE_SELECT
1110         endif
1111         # (symbols on openbsd are prefixed by "_")
1112         YACC=yacc
1113         # no sched_yield on openbsd unless linking with c_r (not recommended)
1114         LIBS= -lfl 
1115         OPENBSD_IS_AOUT= $(shell echo "$(OSREL)" | \
1116                                 sed -e 's/^3\.[0-3][^0-9]*$$/yes/' |sed -e 's/^[0-2]\..*/yes/')
1117 # exception: on sparc openbsd 3.2 is elf and not aout
1118 ifeq ($(OSREL), 3.2)
1119 ifeq    ($(ARCH), sparc)
1120                 OPENBSD_IS_AOUT:=no
1121 endif
1122 ifeq    ($(ARCH), sparc64)
1123                 OPENBSD_IS_AOUT:=no
1124 endif
1125 endif
1126         
1127 ifeq ($(OPENBSD_IS_AOUT), yes)
1128                 DEFS+=-DDLSYM_PREFIX='"_"'
1129                 LDFLAGS=        # openbsd ld doesn't like -O2 or -E
1130 endif
1131 endif   # if opensd
1132         
1133 ifeq ($(OS), netbsd)
1134         DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 \
1135                 -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM
1136         ifneq ($(found_lock_method), yes)
1137                 DEFS+= -DUSE_SYSV_SEM  # try pthread sems
1138                 found_lock_method=yes
1139         endif
1140         # check for ver >= 2.0.0
1141         ifeq ($(shell [ $(OSREL_N) -ge 2000000 ] && echo has_kqueue), has_kqueue)
1142                 ifeq ($(NO_KQUEUE),)
1143                         DEFS+=-DHAVE_KQUEUE
1144                         # netbsd + kqueue and -malign-double don't work
1145                         CFLAGS:=$(filter-out -malign-double, $(CFLAGS))
1146                 endif
1147         endif
1148         ifeq ($(NO_SELECT),)
1149                 DEFS+=-DHAVE_SELECT
1150         endif
1151         YACC=yacc
1152         LIBS= -lfl 
1153 endif
1154
1155 # OS X support, same as freebsd
1156 ifeq ($(OS), darwin)
1157         DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1158                 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1159                 -DUSE_ANON_MMAP \
1160                 -DNDEBUG -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM
1161         # -DNDEBUG used to turn off assert (assert wants to call
1162         # eprintf which doesn't seem to be defined in any shared lib
1163         ifneq ($(found_lock_method), yes)
1164                 DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1165                 found_lock_method=yes
1166                 LIBS= -pthread -lfl -lresolv  #dlopen is in libc
1167         else
1168                 LIBS= -lfl -lresolv  #dlopen is in libc
1169         endif
1170         ifeq ($(NO_KQUEUE),)
1171                 DEFS+=-DHAVE_KQUEUE
1172         endif
1173         ifeq ($(NO_SELECT),)
1174                 DEFS+=-DHAVE_SELECT
1175         endif
1176         LDFLAGS=        # darwin doesn't like -O2 or -E
1177         MOD_LDFLAGS= -bundle -bundle_loader ../../$(MAIN_NAME)
1178         YACC=yacc
1179 endif
1180
1181 ifneq (,$(findstring CYGWIN, $(OS)))
1182         #cygwin is the same as common
1183         ifneq ($(found_lock_method), yes)
1184                 DEFS+= -DUSE_SYSV_SEM  # try sys v sems
1185                 found_lock_method=yes
1186         endif
1187 endif
1188
1189 #add libssl if needed
1190 ifneq ($(TLS),)
1191 DEFS+= -I$(LOCALBASE)/ssl/include
1192 LIBS+= -L$(LOCALBASE)/lib -L$(LOCALBASE)/ssl/lib -lssl  -lcrypto
1193 endif
1194
1195 ifneq ($(found_lock_method), yes)
1196 $(warning       No locking method found so far, trying SYS V sems)
1197                 DEFS+= -DUSE_SYSV_SEM  # try sys v sems
1198                 found_lock_method=yes
1199 endif
1200
1201
1202
1203
1204
1205 endif  # ifeq ($(makefile_defs, 1)