Browse Source

- converted to autoconf compatible format (replaced some os specific ifdefs with HAVE_xxx a.s.o)

Andrei Pelinescu-Onciul 23 years ago
parent
commit
087d09764c
8 changed files with 51 additions and 36 deletions
  1. 1 1
      INSTALL
  2. 24 12
      Makefile.defs
  3. 6 6
      fastlock.h
  4. 6 6
      ip_addr.h
  5. 5 5
      main.c
  6. 1 3
      mem/shm_mem.c
  7. 5 3
      resolve.h
  8. 3 0
      sr_module.c

+ 1 - 1
INSTALL

@@ -4,7 +4,7 @@ $Id$
 Installation Notes
 
 Supported arhitectures: Linux/i386, Linux/armv4l, FreeBSD/i386,
-Solaris/sparc64, Win*/i386 (CYGWIN) - only the core
+Solaris/sparc64 
 (for other arhitectures the Makefile must be edited)
 
 There are various configuration options defined in the Makefile.

+ 24 - 12
Makefile.defs

@@ -12,7 +12,8 @@ EXTRAVERSION =
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
-ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/ )
+ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc/  \
+			-e s/armv4l/arm/)
 
  # install location
 PREFIX = /usr/local
@@ -126,7 +127,7 @@ YACC := $(shell echo "$${YACC}")
 #  		forking (done at the top of main_loop). Needed if you want
 #  		to use the snmp module.
 DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
-	 -DOS='"$(OS)"' -DCOMPILER='"$(CC_VER)"' \
+	 -DOS='"$(OS)"' -DCOMPILER='"$(CC_VER)"' -D__CPU_$(ARCH)\
 	 -DCFG_DIR='"$(cfg-target)"'\
 	 -DPKG_MALLOC \
 	 -DSHM_MEM  -DSHM_MMAP \
@@ -214,7 +215,7 @@ $(warning	Unknown compiler $(CC)\; supported compilers: \
 endif
 
 # find ldname (gnu or solaris)
-ifeq ($(ARCH), sparc64)
+ifeq ($(ARCH), sparc)
 ifeq ($(CC_NAME), gcc)
 		LDGCC=$(shell $(CC) -v 2>&1 | grep with-ld| \
 				   sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
@@ -245,13 +246,13 @@ ifeq ($(ARCH), i386)
 	DEFS+= -DFAST_LOCK
 endif
 
-ifeq ($(ARCH), sparc64)
+ifeq ($(ARCH), sparc)
 ifeq 	($(CC_NAME), gcc)
 		DEFS+= -DFAST_LOCK
 endif
 endif
 
-ifeq ($(ARCH), armv4l)
+ifeq ($(ARCH), arm)
 	DEFS+= -DFAST_LOCK
 endif
 
@@ -302,8 +303,8 @@ endif		#CC_NAME, gcc
 endif	#ARCH, i386
 
 
-	#if sparc64
-ifeq	($(ARCH), sparc64)
+	#if sparc
+ifeq	($(ARCH), sparc)
 			#if gcc
 ifeq		($(CC_NAME), gcc)
 				#common stuff
@@ -344,10 +345,10 @@ else
 $(error 			Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
 endif		#CC_NAME, suncc
 endif		#CC_NAME, gcc
-endif	#ARCH, sparc64
+endif	#ARCH, sparc
 
 	#if ipaq/netwinder
-ifeq	($(ARCH), armv4l)
+ifeq	($(ARCH), arm)
 		# if gcc 
 ifeq		($(CC_NAME), gcc)
 				#common stuff
@@ -383,7 +384,7 @@ endif	#ARCH, i386
 LDFLAGS=
 # setting LDFLAGS
 ifeq	($(CC_NAME), gcc)
-ifeq		($(ARCH), sparc64)
+ifeq		($(ARCH), sparc)
 ifeq			($(LDTYPE), solaris)
 					# solaris ld
 					LDFLAGS+=-O2 $(PROFILE)
@@ -414,7 +415,7 @@ endif
 else	#mode,release
 ifeq	($(CC_NAME), gcc)
 		CFLAGS=-g -Wcast-align -Winline $(PROFILE)
-ifeq		($(ARCH), sparc64)
+ifeq		($(ARCH), sparc)
 			CFLAGS+= -mcpu=ultrasparc 
 endif
 ifeq		($(LDTYPE), solaris)
@@ -462,6 +463,10 @@ YACC_FLAGS=-d -b cfg
 # on solaris add -lxnet (e.g. LIBS= -lxnet)
 LIBS= -lfl -ldl -lresolv
 
+ifneq ($(OS), solaris)
+	DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN
+endif
+
 
 #os specific stuff
 ifeq ($(OS), Linux)
@@ -469,6 +474,7 @@ ifeq ($(OS), Linux)
 endif
 
 ifeq  ($(OS), solaris)
+	DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H
 	ifeq ($(mode), release)
 		#use these only if you're using gcc with Solaris ld
 		#LDFLAGS=-O2 $(PROFILE)
@@ -488,11 +494,17 @@ endif
 endif
 
 ifeq ($(OS), freebsd)
-
+	DEFS+=-DHAVE_SOCKADDR_SA_LEN
 	YACC=yacc
 	LIBS= -lfl  #dlopen is in libc
+endif
 
+ifeq ($(OS), openbsd)
+	DEFS+=-DHAVE_SOCKADDR_SA_LEN
+	YACC=yacc
+	LIBS= -lfl  -lc_r
 endif
+	
 
 ifneq (,$(findstring CYGWIN, $(OS)))
 	#cygwin is the same as common

+ 6 - 6
fastlock.h

@@ -54,7 +54,7 @@ inline static int tsl(fl_lock_t* lock)
 {
 	int val;
 
-#ifdef __i386
+#ifdef __CPU_i386
 
 #ifdef NOSMP
 	val=0;
@@ -69,7 +69,7 @@ inline static int tsl(fl_lock_t* lock)
 		" xchg %b1, %0" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"
 	);
 #endif /*NOSMP*/
-#elif defined __sparc
+#elif defined __CPU_sparc
 	asm volatile(
 			"ldstub [%1], %0 \n\t"
 #ifndef NOSMP
@@ -78,7 +78,7 @@ inline static int tsl(fl_lock_t* lock)
 			: "=r"(val) : "r"(lock):"memory"
 	);
 	
-#elif defined __arm__
+#elif defined __CPU_arm
 	asm volatile(
 			"# here \n\t"
 			"swpb %0, %1, [%2] \n\t"
@@ -115,14 +115,14 @@ inline static void get_lock(fl_lock_t* lock)
 
 inline static void release_lock(fl_lock_t* lock)
 {
-#ifdef __i386
+#ifdef __CPU_i386
 	char val;
 	val=0;
 	asm volatile(
 		" movb $0, (%0)" : /*no output*/ : "r"(lock): "memory"
 		/*" xchg %b0, %1" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"*/
 	); 
-#elif defined __sparc
+#elif defined __CPU_sparc
 	asm volatile(
 #ifndef NOSMP
 			"membar #LoadStore | #StoreStore \n\t" /*is this really needed?*/
@@ -132,7 +132,7 @@ inline static void release_lock(fl_lock_t* lock)
 			: "r" (lock)
 			: "memory"
 	);
-#elif defined __arm__
+#elif defined __CPU_arm
 	asm volatile(
 		" str %0, [%1] \n\r" 
 		: /*no outputs*/ 

+ 6 - 6
ip_addr.h

@@ -84,7 +84,7 @@ struct socket_info{
 
 
 /* len of the sockaddr */
-#ifdef __FreeBSD__
+#ifdef HAVE_SOCKADDR_SA_LEN
 #define sockaddru_len(su)	((su).s.sa_len)
 #else
 #ifdef USE_IPV6
@@ -94,7 +94,7 @@ struct socket_info{
 #else
 #define sockaddru_len(su)	sizeof(struct sockaddr_in)
 #endif /*USE_IPV6*/
-#endif /*__FreeBSD__*/
+#endif /* HAVE_SOCKADDR_SA_LEN*/
 	
 /* inits an ip_addr with the addr. info from a hostent structure
  * ip = struct ip_addr*
@@ -217,7 +217,7 @@ static inline int init_su( union sockaddr_union* su,
 #ifdef USE_IPV6
 	case	AF_INET6:
 		memcpy(&su->sin6.sin6_addr, ip->u.addr, ip->len); 
-		#ifdef __FreeBSD__
+		#ifdef HAVE_SOCKADDR_SA_LEN
 			su->sin6.sin6_len=sizeof(struct sockaddr_in6);
 		#endif
 		su->sin6.sin6_port=port;
@@ -225,7 +225,7 @@ static inline int init_su( union sockaddr_union* su,
 #endif
 	case AF_INET:
 		memcpy(&su->sin.sin_addr, ip->u.addr, ip->len);
-		#ifdef __FreeBSD__
+		#ifdef HAVE_SOCKADDR_SA_LEN
 			su->sin.sin_len=sizeof(struct sockaddr_in);
 		#endif
 		su->sin.sin_port=port;
@@ -254,7 +254,7 @@ static inline int hostent2su( union sockaddr_union* su,
 #ifdef USE_IPV6
 	case	AF_INET6:
 		memcpy(&su->sin6.sin6_addr, he->h_addr_list[idx], he->h_length);
-		#ifdef __FreeBSD__
+		#ifdef HAVE_SOCKADDR_SA_LEN
 			su->sin6.sin6_len=sizeof(struct sockaddr_in6);
 		#endif
 		su->sin6.sin6_port=port;
@@ -262,7 +262,7 @@ static inline int hostent2su( union sockaddr_union* su,
 #endif
 	case AF_INET:
 		memcpy(&su->sin.sin_addr, he->h_addr_list[idx], he->h_length);
-		#ifdef __FreeBSD__
+		#ifdef HAVE_SOCKADDR_SA_LEN
 			su->sin.sin_len=sizeof(struct sockaddr_in);
 		#endif
 		su->sin.sin_port=port;

+ 5 - 5
main.c

@@ -48,7 +48,7 @@
 
 #include <sys/ioctl.h>
 #include <net/if.h>
-#ifdef __sun
+#ifdef HAVE_SYS_SOCKIO_H
 #include <sys/sockio.h>
 #endif
 
@@ -82,7 +82,7 @@
 
 static char id[]="@(#) $Id$";
 static char version[]=  NAME " " VERSION " (" ARCH "/" OS ")" ;
-static char compiled[]= __TIME__ " " __DATE__ ;
+static char compiled[]= __TIME__ __DATE__ ;
 static char flags[]=
 "STATS:"
 #ifdef STATS
@@ -389,7 +389,7 @@ int daemonize(char*  name)
 	}
 	
 	if (log_stderr==0)
-		openlog(name, LOG_PID|LOG_CONS, LOG_LOCAL1 /*LOG_DAEMON*/);
+		openlog(name, LOG_PID|LOG_CONS, LOG_DAEMON);
 		/* LOG_CONS, LOG_PERRROR ? */
 	return  0;
 
@@ -757,7 +757,7 @@ int add_interfaces(char* if_name, int family, unsigned short port)
 	struct ip_addr addr;
 	int ret;
 
-#ifdef __FreeBSD__
+#ifdef HAVE_SOCKADDR_SA_LEN
 	#define MAX(a,b) ( ((a)>(b))?(a):(b))
 #endif
 	/* ipv4 or ipv6 only*/
@@ -787,7 +787,7 @@ int add_interfaces(char* if_name, int family, unsigned short port)
 	last=(char*)ifc.ifc_req+ifc.ifc_len;
 	for(ifr=ifc.ifc_req; (char*)ifr<last;
 			ifr=(struct ifreq*)((char*)ifr+sizeof(ifr->ifr_name)+
-			#ifdef  __FreeBSD__
+			#ifdef  HAVE_SOCKADDR_SA_LEN
 				MAX(ifr->ifr_addr.sa_len, sizeof(struct sockaddr))
 			#else
 				( (ifr->ifr_addr.sa_family==AF_INET)?

+ 1 - 3
mem/shm_mem.c

@@ -53,10 +53,9 @@
 
 
 /* define semun */
-#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
+#if defined(HAVE_UNION_SEMUN) && !defined(_SEM_SEMUN_UNDEFINED)
 	/* union semun is defined by including <sys/sem.h> */
 #else
-#ifndef __FreeBSD__
 	/* according to X/OPEN we have to define it ourselves */
 	union semun {
 		int val;                    /* value for SETVAL */
@@ -65,7 +64,6 @@
 		struct seminfo *__buf;      /* buffer for IPC_INFO */
 	};
 #endif
-#endif
 
 
 

+ 5 - 3
resolve.h

@@ -250,7 +250,7 @@ struct hostent* sip_resolvehost(char* name, unsigned short* port);
 static inline struct hostent* resolvehost(const char* name)
 {
 	static struct hostent* he=0;
-#ifdef __sun
+#ifdef HAVE_GETIPNODEBYNAME 
 	int err;
 	static struct hostent* he2=0;
 #endif
@@ -275,14 +275,16 @@ static inline struct hostent* resolvehost(const char* name)
 #ifdef USE_IPV6
 	if(he==0){
 		/*try ipv6*/
-	#ifdef __sun
+	#ifdef HAVE_GETHOSTBYNAME2
+		he=gethostbyname2(name, AF_INET6);
+	#elif defined HAVE_GETIPNODEBYNAME
 		/* on solaris 8 getipnodebyname has a memory leak,
 		 * after some time calls to it will fail with err=3
 		 * solution: patch your solaris 8 installation */
 		if (he2) freehostent(he2);
 		he=he2=getipnodebyname(name, AF_INET6, 0, &err);
 	#else
-		he=gethostbyname2(name, AF_INET6);
+		#error neither gethostbyname2 or getipnodebyname present
 	#endif
 	}
 #endif

+ 3 - 0
sr_module.c

@@ -166,6 +166,9 @@ int load_module(char* path)
 	struct module_exports* exp;
 	struct sr_module* t;
 	
+#ifndef RTLD_NOW
+#define RTLD_NOW DL_LAZY
+#endif
 	handle=dlopen(path, RTLD_NOW); /* resolve all symbols now */
 	if (handle==0){
 		LOG(L_ERR, "ERROR: load_module: could not open module <%s>: %s\n",