Blame m4macros/gtk-2.0.m4

Packit 98cdb6
# Configure paths for GTK+
Packit 98cdb6
# Owen Taylor     1997-2001
Packit 98cdb6
Packit 98cdb6
dnl AM_PATH_GTK_2_0([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, MODULES]]]])
Packit 98cdb6
dnl Test for GTK+, and define GTK_CFLAGS and GTK_LIBS, if gthread is specified in MODULES, 
Packit 98cdb6
dnl pass to pkg-config
Packit 98cdb6
dnl
Packit 98cdb6
AC_DEFUN([AM_PATH_GTK_2_0],
Packit 98cdb6
[dnl 
Packit 98cdb6
dnl Get the cflags and libraries from pkg-config
Packit 98cdb6
dnl
Packit 98cdb6
AC_ARG_ENABLE(gtktest, [  --disable-gtktest       do not try to compile and run a test GTK+ program],
Packit 98cdb6
		    , enable_gtktest=yes)
Packit 98cdb6
Packit 98cdb6
  pkg_config_args=gtk+-2.0
Packit 98cdb6
  for module in . $4
Packit 98cdb6
  do
Packit 98cdb6
      case "$module" in
Packit 98cdb6
         gthread) 
Packit 98cdb6
             pkg_config_args="$pkg_config_args gthread-2.0"
Packit 98cdb6
         ;;
Packit 98cdb6
      esac
Packit 98cdb6
  done
Packit 98cdb6
Packit 98cdb6
  no_gtk=""
Packit 98cdb6
Packit 98cdb6
  AC_REQUIRE([PKG_PROG_PKG_CONFIG])
Packit 98cdb6
  PKG_PROG_PKG_CONFIG([0.7])
Packit 98cdb6
Packit 98cdb6
  min_gtk_version=ifelse([$1], ,2.0.0,$1)
Packit 98cdb6
  AC_MSG_CHECKING(for GTK+ - version >= $min_gtk_version)
Packit 98cdb6
Packit 98cdb6
  if test x$PKG_CONFIG != xno ; then
Packit 98cdb6
    ## don't try to run the test against uninstalled libtool libs
Packit 98cdb6
    if $PKG_CONFIG --uninstalled $pkg_config_args; then
Packit 98cdb6
	  echo "Will use uninstalled version of GTK+ found in PKG_CONFIG_PATH"
Packit 98cdb6
	  enable_gtktest=no
Packit 98cdb6
    fi
Packit 98cdb6
Packit 98cdb6
    if $PKG_CONFIG --atleast-version $min_gtk_version $pkg_config_args; then
Packit 98cdb6
	  :
Packit 98cdb6
    else
Packit 98cdb6
	  no_gtk=yes
Packit 98cdb6
    fi
Packit 98cdb6
  fi
Packit 98cdb6
Packit 98cdb6
  if test x"$no_gtk" = x ; then
Packit 98cdb6
    GTK_CFLAGS=`$PKG_CONFIG $pkg_config_args --cflags`
Packit 98cdb6
    GTK_LIBS=`$PKG_CONFIG $pkg_config_args --libs`
Packit 98cdb6
    gtk_config_major_version=`$PKG_CONFIG --modversion gtk+-2.0 | \
Packit 98cdb6
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
Packit 98cdb6
    gtk_config_minor_version=`$PKG_CONFIG --modversion gtk+-2.0 | \
Packit 98cdb6
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
Packit 98cdb6
    gtk_config_micro_version=`$PKG_CONFIG --modversion gtk+-2.0 | \
Packit 98cdb6
           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
Packit 98cdb6
    if test "x$enable_gtktest" = "xyes" ; then
Packit 98cdb6
      ac_save_CFLAGS="$CFLAGS"
Packit 98cdb6
      ac_save_LIBS="$LIBS"
Packit 98cdb6
      CFLAGS="$CFLAGS $GTK_CFLAGS"
Packit 98cdb6
      LIBS="$GTK_LIBS $LIBS"
Packit 98cdb6
dnl
Packit 98cdb6
dnl Now check if the installed GTK+ is sufficiently new. (Also sanity
Packit 98cdb6
dnl checks the results of pkg-config to some extent)
Packit 98cdb6
dnl
Packit 98cdb6
      rm -f conf.gtktest
Packit 98cdb6
      AC_TRY_RUN([
Packit 98cdb6
#include <gtk/gtk.h>
Packit 98cdb6
#include <stdio.h>
Packit 98cdb6
#include <stdlib.h>
Packit 98cdb6
Packit 98cdb6
int 
Packit 98cdb6
main ()
Packit 98cdb6
{
Packit 98cdb6
  int major, minor, micro;
Packit 98cdb6
  char *tmp_version;
Packit 98cdb6
Packit 98cdb6
  fclose (fopen ("conf.gtktest", "w"));
Packit 98cdb6
Packit 98cdb6
  /* HP/UX 9 (%@#!) writes to sscanf strings */
Packit 98cdb6
  tmp_version = g_strdup("$min_gtk_version");
Packit 98cdb6
  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
Packit 98cdb6
     printf("%s, bad version string\n", "$min_gtk_version");
Packit 98cdb6
     exit(1);
Packit 98cdb6
   }
Packit 98cdb6
Packit 98cdb6
  if ((gtk_major_version != $gtk_config_major_version) ||
Packit 98cdb6
      (gtk_minor_version != $gtk_config_minor_version) ||
Packit 98cdb6
      (gtk_micro_version != $gtk_config_micro_version))
Packit 98cdb6
    {
Packit 98cdb6
      printf("\n*** 'pkg-config --modversion gtk+-2.0' returned %d.%d.%d, but GTK+ (%d.%d.%d)\n", 
Packit 98cdb6
             $gtk_config_major_version, $gtk_config_minor_version, $gtk_config_micro_version,
Packit 98cdb6
             gtk_major_version, gtk_minor_version, gtk_micro_version);
Packit 98cdb6
      printf ("*** was found! If pkg-config was correct, then it is best\n");
Packit 98cdb6
      printf ("*** to remove the old version of GTK+. You may also be able to fix the error\n");
Packit 98cdb6
      printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
Packit 98cdb6
      printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
Packit 98cdb6
      printf("*** required on your system.\n");
Packit 98cdb6
      printf("*** If pkg-config was wrong, set the environment variable PKG_CONFIG_PATH\n");
Packit 98cdb6
      printf("*** to point to the correct configuration files\n");
Packit 98cdb6
    } 
Packit 98cdb6
  else if ((gtk_major_version != GTK_MAJOR_VERSION) ||
Packit 98cdb6
	   (gtk_minor_version != GTK_MINOR_VERSION) ||
Packit 98cdb6
           (gtk_micro_version != GTK_MICRO_VERSION))
Packit 98cdb6
    {
Packit 98cdb6
      printf("*** GTK+ header files (version %d.%d.%d) do not match\n",
Packit 98cdb6
	     GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
Packit 98cdb6
      printf("*** library (version %d.%d.%d)\n",
Packit 98cdb6
	     gtk_major_version, gtk_minor_version, gtk_micro_version);
Packit 98cdb6
    }
Packit 98cdb6
  else
Packit 98cdb6
    {
Packit 98cdb6
      if ((gtk_major_version > major) ||
Packit 98cdb6
        ((gtk_major_version == major) && (gtk_minor_version > minor)) ||
Packit 98cdb6
        ((gtk_major_version == major) && (gtk_minor_version == minor) && (gtk_micro_version >= micro)))
Packit 98cdb6
      {
Packit 98cdb6
        return 0;
Packit 98cdb6
       }
Packit 98cdb6
     else
Packit 98cdb6
      {
Packit 98cdb6
        printf("\n*** An old version of GTK+ (%d.%d.%d) was found.\n",
Packit 98cdb6
               gtk_major_version, gtk_minor_version, gtk_micro_version);
Packit 98cdb6
        printf("*** You need a version of GTK+ newer than %d.%d.%d. The latest version of\n",
Packit 98cdb6
	       major, minor, micro);
Packit 98cdb6
        printf("*** GTK+ is always available from ftp://ftp.gtk.org.\n");
Packit 98cdb6
        printf("***\n");
Packit 98cdb6
        printf("*** If you have already installed a sufficiently new version, this error\n");
Packit 98cdb6
        printf("*** probably means that the wrong copy of the pkg-config shell script is\n");
Packit 98cdb6
        printf("*** being found. The easiest way to fix this is to remove the old version\n");
Packit 98cdb6
        printf("*** of GTK+, but you can also set the PKG_CONFIG environment to point to the\n");
Packit 98cdb6
        printf("*** correct copy of pkg-config. (In this case, you will have to\n");
Packit 98cdb6
        printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
Packit 98cdb6
        printf("*** so that the correct libraries are found at run-time))\n");
Packit 98cdb6
      }
Packit 98cdb6
    }
Packit 98cdb6
  return 1;
Packit 98cdb6
}
Packit 98cdb6
],, no_gtk=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
Packit 98cdb6
       CFLAGS="$ac_save_CFLAGS"
Packit 98cdb6
       LIBS="$ac_save_LIBS"
Packit 98cdb6
     fi
Packit 98cdb6
  fi
Packit 98cdb6
  if test "x$no_gtk" = x ; then
Packit 98cdb6
     AC_MSG_RESULT(yes (version $gtk_config_major_version.$gtk_config_minor_version.$gtk_config_micro_version))
Packit 98cdb6
     ifelse([$2], , :, [$2])     
Packit 98cdb6
  else
Packit 98cdb6
     AC_MSG_RESULT(no)
Packit 98cdb6
     if test "$PKG_CONFIG" = "no" ; then
Packit 98cdb6
       echo "*** A new enough version of pkg-config was not found."
Packit 98cdb6
       echo "*** See http://pkgconfig.sourceforge.net"
Packit 98cdb6
     else
Packit 98cdb6
       if test -f conf.gtktest ; then
Packit 98cdb6
        :
Packit 98cdb6
       else
Packit 98cdb6
          echo "*** Could not run GTK+ test program, checking why..."
Packit 98cdb6
	  ac_save_CFLAGS="$CFLAGS"
Packit 98cdb6
	  ac_save_LIBS="$LIBS"
Packit 98cdb6
          CFLAGS="$CFLAGS $GTK_CFLAGS"
Packit 98cdb6
          LIBS="$LIBS $GTK_LIBS"
Packit 98cdb6
          AC_TRY_LINK([
Packit 98cdb6
#include <gtk/gtk.h>
Packit 98cdb6
#include <stdio.h>
Packit 98cdb6
],      [ return ((gtk_major_version) || (gtk_minor_version) || (gtk_micro_version)); ],
Packit 98cdb6
        [ echo "*** The test program compiled, but did not run. This usually means"
Packit 98cdb6
          echo "*** that the run-time linker is not finding GTK+ or finding the wrong"
Packit 98cdb6
          echo "*** version of GTK+. If it is not finding GTK+, you'll need to set your"
Packit 98cdb6
          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
Packit 98cdb6
          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
Packit 98cdb6
          echo "*** is required on your system"
Packit 98cdb6
	  echo "***"
Packit 98cdb6
          echo "*** If you have an old version installed, it is best to remove it, although"
Packit 98cdb6
          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" ],
Packit 98cdb6
        [ echo "*** The test program failed to compile or link. See the file config.log for the"
Packit 98cdb6
          echo "*** exact error that occured. This usually means GTK+ is incorrectly installed."])
Packit 98cdb6
          CFLAGS="$ac_save_CFLAGS"
Packit 98cdb6
          LIBS="$ac_save_LIBS"
Packit 98cdb6
       fi
Packit 98cdb6
     fi
Packit 98cdb6
     GTK_CFLAGS=""
Packit 98cdb6
     GTK_LIBS=""
Packit 98cdb6
     ifelse([$3], , :, [$3])
Packit 98cdb6
  fi
Packit 98cdb6
  AC_SUBST(GTK_CFLAGS)
Packit 98cdb6
  AC_SUBST(GTK_LIBS)
Packit 98cdb6
  rm -f conf.gtktest
Packit 98cdb6
])