DESCRIPTION="Gnash - GNU Flash player"
HOMEPAGE="http://www.gnu.org/software/gnash/"
# dummy
SOURCE_URI="http://ports.haiku-files.org/export/682/haikuports/trunk/media-video/gnash/mime.zip"
CHECKSUM_MD5="1d22a6d67f69d0bfaf2f63e7e8e9d39f"
REVISION="1"
STATUS_HAIKU="stable"
MESSAGE="This port only builds with gcc4. Use 'setgcc gcc4' before building."
DEPEND="media-video/ffmpeg >= 0.5
	media-image/giflib >= ??
	agg >= ??
	dev-libs/boost >= ??"
# Use 'install-gnash-deps --compile-time' to install deps
#
# notes:
# * the /boot/preferences/Gnash directory is not inserted into the archive,
# but it might be used to supplement /boot/home/config/settings/Gnash
# * on Haiku alpha
#  ** versioned symlinks to libraries must be created;
#  ** sound must be disabled in ~/config/Gnash/gnashrc;
#  ** if you don't mind replacing system files, installing libroot with chgset 34161 backported will improve stability.
#  ** more info on webpage
#


BUILD()
{
    if test ! -e gnash; then
        bzr branch http://bzr.savannah.gnu.org/r/gnash/trunk/ gnash || true;
    fi

    pushd gnash
    setgcc gcc4
    if test ! -e configure; then
        ./autogen.sh ;
        rm config.status || true ;
    fi
    if test ! -e config.status; then
        ./configure --prefix=/boot/apps/Gnash --exec-prefix=/boot/apps/Gnash --bindir=/boot/apps/Gnash --sysconfdir=/boot/preferences/Gnash --libdir=/boot/common/lib --enable-renderer=agg --enable-fps-debug=yes --enable-plugins --enable-npapi --with-npapi-plugindir=/boot/apps/Gnash CXXFLAGS='-Wno-multichar' --enable-scriptable;
    fi
    make "CXXFLAGS=-I/boot/common/include/boost-1_38/"

    pushd plugin/npapi ;
    mkdir -pv .libs ;
    MIMELOCATION=`pwd` ;
    MIMELOCATION=`dirname "$MIMELOCATION"` ;
    MIMELOCATION=`dirname "$MIMELOCATION"` ;
    MIMELOCATION=`dirname "$MIMELOCATION"` ;
    MIMELOCATION=`dirname "$MIMELOCATION"` ;
    MIMELOCATION="$MIMELOCATION/download/mime.zip" ;
    unzip -o "$MIMELOCATION" ;
    for GCC_VERSION in gcc2 gcc4 ; do
       ( echo "compiling libgnashplugin.$GCC_VERSION.so" &&
        setgcc $GCC_VERSION
        PLUGIN_SRCS="mozilla-sdk/np_entry mozilla-sdk/npp_gate mozilla-sdk/npn_gate plugin callbacks external pluginScriptObject"
        for src in $PLUGIN_SRCS; do
		echo "$src".cpp
                g++ -DHAVE_CONFIG_H -I. -I../.. -DPLUGIN_TRACE -DXP_HAIKU -DGNASHBINDIR=\"/boot/common/bin\" -DSYSCONFDIR=\"/boot/preferences/Gnash\" -I../libcore/parser -I../../libbase -I../backend -I./mozilla-sdk -I./mozilla-sdk/include -I/boot/common/include -I/boot/common/include/boost-1_38/ -g -O2 -W -Wall -Wcast-align -Wcast-qual -Wpointer-arith -Wreturn-type -Wnon-virtual-dtor -Wunused -Wno-multichar -c "$src".cpp -o "$src".o ;
	done ;
	PLUGIN_SRCS="${PLUGIN_SRCS} "
        g++ -shared ${PLUGIN_SRCS// /.o } -lbe -lnetwork -o .libs/libgnashplugin.$GCC_VERSION.so &&
        copyattr x .libs/libgnashplugin.$GCC_VERSION.so
        ) || (setgcc gcc4; exit 1);
    done ;
    rm x ;
    setgcc gcc4
    popd

    popd
}
INSTALL()
{
    cd gnash
    setgcc gcc4
    make install "CXXFLAGS=-I/boot/common/include/boost-1_38/"

    true DISTRODIR=`pwd`/../../distro
    ROOTDIR=/boot/develop/haikuports/media-video/gnash
    DISTRODIR=/boot/develop/haikuports/media-video/gnash/distro
    if test ! -e "$DISTRODIR"; then
        exit 1;
    fi

    install plugin/npapi/.libs/libgnashplugin.gcc2.so "$DISTRODIR/boot/apps/Gnash"
    install plugin/npapi/.libs/libgnashplugin.gcc4.so "$DISTRODIR/boot/apps/Gnash"

    pushd "$DISTRODIR"

    mkdir -pv boot/home/config/settings
    cp -r boot/preferences/Gnash boot/home/config/settings

    mkdir -pv boot/home/config/settings/Mozilla/plugins
    ln -s /boot/apps/Gnash/libgnashplugin.gcc2.so boot/home/config/settings/Mozilla/plugins/
    ln -s /boot/apps/Gnash/libgnashplugin.gcc4.so boot/home/config/settings/Mozilla/plugins/

    rm boot/apps/Gnash/gprocessor boot/apps/Gnash/rtmpget boot/apps/Gnash/gnash
    rm -r boot/apps/Gnash/include boot/apps/Gnash/share
    rm -r boot/common/lib/pkgconfig
    rm -r boot/common/lib/gnash/libmoz* || true
    mkdir -pv boot/common/bin/
    ln -sf /boot/apps/Gnash/haiku-gnash boot/common/bin/haiku-gnash
    ln -sf /boot/apps/Gnash/haiku-gnash boot/common/bin/gnash
    for i in boot/common/lib/gnash/*; do
        strip --strip-unneeded "$i" || true;
    done
    strip --strip-debug boot/apps/Gnash/haiku-gnash || true

    xres -o boot/apps/Gnash/haiku-gnash -a VICN:101:BEOS:ICON $ROOTDIR/additional-files/gnash.hvif

    popd


    read -p "Gnash installed, press key "
}
