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