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