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