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