Merge Irssi 0.8.16-rc1
[silc.git] / apps / irssi / glib-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, gobject or 
6 dnl gthread is specified in MODULES, pass to pkg-config
7 dnl
8 AC_DEFUN([AM_PATH_GLIB_2_0],
9 [dnl 
10 dnl Get the cflags and libraries from pkg-config
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=glib-2.0
16   for module in . $4
17   do
18       case "$module" in
19          gmodule) 
20              pkg_config_args="$pkg_config_args gmodule-2.0"
21          ;;
22          gmodule-no-export) 
23              pkg_config_args="$pkg_config_args gmodule-no-export-2.0"
24          ;;
25          gobject) 
26              pkg_config_args="$pkg_config_args gobject-2.0"
27          ;;
28          gthread) 
29              pkg_config_args="$pkg_config_args gthread-2.0"
30          ;;
31       esac
32   done
33
34   PKG_PROG_PKG_CONFIG([0.7])
35
36   no_glib=""
37
38   if test "x$PKG_CONFIG" = x ; then
39     no_glib=yes
40     PKG_CONFIG=no
41   fi
42
43   min_glib_version=ifelse([$1], ,2.0.0,$1)
44   AC_MSG_CHECKING(for GLIB - version >= $min_glib_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 GLib found in PKG_CONFIG_PATH"
50           enable_glibtest=no
51     fi
52
53     if $PKG_CONFIG --atleast-version $min_glib_version $pkg_config_args; then
54           :
55     else
56           no_glib=yes
57     fi
58   fi
59
60   if test x"$no_glib" = x ; then
61     GLIB_GENMARSHAL=`$PKG_CONFIG --variable=glib_genmarshal glib-2.0`
62     GOBJECT_QUERY=`$PKG_CONFIG --variable=gobject_query glib-2.0`
63     GLIB_MKENUMS=`$PKG_CONFIG --variable=glib_mkenums glib-2.0`
64
65     GLIB_CFLAGS=`$PKG_CONFIG --cflags $pkg_config_args`
66     GLIB_LIBS=`$PKG_CONFIG --libs $pkg_config_args`
67     glib_config_major_version=`$PKG_CONFIG --modversion glib-2.0 | \
68            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
69     glib_config_minor_version=`$PKG_CONFIG --modversion glib-2.0 | \
70            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
71     glib_config_micro_version=`$PKG_CONFIG --modversion glib-2.0 | \
72            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
73     if test "x$enable_glibtest" = "xyes" ; then
74       ac_save_CFLAGS="$CFLAGS"
75       ac_save_LIBS="$LIBS"
76       CFLAGS="$CFLAGS $GLIB_CFLAGS"
77       LIBS="$GLIB_LIBS $LIBS"
78 dnl
79 dnl Now check if the installed GLIB is sufficiently new. (Also sanity
80 dnl checks the results of pkg-config to some extent)
81 dnl
82       rm -f conf.glibtest
83       AC_TRY_RUN([
84 #include <glib.h>
85 #include <stdio.h>
86 #include <stdlib.h>
87
88 int 
89 main ()
90 {
91   int major, minor, micro;
92   char *tmp_version;
93
94   system ("touch conf.glibtest");
95
96   /* HP/UX 9 (%@#!) writes to sscanf strings */
97   tmp_version = g_strdup("$min_glib_version");
98   if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
99      printf("%s, bad version string\n", "$min_glib_version");
100      exit(1);
101    }
102
103   if ((glib_major_version != $glib_config_major_version) ||
104       (glib_minor_version != $glib_config_minor_version) ||
105       (glib_micro_version != $glib_config_micro_version))
106     {
107       printf("\n*** 'pkg-config --modversion glib-2.0' returned %d.%d.%d, but GLIB (%d.%d.%d)\n", 
108              $glib_config_major_version, $glib_config_minor_version, $glib_config_micro_version,
109              glib_major_version, glib_minor_version, glib_micro_version);
110       printf ("*** was found! If pkg-config was correct, then it is best\n");
111       printf ("*** to remove the old version of GLib. You may also be able to fix the error\n");
112       printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n");
113       printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n");
114       printf("*** required on your system.\n");
115       printf("*** If pkg-config was wrong, set the environment variable PKG_CONFIG_PATH\n");
116       printf("*** to point to the correct configuration files\n");
117     } 
118   else if ((glib_major_version != GLIB_MAJOR_VERSION) ||
119            (glib_minor_version != GLIB_MINOR_VERSION) ||
120            (glib_micro_version != GLIB_MICRO_VERSION))
121     {
122       printf("*** GLIB header files (version %d.%d.%d) do not match\n",
123              GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
124       printf("*** library (version %d.%d.%d)\n",
125              glib_major_version, glib_minor_version, glib_micro_version);
126     }
127   else
128     {
129       if ((glib_major_version > major) ||
130         ((glib_major_version == major) && (glib_minor_version > minor)) ||
131         ((glib_major_version == major) && (glib_minor_version == minor) && (glib_micro_version >= micro)))
132       {
133         return 0;
134        }
135      else
136       {
137         printf("\n*** An old version of GLIB (%d.%d.%d) was found.\n",
138                glib_major_version, glib_minor_version, glib_micro_version);
139         printf("*** You need a version of GLIB newer than %d.%d.%d. The latest version of\n",
140                major, minor, micro);
141         printf("*** GLIB is always available from ftp://ftp.gtk.org.\n");
142         printf("***\n");
143         printf("*** If you have already installed a sufficiently new version, this error\n");
144         printf("*** probably means that the wrong copy of the pkg-config shell script is\n");
145         printf("*** being found. The easiest way to fix this is to remove the old version\n");
146         printf("*** of GLIB, but you can also set the PKG_CONFIG environment to point to the\n");
147         printf("*** correct copy of pkg-config. (In this case, you will have to\n");
148         printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
149         printf("*** so that the correct libraries are found at run-time))\n");
150       }
151     }
152   return 1;
153 }
154 ],, no_glib=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
155        CFLAGS="$ac_save_CFLAGS"
156        LIBS="$ac_save_LIBS"
157      fi
158   fi
159   if test "x$no_glib" = x ; then
160      AC_MSG_RESULT(yes (version $glib_config_major_version.$glib_config_minor_version.$glib_config_micro_version))
161      ifelse([$2], , :, [$2])     
162   else
163      AC_MSG_RESULT(no)
164      if test "$PKG_CONFIG" = "no" ; then
165        echo "*** A new enough version of pkg-config was not found."
166        echo "*** See http://www.freedesktop.org/software/pkgconfig/"
167      else
168        if test -f conf.glibtest ; then
169         :
170        else
171           echo "*** Could not run GLIB test program, checking why..."
172           ac_save_CFLAGS="$CFLAGS"
173           ac_save_LIBS="$LIBS"
174           CFLAGS="$CFLAGS $GLIB_CFLAGS"
175           LIBS="$LIBS $GLIB_LIBS"
176           AC_TRY_LINK([
177 #include <glib.h>
178 #include <stdio.h>
179 ],      [ return ((glib_major_version) || (glib_minor_version) || (glib_micro_version)); ],
180         [ echo "*** The test program compiled, but did not run. This usually means"
181           echo "*** that the run-time linker is not finding GLIB or finding the wrong"
182           echo "*** version of GLIB. If it is not finding GLIB, you'll need to set your"
183           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
184           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
185           echo "*** is required on your system"
186           echo "***"
187           echo "*** If you have an old version installed, it is best to remove it, although"
188           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" ],
189         [ echo "*** The test program failed to compile or link. See the file config.log for the"
190           echo "*** exact error that occured. This usually means GLIB is incorrectly installed."])
191           CFLAGS="$ac_save_CFLAGS"
192           LIBS="$ac_save_LIBS"
193        fi
194      fi
195      GLIB_CFLAGS=""
196      GLIB_LIBS=""
197      GLIB_GENMARSHAL=""
198      GOBJECT_QUERY=""
199      GLIB_MKENUMS=""
200      ifelse([$3], , :, [$3])
201   fi
202   AC_SUBST(GLIB_CFLAGS)
203   AC_SUBST(GLIB_LIBS)
204   AC_SUBST(GLIB_GENMARSHAL)
205   AC_SUBST(GOBJECT_QUERY)
206   AC_SUBST(GLIB_MKENUMS)
207   rm -f conf.glibtest
208 ])