#!/bin/bash -e

PREFIX=$PRODTREE/netsurf

if [ \! -f cfg ]; then
    cat << END
Error:  This script must be run in  the same directory  as the associ-
ated "cfg" file.
END
    exit 1
fi
    
DATE6D=250225
SNBS=share/netsurf-buildsystem

for P in \
    buildsystem  libnsbmp     libnsgif     libsvgtiny \
    libhubbub    libutf8proc  libnsutils   libparserutils \
    libwapcaplet libcss       libnsfb      libdom \
    netsurf      nsgenbind
do
    DIR=$P-git-$DATE6D
    if [ "@$P" == "@netsurf" ]; then
        DIR=netsurf-browser-git-$DATE6D
    fi

    URL=git://git.netsurf-browser.org/$P.git

    rm -fr $P $DIR $DIR.tar*
    git clone $URL $DIR

    pushd $DIR
        sed \
-e 's@^\(COMPONENT_TYPE\) *?= *lib-static@\1 ?= lib-shared@' \
-e 's@^\(NSSHARED\) *?=.*@\1 ?= $(PREFIX)'/$SNBS@ \
-e 's@\$(NSBUILD)@$(NSSHARED)/makefiles@' \
-e 's@^\(PREFIX\) *?=.*@\1 ?= '$PRODTREE/netsurf@ \
-i Makefile
    popd

    BALLNAME=$DIR.tar.bz2

    tar cf - $DIR | pbzip2 -c > $BALLNAME
    ls -l                       $BALLNAME
    rm -fr   $DIR

    if [ "@$P" == "@netsurf" ]; then
        P=netsurf-browser
    fi
    mv $BALLNAME ../*$P/
done
