1# Configure paths for SDL 2# Sam Lantinga 9/21/99 3# stolen from Manish Singh 4# stolen back from Frank Belew 5# stolen from Manish Singh 6# Shamelessly stolen from Owen Taylor 7 8dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) 9dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS 10dnl 11AC_DEFUN([AM_PATH_SDL], 12[dnl 13dnl Get the cflags and libraries from the sdl-config script 14dnl 15AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)], 16 sdl_prefix="$withval", sdl_prefix="") 17AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)], 18 sdl_exec_prefix="$withval", sdl_exec_prefix="") 19AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program], 20 , enable_sdltest=yes) 21 22 if test x$sdl_exec_prefix != x ; then 23 sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix" 24 if test x${SDL_CONFIG+set} != xset ; then 25 SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config 26 fi 27 fi 28 if test x$sdl_prefix != x ; then 29 sdl_config_args="$sdl_config_args --prefix=$sdl_prefix" 30 if test x${SDL_CONFIG+set} != xset ; then 31 SDL_CONFIG=$sdl_prefix/bin/sdl-config 32 fi 33 fi 34 35 if test "x$prefix" != xNONE; then 36 PATH="$prefix/bin:$prefix/usr/bin:$PATH" 37 fi 38 AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH]) 39 min_sdl_version=ifelse([$1], ,0.11.0,$1) 40 AC_MSG_CHECKING(for SDL - version >= $min_sdl_version) 41 no_sdl="" 42 if test "$SDL_CONFIG" = "no" ; then 43 no_sdl=yes 44 else 45 SDL_CFLAGS=`$SDL_CONFIG $sdl_config_args --cflags` 46 SDL_LIBS=`$SDL_CONFIG $sdl_config_args --libs` 47 48 sdl_major_version=`$SDL_CONFIG $sdl_config_args --version | \ 49 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` 50 sdl_minor_version=`$SDL_CONFIG $sdl_config_args --version | \ 51 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` 52 sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \ 53 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` 54 if test "x$enable_sdltest" = "xyes" ; then 55 ac_save_CFLAGS="$CFLAGS" 56 ac_save_CXXFLAGS="$CXXFLAGS" 57 ac_save_LIBS="$LIBS" 58 CFLAGS="$CFLAGS $SDL_CFLAGS" 59 CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" 60 LIBS="$LIBS $SDL_LIBS" 61dnl 62dnl Now check if the installed SDL is sufficiently new. (Also sanity 63dnl checks the results of sdl-config to some extent 64dnl 65 rm -f conf.sdltest 66 AC_TRY_RUN([ 67#include <stdio.h> 68#include <stdlib.h> 69#include <string.h> 70#include "SDL.h" 71 72char* 73my_strdup (char *str) 74{ 75 char *new_str; 76 77 if (str) 78 { 79 new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char)); 80 strcpy (new_str, str); 81 } 82 else 83 new_str = NULL; 84 85 return new_str; 86} 87 88int main (int argc, char *argv[]) 89{ 90 int major, minor, micro; 91 char *tmp_version; 92 93 /* This hangs on some systems (?) 94 system ("touch conf.sdltest"); 95 */ 96 { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); } 97 98 /* HP/UX 9 (%@#!) writes to sscanf strings */ 99 tmp_version = my_strdup("$min_sdl_version"); 100 if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { 101 printf("%s, bad version string\n", "$min_sdl_version"); 102 exit(1); 103 } 104 105 if (($sdl_major_version > major) || 106 (($sdl_major_version == major) && ($sdl_minor_version > minor)) || 107 (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro))) 108 { 109 return 0; 110 } 111 else 112 { 113 printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); 114 printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro); 115 printf("*** best to upgrade to the required version.\n"); 116 printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n"); 117 printf("*** to point to the correct copy of sdl-config, and remove the file\n"); 118 printf("*** config.cache before re-running configure\n"); 119 return 1; 120 } 121} 122 123],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) 124 CFLAGS="$ac_save_CFLAGS" 125 CXXFLAGS="$ac_save_CXXFLAGS" 126 LIBS="$ac_save_LIBS" 127 fi 128 fi 129 if test "x$no_sdl" = x ; then 130 AC_MSG_RESULT(yes) 131 ifelse([$2], , :, [$2]) 132 else 133 AC_MSG_RESULT(no) 134 if test "$SDL_CONFIG" = "no" ; then 135 echo "*** The sdl-config script installed by SDL could not be found" 136 echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in" 137 echo "*** your path, or set the SDL_CONFIG environment variable to the" 138 echo "*** full path to sdl-config." 139 else 140 if test -f conf.sdltest ; then 141 : 142 else 143 echo "*** Could not run SDL test program, checking why..." 144 CFLAGS="$CFLAGS $SDL_CFLAGS" 145 CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" 146 LIBS="$LIBS $SDL_LIBS" 147 AC_TRY_LINK([ 148#include <stdio.h> 149#include "SDL.h" 150 151int main(int argc, char *argv[]) 152{ return 0; } 153#undef main 154#define main K_and_R_C_main 155], [ return 0; ], 156 [ echo "*** The test program compiled, but did not run. This usually means" 157 echo "*** that the run-time linker is not finding SDL or finding the wrong" 158 echo "*** version of SDL. If it is not finding SDL, you'll need to set your" 159 echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" 160 echo "*** to the installed location Also, make sure you have run ldconfig if that" 161 echo "*** is required on your system" 162 echo "***" 163 echo "*** If you have an old version installed, it is best to remove it, although" 164 echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], 165 [ echo "*** The test program failed to compile or link. See the file config.log for the" 166 echo "*** exact error that occured. This usually means SDL was incorrectly installed" 167 echo "*** or that you have moved SDL since it was installed. In the latter case, you" 168 echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ]) 169 CFLAGS="$ac_save_CFLAGS" 170 CXXFLAGS="$ac_save_CXXFLAGS" 171 LIBS="$ac_save_LIBS" 172 fi 173 fi 174 SDL_CFLAGS="" 175 SDL_LIBS="" 176 ifelse([$3], , :, [$3]) 177 fi 178 AC_SUBST(SDL_CFLAGS) 179 AC_SUBST(SDL_LIBS) 180 rm -f conf.sdltest 181]) 182 183dnl Updated 2010 by anonymous author (added -llua, -lglu32 on Windows, removed comments) 184dnl 185dnl Copyright 2000-2004 Erik Greenwald <erik@smluc.org> 186dnl 187dnl (this is a BSD style license) 188dnl 189dnl Redistribution and use in source and binary forms, with or without 190dnl modification, are permitted provided that the following conditions 191dnl are met: 192dnl 1. Redistributions of source code must retain the above copyright 193dnl notice, this list of conditions and the following disclaimer. 194dnl 2. Redistributions in binary form must reproduce the above copyright 195dnl notice, this list of conditions and the following disclaimer in the 196dnl documentation and/or other materials provided with the distribution. 197dnl 3. All advertising materials mentioning features or use of this software 198dnl must display the following acknowledgement: 199dnl This product includes software developed by Erik Greenwald. 200dnl 201dnl THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND 202dnl ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 203dnl IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 204dnl ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 205dnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 206dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 207dnl OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 208dnl HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 209dnl LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 210dnl OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 211dnl SUCH DAMAGE. 212dnl 213dnl $Id: LICENSE,v 1.3 2004/08/14 21:17:09 erik Exp $ 214dnl 215dnl # $Id: OpenGL.m4,v 1.12 2004/01/03 16:02:33 erik Exp $ 216dnl # 217dnl # stolen from 'famp' at http://famp.sourceforge.net (google told me to) 218dnl # AC_SUBST's both GL_CFLAGS and GL_LIBS, and sets HAVE_GL 219dnl # 220dnl # oct 26, 2000 221dnl # * Changed CONFIGURE_OPENGL to AM_PATH_OPENGL for consistancy 222dnl # -Erik Greenwald <erik@smluc.org> 223dnl 224dnl 225dnl # 226dnl # AM_PATH_OPENGL([ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]]) 227dnl # 228 229AC_DEFUN([AM_PATH_OPENGL], 230[ 231 AC_REQUIRE([AC_PROG_CC]) 232 AC_REQUIRE([AC_CANONICAL_TARGET]) 233 234case $target in 235 *-*-cygwin* | *-*-mingw*) 236 ;; 237 *) 238 AC_REQUIRE([AC_PATH_X]) 239 AC_REQUIRE([AC_PATH_XTRA]) 240 ;; 241esac 242 243 GL_CFLAGS="" 244 GL_LIBS="" 245 246 AC_LANG_SAVE 247 AC_LANG_C 248 249 if ! test x"$no_x" = xyes; then 250 GL_CFLAGS="$X_CFLAGS" 251 GL_X_LIBS="$X_PRE_LIBS $X_LIBS $X_EXTRA_LIBS $LIBM" 252 fi 253 254 AC_ARG_WITH(gl-prefix, 255 [ --with-gl-prefix=PFX Prefix where OpenGL is installed], 256 [ 257 GL_CFLAGS="-I$withval/include" 258 GL_LIBS="-L$withval/lib" 259 ]) 260 261 AC_ARG_WITH(gl-includes, 262 [ --with-gl-includes=DIR where the OpenGL includes are installed], 263 [ 264 GL_CFLAGS="-I$withval" 265 ]) 266 267 AC_ARG_WITH(gl-libraries, 268 [ --with-gl-libraries=DIR where the OpenGL libraries are installed], 269 [ 270 GL_LIBS="-L$withval" 271 ]) 272 273 saved_CFLAGS="$CFLAGS" 274 saved_LIBS="$LIBS" 275 AC_LANG_SAVE 276 AC_LANG_C 277 HAVE_GL=no 278 279 exec 8>&AC_FD_MSG 280 281case "$target" in 282 *-*-cygwin* | *-*-mingw32*) 283 GL_CFLAGS="" 284 GL_LIBS="-lopengl32 -lglu32" 285 HAVE_GL=yes 286 ;; 287 *-apple-darwin*) 288 GL_LIBS="-framework GLUT -framework OpenGL -framework Carbon -lobjc" 289 HAVE_GL=yes 290 ;; 291 *) 292 AC_SEARCH_LIBS(glFrustum, 293 [GL MesaGL Mesa3d opengl opengl32], 294 [ 295 AC_SEARCH_LIBS(gluPerspective, [GLU MesaGLU glu32], 296 [ 297 HAVE_GL=yes 298 GL_LIBS="$GL_LIBS $LIBS" 299 ], AC_ERROR([GLU not found]), $GL_LIBS $GL_X_LIBS) 300 ], 301 AC_ERROR([OpenGL not found]), 302 $GL_LIBS $GL_X_LIBS) 303 ;; 304esac 305 306 LIBS="$saved_LIBS" 307 CFLAGS="$saved_CFLAGS" 308 309 exec AC_FD_MSG>&8 310 AC_LANG_RESTORE 311 312 if test "$HAVE_GL" = "yes"; then 313 ifelse([$1], , :, [$1]) 314 else 315 GL_CFLAGS="" 316 GL_LIBS="" 317 ifelse([$2], , :, [$2]) 318 fi 319 AC_SUBST(GL_CFLAGS) 320 AC_SUBST(GL_LIBS) 321]) 322 323dnl # $Id: png.m4,v 1.2 2004/01/02 09:46:31 erik Exp $ 324dnl 325dnl # 326dnl # AM_PATH_PNG([ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]]) 327dnl # 328 329AC_DEFUN([AM_PATH_PNG], 330[ 331 AC_REQUIRE([AC_PROG_CC]) 332 333 PNG_CFLAGS="" 334 PNG_LIBS="" 335 336 AC_LANG_SAVE 337 AC_LANG_C 338 339 AC_ARG_WITH(png-prefix, 340 [ --with-png-prefix=PFX Prefix where PNG is installed], 341 [ 342 PNG_CFLAGS="-I$withval/include" 343 PNG_LIBS="-L$withval/lib" 344 ]) 345 346 AC_ARG_WITH(png-includes, 347 [ --with-png-includes=DIR where the PNG includes are installed], 348 [ 349 PNG_CFLAGS="-I$withval" 350 ]) 351 352 AC_ARG_WITH(png-libraries, 353 [ --with-png-libraries=DIR where the PNG libraries are installed], 354 [ 355 PNG_LIBS="-L$withval" 356 ]) 357 358 saved_CFLAGS="$CFLAGS" 359 saved_LIBS="$LIBS" 360 AC_LANG_SAVE 361 AC_LANG_C 362 HAVE_PNG=no 363 364 exec 8>&AC_FD_MSG 365 366 367 AC_CHECK_LIB(z, uncompress, AC_CHECK_LIB(png, png_create_info_struct, [ 368 PNG_LIBS="$PNG_LIBS -lpng -lz" 369 HAVE_PNG=yes 370 ],,$PNG_LIBS)) 371 372 LIBS="$saved_LIBS" 373 CFLAGS="$saved_CFLAGS" 374 375 exec AC_FD_MSG>&8 376 AC_LANG_RESTORE 377 378 if test "$HAVE_PNG" = "yes"; then 379 ifelse([$1], , :, [$1]) 380 else 381 PNG_CFLAGS="" 382 PNG_LIBS="" 383 ifelse([$2], , :, [$2]) 384 fi 385 AC_SUBST(PNG_CFLAGS) 386 AC_SUBST(PNG_LIBS) 387]) 388 389AC_DEFUN([AM_PATH_LUA], 390[ 391 AC_REQUIRE([AC_PROG_CC]) 392 393 LUA_CFLAGS='' 394 LUA_LIBS='' 395 396 PKG_CHECK_MODULES([LUA], [lua-5.1], [HAVE_LUA=yes]) 397 398 AC_LANG_PUSH([C]) 399 AC_LANG_POP() 400 401 if test "$HAVE_LUA" = "yes"; then 402 ifelse([$1], , :, [$1]) 403 else 404 LUA_CFLAGS="" 405 LUA_LIBS="" 406 ifelse([$2], , :, [$2]) 407 fi 408 409 AC_SUBST(LUA_CFLAGS) 410 AC_SUBST(LUA_LIBS) 411]) 412 413AC_DEFUN([AM_PATH_PHYSFS], 414[ 415 AC_REQUIRE([AC_PROG_CC]) 416 417 PHYSFS_CFLAGS="" 418 PHYSFS_LIBS="" 419 420 AC_LANG_PUSH([C]) 421 422 AC_ARG_WITH([physfs-prefix], 423 [ --with-physfs-prefix=PFX Prefix where PhysicsFS is installed], 424 [ 425 PHYSFS_CFLAGS="-I$withval/include" 426 PHYSFS_LIBS="-L$withval/lib" 427 ]) 428 429 AC_ARG_WITH([physfs-includes], 430 [ --with-physfs-includes=DIR where the PhysicsFS includes are installed], 431 [ 432 PHYSFS_CFLAGS="-I$withval" 433 ]) 434 435 AC_ARG_WITH([physfs-libraries], 436 [ --with-physfs-libraries=DIR where the PhysicsFS libraries are installed], 437 [ 438 PHYSFS_LIBS="-L$withval" 439 ]) 440 441 saved_CFLAGS="$CFLAGS" 442 saved_LIBS="$LIBS" 443 HAVE_PHYSFS=no 444 445 AC_CHECK_LIB([physfs],[PHYSFS_init],[ 446 HAVE_PHYSFS=yes 447 PHYSFS_LIBS="$PHYSFS_LIBS -lphysfs" 448 ], 449 AC_SEARCH_LIBS([PHYSFS_init], [physfs], [ 450 HAVE_PHYSFS=yes 451 PHYSFS_LIBS="$PHYSFS_LIBS -lphysfs -lz" 452 ], [HAVE_PHYSFS=no], "-lz") 453 ) 454 455 LIBS="$saved_LIBS" 456 CFLAGS="$saved_CFLAGS" 457 458 AC_LANG_POP() 459 460 if test "$HAVE_PHYSFS" = "yes"; then 461 ifelse([$1], , :, [$1]) 462 else 463 PHYSFS_CFLAGS="" 464 PHYSFS_LIBS="" 465 ifelse([$2], , :, [$2]) 466 fi 467 AC_SUBST(PHYSFS_CFLAGS) 468 AC_SUBST(PHYSFS_LIBS) 469]) 470 471AC_DEFUN([AM_PATH_SDL_SOUND], 472[ 473 AC_REQUIRE([AC_PROG_CC]) 474 475 SDL_SOUND_CFLAGS="" 476 SDL_SOUND_LIBS="" 477 478 AC_LANG_PUSH([C]) 479 480 AC_ARG_WITH([sdl-sound-prefix], 481 [ --with-sdl-sound-prefix=PFX Prefix where SDL_Sound is installed], 482 [ 483 SDL_SOUND_CFLAGS="-I$withval/include" 484 SDL_SOUND_LIBS="-L$withval/lib" 485 ]) 486 487 AC_ARG_WITH([sdl-sound-includes], 488 [ --with-sdl-sound-includes=DIR where the SDL_Sound includes are installed], 489 [ 490 SDL_SOUND_CFLAGS="-I$withval" 491 ]) 492 493 AC_ARG_WITH([sdl-sound-libraries], 494 [ --with-sdl-sound-libraries=DIR where the SDL_Sound libraries are installed], 495 [ 496 SDL_SOUND_LIBS="-L$withval" 497 ]) 498 499 saved_CFLAGS="$CFLAGS" 500 saved_LIBS="$LIBS" 501 HAVE_SDL_SOUND=no 502 503 AC_CHECK_HEADER([SDL/SDL_sound.h], [ 504 SDL_SOUND_LIBS="$SDL_SOUND_LIBS -lSDL_sound" 505 HAVE_SDL_SOUND=yes 506 ]) 507dnl dnl TODO: How to determine SDL_sound dependencies? Hopefully better than just testing them all one at a time... 508dnl AC_CHECK_LIB(SDL_sound, Sound_Init, [ 509dnl SDL_SOUND_LIBS="$SDL_SOUND_LIBS -lSDL_sound" 510dnl HAVE_SDL_SOUND=yes 511dnl ]) 512 513 LIBS="$saved_LIBS" 514 CFLAGS="$saved_CFLAGS" 515 516 AC_LANG_POP() 517 518 if test "$HAVE_SDL_SOUND" = "yes"; then 519 ifelse([$1], , :, [$1]) 520 else 521 SDL_SOUND_CFLAGS="" 522 SDL_SOUND_LIBS="" 523 ifelse([$2], , :, [$2]) 524 fi 525 AC_SUBST(SDL_SOUND_CFLAGS) 526 AC_SUBST(SDL_SOUND_LIBS) 527]) 528 529