1# Configure paths for libcdaudio                -*- Autoconf -*-
2#
3# Derived from glib.m4 (Owen Taylor 97-11-3)
4#
5
6dnl AM_PATH_LIBCDAUDIO([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]])
7dnl Test for libcdaudio, and define LIBCDAUDIO_CFLAGS, LIBCDAUDIO_LIBS and
8dnl LIBCDAUDIO_LDADD
9dnl
10AC_DEFUN([AM_PATH_LIBCDAUDIO],
11[dnl
12dnl Get the cflags and libraries from the libcdaudio-config script
13dnl
14AC_ARG_WITH(libcdaudio-prefix,
15            AS_HELP_STRING([--with-libcdaudio-prefix=PFX],
16                           [Prefix where libcdaudio is installed (optional)]),
17            [libcdaudio_config_prefix="$withval"], [libcdaudio_config_prefix=""])
18AC_ARG_WITH(libcdaudio-exec-prefix,
19            AS_HELP_STRING([--with-libcdaudio-exec-prefix=PFX],
20                           [Exec prefix where libcdaudio is installed (optional)]),
21            [libcdaudio_config_exec_prefix="$withval"],
22            [libcdaudio_config_exec_prefix=""])
23AC_ARG_ENABLE(libcdaudiotest,
24              AS_HELP_STRING([--disable-libcdaudiotest],
25	                     [Do not try to compile and run a test libcdaudio program]),,
26	      [enable_libcdaudiotest=yes])
27
28  if test "x$libcdaudio_config_exec_prefix" != x ; then
29     libcdaudio_config_args="$libcdaudio_config_args --exec-prefix=$libcdaudio_config_exec_prefix"
30     if test "x${LIBCDAUDIO_CONFIG+set}" != xset ; then
31        LIBCDAUDIO_CONFIG=$libcdaudio_config_exec_prefix/bin/libcdaudio-config
32     fi
33  fi
34  if test x$libcdaudio_config_prefix != x ; then
35     libcdaudio_config_args="$libcdaudio_config_args --prefix=$libcdaudio_config_prefix"
36     if test "x${LIBCDAUDIO_CONFIG+set}" != xset ; then
37        LIBCDAUDIO_CONFIG=$libcdaudio_config_prefix/bin/libcdaudio-config
38     fi
39  fi
40
41  AC_PATH_PROG(LIBCDAUDIO_CONFIG, libcdaudio-config, no)
42  min_libcdaudio_version=ifelse([$1], ,0.99.0,$1)
43  AC_MSG_CHECKING([for libcdaudio - version >= $min_libcdaudio_version])
44  no_libcdaudio=""
45  if test "$LIBCDAUDIO_CONFIG" = "no" ; then
46    no_libcdaudio=yes
47  else
48    LIBCDAUDIO_CFLAGS=`$LIBCDAUDIO_CONFIG $libcdaudio_config_args --cflags`
49    LIBCDAUDIO_LIBS=`$LIBCDAUDIO_CONFIG $libcdaudio_config_args --libs`
50    LIBCDAUDIO_LDADD=`$LIBCDAUDIO_CONFIG $libcdaudio_config_args --ldadd`
51    libcdaudio_config_major_version=`$LIBCDAUDIO_CONFIG $libcdaudio_config_args --version | \
52           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\).*/\1/'`
53    libcdaudio_config_minor_version=`$LIBCDAUDIO_CONFIG $libcdaudio_config_args --version | \
54           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\).*/\2/'`
55    libcdaudio_config_micro_version=`$LIBCDAUDIO_CONFIG $libcdaudio_config_args --version | \
56           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\).*/\3/'`
57    if test "x$enable_libcdaudiotest" = "xyes" ; then
58      ac_save_CFLAGS="$CFLAGS"
59      ac_save_LIBS="$LIBS"
60      CFLAGS="$CFLAGS $LIBCDAUDIO_CFLAGS $LIBCDAUDIO_LDADD"
61      LIBS="$LIBCDAUDIO_LIBS $LIBS"
62dnl
63dnl Now check if the installed libcdaudio is sufficiently new. (Also sanity
64dnl checks the results of libcdaudio-config to some extent
65dnl
66      rm -f conf.cdaudiotest
67      AC_TRY_RUN([
68#include <cdaudio.h>
69#include <stdio.h>
70#include <stdlib.h>
71
72char* my_strdup (char *str)
73{
74  char *new_str;
75
76  if (str) {
77    new_str = malloc ((strlen (str) + 1) * sizeof(char));
78    strcpy (new_str, str);
79  } else
80    new_str = NULL;
81
82  return new_str;
83}
84
85int main()
86{
87  int major,minor,micro;
88  int libcdaudio_major_version,libcdaudio_minor_version,libcdaudio_micro_version;
89  char *tmp_version;
90
91  system ("touch conf.cdaudiotest");
92
93  /* HP/UX 9 (%@#!) writes to sscanf strings */
94  tmp_version = my_strdup("$min_libcdaudio_version");
95  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
96     printf("%s, bad version string\n", "$min_libcdaudio_version");
97     exit(1);
98   }
99
100  libcdaudio_major_version=(cdaudio_getversion()>>16)&255;
101  libcdaudio_minor_version=(cdaudio_getversion()>> 8)&255;
102  libcdaudio_micro_version=(cdaudio_getversion()    )&255;
103
104  if ((libcdaudio_major_version != $libcdaudio_config_major_version) ||
105      (libcdaudio_minor_version != $libcdaudio_config_minor_version) ||
106      (libcdaudio_micro_version != $libcdaudio_config_micro_version))
107    {
108      printf("\n*** 'libcdaudio-config --version' returned %d.%d.%d, but libcdaudio (%d.%d.%d)\n",
109             $libcdaudio_config_major_version, $libcdaudio_config_minor_version, $libcdaudio_config_micro_version,
110             libcdaudio_major_version, libcdaudio_minor_version, libcdaudio_micro_version);
111      printf ("*** was found! If libcdaudio-config was correct, then it is best\n");
112      printf ("*** to remove the old version of libcdaudio. You may also be able to fix the error\n");
113      printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
114      printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
115      printf("*** required on your system.\n");
116      printf("*** If libcdaudio-config was wrong, set the environment variable LIBCDAUDIO_CONFIG\n");
117      printf("*** to point to the correct copy of libcdaudio-config, and remove the file config.cache\n");
118      printf("*** before re-running configure\n");
119    }
120  else if ((libcdaudio_major_version != LIBCDAUDIO_VERSION_MAJOR) ||
121	   (libcdaudio_minor_version != LIBCDAUDIO_VERSION_MINOR) ||
122           (libcdaudio_micro_version != LIBCDAUDIO_VERSION_MICRO))
123    {
124      printf("*** libcdaudio header files (version %d.%d.%d) do not match\n",
125	     LIBCDAUDIO_VERSION_MAJOR, LIBCDAUDIO_VERSION_MINOR, LIBCDAUDIO_VERSION_MICRO);
126      printf("*** library (version %d.%d.%d)\n",
127	     libcdaudio_major_version, libcdaudio_minor_version, libcdaudio_micro_version);
128    }
129  else
130    {
131      if ((libcdaudio_major_version > major) ||
132        ((libcdaudio_major_version == major) && (libcdaudio_minor_version > minor)) ||
133        ((libcdaudio_major_version == major) && (libcdaudio_minor_version == minor) && (libcdaudio_micro_version >= micro)))
134      {
135        return 0;
136       }
137     else
138      {
139        printf("\n*** An old version of libcdaudio (%d.%d.%d) was found.\n",
140               libcdaudio_major_version, libcdaudio_minor_version, libcdaudio_micro_version);
141        printf("*** You need a version of libcdaudio newer than %d.%d.%d.\n",
142	       major, minor, micro);
143        printf("***\n");
144        printf("*** If you have already installed a sufficiently new version, this error\n");
145        printf("*** probably means that the wrong copy of the libcdaudio-config shell script is\n");
146        printf("*** being found. The easiest way to fix this is to remove the old version\n");
147        printf("*** of libcdaudio, but you can also set the LIBCDAUDIO_CONFIG environment to point to the\n");
148        printf("*** correct copy of libcdaudio-config. (In this case, you will have to\n");
149        printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
150        printf("*** so that the correct libraries are found at run-time))\n");
151      }
152    }
153  return 1;
154}
155],, no_libcdaudio=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
156       CFLAGS="$ac_save_CFLAGS"
157       LIBS="$ac_save_LIBS"
158     fi
159  fi
160  if test "x$no_libcdaudio" = x ; then
161     AC_MSG_RESULT(yes)
162     ifelse([$2], , :, [$2])
163  else
164     AC_MSG_RESULT(no)
165     if test "$LIBCDAUDIO_CONFIG" = "no" ; then
166       echo "*** The libcdaudio-config script installed by libcdaudio could not be found"
167       echo "*** If libcdaudio was installed in PREFIX, make sure PREFIX/bin is in"
168       echo "*** your path, or set the LIBCDAUDIO_CONFIG environment variable to the"
169       echo "*** full path to libcdaudio-config."
170     else
171       if test -f conf.cdaudiotest ; then
172        :
173       else
174          echo "*** Could not run libcdaudio test program, checking why..."
175          CFLAGS="$CFLAGS $LIBCDAUDIO_CFLAGS"
176          LIBS="$LIBS $LIBCDAUDIO_LIBS"
177          AC_TRY_LINK([
178#include <cdaudio.h>
179#include <stdio.h>
180],      [ return (cdaudio_getversion()!=0); ],
181        [ echo "*** The test program compiled, but did not run. This usually means"
182          echo "*** that the run-time linker is not finding libcdaudio or finding the wrong"
183          echo "*** version of libcdaudio. If it is not finding libcdaudio, you'll need to set your"
184          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
185          echo "*** to the installed location. Also, make sure you have run ldconfig if that"
186          echo "*** is required on your system"
187	  echo "***"
188          echo "*** If you have an old version installed, it is best to remove it, although"
189          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
190        [ echo "*** The test program failed to compile or link. See the file config.log for the"
191          echo "*** exact error that occured. This usually means libcdaudio was incorrectly installed"
192          echo "*** or that you have moved libcdaudio since it was installed. In the latter case, you"
193          echo "*** may want to edit the libcdaudio-config script: $LIBCDAUDIO_CONFIG" ])
194          CFLAGS="$ac_save_CFLAGS"
195          LIBS="$ac_save_LIBS"
196       fi
197     fi
198     LIBCDAUDIO_CFLAGS=""
199     LIBCDAUDIO_LIBS=""
200     LIBCDAUDIO_LDADD=""
201     ifelse([$3], , :, [$3])
202  fi
203  AC_SUBST(LIBCDAUDIO_CFLAGS)
204  AC_SUBST(LIBCDAUDIO_LIBS)
205  AC_SUBST(LIBCDAUDIO_LDADD)
206  rm -f conf.cdaudiotest
207])
208