* app/diapsftrenderer.c: including ftoutln.h
[dia.git] / acinclude.m4
blob68a4f14ab73c4df1b5ada6743c129980a5fc0841
1 dnl Check if the C compiler accepts a certain C flag, and if so adds it to
2 dnl CFLAGS
3 AC_DEFUN(DIA_CHECK_CFLAG, [
4   AC_MSG_CHECKING(if C compiler accepts $1)
5   save_CFLAGS="$CFLAGS"
6   CFLAGS="$CFLAGS $1"
7   AC_TRY_COMPILE([#include <stdio.h>], [printf("hello");],
8     [AC_MSG_RESULT(yes)],dnl
9     [AC_MSG_RESULT(no)
10      CFLAGS="$save_CFLAGS"])
13 ## ------------------------
14 ## Python file handling
15 ## From Andrew Dalke
16 ## Updated by James Henstridge
17 ## ------------------------
19 # AM_PATH_PYTHON([MINIMUM-VERSION])
21 # Adds support for distributing Python modules and packages.  To
22 # install modules, copy them to $(pythondir), using the python_PYTHON
23 # automake variable.  To install a package with the same name as the
24 # automake package, install to $(pkgpythondir), or use the
25 # pkgpython_PYTHON automake variable.
27 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
28 # locations to install python extension modules (shared libraries).
29 # Another macro is required to find the appropriate flags to compile
30 # extension modules.
32 # If your package is configured with a different prefix to python,
33 # users will have to add the install directory to the PYTHONPATH
34 # environment variable, or create a .pth file (see the python
35 # documentation for details).
37 # If the MINIUMUM-VERSION argument is passed, AM_PATH_PYTHON will
38 # cause an error if the version of python installed on the system
39 # doesn't meet the requirement.  MINIMUM-VERSION should consist of
40 # numbers and dots only.
43 AC_DEFUN([AM_PATH_PYTHON],
44  [
45   dnl Find a version of Python.  I could check for python versions 1.4
46   dnl or earlier, but the default installation locations changed from
47   dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
48   dnl in 1.5, and I don't want to maintain that logic.
50   if test -z "$PYTHON"; then
51      AC_PATH_PROGS(PYTHON, python python2.1 python2.0 python1.6 python1.5)
52   fi
54   dnl should we do the version check?
55   ifelse([$1],[],,[
56     AC_MSG_CHECKING(if Python version >= $1)
57     changequote(<<, >>)dnl
58     prog="
59 import sys, string
60 minver = '$1'
61 pyver = string.split(sys.version)[0]  # first word is version string
62 # split strings by '.' and convert to numeric
63 minver = map(string.atoi, string.split(minver, '.'))
64 if hasattr(sys, 'version_info'):
65     pyver = sys.version_info[:3]
66 else:
67     pyver = map(string.atoi, string.split(pyver, '.'))
68 # we can now do comparisons on the two lists:
69 if pyver >= minver:
70         sys.exit(0)
71 else:
72         sys.exit(1)"
73     changequote([, ])dnl
74     if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC
75     then
76       AC_MSG_RESULT(okay)
77     else
78       AC_MSG_ERROR(too old)
79     fi
80   ])
82   AC_MSG_CHECKING([local Python configuration])
84   dnl Query Python for its version number.  Getting [:3] seems to be
85   dnl the best way to do this; it's what "site.py" does in the standard
86   dnl library.  Need to change quote character because of [:3]
88   AC_SUBST(PYTHON_VERSION)
89   changequote(<<, >>)dnl
90   PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[:3]"`
91   changequote([, ])dnl
94   dnl Use the values of $prefix and $exec_prefix for the corresponding
95   dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX.  These are made
96   dnl distinct variables so they can be overridden if need be.  However,
97   dnl general consensus is that you shouldn't need this ability.
99   AC_SUBST([PYTHON_PREFIX], [${prefix}])
100   AC_SUBST([PYTHON_EXEC_PREFIX], [${exec_prefix}])
102   dnl At times (like when building shared libraries) you may want
103   dnl to know which OS platform Python thinks this is.
105   AC_SUBST(PYTHON_PLATFORM)
106   PYTHON_PLATFORM=`$PYTHON -c "import sys; print sys.platform"`
109   dnl Set up 4 directories:
111   dnl pythondir -- where to install python scripts.  This is the
112   dnl   site-packages directory, not the python standard library
113   dnl   directory like in previous automake betas.  This behaviour
114   dnl   is more consistent with lispdir.m4 for example.
115   dnl
116   dnl Also, if the package prefix isn't the same as python's prefix,
117   dnl then the old $(pythondir) was pretty useless.
119   AC_CACHE_CHECK([for $am_display_PYTHON script directory],
120     [am_cv_python_pythondir],
121     [am_cv_python_pythondir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(0,0,prefix='$PYTHON_PREFIX')" 2>/dev/null ||
122      echo "$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages"`])
123   AC_SUBST([pythondir], [$am_cv_python_pythondir])
125   dnl pkgpythondir -- $PACKAGE directory under pythondir.  Was
126   dnl   PYTHON_SITE_PACKAGE in previous betas, but this naming is
127   dnl   more consistent with the rest of automake.
128   dnl   Maybe this should be put in python.am?
130   AC_SUBST(pkgpythondir)
131   pkgpythondir=\${pythondir}/$PACKAGE
133   dnl pyexecdir -- directory for installing python extension modules
134   dnl   (shared libraries)  Was PYTHON_SITE_EXEC in previous betas.
136   AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
137     [am_cv_python_pyexecdir],
138     [am_cv_python_pyexecdir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(1,0,prefix='$PYTHON_EXEC_PREFIX')" 2>/dev/null ||
139      echo "${PYTHON_EXEC_PREFIX}/lib/python${PYTHON_VERSION}/site-packages"`])
140   AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
142   dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
143   dnl   Maybe this should be put in python.am?
145   AC_SUBST(pkgpyexecdir)
146   pkgpyexecdir=\${pyexecdir}/$PACKAGE
148   AC_MSG_RESULT([looks good])
151 dnl AM_CHECK_PYMOD(MODNAME [,SYMBOL [,ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]]])
152 dnl Check if a module containing a given symbol is visible to python.
153 AC_DEFUN(AM_CHECK_PYMOD,
154 [AC_REQUIRE([AM_PATH_PYTHON])
155 py_mod_var=`echo $1['_']$2 | sed 'y%./+-%__p_%'`
156 AC_MSG_CHECKING(for ifelse([$2],[],,[$2 in ])python module $1)
157 AC_CACHE_VAL(py_cv_mod_$py_mod_var, [
158 ifelse([$2],[], [prog="
159 import sys
160 try:
161         import $1
162 except ImportError:
163         sys.exit(1)
164 except:
165         sys.exit(0)
166 sys.exit(0)"], [prog="
167 import $1
168 $1.$2"])
169 if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC
170   then
171     eval "py_cv_mod_$py_mod_var=yes"
172   else
173     eval "py_cv_mod_$py_mod_var=no"
174   fi
176 py_val=`eval "echo \`echo '$py_cv_mod_'$py_mod_var\`"`
177 if test "x$py_val" != xno; then
178   AC_MSG_RESULT(yes)
179   ifelse([$3], [],, [$3
180 ])dnl
181 else
182   AC_MSG_RESULT(no)
183   ifelse([$4], [],, [$4
184 ])dnl
188 dnl a macro to check for ability to create python extensions
189 dnl  AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
190 dnl function also defines PYTHON_INCLUDES
191 AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
192 [AC_REQUIRE([AM_PATH_PYTHON])
193 AC_MSG_CHECKING(for headers required to compile python extensions)
194 dnl deduce PYTHON_INCLUDES
195 py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
196 py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
197 PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
198 if test "$py_prefix" != "$py_exec_prefix"; then
199   PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
201 AC_SUBST(PYTHON_INCLUDES)
202 dnl check if the headers exist:
203 save_CPPFLAGS="$CPPFLAGS"
204 CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
205 AC_TRY_CPP([#include <Python.h>],dnl
206 [AC_MSG_RESULT(found)
207 $1],dnl
208 [AC_MSG_RESULT(not found)
209 $2])
210 CPPFLAGS="$save_CPPFLAGS"
213 AC_DEFUN([AM_CHECK_PYTHON_LIB],
214 [AC_REQUIRE([AM_PATH_PYTHON])
215 AC_REQUIRE([AM_CHECK_PYTHON_HEADERS])
217 AC_MSG_CHECKING(for libpython${PYTHON_VERSION}.a)
219 py_config_dir=`$PYTHON -c "import os; print os.path.abspath('$pyexecdir/../config')"`
221 py_makefile="${py_config_dir}/Makefile"
222 if test -f "$py_makefile"; then
223 dnl extra required libs
224   py_localmodlibs=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $py_makefile`
225   py_basemodlibs=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $py_makefile`
226   py_other_libs=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $py_makefile`
228 dnl now the actual libpython
229   if test -e "${py_config_dir}/libpython${PYTHON_VERSION}.a"; then
230     PYTHON_LIBS="-L${py_config_dir} -lpython${PYTHON_VERSION} $py_localmodlibs $py_basemodlibs $py_other_libs"
231     AC_MSG_RESULT(found)
232   else
233     AC_MSG_RESULT(not found)
234   fi
235 else
236   AC_MSG_RESULT(not found)
238 AC_SUBST(PYTHON_LIBS)])
240 # We need this because freetype is optional
241 # Configure paths for FreeType2
242 # Marcelo Magallon 2001-10-26, based on gtk.m4 by Owen Taylor
244 dnl AC_CHECK_FT2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
245 dnl Test for FreeType2, and define FT2_CFLAGS and FT2_LIBS
247 AC_DEFUN(AC_CHECK_FT2,
248 [dnl
249 dnl Get the cflags and libraries from the freetype-config script
251 AC_ARG_WITH(ft-prefix,
252 [  --with-ft-prefix=PREFIX
253                           Prefix where FreeType is installed (optional)],
254             ft_config_prefix="$withval", ft_config_prefix="")
255 AC_ARG_WITH(ft-exec-prefix,
256 [  --with-ft-exec-prefix=PREFIX
257                           Exec prefix where FreeType is installed (optional)],
258             ft_config_exec_prefix="$withval", ft_config_exec_prefix="")
259 AC_ARG_ENABLE(freetypetest,
260 [  --disable-freetypetest  Do not try to compile and run
261                           a test FreeType program],
262               [], enable_fttest=yes)
264 if test x$ft_config_exec_prefix != x ; then
265   ft_config_args="$ft_config_args --exec-prefix=$ft_config_exec_prefix"
266   if test x${FT2_CONFIG+set} != xset ; then
267     FT2_CONFIG=$ft_config_exec_prefix/bin/freetype-config
268   fi
270 if test x$ft_config_prefix != x ; then
271   ft_config_args="$ft_config_args --prefix=$ft_config_prefix"
272   if test x${FT2_CONFIG+set} != xset ; then
273     FT2_CONFIG=$ft_config_prefix/bin/freetype-config
274   fi
276 AC_PATH_PROG(FT2_CONFIG, freetype-config, no)
278 min_ft_version=ifelse([$1], ,6.1.0,$1)
279 AC_MSG_CHECKING(for FreeType - version >= $min_ft_version)
280 no_ft=""
281 if test "$FT2_CONFIG" = "no" ; then
282   no_ft=yes
283 else
284   FT2_CFLAGS=`$FT2_CONFIG $ft_config_args --cflags`
285   FT2_LIBS=`$FT2_CONFIG $ft_config_args --libs`
286   ft_config_major_version=`$FT2_CONFIG $ft_config_args --version | \
287          sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
288   ft_config_minor_version=`$FT2_CONFIG $ft_config_args --version | \
289          sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
290   ft_config_micro_version=`$FT2_CONFIG $ft_config_args --version | \
291          sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
292   ft_min_major_version=`echo $min_ft_version | \
293          sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
294   ft_min_minor_version=`echo $min_ft_version | \
295          sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
296   ft_min_micro_version=`echo $min_ft_version | \
297          sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
298   if test x$enable_fttest = xyes ; then
299     ft_config_is_lt=""
300     if test $ft_config_major_version -lt $ft_min_major_version ; then
301       ft_config_is_lt=yes
302     else
303       if test $ft_config_major_version -eq $ft_min_major_version ; then
304         if test $ft_config_minor_version -lt $ft_min_minor_version ; then
305           ft_config_is_lt=yes
306         else
307           if test $ft_config_minor_version -eq $ft_min_minor_version ; then
308             if test $ft_config_micro_version -lt $ft_min_micro_version ; then
309               ft_config_is_lt=yes
310             fi
311           fi
312         fi
313       fi
314     fi
315     if test x$ft_config_is_lt = xyes ; then
316       no_ft=yes
317     else
318       ac_save_CFLAGS="$CFLAGS"
319       ac_save_LIBS="$LIBS"
320       CFLAGS="$CFLAGS $FT2_CFLAGS"
321       LIBS="$FT2_LIBS $LIBS"
323 dnl Sanity checks for the results of freetype-config to some extent
325       AC_TRY_RUN([
326 #include <ft2build.h>
327 #include FT_FREETYPE_H
328 #include <stdio.h>
329 #include <stdlib.h>
332 main()
334   FT_Library library;
335   FT_Error error;
337   error = FT_Init_FreeType(&library);
339   if (error)
340     return 1;
341   else
342   {
343     FT_Done_FreeType(library);
344     return 0;
345   }
347 ],, no_ft=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
348       CFLAGS="$ac_save_CFLAGS"
349       LIBS="$ac_save_LIBS"
350     fi             # test $ft_config_version -lt $ft_min_version
351   fi               # test x$enable_fttest = xyes
352 fi                 # test "$FT2_CONFIG" = "no"
353 if test x$no_ft = x ; then
354    AC_MSG_RESULT(yes)
355    ifelse([$2], , :, [$2])
356 else
357    AC_MSG_RESULT(no)
358    if test "$FT2_CONFIG" = "no" ; then
359      echo "*** The freetype-config script installed by FreeType 2 could not be found."
360      echo "*** If FreeType 2 was installed in PREFIX, make sure PREFIX/bin is in"
361      echo "*** your path, or set the FT2_CONFIG environment variable to the"
362      echo "*** full path to freetype-config."
363    else
364      if test x$ft_config_is_lt = xyes ; then
365        echo "*** Your installed version of the FreeType 2 library is too old."
366        echo "*** If you have different versions of FreeType 2, make sure that"
367        echo "*** correct values for --with-ft-prefix or --with-ft-exec-prefix"
368        echo "*** are used, or set the FT2_CONFIG environment variable to the"
369        echo "*** full path to freetype-config."
370      else
371        echo "*** The FreeType test program failed to run.  If your system uses"
372        echo "*** shared libraries and they are installed outside the normal"
373        echo "*** system library path, make sure the variable LD_LIBRARY_PATH"
374        echo "*** (or whatever is appropiate for your system) is correctly set."
375      fi
376    fi
377    FT2_CFLAGS=""
378    FT2_LIBS=""
379    ifelse([$3], , :, [$3])
381 AC_SUBST(FT2_CFLAGS)
382 AC_SUBST(FT2_LIBS)