# Depends on: autoconf2-13 alsa-lib gtk2 zip unzip libevent libvpx nspr nss yasm dbus-glib doxygen libnotify openjdk startup-notification hunspell sqlite wireless-tools xorg-libx11 xorg-libxt xorg-libxrandr desktop-file-utils hicolor-icon-theme shared-mime-info pulseaudio

description="Stand-alone mail/news client based on the Mozilla codebase."
url="http://www.mozilla.org/thunderbird"
packager="tnut <tnut@nutyx.org>"
contributors="Pierre B"

run=(startup-notification hunspell)

name=thunderbird
version=60.5.1

source=(http://ftp.mozilla.org/pub/mozilla.org/thunderbird/releases/$version/source/$name-$version.source.tar.xz
	$name.desktop)

build() {
export PYTHON="/usr/bin/python2"

cd $SRC
ARCH=`uname -m`

for lang in da de en-US es-ES fi fr it nb-NO nl pt-PT sv-SE tr
do 
wget  http://download.cdn.mozilla.net/pub/$name/releases/$version/linux-$ARCH/xpi/$lang.xpi
done

cd $SRC/$name-$version

cat > mozconfig << "EOF"
# If you have a multicore machine, the build may be faster if using parallel
# jobs. The build system automatically adds -jN to the "make" flags, where N
# is the number of CPU cores. The option below is therefore useless, unless
# you want to use a smaller number of jobs:
#mk_add_options MOZ_MAKE_FLAGS="-j1"

# If you have installed dbus-glib, comment out this line:
#ac_add_options --disable-dbus

# If you have installed wireless-tools comment out this line:
ac_add_options --disable-necko-wifi

# Uncomment these lines if you have installed optional dependencies:
ac_add_options --enable-system-hunspell
ac_add_options --enable-startup-notification

# Comment out following option if you have gconf installed
ac_add_options --disable-gconf

# Comment out following options if you have not installed
# recommended dependencies:
ac_add_options --enable-system-sqlite
ac_add_options --enable-system-ffi
ac_add_options --with-system-libevent
ac_add_options --with-system-libvpx
ac_add_options --with-system-nspr
ac_add_options --with-system-nss
ac_add_options --without-system-icu
ac_add_options --with-system-bz2
ac_add_options --with-system-jpeg
ac_add_options --with-system-png
ac_add_options --with-system-zlib


# The BLFS editors recommend not changing anything below this line:
ac_add_options --prefix=/usr
ac_add_options --enable-application=comm/mail
ac_add_options --enable-calendar


ac_add_options --disable-crashreporter
ac_add_options --disable-updater
ac_add_options --disable-debug
ac_add_options --disable-tests
ac_add_options --disable-jack


ac_add_options --enable-optimize=-O2
ac_add_options --enable-strip
ac_add_options --enable-install-strip

ac_add_options --enable-official-branding

EOF

./mach configure
./mach build
./mach buildsymbols
DESTDIR=$PKG ./mach install

mkdir -pv $PKG/usr/bin
ln -sfv ../lib/$name/thunderbird $PKG/usr/bin

mkdir -pv $PKG/usr/share/applications 
install -Dm644 $SRC/thunderbird.desktop \
$PKG/usr/share/applications/thunderbird.desktop

for i in 16 22 24 32 48 128 256; do
   install -Dm644 comm/mail/branding/thunderbird/default${i}.png \
      $PKG/usr/share/icons/hicolor/${i}x${i}/apps/thunderbird.png
done
install -Dm644 comm/mail/branding/thunderbird/TB-symbolic.svg \
$PKG/usr/share/icons/hicolor/symbolic/apps/thunderbird-symbolic.svg

mkdir -p $PKG/etc/ld.so.conf.d
echo "/usr/lib/$name" > $PKG/etc/ld.so.conf.d/$name.conf
cat > $PKG/usr/lib/thunderbird/defaults/pref/vendor.js << "EOF"
// Use LANG environment variable to choose locale
pref("intl.locale.requested", "");
EOF

for lang in da de en-US es-ES fi fr it nb-NO nl pt-PT sv-SE
do  
    install -Dm644 $SRC/$lang.xpi \
    $PKG/usr/lib/thunderbird/extensions/langpack-$lang@thunderbird.mozilla.org.xpi
done
chown -R 0:0 $PKG/usr/lib/$name
}
