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