Fixed building with cygwin
authorSam Lantinga <slouken@libsdl.org>
Sun, 21 Jul 2013 23:01:01 -0700
changeset 7498 bda3639deecc
parent 7497 109f37bca7cc
child 7499 228320dcda31
Fixed building with cygwin Note that building with cygwin gcc results in a DLL that depends on cygwin1.dll
configure
configure.in
include/SDL_platform.h
src/thread/windows/SDL_systhread.c
--- a/configure	Sun Jul 21 22:09:00 2013 +0200
+++ b/configure	Sun Jul 21 23:01:01 2013 -0700
@@ -15802,15 +15802,45 @@
     separate directory so you don't clobber SDL_config.h, SDL_revision.h
 " "$LINENO" 5
 fi
+BASE_CFLAGS=""
+BASE_LDFLAGS=""
 case "$host" in
     *-*-cygwin*)
         # We build SDL on cygwin without the UNIX emulation layer
-        BASE_CFLAGS="-I/usr/include/mingw -mno-cygwin"
-        BASE_LDFLAGS="-mno-cygwin"
-        ;;
-    *)
-        BASE_CFLAGS=""
-        BASE_LDFLAGS=""
+        save_CFLAGS="$CFLAGS"
+        have_no_cygwin=no
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -mno-cygwin option" >&5
+$as_echo_n "checking for GCC -mno-cygwin option... " >&6; }
+        CFLAGS="$save_CFLAGS -mno-cygwin"
+
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+
+int
+main ()
+{
+
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+        have_no_cygwin=yes
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_no_cygwin" >&5
+$as_echo "$have_no_cygwin" >&6; }
+        CFLAGS="$save_CFLAGS"
+
+        if test x$have_no_cygwin = xyes; then
+            BASE_CFLAGS="-mno-cygwin"
+            BASE_LDFLAGS="-mno-cygwin"
+        fi
+        BASE_CFLAGS="$BASE_CFLAGS -I/usr/include/mingw"
         ;;
 esac
 # Uncomment the following line if you want to force SDL and applications
@@ -22428,7 +22458,49 @@
         VERSION_SOURCES="$srcdir/src/main/windows/*.rc"
         SDLMAIN_SOURCES="$srcdir/src/main/windows/*.c"
         SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main"
-        SDL_LIBS="-lmingw32 -lSDL2main $SDL_LIBS -mwindows"
+        SDL_LIBS="-lSDL2main $SDL_LIBS -mwindows"
+
+        # Check to see if this is a mingw or cygwin build
+        have_mingw32=
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for main in -lmingw32" >&5
+$as_echo_n "checking for main in -lmingw32... " >&6; }
+if ${ac_cv_lib_mingw32_main+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lmingw32  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+
+int
+main ()
+{
+return main ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_mingw32_main=yes
+else
+  ac_cv_lib_mingw32_main=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_mingw32_main" >&5
+$as_echo "$ac_cv_lib_mingw32_main" >&6; }
+if test "x$ac_cv_lib_mingw32_main" = xyes; then :
+  have_mingw32=yes
+fi
+
+        if test x$have_mingw32 = xyes; then
+            SDL_LIBS="-lmingw32 $SDL_LIBS"
+        else
+            SDL_LIBS="-lcygwin $SDL_LIBS"
+        fi
         ;;
     *-*-beos* | *-*-haiku*)
         ARCH=beos
--- a/configure.in	Sun Jul 21 22:09:00 2013 +0200
+++ b/configure.in	Sun Jul 21 23:01:01 2013 -0700
@@ -70,15 +70,29 @@
     separate directory so you don't clobber SDL_config.h, SDL_revision.h
 ])
 fi
+BASE_CFLAGS=""
+BASE_LDFLAGS=""
 case "$host" in
     *-*-cygwin*)
         # We build SDL on cygwin without the UNIX emulation layer
-        BASE_CFLAGS="-I/usr/include/mingw -mno-cygwin"
-        BASE_LDFLAGS="-mno-cygwin"
-        ;;
-    *)
-        BASE_CFLAGS=""
-        BASE_LDFLAGS=""
+        save_CFLAGS="$CFLAGS"
+        have_no_cygwin=no
+        AC_MSG_CHECKING(for GCC -mno-cygwin option)
+        CFLAGS="$save_CFLAGS -mno-cygwin"
+
+        AC_TRY_COMPILE([
+        ],[
+        ],[
+        have_no_cygwin=yes
+        ])
+        AC_MSG_RESULT($have_no_cygwin)
+        CFLAGS="$save_CFLAGS"
+
+        if test x$have_no_cygwin = xyes; then
+            BASE_CFLAGS="-mno-cygwin"
+            BASE_LDFLAGS="-mno-cygwin"
+        fi
+        BASE_CFLAGS="$BASE_CFLAGS -I/usr/include/mingw"
         ;;
 esac
 # Uncomment the following line if you want to force SDL and applications
@@ -2511,7 +2525,16 @@
         VERSION_SOURCES="$srcdir/src/main/windows/*.rc"
         SDLMAIN_SOURCES="$srcdir/src/main/windows/*.c"
         SDL_CFLAGS="$SDL_CFLAGS -Dmain=SDL_main"
-        SDL_LIBS="-lmingw32 -lSDL2main $SDL_LIBS -mwindows"
+        SDL_LIBS="-lSDL2main $SDL_LIBS -mwindows"
+
+        # Check to see if this is a mingw or cygwin build
+        have_mingw32=
+        AC_CHECK_LIB(mingw32, main, [have_mingw32=yes])
+        if test x$have_mingw32 = xyes; then
+            SDL_LIBS="-lmingw32 $SDL_LIBS"
+        else
+            SDL_LIBS="-lcygwin $SDL_LIBS"
+        fi
         ;;
     *-*-beos* | *-*-haiku*)
         ARCH=beos
--- a/include/SDL_platform.h	Sun Jul 21 22:09:00 2013 +0200
+++ b/include/SDL_platform.h	Sun Jul 21 23:01:01 2013 -0700
@@ -114,7 +114,7 @@
 #undef __SOLARIS__
 #define __SOLARIS__ 1
 #endif
-#if defined(WIN32) || defined(_WIN32)
+#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
 #undef __WIN32__
 #define __WIN32__   1
 #endif
--- a/src/thread/windows/SDL_systhread.c	Sun Jul 21 22:09:00 2013 +0200
+++ b/src/thread/windows/SDL_systhread.c	Sun Jul 21 23:01:01 2013 -0700
@@ -106,6 +106,12 @@
                      pfnSDL_CurrentBeginThread pfnBeginThread,
                      pfnSDL_CurrentEndThread pfnEndThread)
 {
+#elif defined(__CYGWIN__)
+int
+SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
+{
+    pfnSDL_CurrentBeginThread pfnBeginThread = NULL;
+    pfnSDL_CurrentEndThread pfnEndThread = NULL;
 #else
 int
 SDL_SYS_CreateThread(SDL_Thread * thread, void *args)