initial revision.
[swftools.git] / m4 / fontconfig.m4
1 # ----------- freetype.m4 ----------------
2 #
3 # Checks for:
4 #    * freetype library (-lfreetype)
5 #    * freetype headers (freetype2/freetype/freetype.h)
6 #    * whether a freetype test program can be compiled
7
8 # Environment set:
9 #    * HAVE_FREETYPE
10 #
11 # Defines:
12 #    * HAVE_FREETYPE
13 #    * USE_FREETYPE
14 #
15 # Substitutes:
16 #
17
18 AC_DEFUN(RFX_CHECK_FONTCONFIG,
19 [
20 OLDCPPFLAGS="${CPPFLAGS}"
21 OLDLIBS="${LIBS}"
22         
23 if test -d /usr/include/fontconfig; then
24     CPPFLAGS="$CPPFLAGS -I/usr/include/fontconfig"
25 fi
26
27 AC_CHECK_LIB(fontconfig, FcInit,HAVE_LIB_FONTCONFIG=1,)
28 AC_CHECK_HEADERS(fontconfig.h,HAVE_FONTCONFIG_H=1)
29
30 if test "x${HAVE_LIB_FONTCONFIG}" != "x";then
31 if test "x${HAVE_FONTCONFIG_H}" != "x";then
32     HAVE_FONTCONFIG=1
33 fi
34 fi
35
36 if test "x${HAVE_FONTCONFIG}" = "x1"; then 
37     LIBS="$LIBS -lfontconfig"
38 AC_MSG_CHECKING([whether we can compile the fontconfig test program])
39
40 if (echo $LIBS | grep lfreetype >/dev/null 2>&1); then
41     #move freetype library to the end of libraries, otherwise fontconfig
42     #won't compile.
43     LIBS=`echo $LIBS | sed -e 's/-lfreetype//g' -e 's/$/ -lfreetype/'`
44 fi
45
46 cat > conftest.c << EOF
47 #include <fontconfig.h>
48
49 int main()
50 {
51     FcPattern *pattern, *match;
52     FcResult result;
53     FcChar8 *v;
54     FcInit();
55     pattern = FcPatternBuild(0, FC_FAMILY, FcTypeString, "", 0);
56     FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
57     FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
58     FcConfigSubstitute(0, pattern, FcMatchPattern); 
59     FcDefaultSubstitute(pattern);
60     match = FcFontMatch(0, pattern, &result);
61     FcPatternGetString(match, "family", 0, &v) == FcResultMatch;
62     FcPatternPrint(pattern);
63     FcPatternDestroy(pattern);
64     FcPatternDestroy(match);
65     return 0;
66 }
67 EOF
68
69     ac_link='$CC $CPPFLAGS $CFLAGS conftest.c $LDFLAGS $LIBS -o conftest${ac_exeext}'
70     if { (eval echo freetype.m4:71: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
71         AC_MSG_RESULT(yes)
72         AC_DEFINE_UNQUOTED(HAVE_FONTCONFIG, 1)
73     else
74         echo "configure: failed program was:" >&5
75         cat conftest.c >&5
76         HAVE_FONTCONFIG=0
77         AC_MSG_RESULT(no)
78     fi
79     rm -f conftest*
80 fi
81
82 # if the above didn't work out, reset all changes to the compiler variables.
83 if test "x${HAVE_FREETYPE}" "!=" "x1"; then 
84     CPPFLAGS=$OLDCPPFLAGS
85     LIBS=$OLDLIBS
86 fi 
87 ])
88