acinclude/sdl2.m4
author Sam Lantinga <slouken@libsdl.org>
Mon, 30 Jan 2012 21:41:45 -0500
changeset 582 df72f22b4b41
parent 578 3b2c95ee3398
child 651 bdc42aaa1cf7
permissions -rw-r--r--
Switched the SDL 2 autoconf macro to AM_PATH_SDL2
slouken@578
     1
# Configure paths for SDL
slouken@578
     2
# Sam Lantinga 9/21/99
slouken@578
     3
# stolen from Manish Singh
slouken@578
     4
# stolen back from Frank Belew
slouken@578
     5
# stolen from Manish Singh
slouken@578
     6
# Shamelessly stolen from Owen Taylor
slouken@578
     7
slouken@578
     8
# serial 1
slouken@578
     9
slouken@578
    10
dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
slouken@578
    11
dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
slouken@578
    12
dnl
slouken@582
    13
AC_DEFUN([AM_PATH_SDL2],
slouken@578
    14
[dnl 
slouken@578
    15
dnl Get the cflags and libraries from the sdl2-config script
slouken@578
    16
dnl
slouken@578
    17
AC_ARG_WITH(sdl-prefix,[  --with-sdl-prefix=PFX   Prefix where SDL is installed (optional)],
slouken@578
    18
            sdl_prefix="$withval", sdl_prefix="")
slouken@578
    19
AC_ARG_WITH(sdl-exec-prefix,[  --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
slouken@578
    20
            sdl_exec_prefix="$withval", sdl_exec_prefix="")
slouken@578
    21
AC_ARG_ENABLE(sdltest, [  --disable-sdltest       Do not try to compile and run a test SDL program],
slouken@578
    22
		    , enable_sdltest=yes)
slouken@578
    23
slouken@578
    24
  min_sdl_version=ifelse([$1], ,0.9.0,$1)
slouken@578
    25
slouken@578
    26
  if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
slouken@578
    27
    PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
slouken@578
    28
           [sdl_pc=yes],
slouken@578
    29
           [sdl_pc=no])
slouken@578
    30
  else
slouken@578
    31
    sdl_pc=no
slouken@578
    32
    if test x$sdl_exec_prefix != x ; then
slouken@578
    33
      sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
slouken@578
    34
      if test x${SDL_CONFIG+set} != xset ; then
slouken@578
    35
        SDL_CONFIG=$sdl_exec_prefix/bin/sdl2-config
slouken@578
    36
      fi
slouken@578
    37
    fi
slouken@578
    38
    if test x$sdl_prefix != x ; then
slouken@578
    39
      sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
slouken@578
    40
      if test x${SDL_CONFIG+set} != xset ; then
slouken@578
    41
        SDL_CONFIG=$sdl_prefix/bin/sdl2-config
slouken@578
    42
      fi
slouken@578
    43
    fi
slouken@578
    44
  fi
slouken@578
    45
slouken@578
    46
  if test "x$sdl_pc" = xyes ; then
slouken@578
    47
    no_sdl=""
slouken@578
    48
    SDL_CONFIG="pkg-config sdl2"
slouken@578
    49
  else
slouken@578
    50
    as_save_PATH="$PATH"
slouken@578
    51
    if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
slouken@578
    52
      PATH="$prefix/bin:$prefix/usr/bin:$PATH"
slouken@578
    53
    fi
slouken@578
    54
    AC_PATH_PROG(SDL_CONFIG, sdl2-config, no, [$PATH])
slouken@578
    55
    PATH="$as_save_PATH"
slouken@578
    56
    AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
slouken@578
    57
    no_sdl=""
slouken@578
    58
slouken@578
    59
    if test "$SDL_CONFIG" = "no" ; then
slouken@578
    60
      no_sdl=yes
slouken@578
    61
    else
slouken@578
    62
      SDL_CFLAGS=`$SDL_CONFIG $sdl_config_args --cflags`
slouken@578
    63
      SDL_LIBS=`$SDL_CONFIG $sdl_config_args --libs`
slouken@578
    64
slouken@578
    65
      sdl_major_version=`$SDL_CONFIG $sdl_config_args --version | \
slouken@578
    66
             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
slouken@578
    67
      sdl_minor_version=`$SDL_CONFIG $sdl_config_args --version | \
slouken@578
    68
             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
slouken@578
    69
      sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
slouken@578
    70
             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
slouken@578
    71
      if test "x$enable_sdltest" = "xyes" ; then
slouken@578
    72
        ac_save_CFLAGS="$CFLAGS"
slouken@578
    73
        ac_save_CXXFLAGS="$CXXFLAGS"
slouken@578
    74
        ac_save_LIBS="$LIBS"
slouken@578
    75
        CFLAGS="$CFLAGS $SDL_CFLAGS"
slouken@578
    76
        CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
slouken@578
    77
        LIBS="$LIBS $SDL_LIBS"
slouken@578
    78
dnl
slouken@578
    79
dnl Now check if the installed SDL is sufficiently new. (Also sanity
slouken@578
    80
dnl checks the results of sdl2-config to some extent
slouken@578
    81
dnl
slouken@578
    82
      rm -f conf.sdltest
slouken@578
    83
      AC_TRY_RUN([
slouken@578
    84
#include <stdio.h>
slouken@578
    85
#include <stdlib.h>
slouken@578
    86
#include <string.h>
slouken@578
    87
#include "SDL.h"
slouken@578
    88
slouken@578
    89
char*
slouken@578
    90
my_strdup (char *str)
slouken@578
    91
{
slouken@578
    92
  char *new_str;
slouken@578
    93
  
slouken@578
    94
  if (str)
slouken@578
    95
    {
slouken@578
    96
      new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
slouken@578
    97
      strcpy (new_str, str);
slouken@578
    98
    }
slouken@578
    99
  else
slouken@578
   100
    new_str = NULL;
slouken@578
   101
  
slouken@578
   102
  return new_str;
slouken@578
   103
}
slouken@578
   104
slouken@578
   105
int main (int argc, char *argv[])
slouken@578
   106
{
slouken@578
   107
  int major, minor, micro;
slouken@578
   108
  char *tmp_version;
slouken@578
   109
slouken@578
   110
  /* This hangs on some systems (?)
slouken@578
   111
  system ("touch conf.sdltest");
slouken@578
   112
  */
slouken@578
   113
  { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
slouken@578
   114
slouken@578
   115
  /* HP/UX 9 (%@#!) writes to sscanf strings */
slouken@578
   116
  tmp_version = my_strdup("$min_sdl_version");
slouken@578
   117
  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
slouken@578
   118
     printf("%s, bad version string\n", "$min_sdl_version");
slouken@578
   119
     exit(1);
slouken@578
   120
   }
slouken@578
   121
slouken@578
   122
   if (($sdl_major_version > major) ||
slouken@578
   123
      (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
slouken@578
   124
      (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
slouken@578
   125
    {
slouken@578
   126
      return 0;
slouken@578
   127
    }
slouken@578
   128
  else
slouken@578
   129
    {
slouken@578
   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@578
   131
      printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
slouken@578
   132
      printf("*** best to upgrade to the required version.\n");
slouken@578
   133
      printf("*** If sdl2-config was wrong, set the environment variable SDL_CONFIG\n");
slouken@578
   134
      printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
slouken@578
   135
      printf("*** config.cache before re-running configure\n");
slouken@578
   136
      return 1;
slouken@578
   137
    }
slouken@578
   138
}
slouken@578
   139
slouken@578
   140
],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
slouken@578
   141
        CFLAGS="$ac_save_CFLAGS"
slouken@578
   142
        CXXFLAGS="$ac_save_CXXFLAGS"
slouken@578
   143
        LIBS="$ac_save_LIBS"
slouken@578
   144
      fi
slouken@578
   145
    fi
slouken@578
   146
    if test "x$no_sdl" = x ; then
slouken@578
   147
      AC_MSG_RESULT(yes)
slouken@578
   148
    else
slouken@578
   149
      AC_MSG_RESULT(no)
slouken@578
   150
    fi
slouken@578
   151
  fi
slouken@578
   152
  if test "x$no_sdl" = x ; then
slouken@578
   153
     ifelse([$2], , :, [$2])
slouken@578
   154
  else
slouken@578
   155
     if test "$SDL_CONFIG" = "no" ; then
slouken@578
   156
       echo "*** The sdl2-config script installed by SDL could not be found"
slouken@578
   157
       echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
slouken@578
   158
       echo "*** your path, or set the SDL_CONFIG environment variable to the"
slouken@578
   159
       echo "*** full path to sdl2-config."
slouken@578
   160
     else
slouken@578
   161
       if test -f conf.sdltest ; then
slouken@578
   162
        :
slouken@578
   163
       else
slouken@578
   164
          echo "*** Could not run SDL test program, checking why..."
slouken@578
   165
          CFLAGS="$CFLAGS $SDL_CFLAGS"
slouken@578
   166
          CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
slouken@578
   167
          LIBS="$LIBS $SDL_LIBS"
slouken@578
   168
          AC_TRY_LINK([
slouken@578
   169
#include <stdio.h>
slouken@578
   170
#include "SDL.h"
slouken@578
   171
slouken@578
   172
int main(int argc, char *argv[])
slouken@578
   173
{ return 0; }
slouken@578
   174
#undef  main
slouken@578
   175
#define main K_and_R_C_main
slouken@578
   176
],      [ return 0; ],
slouken@578
   177
        [ echo "*** The test program compiled, but did not run. This usually means"
slouken@578
   178
          echo "*** that the run-time linker is not finding SDL or finding the wrong"
slouken@578
   179
          echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
slouken@578
   180
          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
slouken@578
   181
          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
slouken@578
   182
          echo "*** is required on your system"
slouken@578
   183
	  echo "***"
slouken@578
   184
          echo "*** If you have an old version installed, it is best to remove it, although"
slouken@578
   185
          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
slouken@578
   186
        [ echo "*** The test program failed to compile or link. See the file config.log for the"
slouken@578
   187
          echo "*** exact error that occured. This usually means SDL was incorrectly installed"
slouken@578
   188
          echo "*** or that you have moved SDL since it was installed. In the latter case, you"
slouken@578
   189
          echo "*** may want to edit the sdl2-config script: $SDL_CONFIG" ])
slouken@578
   190
          CFLAGS="$ac_save_CFLAGS"
slouken@578
   191
          CXXFLAGS="$ac_save_CXXFLAGS"
slouken@578
   192
          LIBS="$ac_save_LIBS"
slouken@578
   193
       fi
slouken@578
   194
     fi
slouken@578
   195
     SDL_CFLAGS=""
slouken@578
   196
     SDL_LIBS=""
slouken@578
   197
     ifelse([$3], , :, [$3])
slouken@578
   198
  fi
slouken@578
   199
  AC_SUBST(SDL_CFLAGS)
slouken@578
   200
  AC_SUBST(SDL_LIBS)
slouken@578
   201
  rm -f conf.sdltest
slouken@578
   202
])