]> Pileus Git - ~andy/gtk/blob - gtk.m4
Unset CATOBJEXT so that the macros and Makefiles correctly handle
[~andy/gtk] / gtk.m4
1 # Configure paths for GTK+
2 # Owen Taylor     97-11-3
3
4 dnl AM_PATH_GTK([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
5 dnl Test for GTK, and define GTK_CFLAGS and GTK_LIBS
6 dnl
7 AC_DEFUN(AM_PATH_GTK,
8 [dnl 
9 dnl Get the cflags and libraries from the gtk-config script
10 dnl
11 AC_ARG_WITH(gtk-prefix,[  --with-gtk-prefix=PFX   Prefix where GTK is installed (optional)],
12             gtk_config_prefix="$withval", gtk_config_prefix="")
13 AC_ARG_WITH(gtk-exec-prefix,[  --with-gtk-exec-prefix=PFX Exec prefix where GTK is installed (optional)],
14             gtk_config_exec_prefix="$withval", gtk_config_exec_prefix="")
15 AC_ARG_ENABLE(gtktest, [  --disable-gtktest       Do not try to compile and run a test GTK program],
16                     , enable_gtktest=yes)
17
18   if test x$gtk_config_exec_prefix != x ; then
19      gtk_config_args="$gtk_config_args --exec-prefix=$gtk_config_exec_prefix"
20      if test x${GTK_CONFIG+set} != xset ; then
21         GTK_CONFIG=$gtk_config_exec_prefix/bin/gtk-config
22      fi
23   fi
24   if test x$gtk_config_prefix != x ; then
25      gtk_config_args="$gtk_config_args --prefix=$gtk_config_prefix"
26      if test x${GTK_CONFIG+set} != xset ; then
27         GTK_CONFIG=$gtk_config_prefix/bin/gtk-config
28      fi
29   fi
30
31   AC_PATH_PROG(GTK_CONFIG, gtk-config, no)
32   min_gtk_version=ifelse([$1], ,0.99.7,$1)
33   AC_MSG_CHECKING(for GTK - version >= $min_gtk_version)
34   no_gtk=""
35   if test "$GTK_CONFIG" = "no" ; then
36     no_gtk=yes
37   else
38     GTK_CFLAGS=`$GTK_CONFIG $gtk_config_args --cflags`
39     GTK_LIBS=`$GTK_CONFIG $gtk_config_args --libs`
40     gtk_config_major_version=`$GTK_CONFIG $gtk_config_args --version | \
41            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
42     gtk_config_minor_version=`$GTK_CONFIG $gtk_config_args --version | \
43            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
44     gtk_config_micro_version=`$GTK_CONFIG $gtk_config_args --version | \
45            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
46     if test "x$enable_gtktest" = "xyes" ; then
47       ac_save_CFLAGS="$CFLAGS"
48       ac_save_LIBS="$LIBS"
49       CFLAGS="$CFLAGS $GTK_CFLAGS"
50       LIBS="$GTK_LIBS $LIBS"
51 dnl
52 dnl Now check if the installed GTK is sufficiently new. (Also sanity
53 dnl checks the results of gtk-config to some extent
54 dnl
55       rm -f conf.gtktest
56       AC_TRY_RUN([
57 #include <gtk/gtk.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.gtktest");
68
69   /* HP/UX 9 (%@#!) writes to sscanf strings */
70   tmp_version = g_strdup("$min_gtk_version");
71   if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
72      printf("%s, bad version string\n", "$min_gtk_version");
73      exit(1);
74    }
75
76   if ((gtk_major_version != $gtk_config_major_version) ||
77       (gtk_minor_version != $gtk_config_minor_version) ||
78       (gtk_micro_version != $gtk_config_micro_version))
79     {
80       printf("\n*** 'gtk-config --version' returned %d.%d.%d, but GTK+ (%d.%d.%d)\n", 
81              $gtk_config_major_version, $gtk_config_minor_version, $gtk_config_micro_version,
82              gtk_major_version, gtk_minor_version, gtk_micro_version);
83       printf ("*** was found! If gtk-config was correct, then it is best\n");
84       printf ("*** to remove the old version of GTK+. 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 gtk-config was wrong, set the environment variable GTK_CONFIG\n");
89       printf("*** to point to the correct copy of gtk-config, and remove the file config.cache\n");
90       printf("*** before re-running configure\n");
91     } 
92 #if defined (GTK_MAJOR_VERSION) && defined (GTK_MINOR_VERSION) && defined (GTK_MICRO_VERSION)
93   else if ((gtk_major_version != GTK_MAJOR_VERSION) ||
94            (gtk_minor_version != GTK_MINOR_VERSION) ||
95            (gtk_micro_version != GTK_MICRO_VERSION))
96     {
97       printf("*** GTK+ header files (version %d.%d.%d) do not match\n",
98              GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
99       printf("*** library (version %d.%d.%d)\n",
100              gtk_major_version, gtk_minor_version, gtk_micro_version);
101     }
102 #endif /* defined (GTK_MAJOR_VERSION) ... */
103   else
104     {
105       if ((gtk_major_version > major) ||
106         ((gtk_major_version == major) && (gtk_minor_version > minor)) ||
107         ((gtk_major_version == major) && (gtk_minor_version == minor) && (gtk_micro_version >= micro)))
108       {
109         return 0;
110        }
111      else
112       {
113         printf("\n*** An old version of GTK+ (%d.%d.%d) was found.\n",
114                gtk_major_version, gtk_minor_version, gtk_micro_version);
115         printf("*** You need a version of GTK+ newer than %d.%d.%d. The latest version of\n",
116                major, minor, micro);
117         printf("*** GTK+ is always available from ftp://ftp.gtk.org.\n");
118         printf("***\n");
119         printf("*** If you have already installed a sufficiently new version, this error\n");
120         printf("*** probably means that the wrong copy of the gtk-config shell script is\n");
121         printf("*** being found. The easiest way to fix this is to remove the old version\n");
122         printf("*** of GTK+, but you can also set the GTK_CONFIG environment to point to the\n");
123         printf("*** correct copy of gtk-config. (In this case, you will have to\n");
124         printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n");
125         printf("*** so that the correct libraries are found at run-time))\n");
126       }
127     }
128   return 1;
129 }
130 ],, no_gtk=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
131        CFLAGS="$ac_save_CFLAGS"
132        LIBS="$ac_save_LIBS"
133      fi
134   fi
135   if test "x$no_gtk" = x ; then
136      AC_MSG_RESULT(yes)
137      ifelse([$2], , :, [$2])     
138   else
139      AC_MSG_RESULT(no)
140      if test "$GTK_CONFIG" = "no" ; then
141        echo "*** The gtk-config script installed by GTK could not be found"
142        echo "*** If GTK was installed in PREFIX, make sure PREFIX/bin is in"
143        echo "*** your path, or set the GTK_CONFIG environment variable to the"
144        echo "*** full path to gtk-config."
145      else
146        if test -f conf.gtktest ; then
147         :
148        else
149           echo "*** Could not run GTK test program, checking why..."
150           CFLAGS="$CFLAGS $GTK_CFLAGS"
151           LIBS="$LIBS $GTK_LIBS"
152           AC_TRY_LINK([
153 #include <gtk/gtk.h>
154 #include <stdio.h>
155 ],      [ return ((gtk_major_version) || (gtk_minor_version) || (gtk_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 GTK or finding the wrong"
158           echo "*** version of GTK. If it is not finding GTK, 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 GTK was incorrectly installed"
172           echo "*** or that you have moved GTK since it was installed. In the latter case, you"
173           echo "*** may want to edit the gtk-config script: $GTK_CONFIG" ])
174           CFLAGS="$ac_save_CFLAGS"
175           LIBS="$ac_save_LIBS"
176        fi
177      fi
178      GTK_CFLAGS=""
179      GTK_LIBS=""
180      ifelse([$3], , :, [$3])
181   fi
182   AC_SUBST(GTK_CFLAGS)
183   AC_SUBST(GTK_LIBS)
184   rm -f conf.gtktest
185 ])