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