19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Configure paths for SDL 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Sam Lantinga 9/21/99 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# stolen from Manish Singh 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# stolen back from Frank Belew 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# stolen from Manish Singh 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall# Shamelessly stolen from Owen Taylor 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halldnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halldnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halldnl 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallAC_DEFUN([AM_PATH_SDL], 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall[dnl 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halldnl Get the cflags and libraries from the sdl-config script 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halldnl 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallAC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)], 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sdl_prefix="$withval", sdl_prefix="") 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallAC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)], 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sdl_exec_prefix="$withval", sdl_exec_prefix="") 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallAC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program], 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall , enable_sdltest=yes) 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if test x$sdl_exec_prefix != x ; then 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix" 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if test x${SDL_CONFIG+set} != xset ; then 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fi 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fi 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if test x$sdl_prefix != x ; then 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sdl_args="$sdl_args --prefix=$sdl_prefix" 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if test x${SDL_CONFIG+set} != xset ; then 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CONFIG=$sdl_prefix/bin/sdl-config 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fi 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fi 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if test "x$prefix" != xNONE; then 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall PATH="$prefix/bin:$prefix/usr/bin:$PATH" 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fi 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH]) 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall min_sdl_version=ifelse([$1], ,0.11.0,$1) 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall AC_MSG_CHECKING(for SDL - version >= $min_sdl_version) 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall no_sdl="" 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if test "$SDL_CONFIG" = "no" ; then 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall no_sdl=yes 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags` 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs` 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sdl_major_version=`$SDL_CONFIG $sdl_args --version | \ 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \ 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \ 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if test "x$enable_sdltest" = "xyes" ; then 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ac_save_CFLAGS="$CFLAGS" 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ac_save_CXXFLAGS="$CXXFLAGS" 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ac_save_LIBS="$LIBS" 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CFLAGS="$CFLAGS $SDL_CFLAGS" 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall LIBS="$LIBS $SDL_LIBS" 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halldnl 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halldnl Now check if the installed SDL is sufficiently new. (Also sanity 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halldnl checks the results of sdl-config to some extent 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halldnl 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rm -f conf.sdltest 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall AC_TRY_RUN([ 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdio.h> 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdlib.h> 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <string.h> 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL.h" 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallchar* 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallmy_strdup (char *str) 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall char *new_str; 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (str) 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char)); 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall strcpy (new_str, str); 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall new_str = NULL; 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return new_str; 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint main (int argc, char *argv[]) 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int major, minor, micro; 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall char *tmp_version; 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* This hangs on some systems (?) 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall system ("touch conf.sdltest"); 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */ 969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); } 979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* HP/UX 9 (%@#!) writes to sscanf strings */ 999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall tmp_version = my_strdup("$min_sdl_version"); 1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { 1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("%s, bad version string\n", "$min_sdl_version"); 1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall exit(1); 1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if (($sdl_major_version > major) || 1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (($sdl_major_version == major) && ($sdl_minor_version > minor)) || 1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro))) 1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 0; 1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall { 1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); 1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro); 1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("*** best to upgrade to the required version.\n"); 1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n"); 1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("*** to point to the correct copy of sdl-config, and remove the file\n"); 1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall printf("*** config.cache before re-running configure\n"); 1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return 1; 1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) 1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CFLAGS="$ac_save_CFLAGS" 1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CXXFLAGS="$ac_save_CXXFLAGS" 1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall LIBS="$ac_save_LIBS" 1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fi 1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fi 1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if test "x$no_sdl" = x ; then 1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall AC_MSG_RESULT(yes) 1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ifelse([$2], , :, [$2]) 1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall AC_MSG_RESULT(no) 1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if test "$SDL_CONFIG" = "no" ; then 1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** The sdl-config script installed by SDL could not be found" 1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in" 1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** your path, or set the SDL_CONFIG environment variable to the" 1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** full path to sdl-config." 1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if test -f conf.sdltest ; then 1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall : 1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall else 1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** Could not run SDL test program, checking why..." 1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CFLAGS="$CFLAGS $SDL_CFLAGS" 1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" 1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall LIBS="$LIBS $SDL_LIBS" 1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall AC_TRY_LINK([ 1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include <stdio.h> 1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL.h" 1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint main(int argc, char *argv[]) 1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ return 0; } 1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#undef main 1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define main K_and_R_C_main 1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall], [ return 0; ], 1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall [ echo "*** The test program compiled, but did not run. This usually means" 1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** that the run-time linker is not finding SDL or finding the wrong" 1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** version of SDL. If it is not finding SDL, you'll need to set your" 1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" 1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** to the installed location Also, make sure you have run ldconfig if that" 1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** is required on your system" 1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "***" 1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** If you have an old version installed, it is best to remove it, although" 1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], 1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall [ echo "*** The test program failed to compile or link. See the file config.log for the" 1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** exact error that occured. This usually means SDL was incorrectly installed" 1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** or that you have moved SDL since it was installed. In the latter case, you" 1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ]) 1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CFLAGS="$ac_save_CFLAGS" 1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall CXXFLAGS="$ac_save_CXXFLAGS" 1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall LIBS="$ac_save_LIBS" 1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fi 1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fi 1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_CFLAGS="" 1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_LIBS="" 1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall ifelse([$3], , :, [$3]) 1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall fi 1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall AC_SUBST(SDL_CFLAGS) 1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall AC_SUBST(SDL_LIBS) 1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall rm -f conf.sdltest 1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall]) 182