#!/bin/sh

XFREE=4.5.0
FREETYPE=2.1.9
FONTCONFIG=2.3.1
XFT=2.1.2

if [ "$1" = "clean" ]
then
    rm XFree86-$XFREE-src*gz
    rm -r xc
    rm done.xc
    rm freetype-$FREETYPE.tar.gz
    rm done.freetype
    rm fontconfig-$FONTCONFIG.tar.gz
    rm done.fontconfig
    rm xft-$XFT.tar.gz
    rm done.xft
fi

if [ ! -f done.xc ]
then
    for i in XFree86-$XFREE-src*gz ; do tar xfz $i ; done
    cd xc
    make World || exit 1
    make install || exit 1
    make install.man || exit 1
    cd ..
    touch done.xc
fi

if [ ! -f done.freetype ]
then
    tar xfz freetype-$FREETYPE.tar.gz
    cd freetype-$FREETYPE
    patch -p1 << 'EOF'
diff -u -U 5 -r --new-file -x *~ -X /tmp/diffexclude freetype-2.1.9/include/freetype/config/ftoption.h freetype-2.1.9.doj/include/freetype/config/ftoption.h
--- freetype-2.1.9/include/freetype/config/ftoption.h	Sun Apr 25 22:15:09 2004
+++ freetype-2.1.9.doj/include/freetype/config/ftoption.h	Thu Sep 23 00:17:17 2004
@@ -434,11 +434,11 @@
   /* TrueType glyphs without hinting.                                      */
   /*                                                                       */
   /*   Do not #undef this macro here, since the build system might         */
   /*   define it for certain configurations only.                          */
   /*                                                                       */
-/* #define  TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
+#define  TT_CONFIG_OPTION_BYTECODE_INTERPRETER
 

   /*************************************************************************/
   /*                                                                       */
   /* Define TT_CONFIG_OPTION_UNPATENTED_HINTING (in addition to            */
EOF

    ./configure --prefix=/usr/X11R6 || exit 1
    make || exit 1
    make install || exit 1
    cd ..
    ldconfig
    touch done.freetype
fi

if [ ! -f done.fontconfig ]
then
    tar xfz fontconfig-$FONTCONFIG.tar.gz
    cd fontconfig-$FONTCONFIG
    ./configure --prefix=/usr/X11R6 || exit 1
    make || exit 1
    make install || exit 1
    cd ..
    ldconfig
    touch done.fontconfig
fi

if [ ! -f done.xft ]
then
    tar xfz xft-$XFT.tar.gz
    cd xft-$XFT
    patch -p1 << 'EOF'
--- xft-2.1.2/Xft.h	Tue May  6 07:37:49 2003
+++ xft-2.1.2.doj/Xft.h	Thu Sep 23 11:46:58 2004
@@ -36,11 +36,12 @@
 #define XFT_REVISION	2
 #define XFT_VERSION	((XFT_MAJOR * 10000) + (XFT_MINOR * 100) + (XFT_REVISION))
 #define XftVersion	XFT_VERSION
 
 #include <stdarg.h>
-#include <freetype/freetype.h>
+#include <ft2build.h>
+#include FT_FREETYPE_H
 #include <fontconfig/fontconfig.h>
 #include <X11/extensions/Xrender.h>
 
 #include <X11/Xfuncproto.h>
 /* #include <X11/Xosdefs.h>*/
EOF

    ./configure --prefix=/usr/X11R6 || exit 1
    make || exit 1
    make install || exit 1
    cd ..
    ldconfig
    touch done.xft
fi

