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