Simplify autoconfiguration for Windows
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.
This commit is contained in:
parent
c3d2786f1a
commit
c02468fd69
3 changed files with 34 additions and 30 deletions
16
configure.ac
16
configure.ac
|
@ -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])
|
||||
|
|
18
m4/my_windows_api.m4
Normal file
18
m4/my_windows_api.m4
Normal file
|
@ -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])
|
||||
])
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue