#!/bin/sh
#
# Copyright 2005 Paul Blazejowski <paulb@blazebox.homeip.net>
# Available under the terms of the GNU GPL.
#

NAME="mozilla-thunderbird"
VERSION="1.0.7"
REVISION="1"
PKG_SOURCEURL='http://ftp.mozilla.org/pub/mozilla.org/thunderbird/releases/$VERSION/source/thunderbird-$VERSION-source.tar.bz2'
PKG_SOURCEMD5=''
PKG_TARBALL=thunderbird-$VERSION-source
PKG_PATCH[0]="thunderbird-1.0.2-unversioned-dir.patch"
PKG_PATCH[1]="mozconfig-tb"
PKG_PATCH[2]="mozilla-thunderbird.desktop"

. $DLG_ROOT/config
. $DLG_ROOT/SCRIPTS/dropline-functions.sh

# This build script uses it's own CFLAGS;CXXFLAGS
# cflags
# cxxflags
prepare
applypatch 0 1
analyzesource

# We use mozconfig, no need to pass
# any arguments to configure :-)
findpatch filename mozconfig-tb
spewdo "cp $filename $PKG_SRCROOT/.mozconfig"
export MOZ_THUNDERBIRD=1 BUILD_OFFICIAL=1 MOZILLA_OFFICIAL=1
export LDFLAGS="-O3 -march=i686 -Wl,--as-needed"

configure
make -j2
#makecheck
makeinstall
tidydocumentation
analyzebinaries

# We don't need CVS repo entries in the docs :D
removedir $PKG_STAGEROOT$PKG_PREFIX/doc/$NAME-$VERSION/README

# Move back the startup script to it's original location
# and create a symlink to thunderbird caller script.
spewdo "cd $PKG_STAGEROOT$PKG_PREFIX/bin"
spewdo "mv thunderbird $PKG_STAGEROOT$PKG_PREFIX/lib/thunderbird"
spewdo "ln -sf ../lib/thunderbird/thunderbird thunderbird"

# Before copying desktop files we create the dirs
createdir $PKG_STAGEROOT$PKG_PREFIX/share/applications
createdir $PKG_STAGEROOT$PKG_PREFIX/share/pixmaps

findpatch filename mozilla-thunderbird.desktop
spewdo "cp $filename $PKG_STAGEROOT$PKG_PREFIX/share/applications"

# Copy default icons for the mail :-)
spewdo "cp $PKG_STAGEROOT$PKG_PREFIX/lib/thunderbird/icons/default.xpm $PKG_STAGEROOT$PKG_PREFIX/lib/thunderbird/chrome/icons/default/default.xpm"
spewdo "cp $PKG_STAGEROOT$PKG_PREFIX/lib/thunderbird/icons/default.xpm $PKG_STAGEROOT$PKG_PREFIX/share/pixmaps/mozilla-thunderbird.xpm"

# Workaround for make install not copying RSS/movemail files into $PKG_STAGEROOT
createdir $PKG_STAGEROOT$PKG_PREFIX/lib/thunderbird/defaults/isp
createdir $PKG_STAGEROOT$PKG_PREFIX/lib/thunderbird/defaults/isp/US
spewdo "cp $PKG_SRCROOT/mail/extensions/newsblog/rss.rdf $PKG_STAGEROOT$PKG_PREFIX/lib/thunderbird/defaults/isp"
spewdo "cp $PKG_SRCROOT/mail/extensions/newsblog/rss.rdf $PKG_STAGEROOT$PKG_PREFIX/lib/thunderbird/defaults/isp/US"
spewdo "cp $PKG_SRCROOT/mailnews/base/ispdata/movemail.rdf $PKG_STAGEROOT$PKG_PREFIX/lib/thunderbird/defaults/isp"
spewdo "cp $PKG_SRCROOT/mailnews/base/ispdata/movemail.rdf $PKG_STAGEROOT$PKG_PREFIX/lib/thunderbird/defaults/isp/US"

# Remove uneeded header, pkgconfig, idl files
spewdo "rm -f $PKG_STAGEROOT$PKG_PREFIX/bin/thunderbird-config"
spewdo "rm -rf $PKG_STAGEROOT$PKG_PREFIX/include"
spewdo "rm -rf $PKG_STAGEROOT$PKG_PREFIX/lib/pkgconfig"
spewdo "rm -rf $PKG_STAGEROOT$PKG_PREFIX/share/aclocal"
spewdo "rm -rf $PKG_STAGEROOT$PKG_PREFIX/share/idl"

# Do some magic for default install
THUNDER_DIR=$PKG_STAGEROOT$PKG_PREFIX/lib/thunderbird
REGXPCOM=$THUNDER_DIR/regxpcom
REGCHROME=$THUNDER_DIR/regchrome
THUNDER=$THUNDER_DIR/thunderbird-bin

removedir $THUNDER_DIR/chrome/overlayinfo
spewdo "rm -f $THUNDER_DIR/chrome/*.rdf"
createdir $THUNDER_DIR/chrome/overlayinfo
spewdo "rm -f $THUNDER_DIR/component.reg"
removedir $THUNDER_DIR/extensions

# Register default extensions
spewdo "cd $THUNDER_DIR"
loggedcommand register "./run-mozilla.sh $REGXPCOM && ./run-mozilla.sh $REGCHROME && ./run-mozilla.sh $THUNDER -register"

finalizepackage
packagize
cleanup

