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