1# Configure paths for SDLmm
2# David Hedbor, 2000-07-22
3# stolen from SDL
4# stolen from Manish Singh
5# stolen back from Frank Belew
6# stolen from Manish Singh
7# Shamelessly stolen from Owen Taylor
8
9dnl AM_PATH_SDLMM([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
10dnl Test for SDLmm, and define SDLMM_CXXFLAGS and SDLMM_LIBS
11dnl
12AC_DEFUN(AM_PATH_SDLMM,
13[dnl
14dnl Get the cflags and libraries from the ismap-config script
15dnl
16AC_ARG_WITH(sdlmm-prefix,[  --with-sdlmm-prefix=PFX   Prefix where SDLmm is installed (optional)],
17            sdlmm_prefix="$withval", sdlmm_prefix="")
18AC_ARG_WITH(sdlmm-exec-prefix,[  --with-sdlmm-exec-prefix=PFX Exec prefix where SDLmm is installed (optional)],
19            sdlmm_exec_prefix="$withval", sdlmm_exec_prefix="")
20AC_ARG_ENABLE(sdlmmtest, [  --disable-sdlmmtest       Do not try to compile and run a test SDLmm program],
21		    , enable_sdlmmtest=yes)
22
23  if test x$sdlmm_exec_prefix != x ; then
24     sdlmm_args="$sdlmm_args --exec-prefix=$sdlmm_exec_prefix"
25     if test x${SDLMM_CONFIG+set} != xset ; then
26        SDLMM_CONFIG=$sdlmm_exec_prefix/bin/sdlmm-config
27     fi
28  fi
29  if test x$sdlmm_prefix != x ; then
30     sdlmm_args="$sdlmm_args --prefix=$sdlmm_prefix"
31     if test x${SDLMM_CONFIG+set} != xset ; then
32        SDLMM_CONFIG=$sdlmm_prefix/bin/sdlmm-config
33     fi
34  fi
35
36  AC_PATH_PROG(SDLMM_CONFIG, sdlmm-config, no)
37  min_sdlmm_version=ifelse([$1], ,0.11.0,$1)
38  AC_MSG_CHECKING(for SDLmm version >= $min_sdlmm_version)
39  no_sdlmm=""
40  if test "$SDLMM_CONFIG" = "no" ; then
41    no_sdlmm=yes
42  else
43    SDLMM_CXXFLAGS=`$SDLMM_CONFIG $sdlmmconf_args --cflags`
44    SDLMM_LIBS=`$SDLMM_CONFIG $sdlmmconf_args --libs`
45
46    sdlmm_major_version=`$SDLMM_CONFIG $sdlmm_args --version | \
47           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
48    sdlmm_minor_version=`$SDLMM_CONFIG $sdlmm_args --version | \
49           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
50    sdlmm_micro_version=`$SDLMM_CONFIG $sdlmm_config_args --version | \
51           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
52    if test "x$enable_sdlmmtest" = "xyes" ; then
53      ac_save_CXXFLAGS="$CXXFLAGS"
54      ac_save_LIBS="$LIBS"
55      CXXFLAGS="$CXXFLAGS $SDLMM_CXXFLAGS"
56      LIBS="$LIBS $SDLMM_LIBS"
57dnl
58dnl Now check if the installed SDLmm is sufficiently new. (Also sanity
59dnl checks the results of sdlmm-config to some extent
60dnl
61      rm -f conf.sdlmmtest
62      AC_TRY_RUN([
63#include <cstdio>
64#include <cstring>
65#include "SDLmm/sdlmm.h"
66char*
67my_strdup (char *str)
68{
69  char *new_str;
70
71  if (str)
72    {
73      new_str = (char *)malloc ((std::strlen (str) + 1) * sizeof(char));
74      std::strcpy (new_str, str);
75    }
76  else
77    new_str = NULL;
78
79  return new_str;
80}
81
82int main (int argc, char *argv[])
83{
84  int major, minor, micro;
85  char *tmp_version;
86
87  /* This hangs on some systems (?)
88  system ("touch conf.sdlmmtest");
89  */
90  { FILE *fp = fopen("conf.sdlmmtest", "a"); if ( fp ) fclose(fp); }
91
92  /* HP/UX 9 (%@#!) writes to sscanf strings */
93  tmp_version = my_strdup("$min_sdlmm_version");
94  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
95     printf("%s, bad version string\n", "$min_sdlmm_version");
96     return 1;
97   }
98
99   if (($sdlmm_major_version > major) ||
100      (($sdlmm_major_version == major) && ($sdlmm_minor_version > minor)) ||
101      (($sdlmm_major_version == major) && ($sdlmm_minor_version == minor) && ($sdlmm_micro_version >= micro)))
102    {
103      return 0;
104    }
105  else
106    {
107      printf("\n*** 'sdlmm-config --version' returned %d.%d.%d, but the minimum version\n", $sdlmm_major_version, $sdlmm_minor_version, $sdlmm_micro_version);
108      printf("*** of SDLmm required is %d.%d.%d. If sdlmm-config is correct, then it is\n", major, minor, micro);
109      printf("*** best to upgrade to the required version.\n");
110      printf("*** If sdlmm-config was wrong, set the environment variable SDLMM_CONFIG\n");
111      printf("*** to point to the correct copy of sdlmm-config, and remove the file\n");
112      printf("*** config.cache before re-running configure\n");
113      return 1;
114    }
115}
116
117],, no_sdlmm=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
118       CXXFLAGS="$ac_save_CXXFLAGS"
119       LIBS="$ac_save_LIBS"
120     fi
121  fi
122  if test "x$no_sdlmm" = x ; then
123     AC_MSG_RESULT(yes)
124     ifelse([$2], , :, [$2])
125  else
126     AC_MSG_RESULT(no)
127     if test "$SDLMM_CONFIG" = "no" ; then
128       echo "*** The sdlmm-config script installed by SDLmm could not be found"
129       echo "*** If SDLmm was installed in PREFIX, make sure PREFIX/bin is in"
130       echo "*** your path, or set the SDLMM_CONFIG environment variable to the"
131       echo "*** full path to sdlmm-config."
132     else
133       if test -f conf.sdlmmtest ; then
134        :
135       else
136          echo "*** Could not run SDLmm test program, checking why..."
137          CXXFLAGS="$CXXFLAGS $SDLMM_CXXFLAGS"
138          LIBS="$LIBS $SDLMM_LIBS"
139          AC_TRY_LINK([
140#include <cstdio>
141#include "sdlmm.h"
142],      [ return 0; ],
143        [ echo "*** The test program compiled, but did not run. This usually means"
144          echo "*** that the run-time linker is not finding SDLmm or finding the wrong"
145          echo "*** version of SDLmm. If it is not finding SDLmm, you'll need to set your"
146          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
147          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
148          echo "*** is required on your system"
149	  echo "***"
150          echo "*** If you have an old version installed, it is best to remove it, although"
151          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
152        [ echo "*** The test program failed to compile or link. See the file config.log for the"
153          echo "*** exact error that occured. This usually means SDLmm was incorrectly installed"
154          echo "*** or that you have moved SDLmm since it was installed. In the latter case, you"
155          echo "*** may want to edit the sdlmm-config script: $SDLMM_CONFIG" ])
156          CXXFLAGS="$ac_save_CXXFLAGS"
157          LIBS="$ac_save_LIBS"
158       fi
159     fi
160     SDLMM_CXXFLAGS=""
161     SDLMM_LIBS=""
162     ifelse([$3], , :, [$3])
163  fi
164  AC_SUBST(SDLMM_CXXFLAGS)
165  AC_SUBST(SDLMM_LIBS)
166  rm -f conf.sdlmmtest
167])
168