win32 build fixes

This commit is contained in:
Danny Robson 2016-04-05 11:11:19 +10:00
parent 25520b6097
commit 815e027b24
10 changed files with 212 additions and 66 deletions

View File

@ -3,7 +3,7 @@
ACLOCAL_AMFLAGS = -I m4 ACLOCAL_AMFLAGS = -I m4
AM_CXXFLAGS = $(BOOST_CPPFLAGS) $(ZLIB_CFLAGS) AM_CXXFLAGS = $(BOOST_CPPFLAGS)
AM_DEFAULT_SOURCE_EXT = .cpp AM_DEFAULT_SOURCE_EXT = .cpp
############################################################################### ###############################################################################
@ -178,22 +178,8 @@ UTIL_FILES = \
matrix4.cpp \ matrix4.cpp \
matrix.hpp \ matrix.hpp \
matrix.ipp \ matrix.ipp \
memory/buffer/circular.cpp \
memory/buffer/circular.hpp \
memory/buffer/paged.cpp \
memory/buffer/paged.hpp \
memory/deleter.cpp \ memory/deleter.cpp \
memory/deleter.hpp \ memory/deleter.hpp \
memory/system.cpp \
memory/system.hpp \
net/address.cpp \
net/address.hpp \
net/except.cpp \
net/except.hpp \
net/socket.cpp \
net/socket.hpp \
net/types.cpp \
net/types.hpp \
nocopy.hpp \ nocopy.hpp \
pascal.cpp \ pascal.cpp \
pascal.hpp \ pascal.hpp \
@ -276,6 +262,20 @@ UTIL_FILES = \
if PLATFORM_LINUX if PLATFORM_LINUX
UTIL_FILES += \ UTIL_FILES += \
net/address.cpp \
net/address.hpp \
net/except.cpp \
net/except.hpp \
net/socket.cpp \
net/socket.hpp \
net/types.cpp \
net/types.hpp \
memory/buffer/circular.cpp \
memory/buffer/circular.hpp \
memory/buffer/paged.cpp \
memory/buffer/paged.hpp \
memory/system.cpp \
memory/system.hpp \
debug_posix.cpp \ debug_posix.cpp \
io_posix.cpp \ io_posix.cpp \
io_posix.hpp \ io_posix.hpp \
@ -299,7 +299,7 @@ UTIL_FILES += \
win32/registry.cpp win32/registry.cpp
endif endif
if HAVE_EXECINFO_H if HAVE_EXECINFO
UTIL_FILES += backtrace_execinfo.cpp UTIL_FILES += backtrace_execinfo.cpp
else else
UTIL_FILES += backtrace_null.cpp UTIL_FILES += backtrace_null.cpp
@ -331,7 +331,7 @@ pkgconfig_DATA = libcruft-util.pc
############################################################################### ###############################################################################
## Utility programs ## Utility programs
AM_LDFLAGS = $(BOOST_LDFLAGS) -lrt LDADD = $(top_builddir)/libcruft-util.a $(BOOST_LDFLAGS) $(LIBS)
bin_PROGRAMS = \ bin_PROGRAMS = \
tools/json-clean \ tools/json-clean \
@ -341,14 +341,11 @@ bin_PROGRAMS = \
noinst_PROGRAMS = tools/scratch noinst_PROGRAMS = tools/scratch
LDADD = $(top_builddir)/libcruft-util.a $(BOOST_FILESYSTEM_LIB) $(BOOST_SYSTEM_LIB) $(ZLIB_LIBS)
##----------------------------------------------------------------------------- ##-----------------------------------------------------------------------------
## Tests ## Tests
AM_LDFLAGS += $(BOOST_LDFLAGS) $(BOOST_FILESYSTEM_LIB) $(BOOST_SYSTEM_LIB) AM_CXXFLAGS += -I$(top_srcdir)
AM_CXXFLAGS += -I$(top_srcdir) -I$(top_builddir)
TEST_BIN = \ TEST_BIN = \
test/alloc/arena \ test/alloc/arena \

View File

@ -1,4 +1,4 @@
AC_INIT([cruft-util], [0.1.0], [danny@nerdcruft.net]) AC_INIT([util-cruft], [0.1.0], [danny@nerdcruft.net])
## Explicitly set an empty CXXFLAGS if not present to prevent AC_PROG_CXX from ## Explicitly set an empty CXXFLAGS if not present to prevent AC_PROG_CXX from
## generating a default -O2. This allows us to manually select -O0 when ## generating a default -O2. This allows us to manually select -O0 when
## debugging is enabled. ## debugging is enabled.
@ -44,25 +44,30 @@ AC_C_BIGENDIAN
## Platform features ## Platform features
AC_DEFINE([_XOPEN_SOURCE], [700], [use POSIX 2008]) AC_DEFINE([_XOPEN_SOURCE], [700], [use POSIX 2008])
AC_DEFINE([__STDC_FORMAT_MACROS], [1], [use C format macros])
AC_FUNC_MMAP AC_FUNC_MMAP
AC_CHECK_HEADERS([execinfo.h], [break;], [have_execinfo_h=true]) AC_CHECK_FUNC([backtrace])
AM_CONDITIONAL([HAVE_EXECINFO_H], [test "x$have_execinfo_h" = "xtrue"]) AM_CONDITIONAL([HAVE_EXECINFO], [test "x$ac_cv_func_backtrace" = "xtrue"])
AC_SEARCH_LIBS([clock_gettime], [rt], [], [ AC_SEARCH_LIBS([clock_gettime], [rt], [], [
AC_MSG_ERROR([unable to find the clock library]) # windows doesn't have clock_gettime
AS_IF([test "x${host_os}" != "xmingw32"], [
AC_MSG_ERROR([unable to find the clock library])
])
]) ])
AC_SEARCH_LIBS([cos], [m], [], [ AC_SEARCH_LIBS([cos], [m], [], [AC_MSG_ERROR([unable to find the maths library])])
AC_MSG_ERROR([unable to find the maths library])
])
## Use dynamic loader if present (for util::library) ## Find some POSIX functions that windows doesn't support
AS_IF([test "x${host_os}" != "xmingw32"],[ AS_IF([test "x${host_os}" != "xmingw32"],[
AC_SEARCH_LIBS([dlopen], [dl]) AC_SEARCH_LIBS([dlopen], [dl])
AC_SEARCH_LIBS([shm_open], [rt], [], [AC_MSG_ERROR([unable to find shm library])])
]) ])
AC_SEARCH_LIBS([htons], [ws2_32], [], [AC_MSG_ERROR([unable to find htnos library])])
############################################################################### ###############################################################################
## Debug features ## Debug features
@ -75,30 +80,13 @@ AS_IF([test "x${host_os}" != "xmingw32"],[
CHECK_RAGEL([ip.cpp]) CHECK_RAGEL([ip.cpp])
AX_BOOST_BASE([1.53], [], [AC_MSG_ERROR([Boost version >= 1.53 required])]) NC_BOOST([1.53], [system filesystem thread])
AC_SUBST(BOOST_CPPFLAGS)
# boost-system isn't a hard requirement, it's only really used to fulfill AC_SUBST(BOOST_LDFLAGS)
# some other dependency I've since forgotten about...
AX_BOOST_SYSTEM
AX_BOOST_THREAD
AS_IF([test "x$ax_cv_boost_thread" != "xyes"], [
AC_MSG_ERROR("boost-thread is a hard requirement")
])
AX_BOOST_FILESYSTEM
AS_IF([test "x$ax_cv_boost_filesystem" != "xyes"], [
AC_MSG_ERROR("boost-filesystem is a hard requirement")
])
############################################################################### ###############################################################################
## Optional packages ## Optional packages
PKG_CHECK_MODULES([ZLIB], [zlib >= 1.2.0])
AC_SUBST(ZLIB_CFLAGS)
AC_SUBST(ZLIB_LIBS)
AC_CHECK_TOOL([ADDR2LINE], [addr2line], [:]) AC_CHECK_TOOL([ADDR2LINE], [addr2line], [:])
AS_IF([test "x$ADDR2LINE" != "x:"], [ AS_IF([test "x$ADDR2LINE" != "x:"], [
AC_DEFINE_UNQUOTED([ADDR2LINE], ["$ADDR2LINE"], [addr2line tool name]) AC_DEFINE_UNQUOTED([ADDR2LINE], ["$ADDR2LINE"], [addr2line tool name])
@ -110,6 +98,8 @@ AS_IF([test "x$ADDR2LINE" != "x:"], [
############################################################################### ###############################################################################
## Output ## Output
AC_SUBST(LIBS)
# inclusion of config.h has to go after compilation tests otherwise we risk # inclusion of config.h has to go after compilation tests otherwise we risk
# failure on a clean build # failure on a clean build
AX_APPEND_FLAG([-include config.h]) AX_APPEND_FLAG([-include config.h])

42
m4/nc_boost.m4 Normal file
View File

@ -0,0 +1,42 @@
dnl Attempt to locate boost libraries.
dnl
dnl We explicitly do not use ax_boost_* macros aside from the version checks
dnl because they are catastrophically broken for any remotely complex setup,
dnl and I will just end up punching someone if I have to look at any more
dnl broken M4.
dnl
dnl $1 version required
dnl $2 space delimited list of components required
dnl
dnl sets BOOST_LDFLAGS and BOOST_CPPFLAGS
AC_DEFUN([NC_BOOST], [
AC_REQUIRE([NC_BOOST_BASE])
for _nc_boost_lib in $2; do
AS_CASE([$_nc_boost_lib],
["system"], [NC_BOOST_SYSTEM],
["thread"], [NC_BOOST_THREAD],
["filesystem"], [NC_BOOST_FILESYSTEM],
[AC_MSG_ERROR([unknown boost library $_nc_boost_lib])]
)
dnl find what the variable name is for this package's CPPFLAGS/LIBS
_NAME="$(echo $_nc_boost_lib | tr "[a-z]" "[A-Z]")"
_CPPFLAGS_NAME="BOOST_${_NAME}_CPPFLAGS"
_LDFLAGS_NAME="BOOST_${_NAME}_LDFLAGS"
dnl extract the aforementioned variable's values
_CPPFLAGS="$(eval "echo \$$_CPPFLAGS_NAME")"
_LDFLAGS="$(eval "echo \$$_LDFLAGS_NAME")"
dnl append flags and libs if they don't already exist
for flag in $_CPPFLAGS; do
[[[ ! " $BOOST_CPPFLAGS " =~ " $flag " ]]] && BOOST_CPPFLAGS="$BOOST_CPPFLAGS $flag"
done
for lib in $_LDFLAGS; do
[[[ ! " $BOOST_LDFLAGS " =~ " $lib " ]]] && BOOST_LDFLAGS="$BOOST_LDFLAGS $lib"
done
done
])

7
m4/nc_boost_base.m4 Normal file
View File

@ -0,0 +1,7 @@
AC_DEFUN([NC_BOOST_BASE], [
: ${BOOST_LDFLAGS=""}
: ${BOOST_CPPFLAGS=""}
BOOST_BASE_LDFLAGS=""
BOOST_BASE_CPPFLAGS=""
])

37
m4/nc_boost_filesystem.m4 Normal file
View File

@ -0,0 +1,37 @@
AC_DEFUN([NC_BOOST_FILESYSTEM], [
AC_REQUIRE([NC_BOOST_BASE])
AC_REQUIRE([NC_BOOST_SYSTEM])
AC_LANG_PUSH([C++])
for lib in boost_filesystem; do
AC_MSG_CHECKING([if boost filesystem library is $lib])
nc_save_cflags=$CFLAGS
nc_save_libs=$LIBS
CFLAGS="$CFLAGS $BOOST_BASE_CPPFLAGS $BOOST_SYSTEM_CPPFLAGS"
LIBS="$LIBS $BOOST_BASE_LDFLAGS $BOOST_SYSTEM_LDFLAGS -l$lib"
dnl filesystem::path::filename appears to be extern. try calling it.
AC_TRY_LINK(
[@%:@include <boost/filesystem/path.hpp>],
[boost::filesystem::path (".").filename ();],
[nc_cv_boost_filesystem=yes],
[nc_cv_boost_filesystem=no]
)
BOOST_FILESYSTEM_CPPFLAGS=$CFLAGS
BOOST_FILESYSTEM_LDFLAGS=$LIBS
CFLAGS=$nc_save_cflags
LIBS=$nc_save_libs
AC_MSG_RESULT([$nc_cv_boost_filesystem])
AS_IF([test "x$nc_cv_boost_filesystem" = "xyes"], [break;])
done
AC_LANG_POP([C++])
AS_IF([test "x$nc_cv_boost_filesystem" != "xyes"], [
AC_MSG_ERROR([unable to locate a suitable boost_filesystem])
])
])

36
m4/nc_boost_system.m4 Normal file
View File

@ -0,0 +1,36 @@
AC_DEFUN([NC_BOOST_SYSTEM], [
AC_REQUIRE([NC_BOOST_BASE])
AC_LANG_PUSH([C++])
for lib in boost_system; do
AC_MSG_CHECKING([if boost system library is $lib])
nc_save_cflags=$CFLAGS
nc_save_libs=$LIBS
CFLAGS="$CFLAGS $BOOST_BASE_CPPFLAGS"
LIBS="$LIBS $BOOST_BASE_LDFLAGS -l$lib"
dnl Try to call boost::system::throws as it appears to be extern
AC_TRY_LINK(
[@%:@include <boost/system/error_code.hpp>],
[boost::system::throws ();],
[nc_cv_boost_system=yes],
[nc_cv_boost_system=no]
)
BOOST_SYSTEM_CPPFLAGS=$CFLAGS
BOOST_SYSTEM_LDFLAGS=$LIBS
CFLAGS=$nc_save_cflags
LIBS=$nc_save_libs
AC_MSG_RESULT([$nc_cv_boost_system])
AS_IF([test "x$nc_cv_boost_system" = "xyes"], [break;])
done
AC_LANG_POP([C++])
AS_IF([test "x$nc_cv_boost_system" != "xyes"], [
AC_MSG_ERROR([unable to locate boost_system])
])
])

48
m4/nc_boost_thread.m4 Normal file
View File

@ -0,0 +1,48 @@
AC_DEFUN([NC_BOOST_THREAD], [
AC_REQUIRE([NC_BOOST_BASE])
AC_REQUIRE([NC_BOOST_SYSTEM])
AC_REQUIRE([AC_CANONICAL_HOST])
AS_CASE(["x$host_os"],
["*xmingw*"], [
extra_cflags="-mthreads"
], [
AC_REQUIRE([AX_PTHREAD])
extra_cflags="$PTHREAD_CFLAGS"
extra_libs="$PTHREAD_LIBS"
]
)
AC_LANG_PUSH([C++])
for lib in boost_thread boost_thread_win32; do
AC_MSG_CHECKING([if boost threading library is $lib])
nc_save_cflags=$CFLAGS
nc_save_libs=$LIBS
CFLAGS="$CFLAGS $BOOST_BASE_CPPFLAGS $BOOST_SYSTEM_CPPFLAGS $extra_cflags"
LIBS="$LIBS $BOOST_BASE_LDFLAGS $BOOST_SYSTEM_LDFLAGS $extra_libs -l$lib"
dnl Try to call this_thread::yield as it appears to be extern
AC_TRY_LINK(
[@%:@include <boost/thread/thread.hpp>],
[boost::this_thread::yield ();],
[nc_cv_boost_thread=yes],
[nc_cv_boost_thread=no]
)
BOOST_THREAD_CPPFLAGS=$CFLAGS
BOOST_THREAD_LDFLAGS=$LIBS
CFLAGS=$nc_save_cflags
LIBS=$nc_save_libs
AC_MSG_RESULT([$nc_cv_boost_thread])
AS_IF([test "x$nc_cv_boost_thread" = "xyes"], [break;])
done
AC_LANG_POP([C++])
AS_IF([test "x$nc_cv_boost_thread" != "xyes"], [
AC_MSG_ERROR([unable to locate a suitable boost_thread])
])
])

View File

@ -6,9 +6,7 @@ AC_DEFUN([NC_DEBUGGING],[
AX_REQUIRE_DEFINED([NC_APPEND_ONE_COMPILE_FLAG]) AX_REQUIRE_DEFINED([NC_APPEND_ONE_COMPILE_FLAG])
##------------------------------------------------------------------------- ##-------------------------------------------------------------------------
AC_ARG_ENABLE([sanitizer], [ AC_ARG_ENABLE([sanitizer], [AS_HELP_STRING([--enable-sanitizer], [enable memory sanitizer])])
AS_HELP_STRING([--enable-sanitizer], [enable memory sanitizer])
])
AS_IF([test "x$enable_sanitizer" = "xyes"], [ AS_IF([test "x$enable_sanitizer" = "xyes"], [
m4_foreach([NAME], [ m4_foreach([NAME], [
@ -51,9 +49,7 @@ AC_DEFUN([NC_DEBUGGING],[
]) ])
##------------------------------------------------------------------------- ##-------------------------------------------------------------------------
AC_ARG_ENABLE([debugging], [ AC_ARG_ENABLE([debugging], [AS_HELP_STRING([--enable-debugging], [enables developer debugging support])])
AS_HELP_STRING([--enable-debugging], [enables developer debugging support])
])
AS_IF([test "x${enable_debugging}" = "xyes"], [ AS_IF([test "x${enable_debugging}" = "xyes"], [
AC_DEFINE([ENABLE_DEBUGGING], [], [Debugging support enabled]) AC_DEFINE([ENABLE_DEBUGGING], [], [Debugging support enabled])

View File

@ -1,7 +1,6 @@
AC_DEFUN([NC_OPTIMISATION],[ AC_DEFUN([NC_OPTIMISATION],[
##------------------------------------------------------------------------- ##-------------------------------------------------------------------------
AX_REQUIRE_DEFINED([AX_APPEND_COMPILE_FLAGS]) AX_REQUIRE_DEFINED([AX_APPEND_COMPILE_FLAGS])
AX_REQUIRE_DEFINED([AC_CANONICAL_HOST])
AX_REQUIRE_DEFINED([AX_COMPILER_VENDOR]) AX_REQUIRE_DEFINED([AX_COMPILER_VENDOR])
AX_COMPILER_VENDOR AX_COMPILER_VENDOR
@ -9,15 +8,9 @@ AC_DEFUN([NC_OPTIMISATION],[
##------------------------------------------------------------------------- ##-------------------------------------------------------------------------
## Enable LTO ## Enable LTO
AC_ARG_ENABLE([lto], [ AC_ARG_ENABLE([lto], [AS_HELP_STRING([--enable-lto], [enable link-time optimisation])])
AS_HELP_STRING([--enable-lto], [enable link-time optimisation])
])
AS_IF([test "x$enable_lto" == "xyes"], [ AS_IF([test "x$enable_lto" == "xyes"], [
AS_IF([test x"${host_os}" == x"mingw32"], [
AC_ERROR([mingw32 link-time optimisation is currently broken])
])
AS_IF([test "x$ax_cv_cxx_compiler_vendor" == "xgnu"], [ AS_IF([test "x$ax_cv_cxx_compiler_vendor" == "xgnu"], [
AC_CHECK_TOOLS([RANLIB], [gcc-ranlib ranlib]) AC_CHECK_TOOLS([RANLIB], [gcc-ranlib ranlib])
AC_CHECK_TOOLS([AR], [gcc-ar ar]) AC_CHECK_TOOLS([AR], [gcc-ar ar])
@ -35,9 +28,7 @@ AC_DEFUN([NC_OPTIMISATION],[
##------------------------------------------------------------------------- ##-------------------------------------------------------------------------
## Enable frame pointer ## Enable frame pointer
AC_ARG_ENABLE([frame-pointer], [ AC_ARG_ENABLE([frame-pointer], [AS_HELP_STRING([--enable-frame-pointer], [retain the frame pointer even if optimising])])
AS_HELP_STRING([--enable-frame-pointer], [retain the frame pointer even if optimising])
])
AS_IF([test "x$enable_frame_pointer" = "xyes"], [ AS_IF([test "x$enable_frame_pointer" = "xyes"], [
AX_APPEND_COMPILE_FLAGS([-fno-omit-frame-pointer], [], [-Werror]) AX_APPEND_COMPILE_FLAGS([-fno-omit-frame-pointer], [], [-Werror])

View File

@ -6,6 +6,8 @@ AC_DEFUN([NC_PLATFORM],[
AS_CASE([$host_os], AS_CASE([$host_os],
[mingw32], [ [mingw32], [
AC_DEFINE([WIN32_LEAN_AND_MEAN], [], [reduce win32 header complexity])
AC_CHECK_HEADERS([winsock2.h ws2tcpip.h]) AC_CHECK_HEADERS([winsock2.h ws2tcpip.h])
AC_CHECK_HEADERS([windows.h],[],[],[AC_INCLUDES_DEFAULT]) AC_CHECK_HEADERS([windows.h],[],[],[AC_INCLUDES_DEFAULT])
AC_SUBST([NET_LIBS], [-lws2_32]) AC_SUBST([NET_LIBS], [-lws2_32])