# Tanım: Mozilla.org'dan Bağımsız Web Tarayıcısı
# URL: http://www.mozilla.com/firefox/
# Paketçi: Cihan_Alkan
# Gerekler: libvpx rust cargo binutils-gold autoconf2 pulseaudio gconf yasm sqlite nss alsa-lib gtk2 gtk3 xorg-app zip unzip startup-notification gstreamer gstreamer-plugins-base gstreamer-plugins-good gstreamer1-plugins-libav
# Grup: ağ

isim=firefox
surum=60.0
devir=1

kaynak=(https://ftp.mozilla.org/pub/firefox/releases/60.0/source/firefox-60.0.source.tar.xz
        http://download.cdn.mozilla.net/pub/$isim/releases/$surum/linux-x86_64/xpi/tr.xpi::tr-${surum}.xpi
		google-api-key
		mozilla-api-key)

derle() {

cd $isim-$surum
# Locale autodetect
sed -i '/intl.locale.matchOS/s/false/true/' modules/libpref/init/all.js

cat > mozconfig << "EOF"
ac_add_options --enable-application=browser

ac_add_options --prefix=/usr
ac_add_options --enable-release
ac_add_options --enable-gold
ac_add_options --enable-pie
ac_add_options --enable-optimize="-O2"
ac_add_options --enable-rust-simd

# Branding
ac_add_options --enable-official-branding
ac_add_options --enable-update-channel=release
ac_add_options --with-distribution-id=org.milislinux
export MOZILLA_OFFICIAL=1
export MOZ_TELEMETRY_REPORTING=1
export MOZ_ADDON_SIGNING=1
export MOZ_REQUIRE_SIGNING=1

# Keys
ac_add_options --with-google-api-keyfile=/${SRC}/google-api-key
ac_add_options --with-mozilla-api-keyfile=/${SRC}/mozilla-api-key

# System libraries
ac_add_options --with-system-bz2
#ac_add_options --with-system-icu
ac_add_options --with-system-jpeg
ac_add_options --with-system-libvpx
#ac_add_options --enable-system-hunspell
ac_add_options --enable-system-ffi

# Features
ac_add_options --enable-alsa
ac_add_options --enable-jack
ac_add_options --enable-startup-notification
ac_add_options --enable-crashreporter
ac_add_options --disable-updater
ac_add_options --disable-stylo
EOF

SHELL=/bin/sh ./mach build
SHELL=/bin/sh ./mach buildsymbols

mkdir -pv $PKG/usr/{bin,lib{,/mozilla/plugins}}

SHELL=/bin/sh DESTDIR=$PKG ./mach install

ln -svf ../mozilla/plugins $PKG/usr/lib/firefox/browser/

# Need for gnash
mkdir -p $PKG/usr/include/npapi
cp -v dom/plugins/base/*.h $PKG/usr/include/npapi

# Launcher 
mkdir -pv $PKG/usr/share/applications &&
cat > $PKG/usr/share/applications/firefox.desktop << "EOF" &&
[Desktop Entry]
Encoding=UTF-8
Name=Firefox Web Browser
Comment=İnternette gezinin
GenericName=Web Tarayıcı
Exec=firefox %u
Terminal=false
Type=Application
Icon=firefox
Categories=GNOME;GTK;Network;WebBrowser;
MimeType=application/xhtml+xml;text/xml;application/xhtml+xml;application/vnd.mozilla.xul+xml;text/mml;x-scheme-handler/http;x-scheme-handler/https;
StartupNotify=true
EOF
mkdir -pv $PKG/usr/share/applications
mkdir -pv $PKG/usr/share/pixmaps
ln -sf /usr/lib/firefox-$version/browser/icons/mozicon128.png $PKG/usr/share/pixmaps/firefox.png

for i in 16 22 24 32 48 256
do
   mkdir -p $PKG/usr/share/icons/hicolor/${i}x${i}/apps
   cp browser/branding/official/default${i}.png \
      $PKG/usr/share/icons/hicolor/${i}x${i}/apps/firefox.png
done

for lang in tr
do 
install -Dm644 $SRC/tr-${surum}.xpi \
    $PKG/usr/lib/firefox/browser/extensions/langpack-tr@firefox.mozilla.org.xpi
done
install -Dm644 /dev/stdin $PKG/usr/lib/firefox/browser/defaults/preferences/vendor.js <<END
// Use LANG environment variable to choose locale
pref("intl.locale.requested", "");

// Disable default browser checking.
pref("browser.shell.checkDefaultBrowser", false);

// Don't disable our bundled extensions in the application directory
pref("extensions.autoDisableScopes", 11);
pref("extensions.shownSelectionUI", true);
END

}
