test/acinclude.m4
changeset 6250 cce0ddcf6747
parent 1755 91063c450171
child 6272 f3dbef2cc0f2
     1.1 --- a/test/acinclude.m4	Sun Jan 22 01:29:26 2012 -0500
     1.2 +++ b/test/acinclude.m4	Sun Jan 22 17:21:00 2012 -0500
     1.3 @@ -5,12 +5,14 @@
     1.4  # stolen from Manish Singh
     1.5  # Shamelessly stolen from Owen Taylor
     1.6  
     1.7 +# serial 1
     1.8 +
     1.9  dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
    1.10  dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
    1.11  dnl
    1.12  AC_DEFUN([AM_PATH_SDL],
    1.13  [dnl 
    1.14 -dnl Get the cflags and libraries from the sdl-config script
    1.15 +dnl Get the cflags and libraries from the sdl2-config script
    1.16  dnl
    1.17  AC_ARG_WITH(sdl-prefix,[  --with-sdl-prefix=PFX   Prefix where SDL is installed (optional)],
    1.18              sdl_prefix="$withval", sdl_prefix="")
    1.19 @@ -19,48 +21,63 @@
    1.20  AC_ARG_ENABLE(sdltest, [  --disable-sdltest       Do not try to compile and run a test SDL program],
    1.21  		    , enable_sdltest=yes)
    1.22  
    1.23 -  if test x$sdl_exec_prefix != x ; then
    1.24 -    sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
    1.25 -    if test x${SDL_CONFIG+set} != xset ; then
    1.26 -       SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
    1.27 +  min_sdl_version=ifelse([$1], ,0.9.0,$1)
    1.28 +
    1.29 +  if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
    1.30 +    PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
    1.31 +           [sdl_pc=yes],
    1.32 +           [sdl_pc=no])
    1.33 +  else
    1.34 +    sdl_pc=no
    1.35 +    if test x$sdl_exec_prefix != x ; then
    1.36 +      sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
    1.37 +      if test x${SDL_CONFIG+set} != xset ; then
    1.38 +        SDL_CONFIG=$sdl_exec_prefix/bin/sdl2-config
    1.39 +      fi
    1.40      fi
    1.41 -  fi
    1.42 -  if test x$sdl_prefix != x ; then
    1.43 -    sdl_args="$sdl_args --prefix=$sdl_prefix"
    1.44 -    if test x${SDL_CONFIG+set} != xset ; then
    1.45 -       SDL_CONFIG=$sdl_prefix/bin/sdl-config
    1.46 +    if test x$sdl_prefix != x ; then
    1.47 +      sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
    1.48 +      if test x${SDL_CONFIG+set} != xset ; then
    1.49 +        SDL_CONFIG=$sdl_prefix/bin/sdl2-config
    1.50 +      fi
    1.51      fi
    1.52    fi
    1.53  
    1.54 -  if test "x$prefix" != xNONE; then
    1.55 -    PATH="$prefix/bin:$prefix/usr/bin:$PATH"
    1.56 -  fi
    1.57 -  AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH])
    1.58 -  min_sdl_version=ifelse([$1], ,0.11.0,$1)
    1.59 -  AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
    1.60 -  no_sdl=""
    1.61 -  if test "$SDL_CONFIG" = "no" ; then
    1.62 -    no_sdl=yes
    1.63 +  if test "x$sdl_pc" = xyes ; then
    1.64 +    no_sdl=""
    1.65 +    SDL_CONFIG="pkg-config sdl2"
    1.66    else
    1.67 -    SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags`
    1.68 -    SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs`
    1.69 +    as_save_PATH="$PATH"
    1.70 +    if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
    1.71 +      PATH="$prefix/bin:$prefix/usr/bin:$PATH"
    1.72 +    fi
    1.73 +    AC_PATH_PROG(SDL_CONFIG, sdl2-config, no, [$PATH])
    1.74 +    PATH="$as_save_PATH"
    1.75 +    AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
    1.76 +    no_sdl=""
    1.77  
    1.78 -    sdl_major_version=`$SDL_CONFIG $sdl_args --version | \
    1.79 -           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
    1.80 -    sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \
    1.81 -           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
    1.82 -    sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
    1.83 -           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
    1.84 -    if test "x$enable_sdltest" = "xyes" ; then
    1.85 -      ac_save_CFLAGS="$CFLAGS"
    1.86 -      ac_save_CXXFLAGS="$CXXFLAGS"
    1.87 -      ac_save_LIBS="$LIBS"
    1.88 -      CFLAGS="$CFLAGS $SDL_CFLAGS"
    1.89 -      CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
    1.90 -      LIBS="$LIBS $SDL_LIBS"
    1.91 +    if test "$SDL_CONFIG" = "no" ; then
    1.92 +      no_sdl=yes
    1.93 +    else
    1.94 +      SDL_CFLAGS=`$SDL_CONFIG $sdl_config_args --cflags`
    1.95 +      SDL_LIBS=`$SDL_CONFIG $sdl_config_args --libs`
    1.96 +
    1.97 +      sdl_major_version=`$SDL_CONFIG $sdl_config_args --version | \
    1.98 +             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
    1.99 +      sdl_minor_version=`$SDL_CONFIG $sdl_config_args --version | \
   1.100 +             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
   1.101 +      sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
   1.102 +             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
   1.103 +      if test "x$enable_sdltest" = "xyes" ; then
   1.104 +        ac_save_CFLAGS="$CFLAGS"
   1.105 +        ac_save_CXXFLAGS="$CXXFLAGS"
   1.106 +        ac_save_LIBS="$LIBS"
   1.107 +        CFLAGS="$CFLAGS $SDL_CFLAGS"
   1.108 +        CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
   1.109 +        LIBS="$LIBS $SDL_LIBS"
   1.110  dnl
   1.111  dnl Now check if the installed SDL is sufficiently new. (Also sanity
   1.112 -dnl checks the results of sdl-config to some extent
   1.113 +dnl checks the results of sdl2-config to some extent
   1.114  dnl
   1.115        rm -f conf.sdltest
   1.116        AC_TRY_RUN([
   1.117 @@ -110,32 +127,36 @@
   1.118      }
   1.119    else
   1.120      {
   1.121 -      printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
   1.122 -      printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro);
   1.123 +      printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
   1.124 +      printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
   1.125        printf("*** best to upgrade to the required version.\n");
   1.126 -      printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n");
   1.127 -      printf("*** to point to the correct copy of sdl-config, and remove the file\n");
   1.128 +      printf("*** If sdl2-config was wrong, set the environment variable SDL_CONFIG\n");
   1.129 +      printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
   1.130        printf("*** config.cache before re-running configure\n");
   1.131        return 1;
   1.132      }
   1.133  }
   1.134  
   1.135  ],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
   1.136 -       CFLAGS="$ac_save_CFLAGS"
   1.137 -       CXXFLAGS="$ac_save_CXXFLAGS"
   1.138 -       LIBS="$ac_save_LIBS"
   1.139 -     fi
   1.140 +        CFLAGS="$ac_save_CFLAGS"
   1.141 +        CXXFLAGS="$ac_save_CXXFLAGS"
   1.142 +        LIBS="$ac_save_LIBS"
   1.143 +      fi
   1.144 +    fi
   1.145 +    if test "x$no_sdl" = x ; then
   1.146 +      AC_MSG_RESULT(yes)
   1.147 +    else
   1.148 +      AC_MSG_RESULT(no)
   1.149 +    fi
   1.150    fi
   1.151    if test "x$no_sdl" = x ; then
   1.152 -     AC_MSG_RESULT(yes)
   1.153 -     ifelse([$2], , :, [$2])     
   1.154 +     ifelse([$2], , :, [$2])
   1.155    else
   1.156 -     AC_MSG_RESULT(no)
   1.157       if test "$SDL_CONFIG" = "no" ; then
   1.158 -       echo "*** The sdl-config script installed by SDL could not be found"
   1.159 +       echo "*** The sdl2-config script installed by SDL could not be found"
   1.160         echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
   1.161         echo "*** your path, or set the SDL_CONFIG environment variable to the"
   1.162 -       echo "*** full path to sdl-config."
   1.163 +       echo "*** full path to sdl2-config."
   1.164       else
   1.165         if test -f conf.sdltest ; then
   1.166          :
   1.167 @@ -165,7 +186,7 @@
   1.168          [ echo "*** The test program failed to compile or link. See the file config.log for the"
   1.169            echo "*** exact error that occured. This usually means SDL was incorrectly installed"
   1.170            echo "*** or that you have moved SDL since it was installed. In the latter case, you"
   1.171 -          echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ])
   1.172 +          echo "*** may want to edit the sdl2-config script: $SDL_CONFIG" ])
   1.173            CFLAGS="$ac_save_CFLAGS"
   1.174            CXXFLAGS="$ac_save_CXXFLAGS"
   1.175            LIBS="$ac_save_LIBS"
   1.176 @@ -179,3 +200,160 @@
   1.177    AC_SUBST(SDL_LIBS)
   1.178    rm -f conf.sdltest
   1.179  ])
   1.180 +# pkg.m4 - Macros to locate and utilise pkg-config.            -*- Autoconf -*-
   1.181 +# serial 1 (pkg-config-0.24)
   1.182 +# 
   1.183 +# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
   1.184 +#
   1.185 +# This program is free software; you can redistribute it and/or modify
   1.186 +# it under the terms of the GNU General Public License as published by
   1.187 +# the Free Software Foundation; either version 2 of the License, or
   1.188 +# (at your option) any later version.
   1.189 +#
   1.190 +# This program is distributed in the hope that it will be useful, but
   1.191 +# WITHOUT ANY WARRANTY; without even the implied warranty of
   1.192 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   1.193 +# General Public License for more details.
   1.194 +#
   1.195 +# You should have received a copy of the GNU General Public License
   1.196 +# along with this program; if not, write to the Free Software
   1.197 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   1.198 +#
   1.199 +# As a special exception to the GNU General Public License, if you
   1.200 +# distribute this file as part of a program that contains a
   1.201 +# configuration script generated by Autoconf, you may include it under
   1.202 +# the same distribution terms that you use for the rest of that program.
   1.203 +
   1.204 +# PKG_PROG_PKG_CONFIG([MIN-VERSION])
   1.205 +# ----------------------------------
   1.206 +AC_DEFUN([PKG_PROG_PKG_CONFIG],
   1.207 +[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
   1.208 +m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
   1.209 +AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
   1.210 +AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
   1.211 +AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
   1.212 +
   1.213 +if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
   1.214 +	AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
   1.215 +fi
   1.216 +if test -n "$PKG_CONFIG"; then
   1.217 +	_pkg_min_version=m4_default([$1], [0.9.0])
   1.218 +	AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
   1.219 +	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
   1.220 +		AC_MSG_RESULT([yes])
   1.221 +	else
   1.222 +		AC_MSG_RESULT([no])
   1.223 +		PKG_CONFIG=""
   1.224 +	fi
   1.225 +fi[]dnl
   1.226 +])# PKG_PROG_PKG_CONFIG
   1.227 +
   1.228 +# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
   1.229 +#
   1.230 +# Check to see whether a particular set of modules exists.  Similar
   1.231 +# to PKG_CHECK_MODULES(), but does not set variables or print errors.
   1.232 +#
   1.233 +# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
   1.234 +# only at the first occurence in configure.ac, so if the first place
   1.235 +# it's called might be skipped (such as if it is within an "if", you
   1.236 +# have to call PKG_CHECK_EXISTS manually
   1.237 +# --------------------------------------------------------------
   1.238 +AC_DEFUN([PKG_CHECK_EXISTS],
   1.239 +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
   1.240 +if test -n "$PKG_CONFIG" && \
   1.241 +    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
   1.242 +  m4_default([$2], [:])
   1.243 +m4_ifvaln([$3], [else
   1.244 +  $3])dnl
   1.245 +fi])
   1.246 +
   1.247 +# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
   1.248 +# ---------------------------------------------
   1.249 +m4_define([_PKG_CONFIG],
   1.250 +[if test -n "$$1"; then
   1.251 +    pkg_cv_[]$1="$$1"
   1.252 + elif test -n "$PKG_CONFIG"; then
   1.253 +    PKG_CHECK_EXISTS([$3],
   1.254 +                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
   1.255 +		     [pkg_failed=yes])
   1.256 + else
   1.257 +    pkg_failed=untried
   1.258 +fi[]dnl
   1.259 +])# _PKG_CONFIG
   1.260 +
   1.261 +# _PKG_SHORT_ERRORS_SUPPORTED
   1.262 +# -----------------------------
   1.263 +AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
   1.264 +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
   1.265 +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
   1.266 +        _pkg_short_errors_supported=yes
   1.267 +else
   1.268 +        _pkg_short_errors_supported=no
   1.269 +fi[]dnl
   1.270 +])# _PKG_SHORT_ERRORS_SUPPORTED
   1.271 +
   1.272 +
   1.273 +# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
   1.274 +# [ACTION-IF-NOT-FOUND])
   1.275 +#
   1.276 +#
   1.277 +# Note that if there is a possibility the first call to
   1.278 +# PKG_CHECK_MODULES might not happen, you should be sure to include an
   1.279 +# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
   1.280 +#
   1.281 +#
   1.282 +# --------------------------------------------------------------
   1.283 +AC_DEFUN([PKG_CHECK_MODULES],
   1.284 +[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
   1.285 +AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
   1.286 +AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
   1.287 +
   1.288 +pkg_failed=no
   1.289 +AC_MSG_CHECKING([for $1])
   1.290 +
   1.291 +_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
   1.292 +_PKG_CONFIG([$1][_LIBS], [libs], [$2])
   1.293 +
   1.294 +m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
   1.295 +and $1[]_LIBS to avoid the need to call pkg-config.
   1.296 +See the pkg-config man page for more details.])
   1.297 +
   1.298 +if test $pkg_failed = yes; then
   1.299 +   	AC_MSG_RESULT([no])
   1.300 +        _PKG_SHORT_ERRORS_SUPPORTED
   1.301 +        if test $_pkg_short_errors_supported = yes; then
   1.302 +	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
   1.303 +        else 
   1.304 +	        $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
   1.305 +        fi
   1.306 +	# Put the nasty error message in config.log where it belongs
   1.307 +	echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
   1.308 +
   1.309 +	m4_default([$4], [AC_MSG_ERROR(
   1.310 +[Package requirements ($2) were not met:
   1.311 +
   1.312 +$$1_PKG_ERRORS
   1.313 +
   1.314 +Consider adjusting the PKG_CONFIG_PATH environment variable if you
   1.315 +installed software in a non-standard prefix.
   1.316 +
   1.317 +_PKG_TEXT])dnl
   1.318 +        ])
   1.319 +elif test $pkg_failed = untried; then
   1.320 +     	AC_MSG_RESULT([no])
   1.321 +	m4_default([$4], [AC_MSG_FAILURE(
   1.322 +[The pkg-config script could not be found or is too old.  Make sure it
   1.323 +is in your PATH or set the PKG_CONFIG environment variable to the full
   1.324 +path to pkg-config.
   1.325 +
   1.326 +_PKG_TEXT
   1.327 +
   1.328 +To get pkg-config, see <http://pkg-config.freedesktop.org/>.])dnl
   1.329 +        ])
   1.330 +else
   1.331 +	$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
   1.332 +	$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
   1.333 +        AC_MSG_RESULT([yes])
   1.334 +	$3
   1.335 +fi[]dnl
   1.336 +])# PKG_CHECK_MODULES