- added ser profiling patch from Hendrik Scholz <hendrik.scholz@freenet-ag.de>,
[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 = -dev45-dns_cache
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
355 # Sometimes is needes correct non-quoted $OS. HACK: gcc translates known OS to number ('linux'), so there is added underscore
356
357 DEFS+= $(extra_defs) \
358          -DNAME='"$(MAIN_NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
359          -DOS='$(OS)_' -DOS_QUOTED='"$(OS)"' -DCOMPILER='"$(CC_VER)"' -D__CPU_$(ARCH) -D__OS_$(OS) \
360          -DSER_VER=$(SER_VER) \
361          -DCFG_DIR='"$(cfg-target)"'\
362          -DPKG_MALLOC \
363          -DSHM_MEM  -DSHM_MMAP \
364          -DDNS_IP_HACK \
365          -DUSE_IPV6 \
366          -DUSE_MCAST \
367          -DUSE_TCP \
368          -DDISABLE_NAGLE \
369          -DHAVE_RESOLV_RES \
370          -DDBG_QM_MALLOC \
371          -DUSE_DNS_CACHE \
372          -DUSE_DNS_FAILOVER \
373          -DUSE_DST_BLACKLIST \
374          #-DF_MALLOC \
375          #-DDBG_F_MALLOC \
376          #-DNO_DEBUG \
377          #-DEXTRA_DEBUG \
378          #-DVQ_MALLOC  \
379          #-DDBG_LOCK \
380          #-DNOSMP \
381          #-DUSE_SHM_MEM \
382          #-DSTATS \
383          #-DNO_LOG \
384          #-DPROFILING
385
386 #PROFILE=  -pg  # set this if you want profiling
387                                 # you may also want to set -DPROFILING
388
389 # WARNING: do not add mode=debug or mode=release anymore in the Makefile,
390 # use make mode=debug all instead. Anyway no by default ser is  compiled w/ 
391 # debugging symbols in all cases (-g). --andrei
392
393 ifneq ($(TLS),)
394         DEFS+= -DUSE_TLS
395 endif
396
397 ifeq ($(mode),)
398         mode = release
399 endif
400
401 ifeq ($(mode),debug)
402         DEFS+= -DEXTRA_DEBUG
403 endif
404
405 # platform dependent settings
406
407 # find ld & as name (gnu or solaris)
408 ifeq ($(OS), solaris)
409 ifeq ($(CC_NAME), gcc)
410                 LDGCC=$(shell $(CC) -v 2>&1 | grep with-ld| \
411                                    sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
412                 ASGCC=$(shell $(CC) -v 2>&1 | grep with-as| \
413                                    sed -e 's/.*--with-as=\([^ ][^ ]*\).*/\1/' )
414                 LDPATH=$(shell  if [ -z "$(LDGCC)" ] ; then echo "ld" ;\
415                                                 else \
416                                                 if $(LDGCC) -V 2>/dev/null 1>/dev/null; then \
417                                                         echo $(LDGCC); \
418                                                 else echo "ld" ; \
419                                                 fi\
420                                                 fi)
421                 ASPATH=$(shell  if [ -z "$(ASGCC)" ] ; then echo "as" ;\
422                                                 else \
423                                                 if $(ASGCC) -V 2>/dev/null 1>/dev/null; then \
424                                                         echo $(ASGCC); \
425                                                 else echo "as" ; \
426                                                 fi\
427                                                 fi)
428                                                         
429                 LDTYPE=$(shell if $(LDPATH) -V 1>/dev/null  2>/dev/null; then \
430                                                         if $(LDPATH) -V 2>&1|grep GNU >/dev/null; \
431                                                         then echo gnu; \
432                                                         else \
433                                                         if $(LDPATH) -V 2>&1|grep Solaris >/dev/null;\
434                                                         then echo solaris; \
435                                                         else \
436                                                                 echo unknown ; \
437                                                         fi \
438                                                         fi \
439                                                 fi)
440                 ASTYPE=$(shell if $(ASPATH) -V 1>/dev/null  2>/dev/null </dev/null; \
441                                                 then \
442                                                         if $(ASPATH) -V 2>&1 </dev/null |grep GNU >/dev/null; \
443                                                         then echo gnu; \
444                                                         else \
445                                                         if $(ASPATH) -V 2>&1 </dev/null |grep Sun >/dev/null;\
446                                                         then echo solaris; \
447                                                         else \
448                                                                 echo unknown ; \
449                                                         fi \
450                                                         fi \
451                                                 fi)
452 #$(warning "using ld=$(LDPATH)/$(LDTYPE), as=$(ASPATH)/$(ASTYPE)")
453
454 endif
455 endif
456
457 # arh. specific definitions
458 ifeq ($(ARCH), i386)
459         use_fast_lock=yes
460 endif
461
462 ifeq ($(ARCH), x86_64)
463         use_fast_lock=yes
464 endif
465
466 ifeq ($(ARCH), sparc64)
467 ifeq    ($(CC_NAME), gcc)
468         use_fast_lock=yes
469 endif
470 endif
471
472 ifeq ($(ARCH), sparc)
473         use_fast_lock=yes
474 endif
475
476 ifeq ($(ARCH), arm)
477         use_fast_lock=yes
478         DEFS+=-DNOSMP # very unlikely to have an smp arm
479 endif
480
481 ifeq ($(ARCH), arm6)
482         use_fast_lock=yes
483 endif
484
485 ifeq ($(ARCH), ppc)
486         use_fast_lock=yes
487 endif
488
489 ifeq ($(ARCH), ppc64)
490         use_fast_lock=yes
491 endif
492
493 ifeq ($(ARCH), mips)
494 # mips1 arch. (e.g. R3000) - no hardware locking support
495         use_fast_lock=no
496         DEFS+=-DMIPS_HAS_LLSC # likely
497         DEFS+=-DNOSMP # very likely
498 endif
499
500 ifeq ($(ARCH), mips2)
501 # mips2 arch and newer (mips3=R4000, mips4=R5000 a.s.o)
502         use_fast_lock=yes
503 endif
504
505 ifeq ($(ARCH), mips64)
506 # mips2 arch and newer (mips3=R4000, mips4=R5000 a.s.o)
507         use_fast_lock=yes
508 endif
509
510 ifeq ($(ARCH), alpha)
511         use_fast_lock=yes
512 endif
513
514 ifeq ($(use_fast_lock), yes)
515         DEFS+= -DFAST_LOCK -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 
516         found_lock_method=yes
517 endif
518
519 CFLAGS=
520 LDFLAGS=
521 INCLUDES=
522 # setting CFLAGS
523 ifeq ($(mode), release)
524         #if i386
525 ifeq    ($(ARCH), i386)
526                 # if gcc 
527 ifeq            ($(CC_NAME), gcc)
528                                 DEFS+=-DCC_GCC_LIKE_ASM
529                                 #common stuff
530                                 CFLAGS=-g -O9 -funroll-loops  -Wcast-align $(PROFILE) \
531                                         -Wall  
532                         #if gcc 4.0+
533 ifeq                    ($(CC_SHORTVER), 4.x)
534                                         CPU ?= athlon64
535                                         CFLAGS+=-minline-all-stringops \
536                                                         -falign-loops \
537                                                         -ftree-vectorize \
538                                                         -mtune=$(CPU) 
539 else
540                         #if gcc 3.4+
541 ifeq                    ($(CC_SHORTVER), 3.4)
542                                         CPU ?= athlon
543                                         CFLAGS+=-minline-all-stringops \
544                                                         -falign-loops \
545                                                         -mtune=$(CPU) 
546 else
547                         #if gcc 3.0+
548 ifeq                    ($(CC_SHORTVER), 3.0)
549                                         CPU ?= athlon
550                                         CFLAGS+=-minline-all-stringops \
551                                                         -falign-loops \
552                                                         -mcpu=$(CPU) 
553 else
554 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
555 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
556                                         for better results)
557                                         
558                                         CFLAGS+=-m486 \
559                                                         -malign-loops=4
560 else
561                                 #really old version
562 $(warning                       You are using an old and unsupported gcc \
563                                          version  ($(CC_SHORTVER)), compile at your own risk!)
564
565 endif                   # CC_SHORTVER, 2.9x
566 endif                   # CC_SHORTVER, 3.0
567 endif                   # CC_SHORTVER, 3.4
568 endif                   # CC_SHORTVER, 4.x
569
570 else            # CC_NAME, gcc
571 ifeq            ($(CC_NAME), icc)
572                         DEFS+=-DCC_GCC_LIKE_ASM
573                         CFLAGS=-g -O3  -ipo -ipo_obj -unroll  $(PROFILE) \
574                                          -tpp6 -xK  #-openmp  #optimize for PIII 
575                                 # -prefetch doesn't seem to work
576                                 #( ty to inline acroos files, unroll loops,prefetch,
577                                 # optimize for PIII, use PIII instructions & vect.,
578                                 # mutlithread loops)
579 else
580                                 #other compilers
581 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
582 endif           #CC_NAME, icc
583 endif           #CC_NAME, gcc
584 endif   #ARCH, i386
585
586 #x86_64
587 ifeq    ($(ARCH), x86_64)
588                 # if gcc 
589 ifeq            ($(CC_NAME), gcc)
590                                 DEFS+=-DCC_GCC_LIKE_ASM
591                                 #common stuff
592                                 CFLAGS=-g -O9 -funroll-loops  -Wcast-align $(PROFILE) \
593                                         -Wall 
594                         #if gcc 4.0+
595 ifeq                    ($(CC_SHORTVER), 4.x)
596                                         CPU ?= opteron
597                                         CFLAGS+=-minline-all-stringops \
598                                                         -falign-loops \
599                                                         -ftree-vectorize \
600                                                         -mtune=$(CPU) 
601 else
602                         #if gcc 3.4
603 ifeq                    ($(CC_SHORTVER), 3.4)
604                                         CPU ?= athlon64
605                                         CFLAGS+=-minline-all-stringops \
606                                                         -falign-loops 
607 else
608                         #if gcc 3.0
609 ifeq                    ($(CC_SHORTVER), 3.0)
610                                         CPU ?= athlon64
611                                         CFLAGS+=-minline-all-stringops \
612                                                         -falign-loops 
613                                                         #-mcpu=$(CPU) \ # not working on all x86_64 gccs
614                                                         #-mcpu=athlon
615 else
616 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
617 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
618                                         for better results)
619                                         
620                                         CFLAGS+=-m486 \
621                                                         -malign-loops=4
622 else
623                                 #really old version
624 $(warning                       You are using an old and unsupported gcc \
625                                          version  ($(CC_SHORTVER)), compile at your own risk!)
626
627 endif                   # CC_SHORTVER, 2.9x
628 endif                   # CC_SHORTVER, 3.0
629 endif                   # CC_SHORTVER, 3.4
630 endif                   # CC_SHORTVER, 4.x
631
632 else            # CC_NAME, gcc
633 ifeq            ($(CC_NAME), icc)
634                         DEFS+=-DCC_GCC_LIKE_ASM
635                         CFLAGS=-g -O3  -ipo -ipo_obj -unroll  $(PROFILE) \
636                                          -tpp6 -xK  #-openmp  #optimize for PIII 
637                                 # -prefetch doesn't seem to work
638                                 #( ty to inline acroos files, unroll loops,prefetch,
639                                 # optimize for PIII, use PIII instructions & vect.,
640                                 # mutlithread loops)
641 else
642                                 #other compilers
643 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
644 endif           #CC_NAME, icc
645 endif           #CC_NAME, gcc
646 endif   #ARCH, x86_64
647
648         #if sparc64
649 ifeq    ($(ARCH), sparc64)
650                         #if gcc
651 ifeq            ($(CC_NAME), gcc)
652                                 DEFS+=-DCC_GCC_LIKE_ASM -DSPARC64_MODE
653                                 #common stuff
654                                 CFLAGS=-m64 -g -O9 -funroll-loops  $(PROFILE) \
655                                         -Wall\
656                                         #-Wcast-align \
657                                         #-Wmissing-prototypes 
658                                 # use -m64 to force 64 bit (but add it also to LDFLAGS and
659                                 #  don't forget to define SPARC64_MODE)
660                                 # -m32 for 32 bit (default on solaris),
661                                 # nothing for arch. default
662                                 LDFLAGS+=-m64
663                                 #if gcc 4.x
664 ifeq                    ($(CC_SHORTVER), 4.x)
665                                         CPU ?= ultrasparc
666                                         #use 32bit for now
667                                         CFLAGS+=-mcpu=ultrasparc -minline-all-stringops \
668                                                         -mtune=$(CPU) \
669                                                         -ftree-vectorize
670 else
671                                 #if gcc 3.4
672 ifeq                    ($(CC_SHORTVER), 3.4)
673                                         CPU ?= ultrasparc
674                                         #use 32bit for now
675                                         CFLAGS+= -mcpu=ultrasparc -mtune=$(CPU)
676 else
677                                 #if gcc 3.0
678 ifeq                    ($(CC_SHORTVER), 3.0)
679                                         CPU ?= ultrasparc
680                                         #use 32bit for now
681                                         CFLAGS+= -mcpu=ultrasparc -mtune=$(CPU)   \
682                                         # -mcpu=v9 or ultrasparc? # -mtune implied by -mcpu
683                                         #-mno-epilogue #try to inline function exit code
684                                         #-mflat # omit save/restore
685                                         #-,faster-structs #faster non Sparc ABI structure copy ops
686 else                    # CC_SHORTVER, 3.0
687 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
688 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
689                                         for better results)
690 ifneq                           ($(OS), netbsd)
691                                                 # on netbsd/sparc64,  gcc 2.95.3 does not compile
692                                                 # ser with -mv8
693                                                 CFLAGS+= -mv9 
694 endif
695 ifeq                                    ($(ASTYPE), solaris)
696                                                         CFLAGS+= -Wa,-xarch=v8plus
697 endif                                   
698 else                    #CC_SHORTVER, 2.9x
699                                 #really old version
700 $(warning                       You are using an old and unsupported gcc \
701                                          version ($(CC_SHORTVER)), compile at your own risk!)
702                                         
703                                         CFLAGS+= -mv9 
704 ifeq                                    ($(ASTYPE), solaris)
705                                                         CFLAGS+= -Wa,-xarch=v8plus
706 endif                                   
707         
708 endif                   #CC_SHORTVER, 2.9x
709 endif                   #CC_SHORTVER, 3.0
710 endif                   #CC_SHORTVER, 3.4
711 endif                   #CC_SHORTVER, 4.x
712         
713 else            #CC_NAME, gcc
714 ifeq            ($(CC_NAME), suncc)
715                         DEFS+=-DSPARC64_MODE
716                         CFLAGS+= -m64 -g -xO5 -fast -native -xarch=v9 -xCC \
717                                         -xc99 # C99 support
718                         # -Dinline="" # add this if cc < 5.3 (define inline as null)
719 else
720                                 #other compilers
721 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
722 endif           #CC_NAME, suncc
723 endif           #CC_NAME, gcc
724 endif   #ARCH, sparc64
725
726         #if sparc
727 ifeq    ($(ARCH), sparc)
728                         #if gcc
729 ifeq            ($(CC_NAME), gcc)
730                                 DEFS+=-DCC_GCC_LIKE_ASM
731                                 #common stuff
732                                 CFLAGS=-g -O9 -funroll-loops  $(PROFILE) \
733                                         -Wall\
734                                         #-Wcast-align \
735                                         #-Wmissing-prototypes 
736                                 #if gcc 4.x
737 ifeq                    ($(CC_SHORTVER), 4.x)
738                                         CPU ?= v8 
739                                         #use 32bit for now
740                                         CFLAGS+= -minline-all-stringops \
741                                                         -mtune=$(CPU) \
742                                                         -ftree-vectorize
743 else
744                                 #if gcc 3.4
745 ifeq                    ($(CC_SHORTVER), 3.4)
746                                         CPU ?= v8
747                                         #use 32bit for now
748                                         CFLAGS+= -mtune=$(CPU)
749 else
750                                 #if gcc 3.0
751 ifeq                    ($(CC_SHORTVER), 3.0)
752                                         CPU ?= v8 
753                                         #use 32bit for now
754                                         CFLAGS+= -mtune=$(CPU)   \
755                                         #-mno-epilogue #try to inline function exit code
756                                         #-mflat # omit save/restore
757                                         #-,faster-structs #faster non Sparc ABI structure copy ops
758 else                    # CC_SHORTVER, 3.0
759 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
760 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
761                                         for better results)
762 else                    #CC_SHORTVER, 2.9x
763                                 #really old version
764 $(warning                       You are using an old and unsupported gcc \
765                                          version ($(CC_SHORTVER)), compile at your own risk!)
766                                         
767 endif                   #CC_SHORTVER, 2.9x
768 endif                   #CC_SHORTVER, 3.0
769 endif                   #CC_SHORTVER, 3.4
770 endif                   #CC_SHORTVER, 4.x
771         
772 else            #CC_NAME, gcc
773 ifeq            ($(CC_NAME), suncc)
774                         CFLAGS+= -g -xO5 -fast -native -xCC \
775                                         -xc99 # C99 support
776                         # -Dinline="" # add this if cc < 5.3 (define inline as null)
777 else
778                                 #other compilers
779 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
780 endif           #CC_NAME, suncc
781 endif           #CC_NAME, gcc
782 endif   #ARCH, sparc
783
784         #if ipaq/netwinder
785 ifeq    ($(ARCH), arm)
786                 # if gcc 
787 ifeq            ($(CC_NAME), gcc)
788                                 DEFS+=-DCC_GCC_LIKE_ASM
789                                 #common stuff
790                                 CFLAGS=-O9 -funroll-loops $(PROFILE) \
791                                         -Wall   
792                         #if gcc 4.x+
793 ifeq                    ($(CC_SHORTVER), 4.x)
794                                         CFLAGS+= -ftree-vectorize
795                                         # not supported on arm: -minline-all-stringops 
796 else
797                         #if gcc 3.4+
798 ifeq                    ($(CC_SHORTVER), 3.4)
799                                         CFLAGS+=
800 else
801                         #if gcc 3.0
802 ifeq                    ($(CC_SHORTVER), 3.0)
803                                         CFLAGS+= 
804                                                         #-mcpu=athlon
805 else
806 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
807 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
808                                         for better results)
809                                         
810                                         CFLAGS+=
811 else
812                                 #really old version
813 $(warning                       You are using an old and unsupported gcc \
814                                          version ($(CC_SHORTVER)), compile at your own risk!)
815         
816 endif                   # CC_SHORTVER, 2.9x
817 endif                   # CC_SHORTVER, 3.0
818 endif                   # CC_SHORTVER, 3.4
819 endif                   # CC_SHORTVER, 4.0
820         
821 else            # CC_NAME, gcc
822                                 #other compilers
823 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
824 endif           #CC_NAME, gcc
825 endif   #ARCH, arm 
826
827         #if armv6 cpu 
828 ifeq    ($(ARCH), arm6)
829                 # if gcc 
830 ifeq            ($(CC_NAME), gcc)
831                                 DEFS+=-DCC_GCC_LIKE_ASM
832                                 #common stuff
833                                 CFLAGS=-march=armv6 -O9 -funroll-loops \
834                                                 $(PROFILE) -Wall   
835                         #if gcc 4.x+
836 ifeq                    ($(CC_SHORTVER), 4.x)
837                                         CFLAGS+= -ftree-vectorize
838 else
839                         #if gcc 3.4+
840 ifeq                    ($(CC_SHORTVER), 3.4)
841                                         CFLAGS+=
842 else
843                         #if gcc 3.0
844 ifeq                    ($(CC_SHORTVER), 3.0)
845                                         CFLAGS+= 
846                                                         #-mcpu=athlon
847 else
848 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
849 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
850                                         for better results)
851                                         
852                                         CFLAGS+=
853 else
854                                 #really old version
855 $(warning                       You are using an old and unsupported gcc \
856                                          version ($(CC_SHORTVER)), compile at your own risk!)
857         
858 endif                   # CC_SHORTVER, 2.9x
859 endif                   # CC_SHORTVER, 3.0
860 endif                   # CC_SHORTVER, 3.4
861 endif                   # CC_SHORTVER, 4.0
862         
863 else            # CC_NAME, gcc
864                                 #other compilers
865 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
866 endif           #CC_NAME, gcc
867 endif   #ARCH, arm6
868
869         #if  mips (R3000)
870 ifeq    ($(ARCH), mips)
871                 # if gcc 
872 ifeq            ($(CC_NAME), gcc)
873                                 DEFS+=-DCC_GCC_LIKE_ASM
874                                 #common stuff
875                                 CFLAGS=-O9 -funroll-loops  $(PROFILE) \
876                                         -Wall 
877                         #if gcc 4.0+
878 ifeq                    ($(CC_SHORTVER), 4.x)
879                                         CFLAGS+=-march=r3000 -minline-all-stringops \
880                                                         -ftree-vectorize
881 else
882                         #if gcc 3.4+
883 ifeq                    ($(CC_SHORTVER), 3.4)
884                                         CFLAGS+= -march=r3000
885 else
886                         #if gcc 3.0
887 ifeq                    ($(CC_SHORTVER), 3.0)
888                                         CFLAGS+= -march=r3000
889 else
890 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
891 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
892                                         for better results)
893                                         
894                                         CFLAGS+=-march=r3000
895 else
896                                 #really old version
897 $(warning                       You are using an old and unsupported gcc \
898                                          version ($(CC_SHORTVER)), compile at your own risk!)
899         
900 endif                   # CC_SHORTVER, 2.9x
901 endif                   # CC_SHORTVER, 3.0
902 endif                   # CC_SHORTVER, 3.4
903 endif                   # CC_SHORTVER, 4.x
904         
905 else            # CC_NAME, gcc
906                                 #other compilers
907 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
908 endif           #CC_NAME, gcc
909 endif   #ARCH, mips
910
911         #if  >=mips2 (R4000, R5000, R6000 ....)
912 ifeq    ($(ARCH), mips2)
913                 # if gcc 
914 ifeq            ($(CC_NAME), gcc)
915                                 DEFS+=-DCC_GCC_LIKE_ASM
916                                 #common stuff
917                                 CFLAGS= -mips2 -O9 -funroll-loops $(PROFILE) \
918                                         -Wall 
919                         #if gcc 4.0+
920 ifeq                    ($(CC_SHORTVER), 4.x)
921                                         CFLAGS+=-minline-all-stringops -ftree-vectorize
922 else
923                         #if gcc 3.4+
924 ifeq                    ($(CC_SHORTVER), 3.4)
925                                         CFLAGS+=
926 else
927                         #if gcc 3.0
928 ifeq                    ($(CC_SHORTVER), 3.0)
929                                         CFLAGS+=
930 else
931 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
932 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
933                                         for better results)
934                                         CFLAGS+=
935 else
936                                 #really old version
937 $(warning                       You are using an old and unsupported gcc \
938                                          version ($(CC_SHORTVER)), compile at your own risk!)
939         
940 endif                   # CC_SHORTVER, 2.9x
941 endif                   # CC_SHORTVER, 3.0
942 endif                   # CC_SHORTVER, 3.4
943 endif                   # CC_SHORTVER, 4.x
944         
945 else            # CC_NAME, gcc
946                                 #other compilers
947 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
948 endif           #CC_NAME, gcc
949 endif   #ARCH, mips2
950
951 #if  >=mips64
952 ifeq    ($(ARCH), mips64)
953                 # if gcc 
954 ifeq            ($(CC_NAME), gcc)
955                                 DEFS+=-DCC_GCC_LIKE_ASM
956                                 #common stuff
957                                 CFLAGS= -mips64 -O9 -funroll-loops $(PROFILE) \
958                                         -Wall 
959                         #if gcc 4.0+
960 ifeq                    ($(CC_SHORTVER), 4.x)
961                                         CFLAGS+=-minline-all-stringops -ftree-vectorize
962 else
963                         #if gcc 3.4+
964 ifeq                    ($(CC_SHORTVER), 3.4)
965                                         CFLAGS+=
966 else
967                         #if gcc 3.0
968 ifeq                    ($(CC_SHORTVER), 3.0)
969                                         CFLAGS+=
970 else
971 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
972 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
973                                         for better results)
974                                         CFLAGS+=
975 else
976                                 #really old version
977 $(warning                       You are using an old and unsupported gcc \
978                                          version ($(CC_SHORTVER)), compile at your own risk!)
979         
980 endif                   # CC_SHORTVER, 2.9x
981 endif                   # CC_SHORTVER, 3.0
982 endif                   # CC_SHORTVER, 3.4
983 endif                   # CC_SHORTVER, 4.x
984         
985 else            # CC_NAME, gcc
986                                 #other compilers
987 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
988 endif           #CC_NAME, gcc
989 endif   #ARCH, mips64
990
991 #if  alpha
992 ifeq    ($(ARCH), alpha)
993                 # if gcc 
994 ifeq            ($(CC_NAME), gcc)
995                                 DEFS+=-DCC_GCC_LIKE_ASM
996                                 #common stuff
997                                 CFLAGS= -O9 -funroll-loops $(PROFILE)  -Wall 
998                         #if gcc 4.0+
999 ifeq                    ($(CC_SHORTVER), 4.x)
1000                                         CFLAGS+= 
1001                                         # not supported: -minline-all-stringops
1002 else
1003                         #if gcc 3.4+
1004 ifeq                    ($(CC_SHORTVER), 3.4)
1005                                         CFLAGS+=
1006 else
1007                         #if gcc 3.0
1008 ifeq                    ($(CC_SHORTVER), 3.0)
1009                                         CFLAGS+=
1010 else
1011 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1012 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1013                                         for better results)
1014                                         CFLAGS+=
1015 else
1016                                 #really old version
1017 $(warning                       You are using an old and unsupported gcc \
1018                                          version ($(CC_SHORTVER)), compile at your own risk!)
1019         
1020 endif                   # CC_SHORTVER, 2.9x
1021 endif                   # CC_SHORTVER, 3.0
1022 endif                   # CC_SHORTVER, 3.4
1023 endif                   # CC_SHORTVER, 4.x
1024         
1025 else            # CC_NAME, gcc
1026                                 #other compilers
1027 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1028 endif           #CC_NAME, gcc
1029 endif   #ARCH, alpha 
1030
1031 #if  ppc
1032 ifeq    ($(ARCH), ppc)
1033                 # if gcc 
1034 ifeq            ($(CC_NAME), gcc)
1035                                 DEFS+=-DCC_GCC_LIKE_ASM
1036                                 #common stuff
1037                                 CFLAGS= -O9 -funroll-loops $(PROFILE)  -Wall 
1038                         #if gcc 4.0+
1039 ifeq                    ($(CC_SHORTVER), 4.x)
1040                                         CPU ?= powerpc
1041                                         CFLAGS+=-ftree-vectorize \
1042                                                         -mtune=$(CPU) -maltivec
1043 else
1044                         #if gcc 3.4+
1045 ifeq                    ($(CC_SHORTVER), 3.4)
1046                                         CFLAGS+=
1047 else
1048                         #if gcc 3.0
1049 ifeq                    ($(CC_SHORTVER), 3.0)
1050                                         CFLAGS+=
1051 else
1052 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1053 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1054                                         for better results)
1055                                         CFLAGS+=
1056 else
1057                                 #really old version
1058 $(warning                       You are using an old and unsupported gcc \
1059                                          version ($(CC_SHORTVER)), compile at your own risk!)
1060         
1061 endif                   # CC_SHORTVER, 2.9x
1062 endif                   # CC_SHORTVER, 3.0
1063 endif                   # CC_SHORTVER, 3.4
1064 endif                   # CC_SHORTVER, 4.x
1065         
1066 else            # CC_NAME, gcc
1067                                 #other compilers
1068 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1069 endif           #CC_NAME, gcc
1070 endif   #ARCH, ppc 
1071
1072 #if  ppc64
1073 ifeq    ($(ARCH), ppc64)
1074                 # if gcc 
1075 ifeq            ($(CC_NAME), gcc)
1076                                 DEFS+=-DCC_GCC_LIKE_ASM
1077                                 #common stuff
1078                                 CFLAGS= -O9 -funroll-loops $(PROFILE)  -Wall 
1079 ifeq                    ($(CC_SHORTVER), 4.x)
1080                                         CPU ?= powerpc64
1081                                         CFLAGS+=-ftree-vectorize \
1082                                                         -mtune=$(CPU) -maltivec
1083 else
1084                         #if gcc 3.4+
1085 ifeq                    ($(CC_SHORTVER), 3.4)
1086                                         CFLAGS+=
1087 else
1088                         #if gcc 3.0
1089 ifeq                    ($(CC_SHORTVER), 3.0)
1090                                         CFLAGS+=
1091 else
1092 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
1093 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
1094                                         for better results)
1095                                         CFLAGS+=
1096 else
1097                                 #really old version
1098 $(warning                       You are using an old and unsupported gcc \
1099                                          version ($(CC_SHORTVER)), compile at your own risk!)
1100         
1101 endif                   # CC_SHORTVER, 2.9x
1102 endif                   # CC_SHORTVER, 3.0
1103 endif                   # CC_SHORTVER, 3.4
1104 endif                   # CC_SHORTVER, 4.x
1105         
1106 else            # CC_NAME, gcc
1107                                 #other compilers
1108 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
1109 endif           #CC_NAME, gcc
1110 endif   #ARCH, ppc 
1111
1112
1113
1114 # setting LDFLAGS
1115 ifeq    ($(CC_NAME), gcc)
1116 ifeq            ($(LDTYPE), solaris)
1117                 # solaris ld
1118                 LDFLAGS+=-O2 $(PROFILE)
1119                 MOD_LDFLAGS=-G $(LDFLAGS)
1120 else            
1121                 #gcc and maybe others, => gnu ld
1122                 LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
1123                 MOD_LDFLAGS=-shared $(LDFLAGS)
1124 endif
1125 endif
1126 ifeq    ($(CC_NAME), icc)
1127         #gcc and maybe others
1128         LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
1129         MOD_LDFLAGS=-shared $(LDFLAGS)
1130 endif
1131 ifeq    ($(CC_NAME), suncc)
1132         LDFLAGS+=-xO5 $(PROFILE)
1133         MOD_LDFLAGS=-G $(LDFLAGS)
1134 endif
1135         # we need -fPIC -DPIC only for shared objects, we don't need them for
1136         # the executable file, because it's always loaded at a fixed address
1137         # -andrei
1138 else    #mode,release
1139 ifeq    ($(CC_NAME), gcc)
1140                 CFLAGS=-g -Wcast-align $(PROFILE)
1141                 DEFS+=-DCC_GCC_LIKE_ASM
1142 ifeq            ($(ARCH), sparc64)
1143                         DEFS+=SPARC64_MODE
1144                         CFLAGS+= -mcpu=ultrasparc -m64
1145                         LDFLAGS+=-m64
1146 endif
1147 ifeq            ($(LDTYPE), solaris)
1148                         #solaris ld
1149                         LDFLAGS+=-g $(PROFILE)
1150                         MOD_LDFLAGS=-G $(LDFLAGS)
1151 else
1152                         #gnu or other ld type
1153                         LDFLAGS+=-g -Wl,-E $(PROFILE)
1154                         MOD_LDFLAGS=-shared $(LDFLAGS)
1155 endif
1156 endif
1157 ifeq    ($(CC_NAME), icc)
1158                 DEFS+=-DCC_GCC_LIKE_ASM
1159                 CFLAGS=-g  $(PROFILE)
1160                 LDFLAGS+=-g -Wl,-E $(PROFILE)
1161                 MOD_LDFLAGS=-shared $(LDFLAGS)
1162 endif
1163 ifeq    ($(CC_NAME), suncc)
1164                 CFLAGS= -g $(PROFILE)
1165                 LDFLAGS+=-g $(PROFILE)
1166                 MOD_LDFLAGS=-G $(LDFLAGS)
1167 endif
1168
1169 endif #mode=release
1170
1171 CFLAGS+= $(CC_EXTRA_OPTS)
1172
1173 #*FLAGS used for compiling the modules
1174 ifeq    ($(CC_NAME), gcc)
1175 MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
1176 endif
1177 ifeq    ($(CC_NAME), icc)
1178 MOD_CFLAGS=-Kpic $(CFLAGS)
1179 endif
1180 ifeq    ($(CC_NAME), suncc)
1181 MOD_CFLAGS=-xcode=pic32  $(CFLAGS)
1182 endif
1183
1184 ifeq ($(LEX),)
1185         LEX=flex
1186 endif
1187 ifeq ($(YACC),)
1188         YACC=bison
1189 endif
1190 YACC_FLAGS=-d -b cfg
1191 # on solaris add -lxnet (e.g. LIBS= -lxnet)
1192 LIBS= -ldl -lresolv
1193
1194
1195 #os specific stuff
1196 ifeq ($(OS), linux)
1197         DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD \
1198                         -DHAVE_MSG_NOSIGNAL -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_ALLOCA_H \
1199                         -DHAVE_TIMEGM
1200         ifneq ($(found_lock_method), yes)
1201                 DEFS+= -DUSE_SYSV_SEM  # try posix sems
1202                 found_lock_method=yes
1203         endif
1204         # check for >= 2.5.44
1205         ifeq ($(shell [ $(OSREL_N) -ge 2005044 ] && echo has_epoll), has_epoll)
1206                 ifeq ($(NO_EPOLL),)
1207                         DEFS+=-DHAVE_EPOLL
1208                         # linux + gcc >= 3.0 + -malign-double + epoll => problems
1209                         CFLAGS:=$(filter-out -malign-double, $(CFLAGS))
1210                 endif
1211         endif
1212         # check for >= 2.2.0
1213         ifeq ($(shell [ $(OSREL_N) -ge 2002000 ] && echo has_sigio), has_sigio)
1214                 ifeq ($(NO_SIGIO),)
1215                         DEFS+=-DHAVE_SIGIO_RT -DSIGINFO64_WORKARROUND
1216                 endif
1217         endif
1218         ifeq ($(NO_SELECT),)
1219                 DEFS+=-DHAVE_SELECT
1220         endif
1221 endif
1222
1223 ifeq  ($(OS), solaris)
1224         DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD \
1225                         -DHAVE_ALLOCA_H -DUSE_SIGACTION
1226         ifneq ($(found_lock_method), yes)
1227                 DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1228                 found_lock_method=yes
1229         endif
1230         # check for ver >= 5.7
1231         ifeq ($(shell [ $(OSREL_N) -gt 5007 ] && echo has_devpoll), has_devpoll)
1232                 ifeq ($(NO_DEVPOLL),)
1233                         DEFS+=-DHAVE_DEVPOLL
1234                 endif
1235         endif
1236         ifeq ($(NO_SELECT),)
1237                 DEFS+=-DHAVE_SELECT
1238         endif
1239         ifeq ($(mode), release)
1240                 #use these only if you're using gcc with Solaris ld
1241                 #LDFLAGS=-O2 $(PROFILE)
1242                 #MOD_LDFLAGS=-O2 -G
1243         else
1244                 #LDFLAGS=-g $(PROFILE)
1245                 #MOD_LDFLAGS=-g -G
1246         endif
1247         YACC=yacc
1248
1249 ifeq ($(CC_NAME), suncc)
1250         LIBS= -lfast -ldl -lresolv
1251 endif
1252         OLD_SOLARIS= $(shell echo "$(OSREL)" | \
1253                                 sed -e 's/^5\.[0-6][^0-9]*$$/yes/' )
1254         LIBS+= -L$(LOCALBASE)/lib -lxnet -lnsl 
1255 ifeq    ($(OLD_SOLARIS), yes)
1256                 LIBS+=-lposix4
1257 else
1258                 LIBS+=-lrt
1259 endif
1260         # -lrt needed for sched_yield
1261 endif
1262
1263 ifeq ($(OS), freebsd)
1264         DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1265                 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1266                 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1267                 -DHAVE_NETINET_IN_SYSTM
1268         ifneq ($(found_lock_method), yes)
1269                 DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1270                 found_lock_method=yes
1271                 LIBS= -pthread   #dlopen is in libc
1272         else
1273                 LIBS=   #dlopen is in libc
1274         endif
1275         # check for ver >= 4.1
1276         ifeq ($(shell [ $(OSREL_N) -gt 4001 ] && echo has_kqueue), has_kqueue)
1277                 ifeq ($(NO_KQUEUE),)
1278                         DEFS+=-DHAVE_KQUEUE
1279                 endif
1280         endif
1281         ifeq ($(NO_SELECT),)
1282                 DEFS+=-DHAVE_SELECT
1283         endif
1284         YACC=yacc
1285 endif
1286
1287 ifeq ($(OS), openbsd)
1288         DEFS+=-DHAVE_SOCKADDR_SA_LEN  -DHAVE_GETHOSTBYNAME2 \
1289                 -DHAVE_UNION_SEMUN -DHAVE_MSGHDR_MSG_CONTROL \
1290                 -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1291                 -DHAVE_NETINET_IN_SYSTM -DUSE_SIGWAIT
1292         ifneq ($(found_lock_method), yes)
1293                 DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1294                 found_lock_method=yes
1295         endif
1296         # check for ver >=2 9
1297         ifeq ($(shell [ $(OSREL_N) -ge 2009 ] && echo has_kqueue), has_kqueue)
1298                 ifeq ($(NO_KQUEUE),)
1299                         DEFS+=-DHAVE_KQUEUE
1300                 endif
1301         endif
1302         ifeq ($(NO_SELECT),)
1303                 DEFS+=-DHAVE_SELECT
1304         endif
1305         # (symbols on openbsd are prefixed by "_")
1306         YACC=yacc
1307         # no sched_yield on openbsd unless linking with c_r (not recommended)
1308         # unfortunately pthread is needed for sigwait
1309         LIBS= -lpthread
1310         OPENBSD_IS_AOUT= $(shell echo "$(OSREL)" | \
1311                                 sed -e 's/^3\.[0-3][^0-9]*$$/yes/' |sed -e 's/^[0-2]\..*/yes/')
1312 # exception: on sparc openbsd 3.2 is elf and not aout
1313 ifeq ($(OSREL), 3.2)
1314 ifeq    ($(ARCH), sparc)
1315                 OPENBSD_IS_AOUT:=no
1316 endif
1317 ifeq    ($(ARCH), sparc64)
1318                 OPENBSD_IS_AOUT:=no
1319 endif
1320 endif
1321         
1322 ifeq ($(OPENBSD_IS_AOUT), yes)
1323                 DEFS+=-DDLSYM_PREFIX='"_"'
1324                 LDFLAGS=        # openbsd ld doesn't like -O2 or -E
1325 endif
1326 endif   # if opensd
1327         
1328 ifeq ($(OS), netbsd)
1329         DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 \
1330                 -DHAVE_MSGHDR_MSG_CONTROL -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM
1331         ifneq ($(found_lock_method), yes)
1332                 DEFS+= -DUSE_SYSV_SEM  # try pthread sems
1333                 found_lock_method=yes
1334         endif
1335         # check for ver >= 2.0.0
1336         ifeq ($(shell [ $(OSREL_N) -ge 2000000 ] && echo has_kqueue), has_kqueue)
1337                 ifeq ($(NO_KQUEUE),)
1338                         DEFS+=-DHAVE_KQUEUE
1339                         # netbsd + kqueue and -malign-double don't work
1340                         CFLAGS:=$(filter-out -malign-double, $(CFLAGS))
1341                 endif
1342         endif
1343         ifeq ($(NO_SELECT),)
1344                 DEFS+=-DHAVE_SELECT
1345         endif
1346         YACC=yacc
1347         LIBS=  
1348 endif
1349
1350 # OS X support, same as freebsd
1351 ifeq ($(OS), darwin)
1352         DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
1353                 -DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
1354                 -DUSE_ANON_MMAP \
1355                 -DNDEBUG -DHAVE_CONNECT_ECONNRESET_BUG -DHAVE_TIMEGM \
1356                 -DUSE_SIGWAIT
1357         # -DNDEBUG used to turn off assert (assert wants to call
1358         # eprintf which doesn't seem to be defined in any shared lib
1359         ifneq ($(found_lock_method), yes)
1360                 DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
1361                 found_lock_method=yes
1362                 LIBS= -pthread -lresolv  #dlopen is in libc
1363         else
1364                 LIBS= -lresolv  #dlopen is in libc
1365         endif
1366         ifeq ($(NO_KQUEUE),)
1367                 DEFS+=-DHAVE_KQUEUE
1368         endif
1369         ifeq ($(NO_SELECT),)
1370                 DEFS+=-DHAVE_SELECT
1371         endif
1372         LDFLAGS=        # darwin doesn't like -O2 or -E
1373         MOD_LDFLAGS= -bundle -bundle_loader ../../$(MAIN_NAME)
1374         YACC=yacc
1375 endif
1376
1377 ifneq (,$(findstring CYGWIN, $(OS)))
1378         #cygwin is the same as common
1379         ifneq ($(found_lock_method), yes)
1380                 DEFS+= -DUSE_SYSV_SEM  # try sys v sems
1381                 found_lock_method=yes
1382         endif
1383 endif
1384
1385 #add libssl if needed
1386 ifneq ($(TLS),)
1387 DEFS+= -I$(LOCALBASE)/ssl/include
1388 LIBS+= -L$(LOCALBASE)/lib -L$(LOCALBASE)/ssl/lib -lssl  -lcrypto
1389 endif
1390
1391 ifneq ($(found_lock_method), yes)
1392 $(warning       No locking method found so far, trying SYS V sems)
1393                 DEFS+= -DUSE_SYSV_SEM  # try sys v sems
1394                 found_lock_method=yes
1395 endif
1396
1397
1398
1399
1400
1401 endif  # ifeq ($(makefile_defs, 1)