test/acinclude.m4
author Sam Lantinga <slouken@libsdl.org>
Thu, 07 Dec 2017 16:08:09 -0800
changeset 11730 ac6c607e065c
parent 6272 f3dbef2cc0f2
permissions -rw-r--r--
Enable building the Metal renderer by default, and weak link the Metal framework so the SDL library is safe to use on older Macs
Also generate iOS versions of the Metal shaders
slouken@0
     1
# Configure paths for SDL
slouken@0
     2
# Sam Lantinga 9/21/99
slouken@0
     3
# stolen from Manish Singh
slouken@0
     4
# stolen back from Frank Belew
slouken@0
     5
# stolen from Manish Singh
slouken@0
     6
# Shamelessly stolen from Owen Taylor
slouken@0
     7
slouken@6250
     8
# serial 1
slouken@6250
     9
slouken@0
    10
dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
slouken@0
    11
dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
slouken@0
    12
dnl
slouken@6272
    13
AC_DEFUN([AM_PATH_SDL2],
slouken@0
    14
[dnl 
slouken@6250
    15
dnl Get the cflags and libraries from the sdl2-config script
slouken@0
    16
dnl
slouken@0
    17
AC_ARG_WITH(sdl-prefix,[  --with-sdl-prefix=PFX   Prefix where SDL is installed (optional)],
slouken@0
    18
            sdl_prefix="$withval", sdl_prefix="")
slouken@0
    19
AC_ARG_WITH(sdl-exec-prefix,[  --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
slouken@0
    20
            sdl_exec_prefix="$withval", sdl_exec_prefix="")
slouken@0
    21
AC_ARG_ENABLE(sdltest, [  --disable-sdltest       Do not try to compile and run a test SDL program],
slouken@0
    22
		    , enable_sdltest=yes)
slouken@0
    23
slouken@6250
    24
  min_sdl_version=ifelse([$1], ,0.9.0,$1)
slouken@6250
    25
slouken@6250
    26
  if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
slouken@6250
    27
    PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
slouken@6250
    28
           [sdl_pc=yes],
slouken@6250
    29
           [sdl_pc=no])
slouken@6250
    30
  else
slouken@6250
    31
    sdl_pc=no
slouken@6250
    32
    if test x$sdl_exec_prefix != x ; then
slouken@6250
    33
      sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
slouken@6250
    34
      if test x${SDL_CONFIG+set} != xset ; then
slouken@6250
    35
        SDL_CONFIG=$sdl_exec_prefix/bin/sdl2-config
slouken@6250
    36
      fi
slouken@1755
    37
    fi
slouken@6250
    38
    if test x$sdl_prefix != x ; then
slouken@6250
    39
      sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
slouken@6250
    40
      if test x${SDL_CONFIG+set} != xset ; then
slouken@6250
    41
        SDL_CONFIG=$sdl_prefix/bin/sdl2-config
slouken@6250
    42
      fi
slouken@1755
    43
    fi
slouken@0
    44
  fi
slouken@0
    45
slouken@6250
    46
  if test "x$sdl_pc" = xyes ; then
slouken@6250
    47
    no_sdl=""
slouken@6250
    48
    SDL_CONFIG="pkg-config sdl2"
slouken@0
    49
  else
slouken@6250
    50
    as_save_PATH="$PATH"
slouken@6250
    51
    if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
slouken@6250
    52
      PATH="$prefix/bin:$prefix/usr/bin:$PATH"
slouken@6250
    53
    fi
slouken@6250
    54
    AC_PATH_PROG(SDL_CONFIG, sdl2-config, no, [$PATH])
slouken@6250
    55
    PATH="$as_save_PATH"
slouken@6250
    56
    AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
slouken@6250
    57
    no_sdl=""
slouken@0
    58
slouken@6250
    59
    if test "$SDL_CONFIG" = "no" ; then
slouken@6250
    60
      no_sdl=yes
slouken@6250
    61
    else
slouken@6250
    62
      SDL_CFLAGS=`$SDL_CONFIG $sdl_config_args --cflags`
slouken@6250
    63
      SDL_LIBS=`$SDL_CONFIG $sdl_config_args --libs`
slouken@6250
    64
slouken@6250
    65
      sdl_major_version=`$SDL_CONFIG $sdl_config_args --version | \
slouken@6250
    66
             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
slouken@6250
    67
      sdl_minor_version=`$SDL_CONFIG $sdl_config_args --version | \
slouken@6250
    68
             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
slouken@6250
    69
      sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
slouken@6250
    70
             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
slouken@6250
    71
      if test "x$enable_sdltest" = "xyes" ; then
slouken@6250
    72
        ac_save_CFLAGS="$CFLAGS"
slouken@6250
    73
        ac_save_CXXFLAGS="$CXXFLAGS"
slouken@6250
    74
        ac_save_LIBS="$LIBS"
slouken@6250
    75
        CFLAGS="$CFLAGS $SDL_CFLAGS"
slouken@6250
    76
        CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
slouken@6250
    77
        LIBS="$LIBS $SDL_LIBS"
slouken@0
    78
dnl
slouken@0
    79
dnl Now check if the installed SDL is sufficiently new. (Also sanity
slouken@6250
    80
dnl checks the results of sdl2-config to some extent
slouken@0
    81
dnl
slouken@0
    82
      rm -f conf.sdltest
slouken@0
    83
      AC_TRY_RUN([
slouken@0
    84
#include <stdio.h>
slouken@0
    85
#include <stdlib.h>
slouken@0
    86
#include <string.h>
slouken@0
    87
#include "SDL.h"
slouken@0
    88
slouken@0
    89
char*
slouken@0
    90
my_strdup (char *str)
slouken@0
    91
{
slouken@0
    92
  char *new_str;
slouken@0
    93
  
slouken@0
    94
  if (str)
slouken@0
    95
    {
slouken@0
    96
      new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
slouken@0
    97
      strcpy (new_str, str);
slouken@0
    98
    }
slouken@0
    99
  else
slouken@0
   100
    new_str = NULL;
slouken@0
   101
  
slouken@0
   102
  return new_str;
slouken@0
   103
}
slouken@0
   104
slouken@0
   105
int main (int argc, char *argv[])
slouken@0
   106
{
slouken@0
   107
  int major, minor, micro;
slouken@0
   108
  char *tmp_version;
slouken@0
   109
slouken@0
   110
  /* This hangs on some systems (?)
slouken@0
   111
  system ("touch conf.sdltest");
slouken@0
   112
  */
slouken@0
   113
  { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
slouken@0
   114
slouken@0
   115
  /* HP/UX 9 (%@#!) writes to sscanf strings */
slouken@0
   116
  tmp_version = my_strdup("$min_sdl_version");
slouken@0
   117
  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
slouken@0
   118
     printf("%s, bad version string\n", "$min_sdl_version");
slouken@0
   119
     exit(1);
slouken@0
   120
   }
slouken@0
   121
slouken@0
   122
   if (($sdl_major_version > major) ||
slouken@0
   123
      (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
slouken@0
   124
      (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
slouken@0
   125
    {
slouken@0
   126
      return 0;
slouken@0
   127
    }
slouken@0
   128
  else
slouken@0
   129
    {
slouken@6250
   130
      printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
slouken@6250
   131
      printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
slouken@0
   132
      printf("*** best to upgrade to the required version.\n");
slouken@6250
   133
      printf("*** If sdl2-config was wrong, set the environment variable SDL_CONFIG\n");
slouken@6250
   134
      printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
slouken@0
   135
      printf("*** config.cache before re-running configure\n");
slouken@0
   136
      return 1;
slouken@0
   137
    }
slouken@0
   138
}
slouken@0
   139
slouken@0
   140
],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
slouken@6250
   141
        CFLAGS="$ac_save_CFLAGS"
slouken@6250
   142
        CXXFLAGS="$ac_save_CXXFLAGS"
slouken@6250
   143
        LIBS="$ac_save_LIBS"
slouken@6250
   144
      fi
slouken@6250
   145
    fi
slouken@6250
   146
    if test "x$no_sdl" = x ; then
slouken@6250
   147
      AC_MSG_RESULT(yes)
slouken@6250
   148
    else
slouken@6250
   149
      AC_MSG_RESULT(no)
slouken@6250
   150
    fi
slouken@0
   151
  fi
slouken@0
   152
  if test "x$no_sdl" = x ; then
slouken@6250
   153
     ifelse([$2], , :, [$2])
slouken@0
   154
  else
slouken@0
   155
     if test "$SDL_CONFIG" = "no" ; then
slouken@6250
   156
       echo "*** The sdl2-config script installed by SDL could not be found"
slouken@0
   157
       echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
slouken@0
   158
       echo "*** your path, or set the SDL_CONFIG environment variable to the"
slouken@6250
   159
       echo "*** full path to sdl2-config."
slouken@0
   160
     else
slouken@0
   161
       if test -f conf.sdltest ; then
slouken@0
   162
        :
slouken@0
   163
       else
slouken@0
   164
          echo "*** Could not run SDL test program, checking why..."
slouken@0
   165
          CFLAGS="$CFLAGS $SDL_CFLAGS"
slouken@1380
   166
          CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
slouken@0
   167
          LIBS="$LIBS $SDL_LIBS"
slouken@0
   168
          AC_TRY_LINK([
slouken@0
   169
#include <stdio.h>
slouken@0
   170
#include "SDL.h"
slouken@1
   171
slouken@1
   172
int main(int argc, char *argv[])
slouken@1
   173
{ return 0; }
slouken@1
   174
#undef  main
slouken@1
   175
#define main K_and_R_C_main
slouken@0
   176
],      [ return 0; ],
slouken@0
   177
        [ echo "*** The test program compiled, but did not run. This usually means"
slouken@0
   178
          echo "*** that the run-time linker is not finding SDL or finding the wrong"
slouken@0
   179
          echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
slouken@0
   180
          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
slouken@0
   181
          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
slouken@0
   182
          echo "*** is required on your system"
slouken@0
   183
	  echo "***"
slouken@0
   184
          echo "*** If you have an old version installed, it is best to remove it, although"
slouken@0
   185
          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
slouken@0
   186
        [ echo "*** The test program failed to compile or link. See the file config.log for the"
slouken@0
   187
          echo "*** exact error that occured. This usually means SDL was incorrectly installed"
slouken@0
   188
          echo "*** or that you have moved SDL since it was installed. In the latter case, you"
slouken@6250
   189
          echo "*** may want to edit the sdl2-config script: $SDL_CONFIG" ])
slouken@0
   190
          CFLAGS="$ac_save_CFLAGS"
slouken@1380
   191
          CXXFLAGS="$ac_save_CXXFLAGS"
slouken@0
   192
          LIBS="$ac_save_LIBS"
slouken@0
   193
       fi
slouken@0
   194
     fi
slouken@0
   195
     SDL_CFLAGS=""
slouken@0
   196
     SDL_LIBS=""
slouken@0
   197
     ifelse([$3], , :, [$3])
slouken@0
   198
  fi
slouken@0
   199
  AC_SUBST(SDL_CFLAGS)
slouken@0
   200
  AC_SUBST(SDL_LIBS)
slouken@0
   201
  rm -f conf.sdltest
slouken@0
   202
])
slouken@6250
   203
# pkg.m4 - Macros to locate and utilise pkg-config.            -*- Autoconf -*-
slouken@6250
   204
# serial 1 (pkg-config-0.24)
slouken@6250
   205
# 
slouken@6250
   206
# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
slouken@6250
   207
#
slouken@6250
   208
# This program is free software; you can redistribute it and/or modify
slouken@6250
   209
# it under the terms of the GNU General Public License as published by
slouken@6250
   210
# the Free Software Foundation; either version 2 of the License, or
slouken@6250
   211
# (at your option) any later version.
slouken@6250
   212
#
slouken@6250
   213
# This program is distributed in the hope that it will be useful, but
slouken@6250
   214
# WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@6250
   215
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@6250
   216
# General Public License for more details.
slouken@6250
   217
#
slouken@6250
   218
# You should have received a copy of the GNU General Public License
slouken@6250
   219
# along with this program; if not, write to the Free Software
slouken@6250
   220
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
slouken@6250
   221
#
slouken@6250
   222
# As a special exception to the GNU General Public License, if you
slouken@6250
   223
# distribute this file as part of a program that contains a
slouken@6250
   224
# configuration script generated by Autoconf, you may include it under
slouken@6250
   225
# the same distribution terms that you use for the rest of that program.
slouken@6250
   226
slouken@6250
   227
# PKG_PROG_PKG_CONFIG([MIN-VERSION])
slouken@6250
   228
# ----------------------------------
slouken@6250
   229
AC_DEFUN([PKG_PROG_PKG_CONFIG],
slouken@6250
   230
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
slouken@6250
   231
m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
slouken@6250
   232
AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
slouken@6250
   233
AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
slouken@6250
   234
AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
slouken@6250
   235
slouken@6250
   236
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
slouken@6250
   237
	AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
slouken@6250
   238
fi
slouken@6250
   239
if test -n "$PKG_CONFIG"; then
slouken@6250
   240
	_pkg_min_version=m4_default([$1], [0.9.0])
slouken@6250
   241
	AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
slouken@6250
   242
	if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
slouken@6250
   243
		AC_MSG_RESULT([yes])
slouken@6250
   244
	else
slouken@6250
   245
		AC_MSG_RESULT([no])
slouken@6250
   246
		PKG_CONFIG=""
slouken@6250
   247
	fi
slouken@6250
   248
fi[]dnl
slouken@6250
   249
])# PKG_PROG_PKG_CONFIG
slouken@6250
   250
slouken@6250
   251
# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
slouken@6250
   252
#
slouken@6250
   253
# Check to see whether a particular set of modules exists.  Similar
slouken@6250
   254
# to PKG_CHECK_MODULES(), but does not set variables or print errors.
slouken@6250
   255
#
slouken@6250
   256
# Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
slouken@6250
   257
# only at the first occurence in configure.ac, so if the first place
slouken@6250
   258
# it's called might be skipped (such as if it is within an "if", you
slouken@6250
   259
# have to call PKG_CHECK_EXISTS manually
slouken@6250
   260
# --------------------------------------------------------------
slouken@6250
   261
AC_DEFUN([PKG_CHECK_EXISTS],
slouken@6250
   262
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
slouken@6250
   263
if test -n "$PKG_CONFIG" && \
slouken@6250
   264
    AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
slouken@6250
   265
  m4_default([$2], [:])
slouken@6250
   266
m4_ifvaln([$3], [else
slouken@6250
   267
  $3])dnl
slouken@6250
   268
fi])
slouken@6250
   269
slouken@6250
   270
# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
slouken@6250
   271
# ---------------------------------------------
slouken@6250
   272
m4_define([_PKG_CONFIG],
slouken@6250
   273
[if test -n "$$1"; then
slouken@6250
   274
    pkg_cv_[]$1="$$1"
slouken@6250
   275
 elif test -n "$PKG_CONFIG"; then
slouken@6250
   276
    PKG_CHECK_EXISTS([$3],
slouken@6250
   277
                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
slouken@6250
   278
		     [pkg_failed=yes])
slouken@6250
   279
 else
slouken@6250
   280
    pkg_failed=untried
slouken@6250
   281
fi[]dnl
slouken@6250
   282
])# _PKG_CONFIG
slouken@6250
   283
slouken@6250
   284
# _PKG_SHORT_ERRORS_SUPPORTED
slouken@6250
   285
# -----------------------------
slouken@6250
   286
AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
slouken@6250
   287
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])
slouken@6250
   288
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
slouken@6250
   289
        _pkg_short_errors_supported=yes
slouken@6250
   290
else
slouken@6250
   291
        _pkg_short_errors_supported=no
slouken@6250
   292
fi[]dnl
slouken@6250
   293
])# _PKG_SHORT_ERRORS_SUPPORTED
slouken@6250
   294
slouken@6250
   295
slouken@6250
   296
# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
slouken@6250
   297
# [ACTION-IF-NOT-FOUND])
slouken@6250
   298
#
slouken@6250
   299
#
slouken@6250
   300
# Note that if there is a possibility the first call to
slouken@6250
   301
# PKG_CHECK_MODULES might not happen, you should be sure to include an
slouken@6250
   302
# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac
slouken@6250
   303
#
slouken@6250
   304
#
slouken@6250
   305
# --------------------------------------------------------------
slouken@6250
   306
AC_DEFUN([PKG_CHECK_MODULES],
slouken@6250
   307
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
slouken@6250
   308
AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
slouken@6250
   309
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
slouken@6250
   310
slouken@6250
   311
pkg_failed=no
slouken@6250
   312
AC_MSG_CHECKING([for $1])
slouken@6250
   313
slouken@6250
   314
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
slouken@6250
   315
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
slouken@6250
   316
slouken@6250
   317
m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS
slouken@6250
   318
and $1[]_LIBS to avoid the need to call pkg-config.
slouken@6250
   319
See the pkg-config man page for more details.])
slouken@6250
   320
slouken@6250
   321
if test $pkg_failed = yes; then
slouken@6250
   322
   	AC_MSG_RESULT([no])
slouken@6250
   323
        _PKG_SHORT_ERRORS_SUPPORTED
slouken@6250
   324
        if test $_pkg_short_errors_supported = yes; then
slouken@6250
   325
	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
slouken@6250
   326
        else 
slouken@6250
   327
	        $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
slouken@6250
   328
        fi
slouken@6250
   329
	# Put the nasty error message in config.log where it belongs
slouken@6250
   330
	echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
slouken@6250
   331
slouken@6250
   332
	m4_default([$4], [AC_MSG_ERROR(
slouken@6250
   333
[Package requirements ($2) were not met:
slouken@6250
   334
slouken@6250
   335
$$1_PKG_ERRORS
slouken@6250
   336
slouken@6250
   337
Consider adjusting the PKG_CONFIG_PATH environment variable if you
slouken@6250
   338
installed software in a non-standard prefix.
slouken@6250
   339
slouken@6250
   340
_PKG_TEXT])dnl
slouken@6250
   341
        ])
slouken@6250
   342
elif test $pkg_failed = untried; then
slouken@6250
   343
     	AC_MSG_RESULT([no])
slouken@6250
   344
	m4_default([$4], [AC_MSG_FAILURE(
slouken@6250
   345
[The pkg-config script could not be found or is too old.  Make sure it
slouken@6250
   346
is in your PATH or set the PKG_CONFIG environment variable to the full
slouken@6250
   347
path to pkg-config.
slouken@6250
   348
slouken@6250
   349
_PKG_TEXT
slouken@6250
   350
slouken@6250
   351
To get pkg-config, see <http://pkg-config.freedesktop.org/>.])dnl
slouken@6250
   352
        ])
slouken@6250
   353
else
slouken@6250
   354
	$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
slouken@6250
   355
	$1[]_LIBS=$pkg_cv_[]$1[]_LIBS
slouken@6250
   356
        AC_MSG_RESULT([yes])
slouken@6250
   357
	$3
slouken@6250
   358
fi[]dnl
slouken@6250
   359
])# PKG_CHECK_MODULES