- changed sip_msg (new rcv member containing all the ips, ports, protocol)
[sip-router] / Makefile.defs
1 # $Id$
2 #
3 # makefile defs (CC, LD,a.s.o)
4 #
5
6
7 #version number
8 VERSION = 0
9 PATCHLEVEL = 8
10 SUBLEVEL =   11
11 EXTRAVERSION = pre3-tcp0
12
13 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
14 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
15 ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/  \
16                         -e s/armv4l/arm/)
17
18  # install location
19 PREFIX = /usr/local
20 prefix = $(PREFIX)
21 # install path is $(basedir) $(prefix) 
22 # example:
23 #  creating a bin. archive in /tmp, which unpacks in /usr/local
24 #  basedir=/tmp
25 #  prefix=/usr/local
26 basedir = 
27 # install prefixes for various stuff
28 cfg-prefix = $(basedir)$(prefix)
29 bin-prefix = $(basedir)$(prefix)
30 modules-prefix = $(basedir)$(prefix)
31 doc-prefix = $(basedir)$(prefix)
32 man-prefix = $(basedir)$(prefix)
33 ut-prefix = $(basedir)$(prefix)
34
35 # dirs
36 cfg-dir = etc/ser/
37 bin-dir = sbin/
38 modules-dir = lib/ser/modules/
39 ifeq ($(OS), linux)
40         doc-dir = share/doc/ser/
41         man-dir = share/man/
42 else
43         doc-dir=doc/ser/
44         man-dir=man/
45 endif
46 ut-prefix = bin/
47 # target dirs for various stuff
48 cfg-target = $(prefix)/$(cfg-dir)
49 modules-target = $(prefix)/$(modules-dir)
50
51
52 ifeq ($(OS), solaris)
53 #use GNU versions
54 INSTALL = ginstall
55 TAR = gtar
56 else
57 INSTALL = install 
58 TAR= tar
59 endif
60
61 # INSTALL-CFG = $(INSTALL) -m 644
62 INSTALL-BIN = $(INSTALL) -m 755
63 INSTALL-MODULES = $(INSTALL) -m 755
64 INSTALL-DOC = $(INSTALL) -m 644
65 INSTALL-MAN = $(INSTALL) -m 644
66
67 #set some vars from the environment (and not make builtins)
68 CC   := $(shell echo "$${CC}")
69 LEX  := $(shell echo "$${LEX}")
70 YACC := $(shell echo "$${YACC}")
71
72
73
74
75 # compile-time options
76 #
77 # -DSTATS
78 #               allows to print out number of packets processed on CTRL-C;
79 #               implementation still nasty and reports per-process
80 # -DNO_DEBUG
81 #               turns off some of the debug messages (DBG(...)).
82 # -DNO_LOG
83 #               completely turns of all the logging (and DBG(...))
84 # -DEXTRA_DEBUG
85 #               compiles in some extra debugging code
86 # -DDNS_IP_HACK
87 #               faster ip address resolver for ip strings (e.g "127.0.0.1")
88 # -DSHM_MEM
89 #               compiles in shared mem. support, needed by some modules and
90 #               by USE_SHM_MEM
91 # -DSHM_MMAP
92 #               use mmap instead of SYSV shared memory
93 # -DPKG_MALLOC
94 #               uses a faster malloc (exclusive w/ USE_SHM_MEM)
95 # -DUSE_SHM_MEM
96 #               all pkg_malloc => shm_malloc (most mallocs use a common sh.
97 #               mem. segment); don't define PKG_MALLOC if you want this!
98 # -DDBG_QM_MALLOC
99 #               qm_malloc debug code, will cause pkg_malloc and shm_malloc
100 #               to keep and display lot of debuging information: file name,
101 #               function, line number of malloc/free call for each block,
102 #               extra error checking (trying to free the same pointer
103 #               twice, trying to free a pointer alloc'ed with a different
104 #               malloc etc.)
105 # -DVQ_MALLOC
106 #               additional option to PKG_MALLOC which utilizes a fater then
107 #               qm version
108 #               (not true anymore, q_malloc performs approx. the same)
109 # -DF_MALLOC
110 #               an even faster malloc, not recommended for debugging
111 # -DDBG_MALLOC
112 #               issues additional debugging information if lock/unlock is called
113 # -DFAST_LOCK
114 #               uses fast arhitecture specific locking (see the arh. specific section)
115 # -DBUSY_WAIT
116 #               uses busy waiting on the lock
117 # -DADAPTIVE_WAIT
118 #               try busy waiting for a while and if the lock is still held go to
119 #               force reschedule
120 # -DADAPTIVE_WAIT_LOOPS=number
121 #               number of loops we busy wait, after "number" loops have elapsed we 
122 #               force a reschedule
123 # -DNOSMP
124 #               don't use smp compliant locking (faster but won't work on SMP machines)
125 #               (not yet enabled)
126 # -DNO_PINGTEL_TAG_HACK
127 #               if enabled, To-header-field will be less liberal and will not accept
128 #               'tag=' (tag parameter with equal sign and without value); it is called
129 #               this way because such message was sighted from a Pingtel phone
130 # -DWITH_SNMP_MOD
131 #               if enabled, allows forking of the snmp agent just before child
132 #               forking (done at the top of main_loop). Needed if you want
133 #               to use the snmp module.
134 # -DUSE_TCP
135 #               compiles in tcp support (highly experimental for now, it will probably
136 #               not work, use it only if you really now what you are doing)
137 DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
138          -DOS='"$(OS)"' -DCOMPILER='"$(CC_VER)"' -D__CPU_$(ARCH)\
139          -DCFG_DIR='"$(cfg-target)"'\
140          -DPKG_MALLOC \
141          -DSHM_MEM  -DSHM_MMAP \
142          -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 \
143          -DDNS_IP_HACK \
144          -DUSE_IPV6 \
145          -DDBG_QM_MALLOC \
146          #-DUSE_TCP \
147          #-DF_MALLOC \
148          #-DNO_DEBUG \
149          #-DNO_LOG
150          #-DEXTRA_DEBUG \
151          #-DDBG_QM_MALLOC \
152          #-DVQ_MALLOC  
153          #-DCONTACT_BUG
154          #-DDBG_LOCK
155          #-DNOSMP \
156          #-DEXTRA_DEBUG \
157          #-DUSE_SHM_MEM \
158          #-DSTATS \
159          #-DWITH_SNMP_MOD \
160          #-DNO_LOG
161
162 #PROFILE=  -pg #set this if you want profiling
163 #mode = debug
164 ifeq ($(mode),)
165         mode = release
166 endif
167
168 # platform dependent settings
169
170
171 #common
172 ifeq ($(CC),)
173         CC=gcc
174 endif
175 LD= $(CC)
176 CC_LONGVER=$(shell if  $(CC) -v 2>/dev/null; then \
177                                                 $(CC) -v 2>&1 ;\
178                                         else \
179                                                 $(CC) -V 2>&1 ; \
180                                         fi )
181 MKTAGS=ctags -R .
182
183 #find-out the compiler's name
184
185 ifneq (,$(findstring gcc, $(CC_LONGVER)))
186         CC_NAME=gcc
187         CC_VER=$(CC) $(shell $(CC) --version|head -1| \
188                                  sed -e 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/' -e 's/[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/')
189         # sun sed is a little brain damaged => this complicated expression
190         MKDEP=$(CC) -MM 
191         #transform gcc version into 2.9x or 3.0
192         CC_SHORTVER=$(shell echo "$(CC_VER)" | cut -d" " -f 2| \
193                                  sed -e 's/[^0-9]*-\(.*\)/\1/'| \
194                                  sed -e 's/2\.9.*/2.9x/' -e 's/3\..\..*/3.0/' -e \
195                                         's/3\../3.0/')
196 endif
197
198 ifneq (, $(findstring Sun, $(CC_LONGVER)))
199         CC_NAME=suncc
200         CC_SHORTVER=$(shell echo "$(CC_LONGVER)"|head -1| \
201                                         sed -e 's/.*\([0-9]\.[0-9]\).*/\1/g' )
202         CC_VER=$(CC) $(CC_SHORTVER)
203         MKDEP=$(CC) -xM1 
204 endif
205
206 ifneq (, $(findstring Intel(R) C++ Compiler, $(CC_LONGVER)))
207         # very nice: gcc compatible
208         CC_NAME=icc
209         CC_FULLVER=$(shell echo "$(CC_LONGVER)"|head -1| \
210                                         sed -e 's/.*Version \([0-9]\.[0-9]\.[0-9]*\).*/\1/g' )
211         CC_SHORTVER=$(shell echo "$(CC_FULLVER)" | cut -d. -f1,2 )
212         CC_VER=$(CC) $(CC_FULLVER)
213         MKDEP=$(CC) -MM 
214 endif
215
216
217 ifeq (,$(CC_NAME))
218 #not found
219         CC_NAME=$(CC)
220         CC_SHORTVER=unknown
221         CC_VER=unknown
222         MKDEP=gcc -MM 
223 $(warning       Unknown compiler $(CC)\; supported compilers: \
224                         gcc, sun cc, intel icc )
225 endif
226
227 # find ld & as name (gnu or solaris)
228 ifeq ($(ARCH), sparc64)
229 ifeq ($(CC_NAME), gcc)
230                 LDGCC=$(shell $(CC) -v 2>&1 | grep with-ld| \
231                                    sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
232                 ASGCC=$(shell $(CC) -v 2>&1 | grep with-as| \
233                                    sed -e 's/.*--with-as=\([^ ][^ ]*\).*/\1/' )
234                 LDPATH=$(shell  if [ -z "$(LDGCC)" ] ; then echo "ld" ;\
235                                                 else \
236                                                 if $(LDGCC) -V 2>/dev/null 1>/dev/null; then \
237                                                         echo $(LDGCC); \
238                                                 else echo "ld" ; \
239                                                 fi\
240                                                 fi)
241                 ASPATH=$(shell  if [ -z "$(ASGCC)" ] ; then echo "as" ;\
242                                                 else \
243                                                 if $(ASGCC) -V 2>/dev/null 1>/dev/null; then \
244                                                         echo $(ASGCC); \
245                                                 else echo "as" ; \
246                                                 fi\
247                                                 fi)
248                                                         
249                 LDTYPE=$(shell if $(LDPATH) -V 1>/dev/null  2>/dev/null; then \
250                                                         if $(LDPATH) -V 2>&1|grep GNU >/dev/null; \
251                                                         then echo gnu; \
252                                                         else \
253                                                         if $(LDPATH) -V 2>&1|grep Solaris >/dev/null;\
254                                                         then echo solaris; \
255                                                         else \
256                                                                 echo unknown ; \
257                                                         fi \
258                                                         fi \
259                                                 fi)
260                 ASTYPE=$(shell if $(ASPATH) -V 1>/dev/null  2>/dev/null </dev/null; \
261                                                 then \
262                                                         if $(ASPATH) -V 2>&1 </dev/null |grep GNU >/dev/null; \
263                                                         then echo gnu; \
264                                                         else \
265                                                         if $(ASPATH) -V 2>&1 </dev/null |grep Sun >/dev/null;\
266                                                         then echo solaris; \
267                                                         else \
268                                                                 echo unknown ; \
269                                                         fi \
270                                                         fi \
271                                                 fi)
272 #$(warning "using ld=$(LDPATH)/$(LDTYPE), as=$(ASPATH)/$(ASTYPE)")
273
274 endif
275 endif
276
277 # arh. specific definitions
278 ifeq ($(ARCH), i386)
279         DEFS+= -DFAST_LOCK
280 endif
281
282 ifeq ($(ARCH), sparc64)
283 ifeq    ($(CC_NAME), gcc)
284                 DEFS+= -DFAST_LOCK
285 endif
286 endif
287
288 ifeq ($(ARCH), arm)
289         DEFS+= -DFAST_LOCK
290 endif
291
292 CFLAGS=
293 # setting CFLAGS
294 ifeq ($(mode), release)
295         #if i386
296 ifeq    ($(ARCH), i386)
297                 # if gcc 
298 ifeq            ($(CC_NAME), gcc)
299                                 #common stuff
300                                 CFLAGS=-g -O9 -funroll-loops  -Wcast-align $(PROFILE) \
301                                         -Wall   \
302                         #if gcc 3.0
303 ifeq                    ($(CC_SHORTVER), 3.0)
304                                         CFLAGS+=-minline-all-stringops -malign-double \
305                                                         -falign-loops \
306                                                         -march=athlon \
307                                                         #-mcpu=athlon
308 else
309 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
310 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
311                                         for better results)
312                                         
313                                         CFLAGS+=-m486 \
314                                                         -malign-loops=4
315 else
316                                 #really old version
317 $(warning                       You are using an old and unsupported gcc \
318                                          version  ($(CC_SHORTVER)), compile at your own risk!)
319
320 endif                   # CC_SHORTVER, 2.9x
321 endif                   # CC_SHORTVER, 3.0
322
323 else            # CC_NAME, gcc
324 ifeq            ($(CC_NAME), icc)
325                         CFLAGS=-O3  -ipo -ipo_obj -unroll  $(PROFILE) \
326                                          -tpp6 -xK  #-openmp  #optimize for PIII 
327                                 # -prefetch doesn't seem to work
328                                 #( ty to inline acroos files, unroll loops,prefetch,
329                                 # optimize for PIII, use PIII instructions & vect.,
330                                 # mutlithread loops)
331 else
332                                 #other compilers
333 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
334 endif           #CC_NAME, icc
335 endif           #CC_NAME, gcc
336 endif   #ARCH, i386
337
338
339         #if sparc
340 ifeq    ($(ARCH), sparc64)
341                         #if gcc
342 ifeq            ($(CC_NAME), gcc)
343                                 #common stuff
344                                 CFLAGS=-g -O9 -funroll-loops  $(PROFILE) \
345                                         -Wall\
346                                         #-Wcast-align \
347                                         #-Wmissing-prototypes 
348                                 #if gcc 3.0
349 ifeq                    ($(CC_SHORTVER), 3.0)
350                                         #use 32bit for now
351                                         CFLAGS+= -mcpu=ultrasparc -mtune=ultrasparc  -m32  \
352                                         # -mcpu=v9 or ultrasparc? # -mtune implied by -mcpu
353                                         #-mno-epilogue #try to inline function exit code
354                                         #-mflat # omit save/restore
355                                         #-,faster-structs #faster non Sparc ABI structure copy ops
356 else                    # CC_SHORTVER, 3.0
357 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
358 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc >= 3.1 \
359                                         for better results)
360 ifneq                           ($(OS), netbsd)
361                                                 # on netbsd/sparc64,  gcc 2.95.3 does not compile
362                                                 # ser with -mv8
363                                                 CFLAGS+= -mv8 
364 endif
365 ifeq                                    ($(ASTYPE), solaris)
366                                                         CFLAGS+= -Wa,-xarch=v8plus
367 endif                                   
368 else                    #CC_SHORTVER, 2.9x
369                                 #really old version
370 $(warning                       You are using an old and unsupported gcc \
371                                          version ($(CC_SHORTVER)), compile at your own risk!)
372                                         
373                                         CFLAGS+= -mv8 
374 ifeq                                    ($(ASTYPE), solaris)
375                                                         CFLAGS+= -Wa,-xarch=v8plus
376 endif                                   
377         
378 endif                   #CC_SHORTVER, 2.9x
379 endif                   #CC_SHORTVER, 3.0
380
381 else            #CC_NAME, gcc
382 ifeq            ($(CC_NAME), suncc)
383                         CFLAGS+=-xO5 -fast -native -xarch=v8plusa -xCC \
384                                         -xc99 # C99 support
385                         # -Dinline="" # add this if cc < 5.3 (define inline as null)
386 else
387                                 #other compilers
388 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
389 endif           #CC_NAME, suncc
390 endif           #CC_NAME, gcc
391 endif   #ARCH, sparc
392
393         #if ipaq/netwinder
394 ifeq    ($(ARCH), arm)
395                 # if gcc 
396 ifeq            ($(CC_NAME), gcc)
397                                 #common stuff
398                                 CFLAGS=-O9 -funroll-loops  -Wcast-align $(PROFILE) \
399                                         -Wall   \
400                         #if gcc 3.0
401 ifeq                    ($(CC_SHORTVER), 3.0)
402                                         CFLAGS+= -mcpu=strongarm1100
403                                                         #-mcpu=athlon
404 else
405 ifeq                    ($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
406 $(warning                       Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
407                                         for better results)
408                                         
409                                         CFLAGS+=
410 else
411                                 #really old version
412 $(warning                       You are using an old and unsupported gcc \
413                                          version ($(CC_SHORTVER)), compile at your own risk!)
414
415 endif                   # CC_SHORTVER, 2.9x
416 endif                   # CC_SHORTVER, 3.0
417
418 else            # CC_NAME, gcc
419                                 #other compilers
420 $(error                         Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
421 endif           #CC_NAME, gcc
422 endif   #ARCH, i386
423
424
425         
426
427 LDFLAGS=
428 # setting LDFLAGS
429 ifeq    ($(CC_NAME), gcc)
430 ifeq            ($(ARCH), sparc64)
431 ifeq                    ($(LDTYPE), solaris)
432                                         # solaris ld
433                                         LDFLAGS+=-O2 $(PROFILE)
434                                         MOD_LDFLAGS=-G $(LDFLAGS)
435 else                    
436                                         #gcc and maybe others, on solaris, with gnu ld
437                                         LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
438                                         MOD_LDFLAGS=-shared $(LDFLAGS)
439 endif
440 else
441                         #gcc and maybe others
442                         LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
443                         MOD_LDFLAGS=-shared $(LDFLAGS)
444 endif
445 endif
446 ifeq    ($(CC_NAME), icc)
447         #gcc and maybe others
448         LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
449         MOD_LDFLAGS=-shared $(LDFLAGS)
450 endif
451 ifeq    ($(CC_NAME), suncc)
452         LDFLAGS+=-xO5 $(PROFILE)
453         MOD_LDFLAGS=-G $(LDFLAGS)
454 endif
455         # we need -fPIC -DPIC only for shared objects, we don't need them for
456         # the executable file, because it's always loaded at a fixed address
457         # -andrei
458 else    #mode,release
459 ifeq    ($(CC_NAME), gcc)
460                 CFLAGS=-g -Wcast-align $(PROFILE)
461 ifeq            ($(ARCH), sparc64)
462                         CFLAGS+= -mcpu=ultrasparc 
463 endif
464 ifeq            ($(LDTYPE), solaris)
465                         #solaris ld
466                         LDFLAGS+=-g $(PROFILE)
467                         MOD_LDFLAGS=-G $(LDFLAGS)
468 else
469                         #gnu or other ld type
470                         LDFLAGS+=-g -Wl,-E $(PROFILE)
471                         MOD_LDFLAGS=-shared $(LDFLAGS)
472 endif
473 endif
474 ifeq    ($(CC_NAME), icc)
475                 CFLAGS=-g  $(PROFILE)
476                 LDFLAGS+=-g -Wl,-E $(PROFILE)
477                 MOD_LDFLAGS=-shared $(LDFLAGS)
478 endif
479 ifeq    ($(CC_NAME), suncc)
480                 CFLAGS= -g $(PROFILE)
481                 LDFLAGS+=-g $(PROFILE)
482                 MOD_LDFLAGS=-G $(LDFLAGS)
483 endif
484
485 endif #mode=release
486
487
488 #*FLAGS used for compiling the modules
489 ifeq    ($(CC_NAME), gcc)
490 MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
491 endif
492 ifeq    ($(CC_NAME), icc)
493 MOD_CFLAGS=-Kpic $(CFLAGS)
494 endif
495 ifeq    ($(CC_NAME), suncc)
496 MOD_CFLAGS=-Kpic  $(CFLAGS)
497 endif
498
499 ifeq ($(LEX),)
500         LEX=flex
501 endif
502 ifeq ($(YACC),)
503         YACC=bison
504 endif
505 YACC_FLAGS=-d -b cfg
506 # on solaris add -lxnet (e.g. LIBS= -lxnet)
507 LIBS= -lfl -ldl -lresolv
508
509
510 #os specific stuff
511 ifeq ($(OS), linux)
512         DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN -DHAVE_SCHED_YIELD
513 endif
514
515 ifeq  ($(OS), solaris)
516         DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H -DHAVE_SCHED_YIELD
517         ifeq ($(mode), release)
518                 #use these only if you're using gcc with Solaris ld
519                 #LDFLAGS=-O2 $(PROFILE)
520                 #MOD_LDFLAGS=-O2 -G
521         else
522                 #LDFLAGS=-g $(PROFILE)
523                 #MOD_LDFLAGS=-g -G
524         endif
525
526         YACC=yacc
527
528 ifeq ($(CC_NAME), suncc)
529         LIBS= -lfast -ldl -lresolv
530 endif
531         LIBS+= -L/usr/local/lib -lfl -lxnet -lrt -lnsl 
532         # -lrt needed for sched_yield
533 endif
534
535 ifeq ($(OS), freebsd)
536         DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
537                 -DHAVE_SCHED_YIELD
538         YACC=yacc
539         LIBS= -lfl  #dlopen is in libc
540 endif
541
542 ifeq ($(OS), openbsd)
543         DEFS+=-DHAVE_SOCKADDR_SA_LEN -DDLSYM_PREFIX='"_"' -DHAVE_GETHOSTBYNAME2 \
544                 -DHAVE_UNION_SEMUN
545         # (symbols on openbsd are prefixed by "_")
546         YACC=yacc
547         # no sched_yield on openbsd unless linking with c_r (not recommended)
548         LIBS= -lfl 
549         LDFLAGS=        # openbsd ld doesn't like -O2 or -E
550 endif
551         
552 ifeq ($(OS), netbsd)
553         DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 
554         YACC=yacc
555         LIBS= -lfl 
556 endif
557
558 ifneq (,$(findstring CYGWIN, $(OS)))
559         #cygwin is the same as common
560 endif