From 04f8402c636b06a3b3ed3c109b86a5cacf7b5318 Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Thu, 24 Apr 2008 07:29:24 -0400 Subject: [PATCH] Update Win32 builds to mostly work under Cygwin. Makefile.win32: Add -mno-cygwin to LDFLAGS so native Cygwin builds work. configure.in: Look for stdint.h, localtime() and --with-win32. src/compat.c: Remove "extern" modifiers on function definitions. Only implement localtime_r() if we have localtime() too. src/compat.h: Include stdint.h if we have it; define LINE_MAX if needed. Also define NI_NUMERICHOST for the benefits of getnameinfo(). src/config.h.win32: Resynchronize with config.h.in; set WITH_IOSET_SELECT and WITH_PROTOCOL_P10. --- Makefile.win32 | 3 ++- configure.in | 14 ++++++++++++-- src/compat.c | 26 ++++++++++++++++---------- src/compat.h | 17 ++++++++++++++--- src/config.h.win32 | 37 +++++++++++++++++++++++++++++-------- 5 files changed, 73 insertions(+), 24 deletions(-) diff --git a/Makefile.win32 b/Makefile.win32 index 24c2419..825b92b 100644 --- a/Makefile.win32 +++ b/Makefile.win32 @@ -6,6 +6,7 @@ VPATH=. # CC=i586-mingw32msvc-cc CPPFLAGS=-I$(VPATH) -Isrc CFLAGS=-mno-cygwin -W -Wall -O2 +LDFLAGS=-mno-cygwin EXE_EXT=.exe LIBS=-lws2_32 @@ -64,7 +65,7 @@ SRVX_OBJS = \ $(addsuffix .o,$(addprefix src/mod-,$(MODULES))) srvx$(EXE_EXT): src/config.h src/modules-list.h $(RX_OBJS) $(SRVX_OBJS) - $(CC) -o $@ $(RX_OBJS) $(SRVX_OBJS) $(LIBS) + $(CC) -o $@ $(LDFLAGS) $(RX_OBJS) $(SRVX_OBJS) $(LIBS) src/config.h: $(VPATH)/src/config.h.win32 cp $< $@ src/modules-list.h: diff --git a/configure.in b/configure.in index 30be5ea..3bc1459 100644 --- a/configure.in +++ b/configure.in @@ -69,7 +69,7 @@ AC_HEADER_TIME AC_STRUCT_TM dnl Would rather not bail on headers, BSD has alot of the functions elsewhere. -Jedi -AC_CHECK_HEADERS(fcntl.h malloc.h netdb.h arpa/inet.h netinet/in.h sys/resource.h sys/timeb.h sys/times.h sys/param.h sys/socket.h sys/time.h sys/types.h sys/wait.h unistd.h getopt.h memory.h regex.h arpa/inet.h sys/mman.h sys/stat.h dirent.h sys/epoll.h sys/event.h,,) +AC_CHECK_HEADERS(fcntl.h malloc.h netdb.h arpa/inet.h netinet/in.h sys/resource.h sys/timeb.h sys/times.h sys/param.h sys/socket.h sys/time.h sys/types.h sys/wait.h unistd.h getopt.h memory.h regex.h arpa/inet.h sys/mman.h sys/stat.h dirent.h sys/epoll.h sys/event.h stdint.h,,) dnl portability stuff, hurray! -Jedi AC_CHECK_MEMBER([struct sockaddr.sa_len], @@ -83,7 +83,7 @@ AC_CHECK_MEMBER([struct addrinfo.ai_flags], #include ]) dnl We have fallbacks in case these are missing, so just check for them. -AC_CHECK_FUNCS(freeaddrinfo getaddrinfo gai_strerror getnameinfo getpagesize memcpy memset strdup strerror strsignal localtime_r setrlimit getopt getopt_long regcomp regexec regfree sysconf inet_aton epoll_create kqueue kevent select gettimeofday times GetProcessTimes mprotect,,) +AC_CHECK_FUNCS(freeaddrinfo getaddrinfo gai_strerror getnameinfo getpagesize memcpy memset strdup strerror strsignal localtime localtime_r setrlimit getopt getopt_long regcomp regexec regfree sysconf inet_aton epoll_create kqueue kevent select gettimeofday times GetProcessTimes mprotect,,) dnl Check for the fallbacks for functions missing above. if test $ac_cv_func_gettimeofday = no; then @@ -266,6 +266,16 @@ if test "x$withval" = xyes ; then IOMUXES="$IOMUXES kevent" fi +AC_ARG_WITH([win32], +[ --with-win32 Enables the Win32 I/O backend], +[], +[withval="no"]) +if test "x$withval" = xyes ; then + AC_DEFINE(WITH_IOSET_WIN32, 1, [Define if using the Win32 I/O backend]) + MODULE_OBJS="$MODULE_OBJS ioset-win32.\$(OBJEXT)" + IOMUXES="$IOMUXES win32" +fi + IOMUXES=`echo $IOMUXES | sed 's/^ +//'` if test "x$IOMUXES" = "x" ; then AC_MSG_ERROR([No supported I/O multiplexing backend found]) diff --git a/src/compat.c b/src/compat.c index 2035b85..65ffada 100644 --- a/src/compat.c +++ b/src/compat.c @@ -16,7 +16,7 @@ #endif #if !defined(HAVE_GETTIMEOFDAY) && defined(HAVE_FTIME) -extern int gettimeofday(struct timeval * tv, struct timezone * tz) +int gettimeofday(struct timeval * tv, struct timezone * tz) { if (!tv) { @@ -35,8 +35,8 @@ extern int gettimeofday(struct timeval * tv, struct timezone * tz) } #endif -#ifndef HAVE_GETLOCALTIME_R -extern struct tm *localtime_r(const time_t *timep, struct tm *result) +#if !defined(HAVE_GETLOCALTIME_R) && defined(HAVE_LOCALTIME) +struct tm *localtime_r(const time_t *timep, struct tm *result) { memcpy(result, localtime(timep), sizeof(*result)); return result; @@ -44,7 +44,7 @@ extern struct tm *localtime_r(const time_t *timep, struct tm *result) #endif #ifndef HAVE_MEMCPY -extern void * memcpy(void * dest, void const * src, unsigned long n) +void * memcpy(void * dest, void const * src, unsigned long n) { /* very slow, your fault for not having memcpy()*/ unsigned char * td=dest; @@ -62,7 +62,7 @@ extern void * memcpy(void * dest, void const * src, unsigned long n) #ifndef HAVE_MEMSET /* very slow, deal with it */ -extern void * memset(void * dest, int c, unsigned long n) +void * memset(void * dest, int c, unsigned long n) { unsigned char * temp=dest; unsigned long i; @@ -77,7 +77,7 @@ extern void * memset(void * dest, int c, unsigned long n) #endif #ifndef HAVE_STRDUP -extern char * strdup(char const * str) +char * strdup(char const * str) { char * out; @@ -91,7 +91,7 @@ extern char * strdup(char const * str) #endif #ifndef HAVE_STRERROR -extern char const * strerror(int errornum) +char const * strerror(int errornum) { if (errornum==0) return "No error"; @@ -407,8 +407,6 @@ int getaddrinfo(const char *node, const char *service, const struct addrinfo *hi return 0; } -/* TODO: implement fallback getnameinfo() */ - void freeaddrinfo(struct addrinfo *res) { struct addrinfo *next; @@ -417,7 +415,6 @@ void freeaddrinfo(struct addrinfo *res) free(res); } } - #endif #ifndef HAVE_GAI_STRERROR @@ -464,3 +461,12 @@ const char *gai_strerror(int errcode) return "Unknown GAI_* error"; } #endif + +#ifndef HAVE_GETNAMEINFO +int getnameinfo(const struct sockaddr *sa, socklen_t salen, + char *host, size_t hostlen, + char *serv, size_t servlen, int flags) +{ + /* TODO: implement fallback getnameinfo() */ +} +#endif diff --git a/src/compat.h b/src/compat.h index 40b17ba..66a1fd8 100644 --- a/src/compat.h +++ b/src/compat.h @@ -57,6 +57,10 @@ char *alloca(); #include #endif +#ifdef HAVE_STDINT_H +#include +#endif + #ifdef HAVE_NETDB_H #include #endif @@ -75,6 +79,11 @@ char *alloca(); #include #endif +/* Cygwin (for example) doesn't define LINE_MAX, although mingw does. */ +#if !defined(LINE_MAX) +# define LINE_MAX 2048 +#endif + #ifdef HAVE_VA_COPY #define VA_COPY(DEST, SRC) va_copy(DEST, SRC) #elif HAVE___VA_COPY @@ -130,17 +139,19 @@ struct addrinfo { #endif /* !defined(HAVE_STRUCT_ADDRINFO) */ #ifndef HAVE_GETADDRINFO - int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res); -int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags); void freeaddrinfo(struct addrinfo *res); - #endif #ifndef HAVE_GAI_STRERROR const char *gai_strerror(int errcode); #endif +#ifndef HAVE_GETNAMEINFO +#define NI_NUMERICHOST 1 +int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags); +#endif + #ifndef EINPROGRESS # ifdef WSAEINPROGRESS # define EINPROGRESS WSAEINPROGRESS diff --git a/src/config.h.win32 b/src/config.h.win32 index eabe16f..bb08ba2 100644 --- a/src/config.h.win32 +++ b/src/config.h.win32 @@ -55,6 +55,9 @@ /* Define to 1 if you have the `ftime' function. */ #define HAVE_FTIME 1 +/* Define to 1 if you have the `gai_strerror' function. */ +#define HAVE_GAI_STRERROR 1 + /* Define to 1 if you have the header file. */ #undef HAVE_GC_GC_H @@ -64,9 +67,6 @@ /* Define to 1 if you have the `getnameinfo' function. */ #define HAVE_GETNAMEINFO 1 -/* Define to 1 if you have the `getnameinfo' function. */ -#define HAVE_GAI_STRERROR 1 - /* Define to 1 if you have the `getopt' function. */ #undef HAVE_GETOPT @@ -91,6 +91,12 @@ /* Define to 1 if you have the header file. */ #define HAVE_INTTYPES_H 1 +/* Define to 1 if you have the `kevent' function. */ +#undef HAVE_KEVENT + +/* Define to 1 if you have the `kqueue' function. */ +#undef HAVE_KQUEUE + /* Define to 1 if you have the `dl' library (-ldl). */ #undef HAVE_LIBDL @@ -133,6 +139,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MPATROL_H +/* Define to 1 if you have the `mprotect' function. */ +#undef HAVE_MPROTECT + /* Define to 1 if you have the header file. */ #undef HAVE_NETDB_H @@ -152,7 +161,7 @@ #undef HAVE_REGFREE /* Define to 1 if you have the `select' function. */ -#undef HAVE_SELECT +#define HAVE_SELECT 1 /* Define to 1 if you have the `setrlimit' function. */ #undef HAVE_SETRLIMIT @@ -208,6 +217,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_EPOLL_H +/* Define to 1 if you have the header file. */ +#undef HAVE_SYS_EVENT_H + /* Define to 1 if you have the header file. */ #undef HAVE_SYS_MMAN_H @@ -294,14 +306,17 @@ /* Version number of package */ #define VERSION 1.4 -/* Define if using the Win32 I/O backend */ -#define WITH_IOSET_WIN32 1 - /* Define if using the epoll I/O backend */ #undef WITH_IOSET_EPOLL +/* Define if using the kevent I/O backend */ +#undef WITH_IOSET_KEVENT + /* Define if using the select() I/O backend */ -#undef WITH_IOSET_SELECT +#define WITH_IOSET_SELECT 1 + +/* Define if using the Win32 I/O backend */ +#define WITH_IOSET_WIN32 1 /* Define if using the Boehm GC to garbage collect and check memory leaks */ #undef WITH_MALLOC_BOEHM_GC @@ -321,6 +336,12 @@ /* Define if using the system's malloc */ #undef WITH_MALLOC_SYSTEM +/* Define if using the Bahamut dialect of IRC */ +#undef WITH_PROTOCOL_BAHAMUT + +/* Define if using the P10 dialect of IRC */ +#define WITH_PROTOCOL_P10 1 + /* Define to empty if `const' does not conform to ANSI C. */ #undef const -- 2.20.1