added g_array_insert_vals() to insert elements at an arbitrary index, and
[platform/upstream/glib.git] / glib.m4
1 # Configure paths for GLIB
2 # Owen Taylor     97-11-3
3
4 dnl AM_PATH_GLIB([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, MODULES]]]])
5 dnl Test for GLIB, and define GLIB_CFLAGS and GLIB_LIBS, if "gmodule" is specified
6 dnl in MODULES, feature the glib-config gmodule option.
7 dnl
8 AC_DEFUN(AM_PATH_GLIB,
9 [dnl 
10 dnl Get the cflags and libraries from the glib-config script
11 dnl
12 AC_ARG_WITH(glib-prefix,[  --with-glib-prefix=PFX   Prefix where GLIB is installed (optional)],
13             glib_config_prefix="$withval", glib_config_prefix="")
14 AC_ARG_WITH(glib-exec-prefix,[  --with-glib-exec-prefix=PFX Exec prefix where GLIB is installed (optional)],
15             glib_config_exec_prefix="$withval", glib_config_exec_prefix="")
16 AC_ARG_ENABLE(glibtest, [  --disable-glibtest       Do not try to compile and run a test GLIB program],
17                     , enable_glibtest=yes)
18
19   if test x$glib_config_exec_prefix != x ; then
20      glib_config_args="$glib_config_args --exec-prefix=$glib_config_exec_prefix"
21      if test x${GLIB_CONFIG+set} != xset ; then
22         GLIB_CONFIG=$glib_config_exec_prefix/bin/glib-config
23      fi
24   fi
25   if test x$glib_config_prefix != x ; then
26      glib_config_args="$glib_config_args --prefix=$glib_config_prefix"
27      if test x${GLIB_CONFIG+set} != xset ; then
28         GLIB_CONFIG=$glib_config_prefix/bin/glib-config
29      fi
30   fi
31
32   case "$4" in
33   *gmodule*) glib_config_args="$glib_config_args gmodule";;
34   esac
35
36   AC_PATH_PROG(GLIB_CONFIG, glib-config, no)
37   min_glib_version=ifelse([$1], ,0.99.7,$1)
38   AC_MSG_CHECKING(for GLIB - version >= $min_glib_version)
39   no_glib=""
40   if test "$GLIB_CONFIG" = "no" ; then
41     no_glib=yes
42   else
43     GLIB_CFLAGS=`$GLIB_CONFIG $glib_config_args --cflags`
44     GLIB_LIBS=`$GLIB_CONFIG $glib_config_args --libs`
45     glib_config_major_version=`$GLIB_CONFIG $glib_config_args --version | \
46            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
47     glib_config_minor_version=`$GLIB_CONFIG $glib_config_args --version | \
48            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
49     glib_config_micro_version=`$GLIB_CONFIG $glib_config_args --version | \
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="$LIBS $GLIB_LIBS"
56 dnl
57 dnl Now check if the installed GLIB is sufficiently new. (Also sanity
58 dnl checks the results of glib-config 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*** 'glib-config --version' 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 glib-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 glib-config was wrong, set the environment variable GLIB_CONFIG\n");
94       printf("*** to point to the correct copy of glib-config, and remove the file config.cache\n");
95       printf("*** before re-running configure\n");
96     } 
97   else if ((glib_major_version != GLIB_MAJOR_VERSION) ||
98            (glib_minor_version != GLIB_MINOR_VERSION) ||
99            (glib_micro_version != GLIB_MICRO_VERSION))
100     {
101       printf("*** GLIB header files (version %d.%d.%d) do not match\n",
102              GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
103       printf("*** library (version %d.%d.%d)\n",
104              glib_major_version, glib_minor_version, glib_micro_version);
105     }
106   else
107     {
108       if ((glib_major_version > major) ||
109         ((glib_major_version == major) && (glib_minor_version > minor)) ||
110         ((glib_major_version == major) && (glib_minor_version == minor) && (glib_micro_version >= micro)))
111       {
112         return 0;
113        }
114      else
115       {
116         printf("\n*** An old version of GLIB (%d.%d.%d) was found.\n",
117                glib_major_version, glib_minor_version, glib_micro_version);
118         printf("*** You need a version of GLIB newer than %d.%d.%d. The latest version of\n",
119                major, minor, micro);
120         printf("*** GLIB is always available from ftp://ftp.gtk.org.\n");
121         printf("***\n");
122         printf("*** If you have already installed a sufficiently new version, this error\n");
123         printf("*** probably means that the wrong copy of the glib-config shell script is\n");
124         printf("*** being found. The easiest way to fix this is to remove the old version\n");
125         printf("*** of GLIB, but you can also set the GLIB_CONFIG environment to point to the\n");
126         printf("*** correct copy of glib-config. (In this case, you will have to\n");
127         printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
128         printf("*** so that the correct libraries are found at run-time))\n");
129       }
130     }
131   return 1;
132 }
133 ],, no_glib=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
134        CFLAGS="$ac_save_CFLAGS"
135        LIBS="$ac_save_LIBS"
136      fi
137   fi
138   if test "x$no_glib" = x ; then
139      AC_MSG_RESULT(yes)
140      ifelse([$2], , :, [$2])     
141   else
142      AC_MSG_RESULT(no)
143      if test "$GLIB_CONFIG" = "no" ; then
144        echo "*** The glib-config script installed by GLIB could not be found"
145        echo "*** If GLIB was installed in PREFIX, make sure PREFIX/bin is in"
146        echo "*** your path, or set the GLIB_CONFIG environment variable to the"
147        echo "*** full path to glib-config."
148      else
149        if test -f conf.glibtest ; then
150         :
151        else
152           echo "*** Could not run GLIB test program, checking why..."
153           CFLAGS="$CFLAGS $GLIB_CFLAGS"
154           LIBS="$LIBS $GLIB_LIBS"
155           AC_TRY_LINK([
156 #include <glib.h>
157 #include <stdio.h>
158 ],      [ return ((glib_major_version) || (glib_minor_version) || (glib_micro_version)); ],
159         [ echo "*** The test program compiled, but did not run. This usually means"
160           echo "*** that the run-time linker is not finding GLIB or finding the wrong"
161           echo "*** version of GLIB. If it is not finding GLIB, you'll need to set your"
162           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
163           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
164           echo "*** is required on your system"
165           echo "***"
166           echo "*** If you have an old version installed, it is best to remove it, although"
167           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"
168           echo "***"
169           echo "*** If you have a RedHat 5.0 system, you should remove the GTK package that"
170           echo "*** came with the system with the command"
171           echo "***"
172           echo "***    rpm --erase --nodeps gtk gtk-devel" ],
173         [ echo "*** The test program failed to compile or link. See the file config.log for the"
174           echo "*** exact error that occured. This usually means GLIB was incorrectly installed"
175           echo "*** or that you have moved GLIB since it was installed. In the latter case, you"
176           echo "*** may want to edit the glib-config script: $GLIB_CONFIG" ])
177           CFLAGS="$ac_save_CFLAGS"
178           LIBS="$ac_save_LIBS"
179        fi
180      fi
181      GLIB_CFLAGS=""
182      GLIB_LIBS=""
183      ifelse([$3], , :, [$3])
184   fi
185   AC_SUBST(GLIB_CFLAGS)
186   AC_SUBST(GLIB_LIBS)
187   rm -f conf.glibtest
188 ])