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