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