2005-02-10 [paul] 1.0.1cvs3.2
[claws.git] / m4 / missing / imlib.m4
1 # Configure paths for IMLIB
2 # Frank Belew     98-8-31
3 # stolen from Manish Singh
4 # Shamelessly stolen from Owen Taylor
5
6 dnl AM_PATH_IMLIB([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
7 dnl Test for IMLIB, and define IMLIB_CFLAGS and IMLIB_LIBS
8 dnl
9 AC_DEFUN([AM_PATH_IMLIB],
10 [dnl 
11 dnl Get the cflags and libraries from the imlib-config script
12 dnl
13 AC_ARG_WITH(imlib-prefix,[  --with-imlib-prefix=PFX   Prefix where IMLIB is installed (optional)],
14             imlib_prefix="$withval", imlib_prefix="")
15 AC_ARG_WITH(imlib-exec-prefix,[  --with-imlib-exec-prefix=PFX Exec prefix where IMLIB is installed (optional)],
16             imlib_exec_prefix="$withval", imlib_exec_prefix="")
17 AC_ARG_ENABLE(imlibtest, [  --disable-imlibtest       Do not try to compile and run a test IMLIB program],
18                     , enable_imlibtest=yes)
19
20   if test x$imlib_exec_prefix != x ; then
21      imlib_args="$imlib_args --exec-prefix=$imlib_exec_prefix"
22      if test x${IMLIB_CONFIG+set} != xset ; then
23         IMLIB_CONFIG=$imlib_exec_prefix/bin/imlib-config
24      fi
25   fi
26   if test x$imlib_prefix != x ; then
27      imlib_args="$imlib_args --prefix=$imlib_prefix"
28      if test x${IMLIB_CONFIG+set} != xset ; then
29         IMLIB_CONFIG=$imlib_prefix/bin/imlib-config
30      fi
31   fi
32
33   AC_PATH_PROG(IMLIB_CONFIG, imlib-config, no)
34   min_imlib_version=ifelse([$1], ,1.8.2,$1)
35   AC_MSG_CHECKING(for IMLIB - version >= $min_imlib_version)
36   no_imlib=""
37   if test "$IMLIB_CONFIG" = "no" ; then
38     no_imlib=yes
39   else
40     IMLIB_CFLAGS=`$IMLIB_CONFIG $imlibconf_args --cflags`
41     IMLIB_LIBS=`$IMLIB_CONFIG $imlibconf_args --libs`
42
43     imlib_major_version=`$IMLIB_CONFIG $imlib_args --version | \
44            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
45     imlib_minor_version=`$IMLIB_CONFIG $imlib_args --version | \
46            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
47     imlib_micro_version=`$IMLIB_CONFIG $imlib_args --version | \
48            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
49     if test "x$enable_imlibtest" = "xyes" ; then
50       ac_save_CFLAGS="$CFLAGS"
51       ac_save_LIBS="$LIBS"
52       CFLAGS="$CFLAGS $IMLIB_CFLAGS"
53       LIBS="$LIBS $IMLIB_LIBS"
54 dnl
55 dnl Now check if the installed IMLIB is sufficiently new. (Also sanity
56 dnl checks the results of imlib-config to some extent
57 dnl
58       rm -f conf.imlibtest
59       AC_TRY_RUN([
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <string.h>
63 #include <Imlib.h>
64
65 char*
66 my_strdup (char *str)
67 {
68   char *new_str;
69   
70   if (str)
71     {
72       new_str = malloc ((strlen (str) + 1) * sizeof(char));
73       strcpy (new_str, str);
74     }
75   else
76     new_str = NULL;
77   
78   return new_str;
79 }
80
81 int main ()
82 {
83   int major, minor, micro;
84   char *tmp_version;
85
86   system ("touch conf.imlibtest");
87
88   /* HP/UX 9 (%@#!) writes to sscanf strings */
89   tmp_version = my_strdup("$min_imlib_version");
90   if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
91      printf("%s, bad version string\n", "$min_imlib_version");
92      exit(1);
93    }
94
95     if (($imlib_major_version > major) ||
96         (($imlib_major_version == major) && ($imlib_minor_version > minor)) ||
97         (($imlib_major_version == major) && ($imlib_minor_version == minor) &&
98         ($imlib_micro_version >= micro)))
99     {
100       return 0;
101     }
102   else
103     {
104       printf("\n*** 'imlib-config --version' returned %d.%d, but the minimum version\n", $imlib_major_version, $imlib_minor_version);
105       printf("*** of IMLIB required is %d.%d. If imlib-config is correct, then it is\n", major, minor);
106       printf("*** best to upgrade to the required version.\n");
107       printf("*** If imlib-config was wrong, set the environment variable IMLIB_CONFIG\n");
108       printf("*** to point to the correct copy of imlib-config, and remove the file\n");
109       printf("*** config.cache before re-running configure\n");
110       return 1;
111     }
112 }
113
114 ],, no_imlib=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
115        CFLAGS="$ac_save_CFLAGS"
116        LIBS="$ac_save_LIBS"
117      fi
118   fi
119   if test "x$no_imlib" = x ; then
120      AC_MSG_RESULT(yes)
121      ifelse([$2], , :, [$2])     
122   else
123      AC_MSG_RESULT(no)
124      if test "$IMLIB_CONFIG" = "no" ; then
125        echo "*** The imlib-config script installed by IMLIB could not be found"
126        echo "*** If IMLIB was installed in PREFIX, make sure PREFIX/bin is in"
127        echo "*** your path, or set the IMLIB_CONFIG environment variable to the"
128        echo "*** full path to imlib-config."
129      else
130        if test -f conf.imlibtest ; then
131         :
132        else
133           echo "*** Could not run IMLIB test program, checking why..."
134           CFLAGS="$CFLAGS $IMLIB_CFLAGS"
135           LIBS="$LIBS $IMLIB_LIBS"
136           AC_TRY_LINK([
137 #include <stdio.h>
138 #include <Imlib.h>
139 ],      [ return 0; ],
140         [ echo "*** The test program compiled, but did not run. This usually means"
141           echo "*** that the run-time linker is not finding IMLIB or finding the wrong"
142           echo "*** version of IMLIB. If it is not finding IMLIB, you'll need to set your"
143           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
144           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
145           echo "*** is required on your system"
146           echo "***"
147           echo "*** If you have an old version installed, it is best to remove it, although"
148           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
149         [ echo "*** The test program failed to compile or link. See the file config.log for the"
150           echo "*** exact error that occured. This usually means IMLIB was incorrectly installed"
151           echo "*** or that you have moved IMLIB since it was installed. In the latter case, you"
152           echo "*** may want to edit the imlib-config script: $IMLIB_CONFIG" ])
153           CFLAGS="$ac_save_CFLAGS"
154           LIBS="$ac_save_LIBS"
155        fi
156      fi
157      IMLIB_CFLAGS=""
158      IMLIB_LIBS=""
159      ifelse([$3], , :, [$3])
160   fi
161   AC_SUBST(IMLIB_CFLAGS)
162   AC_SUBST(IMLIB_LIBS)
163   rm -f conf.imlibtest
164 ])
165
166 # Check for gdk-imlib
167 AC_DEFUN(AM_PATH_GDK_IMLIB,
168 [dnl 
169 dnl Get the cflags and libraries from the imlib-config script
170 dnl
171 AC_ARG_WITH(imlib-prefix,[  --with-imlib-prefix=PFX   Prefix where IMLIB is installed (optional)],
172             imlib_prefix="$withval", imlib_prefix="")
173 AC_ARG_WITH(imlib-exec-prefix,[  --with-imlib-exec-prefix=PFX Exec prefix where IMLIB is installed (optional)],
174             imlib_exec_prefix="$withval", imlib_exec_prefix="")
175 AC_ARG_ENABLE(imlibtest, [  --disable-imlibtest       Do not try to compile and run a test IMLIB program],
176                     , enable_imlibtest=yes)
177
178   if test x$imlib_exec_prefix != x ; then
179      imlib_args="$imlib_args --exec-prefix=$imlib_exec_prefix"
180      if test x${IMLIB_CONFIG+set} != xset ; then
181         IMLIB_CONFIG=$imlib_exec_prefix/bin/imlib-config
182      fi
183   fi
184   if test x$imlib_prefix != x ; then
185      imlib_args="$imlib_args --prefix=$imlib_prefix"
186      if test x${IMLIB_CONFIG+set} != xset ; then
187         IMLIB_CONFIG=$imlib_prefix/bin/imlib-config
188      fi
189   fi
190
191   AC_PATH_PROG(IMLIB_CONFIG, imlib-config, no)
192   min_imlib_version=ifelse([$1], ,1.8.2,$1)
193   AC_MSG_CHECKING(for IMLIB - version >= $min_imlib_version)
194   no_imlib=""
195   if test "$IMLIB_CONFIG" = "no" ; then
196     no_imlib=yes
197   else
198     GDK_IMLIB_CFLAGS=`$IMLIB_CONFIG $imlibconf_args --cflags-gdk`
199     GDK_IMLIB_LIBS=`$IMLIB_CONFIG $imlibconf_args --libs-gdk`
200
201     imlib_major_version=`$IMLIB_CONFIG $imlib_args --version | \
202            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
203     imlib_minor_version=`$IMLIB_CONFIG $imlib_args --version | \
204            sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
205     if test "x$enable_imlibtest" = "xyes" ; then
206       ac_save_CFLAGS="$CFLAGS"
207       ac_save_LIBS="$LIBS"
208       CFLAGS="$CFLAGS $GDK_IMLIB_CFLAGS"
209       LIBS="$LIBS $GDK_IMLIB_LIBS"
210 dnl
211 dnl Now check if the installed IMLIB is sufficiently new. (Also sanity
212 dnl checks the results of imlib-config to some extent
213 dnl
214       rm -f conf.imlibtest
215       AC_TRY_RUN([
216 #include <stdio.h>
217 #include <stdlib.h>
218 #include <gdk_imlib.h>
219
220 int main ()
221 {
222   int major, minor;
223   char *tmp_version;
224
225   system ("touch conf.gdkimlibtest");
226
227   /* HP/UX 9 (%@#!) writes to sscanf strings */
228   tmp_version = g_strdup("$min_imlib_version");
229   if (sscanf(tmp_version, "%d.%d", &major, &minor) != 2) {
230      printf("%s, bad version string\n", "$min_imlib_version");
231      exit(1);
232    }
233
234     if (($imlib_major_version > major) ||
235         (($imlib_major_version == major) && ($imlib_minor_version >= minor)))
236     {
237       return 0;
238     }
239   else
240     {
241       printf("\n*** 'imlib-config --version' returned %d.%d, but the minimum version\n", $imlib_major_version, $imlib_minor_version);
242       printf("*** of IMLIB required is %d.%d. If imlib-config is correct, then it is\n", major, minor);
243       printf("*** best to upgrade to the required version.\n");
244       printf("*** If imlib-config was wrong, set the environment variable IMLIB_CONFIG\n");
245       printf("*** to point to the correct copy of imlib-config, and remove the file\n");
246       printf("*** config.cache before re-running configure\n");
247       return 1;
248     }
249 }
250
251 ],, no_imlib=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
252        CFLAGS="$ac_save_CFLAGS"
253        LIBS="$ac_save_LIBS"
254      fi
255   fi
256   if test "x$no_imlib" = x ; then
257      AC_MSG_RESULT(yes)
258      ifelse([$2], , :, [$2])     
259   else
260      AC_MSG_RESULT(no)
261      if test "$IMLIB_CONFIG" = "no" ; then
262        echo "*** The imlib-config script installed by IMLIB could not be found"
263        echo "*** If IMLIB was installed in PREFIX, make sure PREFIX/bin is in"
264        echo "*** your path, or set the IMLIB_CONFIG environment variable to the"
265        echo "*** full path to imlib-config."
266      else
267        if test -f conf.gdkimlibtest ; then
268         :
269        else
270           echo "*** Could not run IMLIB test program, checking why..."
271           CFLAGS="$CFLAGS $GDK_IMLIB_CFLAGS"
272           LIBS="$LIBS $GDK_IMLIB_LIBS"
273           AC_TRY_LINK([
274 #include <stdio.h>
275 #include <gdk_imlib.h>
276 ],      [ return 0; ],
277         [ echo "*** The test program compiled, but did not run. This usually means"
278           echo "*** that the run-time linker is not finding IMLIB or finding the wrong"
279           echo "*** version of IMLIB. If it is not finding IMLIB, you'll need to set your"
280           echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
281           echo "*** to the installed location  Also, make sure you have run ldconfig if that"
282           echo "*** is required on your system"
283           echo "***"
284           echo "*** If you have an old version installed, it is best to remove it, although"
285           echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
286         [ echo "*** The test program failed to compile or link. See the file config.log for the"
287           echo "*** exact error that occured. This usually means IMLIB was incorrectly installed"
288           echo "*** or that you have moved IMLIB since it was installed. In the latter case, you"
289           echo "*** may want to edit the imlib-config script: $IMLIB_CONFIG" ])
290           CFLAGS="$ac_save_CFLAGS"
291           LIBS="$ac_save_LIBS"
292        fi
293      fi
294      IMLIB_CFLAGS=""
295      IMLIB_LIBS=""
296      ifelse([$3], , :, [$3])
297   fi
298   AC_SUBST(GDK_IMLIB_CFLAGS)
299   AC_SUBST(GDK_IMLIB_LIBS)
300   rm -f conf.gdkimlibtest
301 ])