<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39600 >
On some platforms (including Windows and Mac OS X) it's necessary to
include SDL.h in civclient.c when SDL is used (for sound support,
gui-sdl or gui-ftwl) to avoid a compiler warning about missing previous
prototype for 'SDL_main' and, in the case of Mac OS X, to make the
client run at all (unless the sdl-config script is patched to add
"-Dmain=SDL_main" to the CFLAGS).
Explanation from the SDL FAQ at www.libsdl.org:
"Just like main() is the entry point for C programs (inc. C++,
Objective-C, and Objective-C++), SDL_main() is the main entry point for
SDL programs. However, you don't actually write an SDL_main() function.
The header file "SDL_main.h" remaps your main() function to the
SDL_main() function with a function macro. Your SDL_main() function is
called after the code in SDLMain.m has performed the required
"bootstrap" initializations to support the SDL runtime.
There are three things you have to do:
1. You must include either SDLMain.m/.h or libSDLmain in your
application, because this is the code that defines SDL's entry point. If
you fail to do this, it is likely that "_main undefined" will be thrown
by the linker.
2. You must give your main() procedure the following prototype:
int main(int argc, char*argv[]);
3. You must make sure the file containing your main() procedure
#includes SDL.h.
Otherwise, the macro will not remap main() to SDL_main(), you will get
an undefined _main error, or the bootstrap process will not run, and SDL
will behave strangely or your application will crash or hang."
--------------------------------------------------------------------
Patches for S2_0, S2_1 and trunk are attached. BTW, since ESD and ALSA
sound support was removed from S2_1 and trunk a while ago, we don't need
esd.m4 and alsa.m4 anymore, do we?
Index: client/audio.c
===================================================================
--- client/audio.c (revision 13366)
+++ client/audio.c (working copy)
@@ -29,7 +29,7 @@
#include "support.h"
#include "audio_none.h"
-#ifdef SDL
+#ifdef AUDIO_SDL
#include "audio_sdl.h"
#endif
@@ -142,7 +142,7 @@
assert(num_plugins_used == 1);
selected_plugin = 0;
-#ifdef SDL
+#ifdef AUDIO_SDL
audio_sdl_init();
#endif
}
@@ -250,7 +250,7 @@
return;
}
-#ifdef SDL
+#ifdef AUDIO_SDL
if (audio_select_plugin("sdl")) return;
#endif
freelog(LOG_ERROR,
Index: client/civclient.c
===================================================================
--- client/civclient.c (revision 13366)
+++ client/civclient.c (working copy)
@@ -19,6 +19,10 @@
#include <windows.h> /* LoadLibrary() */
#endif
+#ifdef SDL
+#include "SDL.h"
+#endif
+
#include <assert.h>
#include <math.h>
#include <stdio.h>
Index: client/Makefile.am
===================================================================
--- client/Makefile.am (revision 13366)
+++ client/Makefile.am (working copy)
@@ -27,10 +27,10 @@
LIBFTWL = ../utility/ftwl/libftwl.a
endif
-ALL_SDL_FILES=audio_sdl.c audio_sdl.h
+ALL_AUDIO_SDL_FILES=audio_sdl.c audio_sdl.h
-if SDL
-SDL_FILES=$(ALL_SDL_FILES)
+if AUDIO_SDL
+AUDIO_SDL_FILES=$(ALL_AUDIO_SDL_FILES)
endif
if MINGW32
@@ -105,7 +105,7 @@
gui-mui/worklistclass.c \
gui-mui/worklistclass.h \
\
- $(ALL_SDL_FILES)
+ $(ALL_AUDIO_SDL_FILES)
## This is usually false, so "include" is not recursed into
@@ -126,7 +126,7 @@
## Above, note -I../intl instead of -I$(top_srdir/intl) is deliberate.
-civclient_SOURCES = $(ESD_FILES) $(SDL_FILES) $(ALSA_FILES) $(WINMM_FILES) \
+civclient_SOURCES = $(AUDIO_SDL_FILES) \
attribute.h \
attribute.c \
citydlg_common.c \
Index: configure.ac
===================================================================
--- configure.ac (revision 13366)
+++ configure.ac (working copy)
@@ -385,6 +385,7 @@
if test "$ftwl" = sdl ; then
FTWL_CFLAGS=`sdl-config --cflags`" "`freetype-config --cflags`
FTWL_LIBS=`sdl-config --libs`" -lpng "`freetype-config --libs`
+ AC_DEFINE(SDL, 1, [SDL is used])
fi
if test "$ftwl" = opengl ; then
@@ -457,7 +458,7 @@
AC_MSG_ERROR(could not guess which client to compile)
fi
- dnl Check for sound support, sets SOUND_CFLAGS, SOUND_LIBS, SDL
+ dnl Check for sound support, sets SOUND_CFLAGS, SOUND_LIBS, AUDIO_SDL
FC_CHECK_SOUND()
gui_sources="gui-$client"
@@ -480,7 +481,7 @@
AC_SUBST(SOUND_LIBS)
AC_SUBST([VERSION_WITHOUT_LABEL])
AC_SUBST([VERSION_LABEL])
-AM_CONDITIONAL(SDL, test "x$SDL_mixer" = "xyes")
+AM_CONDITIONAL(AUDIO_SDL, test "x$SDL_mixer" = "xyes")
AM_CONDITIONAL(CLIENT_GUI_SDL, test "$gui_sources" = "gui-sdl")
AM_CONDITIONAL(CLIENT_GUI_GTK_2_0, test "$gui_sources" = "gui-gtk-2.0")
AM_CONDITIONAL(CLIENT_GUI_XAW, test "$gui_sources" = "gui-xaw")
Index: m4/sdl-client.m4
===================================================================
--- m4/sdl-client.m4 (revision 13366)
+++ m4/sdl-client.m4 (working copy)
@@ -10,9 +10,9 @@
elif test "$client" = sdl ; then
AM_PATH_SDL([1.1.4], [sdl_found="yes"], [sdl_found="no"])
if test "$sdl_found" = yes; then
+ ac_save_CPPFLAGS="$CPPFLAGS"
ac_save_CFLAGS="$CFLAGS"
ac_save_LIBS="$LIBS"
- ac_save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $SDL_CFLAGS"
CFLAGS="$CFLAGS $SDL_CFLAGS"
LIBS="$LIBS $SDL_LIBS"
@@ -22,24 +22,24 @@
AC_CHECK_HEADER([SDL/SDL_image.h],
[sdl_image_h_found="yes"], [sdl_image_h_found="no"])
if test "$sdl_image_h_found" = yes; then
+ CPPFLAGS="$ac_save_CPPFLAGS"
+ CFLAGS="$ac_save_CFLAGS"
+ LIBS="$ac_save_LIBS"
AC_CHECK_FT2([2.1.3], [freetype_found="yes"],[freetype_found="no"])
- if test "$freetype_found" = yes; then
- LIBS=""
- CLIENT_CFLAGS="$SDL_CFLAGS $FT2_CFLAGS"
- CLIENT_LIBS="$SDL_LIBS -lSDL_image $FT2_LIBS"
- found_client=yes
- elif test "$client" = "sdl"; then
- AC_MSG_ERROR([specified client 'sdl' not configurable (FreeType2 >= 2.1.3 is needed (www.freetype.org))])
- fi
+ if test "$freetype_found" = yes; then
+ CLIENT_CFLAGS="$SDL_CFLAGS $FT2_CFLAGS"
+ CLIENT_LIBS="$SDL_LIBS -lSDL_image $FT2_LIBS"
+ AC_DEFINE(SDL, 1, [SDL is used])
+ found_client=yes
+ elif test "$client" = "sdl"; then
+ AC_MSG_ERROR([specified client 'sdl' not configurable (FreeType2 >= 2.1.3 is needed (www.freetype.org))])
+ fi
elif test "$client" = "sdl"; then
AC_MSG_ERROR([specified client 'sdl' not configurable (SDL_image-devel is needed (www.libsdl.org))])
fi
elif test "$client" = "sdl"; then
AC_MSG_ERROR([specified client 'sdl' not configurable (SDL_image is needed (www.libsdl.org))])
fi
- CPPFLAGS="$ac_save_CPPFLAGS"
- CFLAGS="$ac_save_CFLAGS"
- LIBS="$ac_save_LIBS"
fi
if test "$found_client" = yes; then
Index: m4/sound.m4
===================================================================
--- m4/sound.m4 (revision 13366)
+++ m4/sound.m4 (working copy)
@@ -15,7 +15,8 @@
if test "x$SDL_mixer" = "xyes"; then
SOUND_CFLAGS="$SOUND_CFLAGS $SDL_CFLAGS"
SOUND_LIBS="$SOUND_LIBS $SDL_LIBS -lSDL_mixer"
- AC_DEFINE(SDL, 1, [SDL_Mixer support])
+ AC_DEFINE(AUDIO_SDL, 1, [SDL_Mixer support])
+ AC_DEFINE(SDL, 1, [SDL is used])
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT([no, found header but not library!])
Index: client/civclient.c
===================================================================
--- client/civclient.c (revision 13354)
+++ client/civclient.c (working copy)
@@ -19,6 +19,10 @@
#include <windows.h> /* LoadLibrary() */
#endif
+#ifdef SDL
+#include "SDL.h"
+#endif
+
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev