Skip to content

Commit

Permalink
Make multistresstext.exe compile, and work, with mingw cross compiler…
Browse files Browse the repository at this point in the history
… (autoconf build)
  • Loading branch information
rouault committed Jul 9, 2015
1 parent d895a12 commit 9f05b2d
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 6 deletions.
1 change: 1 addition & 0 deletions Makefile.in
Expand Up @@ -289,6 +289,7 @@ SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
THREAD_LIB = @THREAD_LIB@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
Expand Down
1 change: 1 addition & 0 deletions cmake/Makefile.in
Expand Up @@ -177,6 +177,7 @@ SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
THREAD_LIB = @THREAD_LIB@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
Expand Down
47 changes: 47 additions & 0 deletions configure
Expand Up @@ -635,6 +635,7 @@ ac_subst_vars='am__EXEEXT_FALSE
am__EXEEXT_TRUE
LTLIBOBJS
LIBOBJS
THREAD_LIB
MUTEX_SETTING
JNI_INCLUDE
CPP
Expand Down Expand Up @@ -12575,8 +12576,52 @@ fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for mutexes" >&5
$as_echo_n "checking for mutexes... " >&6; }
THREAD_LIB=""
if test "$with_mutex" = yes -o x"$with_mutex" = x ; then
MUTEX_SETTING=pthread
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5
$as_echo_n "checking for pthread_create in -lpthread... " >&6; }
if ${ac_cv_lib_pthread_pthread_create+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lpthread $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char pthread_create ();
int
main ()
{
return pthread_create ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_pthread_pthread_create=yes
else
ac_cv_lib_pthread_pthread_create=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_create" >&5
$as_echo "$ac_cv_lib_pthread_pthread_create" >&6; }
if test "x$ac_cv_lib_pthread_pthread_create" = xyes; then :
PTHREAD_EXISTS=YES
fi

if test -n "$PTHREAD_EXISTS" ; then
THREAD_LIB="-lpthread"
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutexattr_settype in -lpthread" >&5
$as_echo_n "checking for pthread_mutexattr_settype in -lpthread... " >&6; }
if ${ac_cv_lib_pthread_pthread_mutexattr_settype+:} false; then :
Expand Down Expand Up @@ -12632,6 +12677,8 @@ fi

MUTEX_SETTING=$MUTEX_SETTING

THREAD_LIB=$THREAD_LIB


ac_config_files="$ac_config_files Makefile cmake/Makefile src/Makefile man/Makefile man/man1/Makefile man/man3/Makefile nad/Makefile jniwrap/Makefile jniwrap/org/Makefile jniwrap/org/proj4/Makefile"

Expand Down
6 changes: 6 additions & 0 deletions configure.in
Expand Up @@ -90,8 +90,13 @@ AC_ARG_WITH([mutex],
[Disable real mutex locks (lacking pthreads)]),,)

AC_MSG_CHECKING([for mutexes])
THREAD_LIB=""
if test "$with_mutex" = yes -o x"$with_mutex" = x ; then
MUTEX_SETTING=pthread
AC_CHECK_LIB(pthread,pthread_create,PTHREAD_EXISTS=YES,,,)
if test -n "$PTHREAD_EXISTS" ; then
THREAD_LIB="-lpthread"
fi
AC_CHECK_LIB(pthread,pthread_mutexattr_settype,,,)
AC_MSG_RESULT([enabled, pthread])
else
Expand All @@ -100,6 +105,7 @@ else
fi

AC_SUBST(MUTEX_SETTING,$MUTEX_SETTING)
AC_SUBST(THREAD_LIB,$THREAD_LIB)

AC_OUTPUT(Makefile cmake/Makefile src/Makefile man/Makefile man/man1/Makefile \
man/man3/Makefile nad/Makefile \
Expand Down
1 change: 1 addition & 0 deletions jniwrap/Makefile.in
Expand Up @@ -237,6 +237,7 @@ SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
THREAD_LIB = @THREAD_LIB@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
Expand Down
1 change: 1 addition & 0 deletions jniwrap/org/Makefile.in
Expand Up @@ -237,6 +237,7 @@ SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
THREAD_LIB = @THREAD_LIB@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
Expand Down
1 change: 1 addition & 0 deletions jniwrap/org/proj4/Makefile.in
Expand Up @@ -177,6 +177,7 @@ SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
THREAD_LIB = @THREAD_LIB@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
Expand Down
1 change: 1 addition & 0 deletions man/Makefile.in
Expand Up @@ -237,6 +237,7 @@ SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
THREAD_LIB = @THREAD_LIB@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
Expand Down
1 change: 1 addition & 0 deletions man/man1/Makefile.in
Expand Up @@ -208,6 +208,7 @@ SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
THREAD_LIB = @THREAD_LIB@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
Expand Down
1 change: 1 addition & 0 deletions man/man3/Makefile.in
Expand Up @@ -208,6 +208,7 @@ SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
THREAD_LIB = @THREAD_LIB@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
Expand Down
1 change: 1 addition & 0 deletions nad/Makefile.in
Expand Up @@ -207,6 +207,7 @@ SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
THREAD_LIB = @THREAD_LIB@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
Expand Down
4 changes: 2 additions & 2 deletions src/Makefile.am
Expand Up @@ -24,8 +24,8 @@ proj_LDADD = libproj.la
cs2cs_LDADD = libproj.la
nad2bin_LDADD = libproj.la
geod_LDADD = libproj.la
multistresstest_LDADD = libproj.la -lpthread
test228_LDADD = libproj.la -lpthread
multistresstest_LDADD = libproj.la @THREAD_LIB@
test228_LDADD = libproj.la @THREAD_LIB@

lib_LTLIBRARIES = libproj.la

Expand Down
5 changes: 3 additions & 2 deletions src/Makefile.in
Expand Up @@ -324,6 +324,7 @@ SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
THREAD_LIB = @THREAD_LIB@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
Expand Down Expand Up @@ -398,8 +399,8 @@ proj_LDADD = libproj.la
cs2cs_LDADD = libproj.la
nad2bin_LDADD = libproj.la
geod_LDADD = libproj.la
multistresstest_LDADD = libproj.la -lpthread
test228_LDADD = libproj.la -lpthread
multistresstest_LDADD = libproj.la @THREAD_LIB@
test228_LDADD = libproj.la @THREAD_LIB@
lib_LTLIBRARIES = libproj.la
libproj_la_LDFLAGS = -no-undefined -version-info 9:0:0
libproj_la_SOURCES = \
Expand Down
24 changes: 22 additions & 2 deletions src/multistresstest.c
Expand Up @@ -287,8 +287,11 @@ static void *PosixTestThread( void *pData )
/************************************************************************/
/* main() */
/************************************************************************/
int main( int argc, char **argv )

#ifdef _WIN32
static DWORD WINAPI do_main( LPVOID unused )
#else
int do_main(void)
#endif
{
/* -------------------------------------------------------------------- */
/* Our first pass is to establish the correct answers for all */
Expand Down Expand Up @@ -393,3 +396,20 @@ int main( int argc, char **argv )

return 0;
}


int main( int argc, char **argv )
{
#ifdef _WIN32
/* This is an incredible weirdness but with mingw cross-compiler */
/* 1. - b/a; where double a = 6378206.4; and double b = 6356583.8; */
/* does not evaluate the same in the main thread or in a thread forked */
/* by CreateThread(), so run the main in a thread... */
HANDLE thread = CreateThread(NULL, 0, do_main, NULL, 0, NULL);
WaitForSingleObject(thread, INFINITE);
CloseHandle( thread );
#else
do_main();
#endif
return 0;
}

0 comments on commit 9f05b2d

Please sign in to comment.