shithub: choc

Download patch

ref: be3bba2a1cf9551778683e25f61bffc7c187f93c
parent: 0de7210f96259b4bc6850d4119e8069e31c4a14c
author: Simon Howard <fraggle@gmail.com>
date: Mon Sep 7 15:43:04 EDT 2009

Fix compilation under MacOS X.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1659

--- /dev/null
+++ b/acinclude.m4
@@ -1,0 +1,31 @@
+
+dnl Macro to check if autoconf's compile tests have been broken by
+dnl SDL.  Tries to build the simplest possible program, and if it
+dnl fails, calls the given block.
+
+AC_DEFUN([AC_CHECK_SDL_BREAKAGE], [
+    AC_LINK_IFELSE(AC_LANG_PROGRAM([], []), [], [
+        $1
+    ])
+])
+
+dnl Macro to work around SDL redefining main.  The provided block
+dnl is run with main #defined to SDL_main via a compiler switch
+dnl if autoconf tests are found to be broken.
+
+AC_DEFUN([AC_SDL_MAIN_WORKAROUND], [
+    sdl_workaround_saved_CFLAGS="$CFLAGS"
+
+    AC_CHECK_SDL_BREAKAGE([
+        CFLAGS="$CFLAGS -Dmain=SDL_main"
+    ])
+
+    AC_CHECK_SDL_BREAKAGE([
+        AC_MSG_ERROR([Autoconf checks broken by SDL, and can't figure out how to fix them.])
+    ])
+
+    $1
+
+    CFLAGS="$sdl_workaround_saved_CFLAGS"
+])
+
--- a/configure.in
+++ b/configure.in
@@ -39,20 +39,42 @@
 CFLAGS="$CFLAGS $SDL_CFLAGS"
 LDFLAGS="$LDFLAGS $SDL_LIBS"
 
-AC_CHECK_LIB(SDL_mixer,Mix_LoadMUS,[
-    SDLMIXER_LIBS="$SDLMIXER_LIBS -lSDL_mixer"
-],[
-    echo "*** Could not find SDL_mixer.  Please install it."
-    exit -1
-])
+# On some platforms, SDL renames main() to SDL_main() using a #define,
+# so that its own main, stored in the SDLmain library, can be run first.
+# Unfortunately, this causes problems for autoconf, which builds
+# test programs to probe the system.  All library/header/symbol checks
+# must be run in this block, that performs a workaround for the problem.
 
-AC_CHECK_LIB(SDL_net,SDLNet_UDP_Send,[
-    SDLNET_LIBS="$SDLNET_LIBS -lSDL_net"
-],[
-    echo "*** Could not find SDL_net.  Please install it."
-    exit -1
+AC_SDL_MAIN_WORKAROUND([
+
+    # Check for SDL_mixer.
+
+    AC_CHECK_LIB(SDL_mixer,Mix_LoadMUS,[
+        SDLMIXER_LIBS="$SDLMIXER_LIBS -lSDL_mixer"
+    ],[
+        echo "*** Could not find SDL_mixer.  Please install it."
+        exit -1
+    ])
+
+    # Check for SDL_net.
+
+    AC_CHECK_LIB(SDL_net,SDLNet_UDP_Send,[
+        SDLNET_LIBS="$SDLNET_LIBS -lSDL_net"
+    ],[
+        echo "*** Could not find SDL_net.  Please install it."
+        exit -1
+    ])
+
+    # Check for libsamplerate.
+
+    AC_CHECK_LIB(samplerate, src_new)
+
+    AC_CHECK_HEADERS([linux/kd.h dev/isa/spkrio.h dev/speaker/speaker.h])
+    AC_CHECK_FUNCS(mmap sched_setaffinity)
 ])
 
+AC_CHECK_TOOL(WINDRES, windres, )
+
 # Windows CE build?
 
 WINDOWS_CE=false
@@ -65,14 +87,6 @@
     *)
         ;;
 esac
-
-AC_CHECK_HEADERS([linux/kd.h dev/isa/spkrio.h dev/speaker/speaker.h])
-AC_CHECK_FUNCS(mmap sched_setaffinity)
-
-# DWF 2008-02-10:  FIXME
-AC_CHECK_LIB(samplerate, src_new)
-
-AC_CHECK_TOOL(WINDRES, windres, )
 
 AM_CONDITIONAL(WINDOWS_CE, $WINDOWS_CE)
 AM_CONDITIONAL(HAVE_WINDRES, test "$WINDRES" != "")
--- a/wince/Makefile.am
+++ b/wince/Makefile.am
@@ -10,7 +10,7 @@
 
 else
 
-libc_wince_a_SOURCES =
+libc_wince_a_SOURCES = dummy.c
 
 endif
 
--- /dev/null
+++ b/wince/dummy.c
@@ -1,0 +1,8 @@
+
+// Dummy source file so that the Windows CE workaround library is
+// not empty.  Some platforms don't like empty libraries.
+
+void DummyWindowsCEFunction(void)
+{
+}
+