#!/bin/sh
export DEST=/home/sound79/projects/opensource/lighttpd
CC=gcc
AR=ar
RANLIB=ranlib

wget http://zlib.net/zlib-1.2.8.tar.gz
tar zxf zlib-1.2.8.tar.gz
cd zlib-1.2.8
CFLAGS="$CFLAGS -O3 -fPIC" ./configure --prefix=$DEST --static
make clean && make
ZLIB=`pwd`
cd ..

wget http://bzip.org/1.0.6/bzip2-1.0.6.tar.gz
tar zxf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6/
make clean
make libbz2.a CC=$CC AR=$AR RANLIB=$RANLIB CFLAGS="$CFLAGS -Wall -O3 -fPIC -g -D_FILE_OFFSET_BITS=64"
BZIP=`pwd`
cd ..

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz
tar zxf pcre-8.33.tar.gz
cd pcre-8.33
CFLAGS="$CFLAGS -O3 -I$ZLIB -fPIC -I$BZIP" CXXFLAGS="$CFLAGS" LDFLAGS="-L$ZLIB -L$BZIP" ./configure --prefix=$DEST --enable-pcregrep-libz --enable-pcregrep-libbz2 --enable-unicode-properties --disable-shared
make clean && make
PCRE=`pwd`
cd ..

wget http://openssl.org/source/openssl-1.0.0f.tar.gz
tar zxf openssl-1.0.0f.tar.gz
cd openssl-1.0.0f
./Configure linux-generic32 -DL_ENDIAN -fPIC --prefix=$DEST --openssldir=$DEST/etc/ssl no-shared no-zlib-dynamic --with-zlib-include=$ZLIB --with-zlib-lib=$ZLIB
sed -i -e "s/CFLAG= /CFLAG=${CFLAGS} /g" Makefile
make clean && make && make install_sw
rm -fr $DEST/include
rm -fr $DEST/lib
OPENSSL=`pwd`
cd ..

wget http://www.lua.org/ftp/lua-5.1.4.tar.gz
tar zxf lua-5.1.4.tar.gz
cd lua-5.1.4/
make clean
make PLAT=linux INSTALL_TOP=$DEST RANLIB=$RANLIB CC=$CC AR="$AR rcu" CFLAGS="$CFLAGS -O3 -Wall " LIBS="-lm "
LUA=`pwd`
cd ..

wget ftp://xmlsoft.org/libxml2/libxml2-2.7.8.tar.gz
tar zxf libxml2-2.7.8.tar.gz
cd libxml2-2.7.8
CFLAGS="$CFLAGS -O3 -fPIC -I$ZLIB" LDFLAGS="$LDFLAGS -L$ZLIB -lz -lm" ./configure --prefix=$DEST --with-zlib --without-python --disable-shared
make clean && make
LIBXML=`pwd`
cd ..

wget http://www.sqlite.org/sqlite-autoconf-3070900.tar.gz
tar zxf sqlite-autoconf-3070900.tar.gz
cd sqlite-autoconf-3070900/
CFLAGS="$CFLAGS -O3 -fPIC" LIBS="-ldl -lpthread" ./configure --prefix=$DEST --enable-shared=no
make clean && make
SQLITE=`pwd`
cd ..

wget http://sourceforge.net/projects/e2fsprogs/files/e2fsprogs/1.42/e2fsprogs-libs-1.42.tar.gz
tar zxf e2fsprogs-libs-1.42.tar.gz
cd e2fsprogs-libs-1.42/
CFLAGS="$CFLAGS -O3 -fPIC" ./configure --prefix=$DEST --disable-elf-shlibs 
cd lib/uuid/
make clean && make
LIBUUID=`pwd`
cd ../../..

wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.30.tar.gz
tar zxf lighttpd-1.4.30.tar.gz
cd lighttpd-1.4.30/
CFLAGS="$CFLAGS -O3 -I$ZLIB -I$BZIP -I$PCRE -DPCRE_STATIC -I$OPENSSL/include -I$LIBUUID/.." LDFLAGS="$LDFLAGS -L$ZLIB -L$BZIP -L$PCRE/.libs -L$OPENSSL -L$LIBUUID" LIBS="-lz -lbz2 -lpcre -luuid -lssl -lcrypto -ldl -lm -lpthread" LUA_CFLAGS="-I$LUA/src" LUA_LIBS="-L$LUA/src" XML_CFLAGS="-I$LIBXML/include" XML_LIBS="-L$LIBXML/.libs -lxml2 -lm" SQLITE_CFLAGS="-I$SQLITE" SQLITE_LIBS="-L$SQLITE/.libs -lsqlite3" ac_cv_path_PCRECONFIG=$PCRE/pcre-config ./configure --prefix=$DEST --with-openssl --with-pcre --with-zlib --with-bzip2 --with-lua --with-webdav-props --with-webdav-locks
make clean && make && make install
find $DEST -executable -type f -exec $STRIP "{}" \;
