#! /bin/bash

set -ex -o pipefail
umask 022
export PATH='/bin:/usr/bin:/usr/local/bin:~/diet-pc/tools'
export CFLAGS=${CFLAGS:--Os}
export CXXFLAGS=${CXXFLAGS:--Os}

rebuild () {
    tar xjf curl-7.18.1.tar.bz2
    cd curl-7.18.1
    CFLAGS="$CFLAGS -fPIC" ./configure --prefix=/usr/local --sysconfdir=/etc \
	    --enable-http --enable-ftp --disable-file --disable-ldap \
	    --disable-ldaps --disable-dict --disable-telnet --disable-tftp \
	    --disable-manual --enable-nonblocking --enable-thread \
	    --disable-verbose --disable-sspi --disable-debug --enable-cookies \
	    --enable-hidden-symbols --without-libidn --disable-shared \
	    --with-ca-path=/usr/openssl/certs
    make
    chmod 0755 curl-config
    sudo make -C include install
    sudo make -C lib install
    sudo make -C src install
    sudo make install-pkgconfigDATA
    sudo make install-binSCRIPTS
    cd ..
    rm -rf curl-7.18.1
}

while read FN; do
    eval "[ -e $FN ] || rebuild"
done < MANIFEST
