From 4dd311c3c19eb6a4d062b79e965c5fc2772b4c58 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 21 Jul 2013 23:01:01 -0700 Subject: [PATCH] Fixed building with cygwin Note that building with cygwin gcc results in a DLL that depends on cygwin1.dll --- configure | 86 +++++++++++++++++++++++++++--- configure.in | 37 ++++++++++--- include/SDL_platform.h | 2 +- src/thread/windows/SDL_systhread.c | 6 +++ 4 files changed, 116 insertions(+), 15 deletions(-) mode change 100644 => 100755 src/thread/windows/SDL_systhread.c diff --git a/configure b/configure index 134136f66..ff1702ed5 100755 --- a/configure +++ b/configure @@ -15802,15 +15802,45 @@ elif test -d .hg; then 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 @@ $as_echo "#define SDL_LOADSO_WINDOWS 1" >>confdefs.h 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 diff --git a/configure.in b/configure.in index 018a58aef..3346985ea 100644 --- a/configure.in +++ b/configure.in @@ -70,15 +70,29 @@ elif test -d .hg; then 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 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau 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 diff --git a/include/SDL_platform.h b/include/SDL_platform.h index 77ee437cb..f4f23c41a 100644 --- a/include/SDL_platform.h +++ b/include/SDL_platform.h @@ -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 diff --git a/src/thread/windows/SDL_systhread.c b/src/thread/windows/SDL_systhread.c old mode 100644 new mode 100755 index ada365413..6cf826ec7 --- a/src/thread/windows/SDL_systhread.c +++ b/src/thread/windows/SDL_systhread.c @@ -106,6 +106,12 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args, 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)