]> git.pond.sub.org Git - empserver/commitdiff
Simplify autoconfiguration for Windows
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 12 Apr 2009 17:00:55 +0000 (19:00 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 13 Apr 2009 10:51:24 +0000 (12:51 +0200)
Checking Windows libraries with autoconf is cumbersome, because
linking often fails unless you include the header, and AC_SEARCH_LIBS
doesn't permit that.

Just detect the Windows API instead, with new MY_WINDOWS_API.

configure.ac
m4/my_windows_api.m4 [new file with mode: 0644]
src/client/configure.ac

index fef05085f0f50e270ee3377f593d28e2957c48d1..2faa2427900cfff797852e40869a93e0c8d78a8f 100644 (file)
@@ -63,15 +63,14 @@ else revctrl=
 fi
 AC_SUBST(revctrl,$revctrl)
 
+# Not a program, but need to check this early
+MY_WINDOWS_API
+
 
 ### Checks for libraries
 ACX_PTHREAD
+LIBS="$LIBS_SOCKETS $LIBS"
 LIB_SOCKET_NSL
-# TODO merge this into LIB_SOCKET_NSL?
-case "$host_os" in
-*mingw32)
-    LIBS="-lws2_32 $LIBS" ;;
-esac
 
 # TODO turn this into a macro?
 save_LIBS=$LIBS
@@ -123,10 +122,9 @@ if test -z "$with_pthread" || test "$with_pthread" = no; then
     if test "$ac_cv_func_makecontext" = yes; then
        empthread=LWP
     fi
-    case "$host_os" in
-    *mingw32)
-       empthread=Windows ;;
-    esac
+    if test $Windows_API = yes; then
+       empthread=Windows
+    fi
 fi
 if test -z "$empthread"; then
     AC_MSG_ERROR([No usable thread package found])
diff --git a/m4/my_windows_api.m4 b/m4/my_windows_api.m4
new file mode 100644 (file)
index 0000000..3404cdb
--- /dev/null
@@ -0,0 +1,18 @@
+AC_DEFUN([MY_WINDOWS_API],
+[
+       AC_MSG_CHECKING([whether compiling for Windows API])
+       AC_COMPILE_IFELSE(
+               [AC_LANG_SOURCE([[#ifdef _WIN32
+#Here's a nickel, kid
+#endif]])],
+               [Windows_API=no],
+               [Windows_API=yes])
+       AC_MSG_RESULT([$Windows_API])
+       if test $Windows_API = yes; then
+               AC_DEFINE([WINDOWS], 1, [Define if compiling for Windows API])
+               LIBS_SOCKETS="-lws2_32"
+       else
+               LIBS_SOCKETS=
+       fi
+       AC_SUBST([LIBS_SOCKETS])
+])
index 2dc6a67736bb900753c2fe9f1fff85f4d7de3fd6..7a74286ab08b281030468507da153e1d412d52cc 100644 (file)
@@ -47,36 +47,24 @@ AC_CONFIG_HEADERS([config.h])
 AC_PROG_CC
 AC_PROG_INSTALL
 
+# Not a program, but need to check this early
+MY_WINDOWS_API
+
 
 ### Checks for libraries.
-AC_SEARCH_LIBS([setupterm], [termlib termcap curses ncurses])
+LIBS="$LIBS_SOCKETS $LIBS"
 LIB_SOCKET_NSL
-# TODO merge this into LIB_SOCKET_NSL?
-if test "$ac_cv_search_gethostbyname" = no; then
-    dnl Can't search ws2_32 for gethostbyname using AC_SEARCH_LIBS, because
-    dnl it requires #include <winsock2.h> to work.
-    AC_MSG_CHECKING([for gethostbyname in -lws2_32])
-    save_LIBS=$LIBS
-    LIBS="-lws2_32 $LIBS"
-    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <winsock2.h>]],
-                                   [[gethostbyname ("");]])],
-                  [ws2_res=yes], [LIBS=save_LIBS ws2_res=no])
-    AC_MSG_RESULT([$ws2_res])
-fi
+AC_SEARCH_LIBS([setupterm], [termlib termcap curses ncurses])
+
 
 ### Checks for header files.
 
 
 ### Checks for typedefs, structures, and compiler characteristics.
 
-AC_MSG_CHECKING([for Windows])
-AC_COMPILE_IFELSE(
-    [AC_LANG_SOURCE([[#ifdef _WIN32
-#Here's a nickel, kid
-#endif]])],
-    [Windows_res=no],
-    [Windows_res=yes CFLAGS="$CFLAGS -mthreads"])
-AC_MSG_RESULT([$Windows_res])
+if test "$Windows_API" = yes; then
+       CFLAGS="$CFLAGS -mthreads"
+fi
 
 
 ### Checks for library functions.