Makefile.defs
e0a6ffa6
 # $Id$
247c2b65
 #
 # makefile defs (CC, LD,a.s.o)
 #
 
 
 #version number
 VERSION = 0
 PATCHLEVEL = 8
9b47a45c
 SUBLEVEL = 7
0bafb279
 EXTRAVERSION = -16
247c2b65
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
0bafb279
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
b2dec9c6
 ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/ )
247c2b65
 
db1b5017
 prefix = /usr/local
 cfg-prefix = $(prefix)
 bin-prefix = $(prefix)
 modules-prefix= $(prefix)
 doc-prefix = $(prefix)
6ac71d10
 man-prefix = $(prefix)
db1b5017
 
 # dirs
 cfg-dir = etc/ser/
 bin-dir = sbin/
 modules-dir = lib/ser/modules/
6ac71d10
 doc-dir = share/doc/ser/
 man-dir = share/man/
db1b5017
 
0bafb279
 
 ifeq ($(OS), solaris)
 #use GNU versions
 INSTALL = ginstall
 TAR = gtar
 else
a18366db
 INSTALL = install 
0bafb279
 TAR= tar
 endif
db1b5017
 INSTALL-CFG = $(INSTALL) -m 644
 INSTALL-BIN = $(INSTALL) -m 755
 INSTALL-MODULES = $(INSTALL) -m 755
 INSTALL-DOC = $(INSTALL) -m 644
6ac71d10
 INSTALL-MAN = $(INSTALL) -m 644
db1b5017
 
 
247c2b65
 # compile-time options
efd6c2fe
 #
 # -DSTATS
 #		allows to print out number of packets processed on CTRL-C;
247c2b65
 # 		implementation still nasty and reports per-process
efd6c2fe
 # -DNO_DEBUG
247c2b65
 #		turns off some of the debug messages (DBG(...)).
efd6c2fe
 # -DNO_LOG
247c2b65
 #		completely turns of all the logging (and DBG(...))
efd6c2fe
 # -DEXTRA_DEBUG
247c2b65
 #		compiles in some extra debugging code
efd6c2fe
 # -DDNS_IP_HACK
247c2b65
 #		faster ip address resolver for ip strings (e.g "127.0.0.1")
efd6c2fe
 # -DSHM_MEM
247c2b65
 #		compiles in shared mem. support, needed by some modules and
 #		by USE_SHM_MEM
dcb5f364
 # -DSHM_MMAP
 #		use mmap instead of SYSV shared memory
efd6c2fe
 # -DPKG_MALLOC
247c2b65
 #		uses a faster malloc (exclusive w/ USE_SHM_MEM)
efd6c2fe
 # -DUSE_SHM_MEM
 #		all pkg_malloc => shm_malloc (most mallocs use a common sh.
247c2b65
 #		mem. segment); don't define PKG_MALLOC if you want this!
 # -DDBG_QM_MALLOC
 #		qm_malloc debug code, will cause pkg_malloc and shm_malloc
 #		to keep and display lot of debuging information: file name,
 #		function, line number of malloc/free call for each block,
 #		extra error checking (trying to free the same pointer
 #		twice, trying to free a pointer alloc'ed with a different
 #		malloc etc.)
dda9dab1
 # -DVQ_MALLOC
 #		additional option to PKG_MALLOC which utilizes a fater then
 #		qm version
b2dec9c6
 #		(not true anymore, q_malloc performs approx. the same)
 # -DF_MALLOC
 #		an even faster malloc, not recommended for debugging
ea6721d7
 # -DDBG_MALLOC
 #		issues additional debugging information if lock/unlock is called
b2dec9c6
 # -DFAST_LOCK
 #		uses fast arhitecture specific locking (see the arh. specific section)
30f1f956
 # -DBUSY_WAIT
 #		uses busy waiting on the lock
 # -DADAPTIVE_WAIT
 #		try busy waiting for a while and if the lock is still held go to
 #		force reschedule
 # -DADAPTIVE_WAIT_LOOPS=number
 #		number of loops we busy wait, after "number" loops have elapsed we 
 #		force a reschedule
 # -DNOSMP
 #		don't use smp compliant locking (faster but won't work on SMP machines)
 #		(not yet enabled)
caf80ae6
 # -DNO_PINGTEL_TAG_HACK
 #		if enabled, To-header-field will be less liberal and will not accept
 #		'tag=' (tag parameter with equal sign and without value); it is called
 #		this way because such message was sighted from a Pingtel phone
40ea70f4
 # -DWITH_SNMP_MOD
 #  		if enabled, allows forking of the snmp agent just before child
 #  		forking (done at the top of main_loop). Needed if you want
 #  		to use the snmp module.
dda9dab1
 
404073d3
 DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
b2dec9c6
 	 -DOS='"$(OS)"' -DCOMPILER='"$(CC_VER)"'\
9b47a45c
 	 -DPKG_MALLOC \
51eadd0c
 	 -DSHM_MEM  -DSHM_MMAP \
 	 -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 \
ba506d03
 	 -DDNS_IP_HACK \
a18366db
 	 -DUSE_IPV6 \
1e8e3e0b
 	 -DF_MALLOC \
 	 -DNO_DEBUG \
e5bcdb99
 	 #-DDBG_QM_MALLOC \
855c2e68
 	 #-DVQ_MALLOC  
caf80ae6
 	 #-DCONTACT_BUG
 	 #-DDBG_LOCK
1f377e97
 	 #-DNO_DEBUG \
db829953
 	 #-DNOSMP \
e5bcdb99
 	 #-DEXTRA_DEBUG \
 	 #-DUSE_SHM_MEM \
 	 #-DSTATS \
40ea70f4
 	 #-DWITH_SNMP_MOD \
caf80ae6
 	 #-DNO_LOG
b2dec9c6
 
 #PROFILE=  -pg #set this if you want profiling
c64e586d
 #mode = debug
 mode = release
247c2b65
 
 # platform dependent settings
 
 
 #common
da3257c8
 CC=gcc
b2dec9c6
 LD= $(CC)
51eadd0c
 CC_LONGVER=$(shell if  $(CC) -v 2>/dev/null; then \
 						$(CC) -v 2>&1 ;\
 					else \
 						$(CC) -V 2>&1 ; \
 					fi )
3b06abf2
 MKTAGS=ctags -R .
247c2b65
 
11ece359
 #find-out the compiler's name
 
 ifneq (,$(findstring gcc, $(CC_LONGVER)))
 	CC_NAME=gcc
65531ed9
 	CC_VER=$(CC) $(shell $(CC) --version|head -1| \
6d244fb5
 				 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/')
 	# sun sed is a little brain damaged => this complicated expression
51eadd0c
 	MKDEP=$(CC) -MM $(DEFS)
11ece359
 	#transform gcc version into 2.9x or 3.0
13623729
 	CC_SHORTVER=$(shell echo "$(CC_VER)" | cut -d" " -f 2| \
11ece359
 				 sed -e 's/[^0-9]*-\(.*\)/\1/'| \
13623729
 				 sed -e 's/2\.9.*/2.9x/' -e 's/3\..\..*/3.0/' -e \
 				 	's/3\../3.0/')
51eadd0c
 endif
 
 ifneq (, $(findstring Sun, $(CC_LONGVER)))
 	CC_NAME=suncc
13623729
 	CC_SHORTVER=$(shell echo "$(CC_LONGVER)"|head -1| \
51eadd0c
 					sed -e 's/.*\([0-9]\.[0-9]\).*/\1/g' )
 	CC_VER=$(CC) $(CC_SHORTVER)
 	MKDEP=$(CC) -xM1 $(DEFS)
 endif
 
9c61e9f9
 ifneq (, $(findstring Intel(R) C++ Compiler, $(CC_LONGVER)))
 	# very nice: gcc compatible
 	CC_NAME=icc
 	CC_FULLVER=$(shell echo "$(CC_LONGVER)"|head -1| \
 					sed -e 's/.*Version \([0-9]\.[0-9]\.[0-9]*\).*/\1/g' )
 	CC_SHORTVER=$(shell echo "$(CC_FULLVER)" | cut -d. -f1,2 )
 	CC_VER=$(CC) $(CC_FULLVER)
 	MKDEP=$(CC) -MM $(DEFS)
 endif
 
 
51eadd0c
 ifeq (,$(CC_NAME))
 #not found
11ece359
 	CC_NAME=$(CC)
 	CC_SHORTVER=unknown
51eadd0c
 	CC_VER=unknown
 	MKDEP=gcc -MM $(DEFS)
9c61e9f9
 $(warning	Unknown compiler $(CC)\; supported compilers: \
 			gcc, sun cc, intel icc )
11ece359
 endif
 
629fca1e
 # find ldname (gnu or solaris)
 ifeq ($(ARCH), sparc64)
 ifeq ($(CC_NAME), gcc)
 		LDGCC=$(shell $(CC) -v 2>&1 | grep with-ld| \
 				   sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
 		LDPATH=$(shell  if [ -z "$(LDGCC)" ] ; then echo "ld" ;\
 						else \
 						if $(LDGCC) -V 2>/dev/null 1>/dev/null; then \
 							echo $(LDGCC); \
 						else echo "ld" ; \
 						fi\
 						fi)
 						
 		LDTYPE=$(shell if $(LDPATH) -V 1>/dev/null  2>/dev/null; then \
 							if $(LDPATH) -V 2>&1|grep GNU >/dev/null; \
 							then echo gnu; \
 							else \
 							if $(LDPATH) -V 2>&1|grep Solaris >/dev/null;\
 							then echo solaris; \
 							else \
 								echo unknown ; \
 							fi \
 							fi \
 						fi)
 endif
 endif
11ece359
 
43fcad56
 # arh. specific definitions
 ifeq ($(ARCH), i386)
 	DEFS+= -DFAST_LOCK
 endif
 
 ifeq ($(ARCH), sparc64)
 ifeq 	($(CC_NAME), gcc)
 		DEFS+= -DFAST_LOCK
 endif
 endif
 
733a6458
 ifeq ($(ARCH), armv4l)
 	DEFS+= -DFAST_LOCK
 endif
 
 
43fcad56
 
11ece359
 # setting CFLAGS
247c2b65
 ifeq ($(mode), release)
11ece359
 	#if i386
 ifeq	($(ARCH), i386)
 		# if gcc 
 ifeq		($(CC_NAME), gcc)
51eadd0c
 				#common stuff
 				CFLAGS=-O9 -funroll-loops  -Wcast-align $(PROFILE) -Winline\
a1e5c977
 					-Wall   \
11ece359
 			#if gcc 3.0
 ifeq			($(CC_SHORTVER), 3.0)
 					CFLAGS+=-minline-all-stringops -malign-double \
65531ed9
 							-falign-loops \
11ece359
 							-march=athlon \
 							#-mcpu=athlon
 else
 ifeq			($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
 $(warning 			Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
 					for better results)
 					
 					CFLAGS+=-m486 \
 							-malign-loops=4
 else
 				#really old version
 $(warning			You are using an old and unsupported gcc \
65531ed9
 					 version  ($(CC_SHORTVER)), compile at your own risk!)
11ece359
 
 endif			# CC_SHORTVER, 2.9x
 endif			# CC_SHORTVER, 3.0
 
 else		# CC_NAME, gcc
9c61e9f9
 ifeq		($(CC_NAME), icc)
 			CFLAGS=-O3  -ipo -ipo_obj -unroll  $(PROFILE) \
 					 -tpp6 -xK  #-openmp  #optimize for PIII 
 				# -prefetch doesn't seem to work
 				#( ty to inline acroos files, unroll loops,prefetch,
 				# optimize for PIII, use PIII instructions & vect.,
 				# mutlithread loops)
 else
11ece359
 				#other compilers
 $(error 			Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
9c61e9f9
 endif		#CC_NAME, icc
11ece359
 endif		#CC_NAME, gcc
 endif	#ARCH, i386
 
 
 	#if sparc64
 ifeq	($(ARCH), sparc64)
 			#if gcc
 ifeq		($(CC_NAME), gcc)
51eadd0c
 				#common stuff
219627a2
 				CFLAGS=-O9 -funroll-loops  $(PROFILE) -Winline\
462cf6f9
 					-Wall\
 					#-Wcast-align \
 					#-Wmissing-prototypes 
11ece359
 				#if gcc 3.0
 ifeq			($(CC_SHORTVER), 3.0)
 					#use 32bit for now
e7a9bd30
 					CFLAGS+= -mcpu=ultrasparc -mtune=ultrasparc  -m32  \
11ece359
 					# -mcpu=v9 or ultrasparc? # -mtune implied by -mcpu
 					#-mno-epilogue #try to inline function exit code
 					#-mflat # omit save/restore
 					#-,faster-structs #faster non Sparc ABI structure copy ops
 else			# CC_SHORTVER, 3.0
 ifeq			($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
 $(warning 			Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
 					for better results)
 					
 					CFLAGS+= -mv8 -Wa,-xarch=v8plus
 else			#CC_SHORTVER, 2.9x
 				#really old version
 $(warning			You are using an old and unsupported gcc \
 					 version ($(CC_SHORTVER)), compile at your own risk!)
 					
 					CFLAGS+= -mv8 -Wa,-xarch=v8plus
 endif			#CC_SHORTVER, 2.9x
 endif			#CC_SHORTVER, 3.0
 
 else		#CC_NAME, gcc
51eadd0c
 ifeq		($(CC_NAME), suncc)
 			CFLAGS+=-xO5 -fast -native -xarch=v8plusa -xCC \
 					-xc99 # C99 support
 			# -Dinline="" # add this if cc < 5.3 (define inline as null)
 else
11ece359
 				#other compilers
 $(error 			Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
51eadd0c
 endif		#CC_NAME, suncc
11ece359
 endif		#CC_NAME, gcc
 endif	#ARCH, sparc64
 
8c141481
 	#if ipaq/netwinder
 ifeq	($(ARCH), armv4l)
 		# if gcc 
 ifeq		($(CC_NAME), gcc)
 				#common stuff
 				CFLAGS=-O9 -funroll-loops  -Wcast-align $(PROFILE) -Winline\
 					-Wall   \
 			#if gcc 3.0
 ifeq			($(CC_SHORTVER), 3.0)
 					CFLAGS+= -mcpu=strongarm1100
 							#-mcpu=athlon
 else
 ifeq			($(CC_SHORTVER), 2.9x) #older gcc version (2.9[1-5])
 $(warning 			Old gcc detected ($(CC_SHORTVER)), use  gcc 3.0.x \
 					for better results)
 					
 					CFLAGS+=
 else
 				#really old version
 $(warning			You are using an old and unsupported gcc \
 					 version ($(CC_SHORTVER)), compile at your own risk!)
 
 endif			# CC_SHORTVER, 2.9x
 endif			# CC_SHORTVER, 3.0
 
 else		# CC_NAME, gcc
 				#other compilers
 $(error 			Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
 endif		#CC_NAME, gcc
 endif	#ARCH, i386
 
 
 	
11ece359
 
 
 # setting LDFLAGS
51eadd0c
 ifeq	($(CC_NAME), gcc)
629fca1e
 ifeq		($(ARCH), sparc64)
 ifeq			($(LDTYPE), solaris)
 					# solaris ld
 					LDFLAGS+=-O2 $(PROFILE)
 					MOD_LDFLAGS=-G $(LDFLAGS)
 else			
 					#gcc and maybe others, on solaris, with gnu ld
 					LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
 					MOD_LDFLAGS=-shared $(LDFLAGS)
 endif
 else
 			#gcc and maybe others
 			LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
 			MOD_LDFLAGS=-shared $(LDFLAGS)
 endif
51eadd0c
 endif
9c61e9f9
 ifeq	($(CC_NAME), icc)
 	#gcc and maybe others
 	LDFLAGS+=-Wl,-O2 -Wl,-E $(PROFILE) 
629fca1e
 	MOD_LDFLAGS=-shared $(LDFLAGS)
9c61e9f9
 endif
51eadd0c
 ifeq	($(CC_NAME), suncc)
 	LDFLAGS+=-xO5 $(PROFILE)
629fca1e
 	MOD_LDFLAGS=-G $(LDFLAGS)
51eadd0c
 endif
247c2b65
 	# we need -fPIC -DPIC only for shared objects, we don't need them for
 	# the executable file, because it's always loaded at a fixed address
 	# -andrei
11ece359
 else	#mode,release
51eadd0c
 ifeq	($(CC_NAME), gcc)
9b47a45c
 		CFLAGS=-g -Wcast-align -Winline $(PROFILE)
629fca1e
 ifeq		($(ARCH), sparc64)
 			CFLAGS+= -mcpu=ultrasparc 
 endif
 ifeq		($(LDTYPE), solaris)
 			#solaris ld
 			LDFLAGS+=-g $(PROFILE)
 			MOD_LDFLAGS=-G $(LDFLAGS)
 else
 			#gnu or other ld type
 			LDFLAGS+=-g -Wl,-E $(PROFILE)
 			MOD_LDFLAGS=-shared $(LDFLAGS)
 endif
51eadd0c
 endif
9c61e9f9
 ifeq	($(CC_NAME), icc)
 		CFLAGS=-g  $(PROFILE)
 		LDFLAGS+=-g -Wl,-E $(PROFILE)
629fca1e
 		MOD_LDFLAGS=-shared $(LDFLAGS)
9c61e9f9
 endif
51eadd0c
 ifeq	($(CC_NAME), suncc)
 		CFLAGS= -g $(PROFILE)
 		LDFLAGS+=-g $(PROFILE)
629fca1e
 		MOD_LDFLAGS=-G $(LDFLAGS)
51eadd0c
 endif
 
11ece359
 endif #mode=release
 
247c2b65
 
 #*FLAGS used for compiling the modules
51eadd0c
 ifeq	($(CC_NAME), gcc)
247c2b65
 MOD_CFLAGS=-fPIC -DPIC $(CFLAGS)
51eadd0c
 endif
9c61e9f9
 ifeq	($(CC_NAME), icc)
 MOD_CFLAGS=-Kpic $(CFLAGS)
 endif
51eadd0c
 ifeq	($(CC_NAME), suncc)
 MOD_CFLAGS=-Kpic  $(CFLAGS)
 endif
247c2b65
 
 LEX=flex
 YACC=bison
 YACC_FLAGS=-d -b cfg
 # on linux and freebsd keep it empty (e.g. LIBS= )
 # on solaris add -lxnet (e.g. LIBS= -lxnet)
1b71270a
 LIBS=-lfl -ldl -lresolv
247c2b65
 
 
11ece359
 #os specific stuff
b2dec9c6
 ifeq ($(OS), Linux)
11ece359
 	#same as common
247c2b65
 endif
11ece359
 
0bafb279
 ifeq  ($(OS), solaris)
7c0265cc
 	ifeq ($(mode), release)
687e82fe
 		#use these only if you're using gcc with Solaris ld
db829953
 		#LDFLAGS=-O2 $(PROFILE)
 		#MOD_LDFLAGS=-O2 -G
7c0265cc
 	else
db829953
 		#LDFLAGS=-g $(PROFILE)
 		#MOD_LDFLAGS=-g -G
7c0265cc
 	endif
247c2b65
 
11ece359
 	YACC=yacc
51eadd0c
 
 ifeq ($(CC_NAME), suncc)
e998c342
 	LIBS=-lfast -lresolv
51eadd0c
 endif
629fca1e
 	LIBS+=-ldl -L/usr/local/lib -L/usr/lib/mysql -lfl -lxnet -lrt -lnsl
51eadd0c
 	# -lrt needed for sched_yield
247c2b65
 endif
11ece359
 
0bafb279
 ifeq ($(OS), freebsd)
247c2b65
 
11ece359
 	YACC=yacc
 	LIBS= -lfl  #dlopen is in libc
247c2b65
 
 endif
 
11ece359
 ifneq (,$(findstring CYGWIN, $(OS)))
 	#cygwin is the same as common
247c2b65
 endif