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