gtk-2.0.m4 7.47 KB
Newer Older
1
# Configure paths for GTK+
Owen Taylor's avatar
Owen Taylor committed
2
# Owen Taylor     1997-2001
3

4 5 6
dnl AM_PATH_GTK_2_0([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, MODULES]]]])
dnl Test for GTK+, and define GTK_CFLAGS and GTK_LIBS, if gthread is specified in MODULES, 
dnl pass to pkg-config
7
dnl
8
AC_DEFUN(AM_PATH_GTK_2_0,
9
[dnl 
10
dnl Get the cflags and libraries from pkg-config
11
dnl
12
AC_ARG_ENABLE(gtktest, [  --disable-gtktest       do not try to compile and run a test GTK+ program],
13
		    , enable_gtktest=yes)
14

Owen Taylor's avatar
Owen Taylor committed
15
  pkg_config_args=gtk+-2.0
Owen Taylor's avatar
Owen Taylor committed
16 17 18 19
  for module in . $4
  do
      case "$module" in
         gthread) 
Owen Taylor's avatar
Owen Taylor committed
20
             pkg_config_args="$pkg_config_args gthread-2.0"
Owen Taylor's avatar
Owen Taylor committed
21 22 23 24
         ;;
      esac
  done

25
  no_gtk=""
Owen Taylor's avatar
Owen Taylor committed
26 27 28 29

  AC_PATH_PROG(PKG_CONFIG, pkg-config, no)

  if test x$PKG_CONFIG != xno ; then
30
    if pkg-config --atleast-pkgconfig-version 0.7 ; then
Owen Taylor's avatar
Owen Taylor committed
31 32
      :
    else
33
      echo *** pkg-config too old; version 0.7 or better required.
34
      no_gtk=yes
Owen Taylor's avatar
Owen Taylor committed
35 36
      PKG_CONFIG=no
    fi
37 38
  else
    no_gtk=yes
39 40
  fi

Owen Taylor's avatar
Owen Taylor committed
41
  min_gtk_version=ifelse([$1], ,2.0.0,$1)
42 43
  AC_MSG_CHECKING(for GTK+ - version >= $min_gtk_version)

44 45 46 47 48 49
  if test x$PKG_CONFIG != xno ; then
    ## don't try to run the test against uninstalled libtool libs
    if $PKG_CONFIG --uninstalled $pkg_config_args; then
	  echo "Will use uninstalled version of GTK+ found in PKG_CONFIG_PATH"
	  enable_gtktest=no
    fi
50

51 52 53 54 55
    if $PKG_CONFIG --atleast-version $min_gtk_version $pkg_config_args; then
	  :
    else
	  no_gtk=yes
    fi
56 57
  fi

58 59 60 61
  if test x"$no_gtk" = x ; then
    GTK_CFLAGS=`$PKG_CONFIG $pkg_config_args --cflags`
    GTK_LIBS=`$PKG_CONFIG $pkg_config_args --libs`
    gtk_config_major_version=`$PKG_CONFIG --modversion gtk+-2.0 | \
62
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
63
    gtk_config_minor_version=`$PKG_CONFIG --modversion gtk+-2.0 | \
64
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
65
    gtk_config_micro_version=`$PKG_CONFIG --modversion gtk+-2.0 | \
66
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
67
    if test "x$enable_gtktest" = "xyes" ; then
68 69
      ac_save_CFLAGS="$CFLAGS"
      ac_save_LIBS="$LIBS"
70 71
      CFLAGS="$CFLAGS $GTK_CFLAGS"
      LIBS="$GTK_LIBS $LIBS"
72
dnl
73 74
dnl Now check if the installed GTK+ is sufficiently new. (Also sanity
dnl checks the results of pkg-config to some extent)
75
dnl
76
      rm -f conf.gtktest
77
      AC_TRY_RUN([
78
#include <gtk/gtk.h>
79
#include <stdio.h>
Owen Taylor's avatar
Owen Taylor committed
80
#include <stdlib.h>
81 82 83 84 85

int 
main ()
{
  int major, minor, micro;
Tim Janik's avatar
Tim Janik committed
86
  char *tmp_version;
87

88
  system ("touch conf.gtktest");
89

Tim Janik's avatar
Tim Janik committed
90
  /* HP/UX 9 (%@#!) writes to sscanf strings */
91
  tmp_version = g_strdup("$min_gtk_version");
Tim Janik's avatar
Tim Janik committed
92
  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
93
     printf("%s, bad version string\n", "$min_gtk_version");
94 95 96
     exit(1);
   }

97 98 99
  if ((gtk_major_version != $gtk_config_major_version) ||
      (gtk_minor_version != $gtk_config_minor_version) ||
      (gtk_micro_version != $gtk_config_micro_version))
100
    {
101 102 103
      printf("\n*** 'pkg-config --modversion gtk+-2.0' returned %d.%d.%d, but GTK+ (%d.%d.%d)\n", 
             $gtk_config_major_version, $gtk_config_minor_version, $gtk_config_micro_version,
             gtk_major_version, gtk_minor_version, gtk_micro_version);
Owen Taylor's avatar
Owen Taylor committed
104
      printf ("*** was found! If pkg-config was correct, then it is best\n");
105
      printf ("*** to remove the old version of GTK+. You may also be able to fix the error\n");
106 107 108
      printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
      printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
      printf("*** required on your system.\n");
Owen Taylor's avatar
Owen Taylor committed
109 110
      printf("*** If pkg-config was wrong, set the environment variable PKG_CONFIG_PATH\n");
      printf("*** to point to the correct configuration files\n");
111
    } 
112 113 114
  else if ((gtk_major_version != GTK_MAJOR_VERSION) ||
	   (gtk_minor_version != GTK_MINOR_VERSION) ||
           (gtk_micro_version != GTK_MICRO_VERSION))
Owen Taylor's avatar
Owen Taylor committed
115
    {
116 117
      printf("*** GTK+ header files (version %d.%d.%d) do not match\n",
	     GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
Owen Taylor's avatar
Owen Taylor committed
118
      printf("*** library (version %d.%d.%d)\n",
119
	     gtk_major_version, gtk_minor_version, gtk_micro_version);
Owen Taylor's avatar
Owen Taylor committed
120
    }
121 122
  else
    {
123 124 125
      if ((gtk_major_version > major) ||
        ((gtk_major_version == major) && (gtk_minor_version > minor)) ||
        ((gtk_major_version == major) && (gtk_minor_version == minor) && (gtk_micro_version >= micro)))
126 127 128 129 130
      {
        return 0;
       }
     else
      {
131 132 133
        printf("\n*** An old version of GTK+ (%d.%d.%d) was found.\n",
               gtk_major_version, gtk_minor_version, gtk_micro_version);
        printf("*** You need a version of GTK+ newer than %d.%d.%d. The latest version of\n",
134
	       major, minor, micro);
135
        printf("*** GTK+ is always available from ftp://ftp.gtk.org.\n");
136 137
        printf("***\n");
        printf("*** If you have already installed a sufficiently new version, this error\n");
Owen Taylor's avatar
Owen Taylor committed
138
        printf("*** probably means that the wrong copy of the pkg-config shell script is\n");
139
        printf("*** being found. The easiest way to fix this is to remove the old version\n");
140
        printf("*** of GTK+, but you can also set the PKG_CONFIG environment to point to the\n");
Owen Taylor's avatar
Owen Taylor committed
141
        printf("*** correct copy of pkg-config. (In this case, you will have to\n");
142 143 144 145 146
        printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
        printf("*** so that the correct libraries are found at run-time))\n");
      }
    }
  return 1;
147
}
148
],, no_gtk=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
149 150 151
       CFLAGS="$ac_save_CFLAGS"
       LIBS="$ac_save_LIBS"
     fi
152
  fi
153 154
  if test "x$no_gtk" = x ; then
     AC_MSG_RESULT(yes (version $gtk_config_major_version.$gtk_config_minor_version.$gtk_config_micro_version))
155 156 157
     ifelse([$2], , :, [$2])     
  else
     AC_MSG_RESULT(no)
Owen Taylor's avatar
Owen Taylor committed
158 159 160
     if test "$PKG_CONFIG" = "no" ; then
       echo "*** A new enough version of pkg-config was not found."
       echo "*** See http://pkgconfig.sourceforge.net"
161
     else
162
       if test -f conf.gtktest ; then
163 164
        :
       else
165 166 167
          echo "*** Could not run GTK+ test program, checking why..."
          CFLAGS="$CFLAGS $GTK_CFLAGS"
          LIBS="$LIBS $GTK_LIBS"
168
          AC_TRY_LINK([
169
#include <gtk/gtk.h>
170
#include <stdio.h>
171
],      [ return ((gtk_major_version) || (gtk_minor_version) || (gtk_micro_version)); ],
172
        [ echo "*** The test program compiled, but did not run. This usually means"
173 174
          echo "*** that the run-time linker is not finding GTK+ or finding the wrong"
          echo "*** version of GTK+. If it is not finding GTK+, you'll need to set your"
175 176 177 178 179
          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
          echo "*** is required on your system"
	  echo "***"
          echo "*** If you have an old version installed, it is best to remove it, although"
180
          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" ],
181
        [ echo "*** The test program failed to compile or link. See the file config.log for the"
182 183
          echo "*** exact error that occured. This usually means GTK+ was incorrectly installed"
          echo "*** or that you have moved GTK+ since it was installed. In the latter case, you"
Owen Taylor's avatar
Owen Taylor committed
184
          echo "*** may want to edit the pkg-config script: $PKG_CONFIG" ])
185 186 187 188
          CFLAGS="$ac_save_CFLAGS"
          LIBS="$ac_save_LIBS"
       fi
     fi
189 190
     GTK_CFLAGS=""
     GTK_LIBS=""
191 192
     ifelse([$3], , :, [$3])
  fi
193 194 195
  AC_SUBST(GTK_CFLAGS)
  AC_SUBST(GTK_LIBS)
  rm -f conf.gtktest
196
])