1# Configure paths for GIMP
2# Manish Singh    98-6-11
3# Shamelessly stolen from Owen Taylor
4
5dnl AM_PATH_GIMP([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
6dnl Test for GIMP, and define GIMP_CFLAGS and GIMP_LIBS
7dnl
8AC_DEFUN(AM_PATH_GIMP,
9[dnl
10dnl Get the cflags and libraries from the gimptool script
11dnl
12AC_ARG_WITH(gimp-prefix,[  --with-gimp-prefix=PFX  Prefix where GIMP is installed (optional)],
13            gimptool_prefix="$withval", gimptool_prefix="")
14AC_ARG_WITH(gimp-exec-prefix,[  --with-gimp-exec-prefix=PFX Exec prefix where GIMP is installed (optional)],
15            gimptool_exec_prefix="$withval", gimptool_exec_prefix="")
16AC_ARG_ENABLE(gimptest, [  --disable-gimptest      Do not try to compile and run a test GIMP program],
17		    , enable_gimptest=yes)
18
19  if test x$gimptool_exec_prefix != x ; then
20     gimptool_args="$gimptool_args --exec-prefix=$gimptool_exec_prefix"
21     if test x${GIMPTOOL+set} != xset ; then
22        GIMPTOOL=$gimptool_exec_prefix/bin/gimptool
23     fi
24  fi
25  if test x$gimptool_prefix != x ; then
26     gimptool_args="$gimptool_args --prefix=$gimptool_prefix"
27     if test x${GIMPTOOL+set} != xset ; then
28        GIMPTOOL=$gimptool_prefix/bin/gimptool
29     fi
30  fi
31
32  AC_PATH_PROG(GIMPTOOL, gimptool, no)
33  min_gimp_version=ifelse([$1], ,1.0.0,$1)
34  AC_MSG_CHECKING(for GIMP - version >= $min_gimp_version)
35  no_gimp=""
36  if test "$GIMPTOOL" = "no" ; then
37    no_gimp=yes
38  else
39    GIMP_CFLAGS=`$GIMPTOOL $gimptool_args --cflags`
40    GIMP_LIBS=`$GIMPTOOL $gimptool_args --libs`
41
42    GIMP_CFLAGS_NOUI=`$GIMPTOOL $gimptool_args --cflags-noui`
43    noui_test=`echo $GIMP_CFLAGS_NOUI | sed 's/^\(Usage\).*/\1/'`
44    if test "$noui_test" = "Usage" ; then
45       GIMP_CFLAGS_NOUI=$GIMP_CFLAGS
46       GIMP_LIBS_NOUI=$GIMP_LIBS
47    else
48       GIMP_LIBS_NOUI=`$GIMPTOOL $gimptool_args --libs-noui`
49    fi
50
51    GIMP_DATA_DIR=`$GIMPTOOL $gimptool_args --gimpdatadir`
52    GIMP_PLUGIN_DIR=`$GIMPTOOL $gimptool_args --gimpplugindir`
53    nodatadir_test=`echo $GIMP_DATA_DIR | sed 's/^\(Usage\).*/\1/'`
54    if test "$nodatadir_test" = "Usage" ; then
55       GIMP_DATA_DIR=""
56       GIMP_PLUGIN_DIR=""
57    fi
58
59    gimptool_major_version=`$GIMPTOOL $gimptool_args --version | \
60           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
61    gimptool_minor_version=`$GIMPTOOL $gimptool_args --version | \
62           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
63    gimptool_micro_version=`$GIMPTOOL $gimptool_args --version | \
64           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
65    if test "x$enable_gimptest" = "xyes" ; then
66      ac_save_CFLAGS="$CFLAGS"
67      ac_save_LIBS="$LIBS"
68      CFLAGS="$CFLAGS $GIMP_CFLAGS"
69      LIBS="$LIBS $GIMP_LIBS"
70dnl
71dnl Now check if the installed GIMP is sufficiently new. (Also sanity
72dnl checks the results of gimptool to some extent
73dnl
74      rm -f conf.gimptest
75      AC_TRY_RUN([
76#include <stdio.h>
77#include <stdlib.h>
78
79#include <libgimp/gimp.h>
80
81#ifndef GIMP_CHECK_VERSION
82#define GIMP_CHECK_VERSION(major, minor, micro) \
83    (GIMP_MAJOR_VERSION > (major) || \
84     (GIMP_MAJOR_VERSION == (major) && GIMP_MINOR_VERSION > (minor)) || \
85     (GIMP_MAJOR_VERSION == (major) && GIMP_MINOR_VERSION == (minor) && \
86      GIMP_MICRO_VERSION >= (micro)))
87#endif
88
89#if GIMP_CHECK_VERSION(1,1,20)
90GimpPlugInInfo
91#else
92GPlugInInfo
93#endif
94PLUG_IN_INFO =
95{
96  NULL,  /* init_proc */
97  NULL,  /* quit_proc */
98  NULL,  /* query_proc */
99  NULL   /* run_proc */
100};
101
102int main ()
103{
104  int major, minor, micro;
105  char *tmp_version;
106
107  system ("touch conf.gimptest");
108
109  /* HP/UX 9 (%@#!) writes to sscanf strings */
110  tmp_version = g_strdup("$min_gimp_version");
111  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
112     printf("%s, bad version string\n", "$min_gimp_version");
113     exit(1);
114   }
115
116    if (($gimptool_major_version > major) ||
117        (($gimptool_major_version == major) && ($gimptool_minor_version > minor)) ||
118        (($gimptool_major_version == major) && ($gimptool_minor_version == minor) && ($gimptool_micro_version >= micro)))
119    {
120      return 0;
121    }
122  else
123    {
124      printf("\n*** 'gimptool --version' returned %d.%d.%d, but the minimum version\n", $gimptool_major_version, $gimptool_minor_version, $gimptool_micro_version);
125      printf("*** of GIMP required is %d.%d.%d. If gimptool is correct, then it is\n", major, minor, micro);
126      printf("*** best to upgrade to the required version.\n");
127      printf("*** If gimptool was wrong, set the environment variable GIMPTOOL\n");
128      printf("*** to point to the correct copy of gimptool, and remove the file\n");
129      printf("*** config.cache before re-running configure\n");
130      return 1;
131    }
132}
133
134],, no_gimp=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
135       CFLAGS="$ac_save_CFLAGS"
136       LIBS="$ac_save_LIBS"
137     fi
138  fi
139  if test "x$no_gimp" = x ; then
140     AC_MSG_RESULT(yes)
141     ifelse([$2], , :, [$2])
142  else
143     AC_MSG_RESULT(no)
144     if test "$GIMPTOOL" = "no" ; then
145       echo "*** The gimptool script installed by GIMP could not be found"
146       echo "*** If GIMP was installed in PREFIX, make sure PREFIX/bin is in"
147       echo "*** your path, or set the GIMPTOOL environment variable to the"
148       echo "*** full path to gimptool."
149     else
150       if test -f conf.gimptest ; then
151        :
152       else
153          echo "*** Could not run GIMP test program, checking why..."
154          CFLAGS="$CFLAGS $GIMP_CFLAGS"
155          LIBS="$LIBS $GIMP_LIBS"
156          AC_TRY_LINK([
157#include <stdio.h>
158#include <libgimp/gimp.h>
159
160#ifndef GIMP_CHECK_VERSION
161#define GIMP_CHECK_VERSION(major, minor, micro) \
162    (GIMP_MAJOR_VERSION > (major) || \
163     (GIMP_MAJOR_VERSION == (major) && GIMP_MINOR_VERSION > (minor)) || \
164     (GIMP_MAJOR_VERSION == (major) && GIMP_MINOR_VERSION == (minor) && \
165      GIMP_MICRO_VERSION >= (micro)))
166#endif
167
168#if GIMP_CHECK_VERSION(1,1,20)
169GimpPlugInInfo
170#else
171GPlugInInfo
172#endif
173PLUG_IN_INFO =
174{
175  NULL,  /* init_proc */
176  NULL,  /* quit_proc */
177  NULL,  /* query_proc */
178  NULL   /* run_proc */
179};
180],      [ return 0; ],
181        [ echo "*** The test program compiled, but did not run. This usually means"
182          echo "*** that the run-time linker is not finding GIMP or finding the wrong"
183          echo "*** version of GIMP. If it is not finding GIMP, 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 GIMP was incorrectly installed"
192          echo "*** or that you have moved GIMP since it was installed. In the latter case, you"
193          echo "*** may want to edit the gimptool script: $GIMPTOOL" ])
194          CFLAGS="$ac_save_CFLAGS"
195          LIBS="$ac_save_LIBS"
196       fi
197     fi
198     GIMP_CFLAGS=""
199     GIMP_LIBS=""
200     GIMP_CFLAGS_NOUI=""
201     GIMP_LIBS_NOUI=""
202     ifelse([$3], , :, [$3])
203  fi
204  AC_SUBST(GIMP_CFLAGS)
205  AC_SUBST(GIMP_LIBS)
206  AC_SUBST(GIMP_CFLAGS_NOUI)
207  AC_SUBST(GIMP_LIBS_NOUI)
208  AC_SUBST(GIMP_DATA_DIR)
209  AC_SUBST(GIMP_PLUGIN_DIR)
210  rm -f conf.gimptest
211])
212