1# Configure paths for FreeType2
2# Marcelo Magallon 2001-10-26, based on gtk.m4 by Owen Taylor
3
4dnl AC_CHECK_FT2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
5dnl Test for FreeType2, and define FT2_CFLAGS and FT2_LIBS
6dnl
7AC_DEFUN([AC_CHECK_FT2],
8[dnl
9dnl Get the cflags and libraries from the freetype-config script
10dnl
11AC_ARG_WITH(ft-prefix,
12[  --with-ft-prefix=PREFIX
13                          Prefix where FreeType is installed (optional)],
14            ft_config_prefix="$withval", ft_config_prefix="")
15AC_ARG_WITH(ft-exec-prefix,
16[  --with-ft-exec-prefix=PREFIX
17                          Exec prefix where FreeType is installed (optional)],
18            ft_config_exec_prefix="$withval", ft_config_exec_prefix="")
19AC_ARG_ENABLE(freetypetest,
20[  --disable-freetypetest  Do not try to compile and run
21                          a test FreeType program],
22              [], enable_fttest=yes)
23
24if test x$ft_config_exec_prefix != x ; then
25  ft_config_args="$ft_config_args --exec-prefix=$ft_config_exec_prefix"
26  if test x${FT2_CONFIG+set} != xset ; then
27    FT2_CONFIG=$ft_config_exec_prefix/bin/freetype-config
28  fi
29fi
30if test x$ft_config_prefix != x ; then
31  ft_config_args="$ft_config_args --prefix=$ft_config_prefix"
32  if test x${FT2_CONFIG+set} != xset ; then
33    FT2_CONFIG=$ft_config_prefix/bin/freetype-config
34  fi
35fi
36AC_PATH_PROG(FT2_CONFIG, freetype-config, no)
37
38min_ft_version=ifelse([$1], ,6.1.0,$1)
39AC_MSG_CHECKING(for FreeType - version >= $min_ft_version)
40no_ft=""
41if test "$FT2_CONFIG" = "no" ; then
42  no_ft=yes
43else
44  FT2_CFLAGS=`$FT2_CONFIG $ft_config_args --cflags`
45  FT2_LIBS=`$FT2_CONFIG $ft_config_args --libs`
46  ft_config_major_version=`$FT2_CONFIG $ft_config_args --version | \
47         sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
48  ft_config_minor_version=`$FT2_CONFIG $ft_config_args --version | \
49         sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
50  ft_config_micro_version=`$FT2_CONFIG $ft_config_args --version | \
51         sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
52  ft_min_major_version=`echo $min_ft_version | \
53         sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
54  ft_min_minor_version=`echo $min_ft_version | \
55         sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
56  ft_min_micro_version=`echo $min_ft_version | \
57         sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
58  if test x$enable_fttest = xyes ; then
59    ft_config_is_lt=""
60    if test $ft_config_major_version -lt $ft_min_major_version ; then
61      ft_config_is_lt=yes
62    else
63      if test $ft_config_major_version -eq $ft_min_major_version ; then
64        if test $ft_config_minor_version -lt $ft_min_minor_version ; then
65          ft_config_is_lt=yes
66        else
67          if test $ft_config_minor_version -eq $ft_min_minor_version ; then
68            if test $ft_config_micro_version -lt $ft_min_micro_version ; then
69              ft_config_is_lt=yes
70            fi
71          fi
72        fi
73      fi
74    fi
75    if test x$ft_config_is_lt = xyes ; then
76      no_ft=yes
77    else
78      ac_save_CFLAGS="$CFLAGS"
79      ac_save_LIBS="$LIBS"
80      CFLAGS="$CFLAGS $FT2_CFLAGS"
81      LIBS="$FT2_LIBS $LIBS"
82dnl
83dnl Sanity checks for the results of freetype-config to some extent
84dnl
85      AC_TRY_RUN([
86#include <ft2build.h>
87#include FT_FREETYPE_H
88#include <stdio.h>
89#include <stdlib.h>
90
91int
92main()
93{
94  FT_Library library;
95  FT_Error error;
96
97  error = FT_Init_FreeType(&library);
98
99  if (error)
100    return 1;
101  else
102  {
103    FT_Done_FreeType(library);
104    return 0;
105  }
106}
107],, no_ft=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
108      CFLAGS="$ac_save_CFLAGS"
109      LIBS="$ac_save_LIBS"
110    fi             # test $ft_config_version -lt $ft_min_version
111  fi               # test x$enable_fttest = xyes
112fi                 # test "$FT2_CONFIG" = "no"
113if test x$no_ft = x ; then
114   AC_MSG_RESULT(yes)
115   ifelse([$2], , :, [$2])
116else
117   AC_MSG_RESULT(no)
118   if test "$FT2_CONFIG" = "no" ; then
119     echo "*** The freetype-config script installed by FreeType 2 could not be found."
120     echo "*** If FreeType 2 was installed in PREFIX, make sure PREFIX/bin is in"
121     echo "*** your path, or set the FT2_CONFIG environment variable to the"
122     echo "*** full path to freetype-config."
123   else
124     if test x$ft_config_is_lt = xyes ; then
125       echo "*** Your installed version of the FreeType 2 library is too old."
126       echo "*** If you have different versions of FreeType 2, make sure that"
127       echo "*** correct values for --with-ft-prefix or --with-ft-exec-prefix"
128       echo "*** are used, or set the FT2_CONFIG environment variable to the"
129       echo "*** full path to freetype-config."
130     else
131       echo "*** The FreeType test program failed to run.  If your system uses"
132       echo "*** shared libraries and they are installed outside the normal"
133       echo "*** system library path, make sure the variable LD_LIBRARY_PATH"
134       echo "*** (or whatever is appropiate for your system) is correctly set."
135     fi
136   fi
137   FT2_CFLAGS=""
138   FT2_LIBS=""
139   ifelse([$3], , :, [$3])
140fi
141AC_SUBST(FT2_CFLAGS)
142AC_SUBST(FT2_LIBS)
143])
144