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