2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003 The GemRB Project
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 ###################################################
21 dnl Configure paths for SDL
22 dnl Edheldil & Subvertir - 12/09/03
23 dnl Sam Lantinga 9/21/99
24 dnl stolen from Manish Singh
25 dnl stolen back from Frank Belew
26 dnl stolen from Manish Singh
27 dnl Shamelessly stolen from Owen Taylor
29 dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
30 dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
33 AC_DEFUN([AM_PATH_SDL],
35 dnl Get the cflags and libraries from the sdl-config script
37 AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)],
38 sdl_prefix="$withval", sdl_prefix="")
39 AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
40 sdl_exec_prefix="$withval", sdl_exec_prefix="")
41 AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program],
44 if test x$sdl_exec_prefix != x ; then
45 sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
46 if test x${SDL_CONFIG+set} != xset ; then
47 SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
50 if test x$sdl_prefix != x ; then
51 sdl_args="$sdl_args --prefix=$sdl_prefix"
52 if test x${SDL_CONFIG+set} != xset ; then
53 SDL_CONFIG=$sdl_prefix/bin/sdl-config
57 AC_REQUIRE([AC_CANONICAL_TARGET])
58 PATH="$prefix/bin:$prefix/usr/bin:$PATH"
59 AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH])
60 min_sdl_version=ifelse([$1], ,0.11.0,$1)
61 AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
63 if test "$SDL_CONFIG" = "no" ; then
66 SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags`
67 SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs`
69 sdl_major_version=`$SDL_CONFIG $sdl_args --version | \
70 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
71 sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \
72 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
73 sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
74 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
75 if test "x$enable_sdltest" = "xyes" ; then
76 ac_save_CFLAGS="$CFLAGS"
78 CFLAGS="$CFLAGS $SDL_CFLAGS"
79 CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
80 LIBS="$LIBS $SDL_LIBS"
82 dnl Now check if the installed SDL is sufficiently new. (Also sanity
83 dnl checks the results of sdl-config to some extent
99 new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
100 strcpy (new_str, str);
108 int main (int argc, char *argv[])
110 int major, minor, micro;
113 /* This hangs on some systems (?)
114 system ("touch conf.sdltest");
116 { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
118 /* HP/UX 9 (%@#!) writes to sscanf strings */
119 tmp_version = my_strdup("$min_sdl_version");
120 if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) {
121 printf("%s, bad version string\n", "$min_sdl_version");
125 if (($sdl_major_version > major) ||
126 (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
127 (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
133 printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
134 printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro);
135 printf("*** best to upgrade to the required version.\n");
136 printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n");
137 printf("*** to point to the correct copy of sdl-config, and remove the file\n");
138 printf("*** config.cache before re-running configure\n");
143 ],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
144 CFLAGS="$ac_save_CFLAGS"
148 if test "x$no_sdl" = x ; then
150 ifelse([$2], , :, [$2])
153 if test "$SDL_CONFIG" = "no" ; then
154 echo "*** The sdl-config script installed by SDL could not be found"
155 echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
156 echo "*** your path, or set the SDL_CONFIG environment variable to the"
157 echo "*** full path to sdl-config."
159 if test -f conf.sdltest ; then
162 echo "*** Could not run SDL test program, checking why..."
163 CFLAGS="$CFLAGS $SDL_CFLAGS"
164 LIBS="$LIBS $SDL_LIBS"
169 int main(int argc, char *argv[])
172 #define main K_and_R_C_main
174 [ echo "*** The test program compiled, but did not run. This usually means"
175 echo "*** that the run-time linker is not finding SDL or finding the wrong"
176 echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
177 echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
178 echo "*** to the installed location Also, make sure you have run ldconfig if that"
179 echo "*** is required on your system"
181 echo "*** If you have an old version installed, it is best to remove it, although"
182 echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
183 [ echo "*** The test program failed to compile or link. See the file config.log for the"
184 echo "*** exact error that occured. This usually means SDL was incorrectly installed"
185 echo "*** or that you have moved SDL since it was installed. In the latter case, you"
186 echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ])
187 CFLAGS="$ac_save_CFLAGS"
193 ifelse([$3], , :, [$3])
200 ###################################################
201 dnl Configure paths for OPENAL
202 dnl AM_PATH_OPENAL([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
203 dnl Test for OPENAL, and define OPENAL_CFLAGS and OPENAL_LIBS
206 AC_DEFUN([AM_PATH_OPENAL],
208 dnl Get the cflags and libraries from the openal-config script
210 AC_ARG_WITH(openal-prefix,[ --with-openal-prefix=PFX Prefix where OPENAL is installed (optional)],
211 openal_prefix="$withval", openal_prefix="")
212 AC_ARG_WITH(openal-exec-prefix,[ --with-openal-exec-prefix=PFX Exec prefix where OPENAL is installed (optional)],
213 openal_exec_prefix="$withval", openal_exec_prefix="")
214 AC_ARG_ENABLE(openaltest, [ --disable-openaltest Do not try to compile and run a test OPENAL program],
215 , enable_openaltest=yes)
217 if test x$openal_exec_prefix != x ; then
218 openal_args="$openal_args --exec-prefix=$openal_exec_prefix"
219 if test x${OPENAL_CONFIG+set} != xset ; then
220 OPENAL_CONFIG=$openal_exec_prefix/bin/openal-config
223 if test x$openal_prefix != x ; then
224 openal_args="$openal_args --prefix=$openal_prefix"
225 if test x${OPENAL_CONFIG+set} != xset ; then
226 OPENAL_CONFIG=$openal_prefix/bin/openal-config
230 AC_REQUIRE([AC_CANONICAL_TARGET])
231 PATH="$prefix/bin:$prefix/usr/bin:$PATH"
232 AC_PATH_PROG(OPENAL_CONFIG, openal-config, no, [$PATH])
233 AC_PATH_PROG(PKGCONFIG, pkg-config, no, [$PATH])
234 AC_MSG_CHECKING(for OPENAL library)
236 if test "$OPENAL_CONFIG" = "no" && test "$PKGCONFIG" = "no" ; then
239 if test "$OPENAL_CONFIG" = "no" ; then
240 OPENAL_CFLAGS=`$PKGCONFIG openal --cflags`
241 OPENAL_LIBS="`$PKGCONFIG openal --libs` $LIBPTHREAD"
243 OPENAL_CFLAGS=`$OPENAL_CONFIG $openalconf_args --cflags`
244 OPENAL_LIBS="`$OPENAL_CONFIG $openalconf_args --libs` $LIBPTHREAD"
247 if test "x$enable_openaltest" = "xyes" ; then
248 ac_save_CFLAGS="$CFLAGS"
250 CFLAGS="$CFLAGS $OPENAL_CFLAGS"
251 CXXFLAGS="$CXXFLAGS $OPENAL_CFLAGS"
252 LIBS="$LIBS $OPENAL_LIBS"
254 dnl Now check if the installed OPENAL is sufficiently new.
256 rm -f conf.openaltest
259 ],[ return alGetError(); ],no_openal="",no_openal=yes)
260 CFLAGS="$ac_save_CFLAGS"
264 if test "x$no_openal" = x ; then
266 ifelse([$1], , :, [$1])
269 echo "*** The test program failed to compile or link. See the file config.log for the"
270 echo "*** exact error that occured. This usually means OPENAL is not installed,"
271 echo "*** that it's installed incorrectly or that it has been moved since"
272 echo "*** installation. In the latter case, you may want to edit the "
273 echo "*** openal-config script: $OPENAL_CONFIG"
276 ifelse([$2], , :, [$2])
278 AC_SUBST(OPENAL_CFLAGS)
279 AC_SUBST(OPENAL_LIBS)
280 rm -f conf.openaltest
285 ###################################################
286 dnl Configure paths for python
287 dnl Shamelessly ripped from dia 0.92
288 dnl From Andrew Dalke
289 dnl Updated by James Henstridge
291 AC_DEFUN([AM_PATH_PYTHON],
293 dnl Find a version of Python. I could check for python versions 1.4
294 dnl or earlier, but the default installation locations changed from
295 dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
296 dnl in 1.5, and I don't want to maintain that logic.
298 if test -z "$PYTHON"; then
299 AC_PATH_PROGS(PYTHON, python python2.3 python2.2 python2.1 python2.0 python1.6 python1.5)
302 dnl should we do the version check?
304 AC_MSG_CHECKING(if Python version >= $1)
305 changequote(<<, >>)dnl
309 pyver = string.split(sys.version)[0] # first word is version string
310 # split strings by '.' and convert to numeric
311 minver = map(string.atoi, string.split(minver, '.'))
312 if hasattr(sys, 'version_info'):
313 pyver = sys.version_info[:3]
315 pyver = map(string.atoi, string.split(pyver, '.'))
316 # we can now do comparisons on the two lists:
317 if tuple(pyver) >= tuple(minver):
322 if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC
327 AC_MSG_RESULT(too old)
332 AC_MSG_CHECKING([local Python configuration])
335 dnl Query Python for its version number. Getting [:3] seems to be
336 dnl the best way to do this; it's what "site.py" does in the standard
337 dnl library. Need to change quote character because of [:3]
339 AC_SUBST(PYTHON_VERSION)
340 changequote(<<, >>)dnl
341 PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[:3]"`
345 dnl Use the values of $prefix and $exec_prefix for the corresponding
346 dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
347 dnl distinct variables so they can be overridden if need be. However,
348 dnl general consensus is that you shouldn't need this ability.
350 AC_SUBST(PYTHON_PREFIX)
351 PYTHON_PREFIX='${prefix}'
353 AC_SUBST(PYTHON_EXEC_PREFIX)
354 PYTHON_EXEC_PREFIX='${exec_prefix}'
359 ###################################################
360 dnl Macro to check for availability of python headers
361 dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
362 dnl function also defines PYTHON_INCLUDES
364 AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
365 [AC_REQUIRE([AM_PATH_PYTHON])
366 AC_MSG_CHECKING(for python headers)
367 dnl deduce PYTHON_INCLUDES
368 py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
369 py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
370 PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
371 if test "$py_prefix" != "$py_exec_prefix"; then
372 PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
374 AC_SUBST(PYTHON_INCLUDES)
375 dnl check if the headers exist:
376 save_CPPFLAGS="$CPPFLAGS"
377 CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
378 AC_TRY_CPP([#include <Python.h>],dnl
379 [AC_MSG_RESULT(found)
381 [AC_MSG_RESULT(not found)
383 CPPFLAGS="$save_CPPFLAGS"
386 ###################################################
387 dnl Macro to check for availability of python libraries
388 dnl AM_CHECK_PYTHON_LIBS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
389 dnl function also defines PYTHON_LIBS
391 AC_DEFUN([AM_CHECK_PYTHON_LIBS],
392 [AC_REQUIRE([AM_PATH_PYTHON])
393 AC_MSG_CHECKING(for python libraries)
394 dnl deduce PYTHON_LIBS
395 py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
396 py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
397 PYTHON_LIBS="-L${py_prefix}/lib -lpython${PYTHON_VERSION}"
398 if test "$py_prefix" != "$py_exec_prefix"; then
399 PYTHON_LIBS="$PYTHON_LIBS -L${py_exec_prefix}/lib -lpython${PYTHON_VERSION}"
401 AC_SUBST(PYTHON_LIBS)
402 dnl check if the lib links:
403 save_CPPFLAGS="$CPPFLAGS"
404 CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
406 LIBS="$LIBS $PYTHON_LIBS $LIBPTHREAD"
407 AC_TRY_LINK([#include <Python.h>],[
410 [AC_MSG_RESULT(found)
412 [AC_MSG_RESULT(not found)
415 CPPFLAGS="$save_CPPFLAGS"
419 ###################################################
420 dnl Check for ZLib (gzip compression) library
421 dnl Available from the GNU Autoconf Macro Archive at:
422 dnl http://www.gnu.org/software/ac-archive/htmldoc/check_zlib.html
425 AC_DEFUN([CHECK_ZLIB],
429 [AC_MSG_CHECKING(if zlib is wanted)
431 [ --with-zlib=DIR root directory path of zlib installation [defaults to
432 /usr/local or /usr if not found in /usr/local]
433 --without-zlib to disable zlib usage completely],
434 [if test "$withval" != no ; then
442 if test ! -f "${ZLIB_HOME}/include/zlib.h"
449 # Locate zlib, if wanted
451 if test -n "${ZLIB_HOME}"
453 ZLIB_OLD_LDFLAGS=$LDFLAGS
454 ZLIB_OLD_CPPFLAGS=$LDFLAGS
455 LDFLAGS="$LDFLAGS -L${ZLIB_HOME}/lib"
456 CPPFLAGS="$CPPFLAGS -I${ZLIB_HOME}/include"
459 AC_CHECK_LIB(z, inflateEnd, [zlib_cv_libz=yes], [zlib_cv_libz=no])
460 AC_CHECK_HEADER(zlib.h, [zlib_cv_zlib_h=yes], [zlib_cvs_zlib_h=no])
462 if test "$zlib_cv_libz" = "yes" -a "$zlib_cv_zlib_h" = "yes"
465 # If both library and header were found, use them
467 AC_CHECK_LIB(z, inflateEnd)
468 AC_MSG_CHECKING(zlib in ${ZLIB_HOME})
472 # If either header or library was not found, revert and bomb
474 AC_MSG_CHECKING(zlib in ${ZLIB_HOME})
475 LDFLAGS="$ZLIB_OLD_LDFLAGS"
476 CPPFLAGS="$ZLIB_OLD_CPPFLAGS"
477 AC_MSG_RESULT(failed)
478 AC_MSG_ERROR(either specify a valid zlib installation with --with-zlib=DIR or disable zlib usage with --without-zlib)
485 ###################################################
486 dnl Test whether STL library defines method container::at().
487 dnl Older versions (e.g. 2.95.x on Debian) don't and newer (3.x) do
488 dnl Syntax: AC_CHECK_STL_CONTAINER_AT([ACTION-IF-YES], [ACTION-IF-NO])
490 AC_DEFUN([AC_CHECK_STL_CONTAINER_AT],
492 AC_MSG_CHECKING(for container::at)
502 deque<int> test_deque(3);
504 vector<int> test_vector(2);
506 string test_string("test_string");
510 dnl AC_DEFINE(HAVE_CONTAINER_AT)
516 ###################################################
517 dnl Test whether the compiler permits casting from pointer-to-object
518 dnl to pointer-to-function (forbidden in GCC v4 and ISO C++).
519 dnl If the cast is forbidden, define HAVE_FORBIDDEN_OBJECT_TO_FUNCTION_CAST.
520 dnl Syntax: AC_CHECK_OBJECT_TO_FUNCTION_CAST()
522 AC_DEFUN([AC_CHECK_OBJECT_TO_FUNCTION_CAST],
524 AC_MSG_CHECKING(whether compiler permits casting between ptr-to-object and ptr-to-function)
527 typedef void *(* voidvoid)(void);
532 function = (voidvoid) object;
537 AC_DEFINE(HAVE_FORBIDDEN_OBJECT_TO_FUNCTION_CAST, 1, [Define to 1 if compiler forbids casting between pointer-to-function and pointer-to-object])
542 ###################################################
543 dnl Check for the name of Posix threads library.
544 dnl Ripped from XMMS by Peter Alm & co and modified to integrate w/ GemRB
546 AC_DEFUN([AC_CHECK_PTHREADS],
549 AC_MSG_CHECKING(for old style FreeBSD -pthread flag)
551 [#if (defined(__FreeBSD_cc_version) && __FreeBSD_cc_version <= 500001) || defined(__OpenBSD__)
554 ], AC_MSG_RESULT(yes)
555 CXXFLAGS="$CXXFLAGS -D_THREAD_SAFE"
556 LIBPTHREAD="-pthread",
558 if test "x$LIBPTHREAD" = xerror; then
559 AC_CHECK_LIB(pthread, pthread_attr_init,
560 LIBPTHREAD="-lpthread")
562 if test "x$LIBPTHREAD" = xerror; then
563 AC_CHECK_LIB(pthreads, pthread_attr_init,
564 LIBPTHREAD="-lpthreads")
566 if test "x$LIBPTHREAD" = xerror; then
567 AC_CHECK_LIB(c_r, pthread_attr_init,
570 if test "x$LIBPTHREAD" = xerror; then
571 AC_CHECK_FUNC(pthread_attr_init, LIBPTHREAD="")
573 if test "x$LIBPTHREAD" = xerror; then
574 AC_MSG_ERROR(*** Unable to locate working posix thread library)