CROSS_COMPILE=1

ac_add_options --enable-application=browser

CC="clang -B /var/tmp/dist/binutils/bin"
CXX="clang++ -B /var/tmp/dist/binutils/bin"
HOST_CC="clang"
HOST_CXX="clang++"

# Are all of these LDFLAGS things actually needed?
FIX_LINK_LDFLAGS="-Wl,-rpath-link=/lib/arm-linux-gnueabihf -Wl,-rpath-link=/usr/lib/arm-linux-gnueabihf"
export LDFLAGS="$FIX_LINK_LDFLAGS"
LDFLAGS="$FIX_LINK_LDFLAGS"
export WRAP_LDFLAGS="$FIX_LINK_LDFLAGS"
mk_add_options LDFLAGS="$FIX_LINK_LDFLAGS"

ac_add_options --target=arm-linux-gnueabihf
ac_add_options --with-toolchain-prefix=arm-linux-gnueabihf-
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-arm

# XXX: gold and lld break when linking libxul, resort to bfd
ac_add_options --enable-linker=bfd

mk_add_options MOZ_APP_DISPLAYNAME="Tor Browser"
mk_add_options MOZILLA_OFFICIAL=1
mk_add_options BUILD_OFFICIAL=1

# From Mozilla MDN "Compiling 32-bit Firefox on a Linux 64-bit OS" docs
# Should fix "error: Can't find header fontconfig/fcfreetype.h"
mk_add_options MOZ_TREE_FREETYPE=1

ac_add_options --enable-official-branding

# Let's support GTK3 for ESR60
ac_add_options --enable-default-toolkit=cairo-gtk3

ac_add_options --enable-tor-browser-update
ac_add_options --enable-signmar
ac_add_options --enable-verify-mar

ac_add_options --disable-tests
ac_add_options --disable-debug
ac_add_options --disable-debug-symbols
ac_add_options --disable-crashreporter
ac_add_options --disable-webrtc

# Let's make sure no preference is enabling either Adobe's or Google's CDM.
# TODO: Firefox ESR 68 has a stupid bug. The --enable-eme flag is defined with
# "when=eme_choices". eme_choices is defined as follows:
# def eme_choices(target):
#     if (target.kernel in ('Darwin', 'WINNT', 'Linux') and
#         target.os not in ('Android', 'iOS') and
#         target.cpu in ('x86', 'x86_64')):
#         return ('widevine',)
#     if target.kernel == 'WINNT' and target.cpu == 'aarch64':
#         return ('widevine',)
# Which excludes GNU/Linux/ARM. When the "when" condition for --enable-foo
# isn't enabled, it's also not enabled for --disable-foo. So using
# --disable-eme results in the error
# "mozbuild.configure.options.InvalidOptionError: --disable-eme is not
# available in this configuration". This means we have to omit --disable-eme.
# Which means EME will stay disabled... UNTIL Mozilla implements EME for
# GNU/Linux/ARM. At which point EME will silently enable itself in Tor Browser
# unless the Tor devs carefully audit all merges from upstream to see if they
# implement EME for GNU/Linux/ARM. Someone should report this to Mozilla and
# get it fixed upstream.
#ac_add_options --disable-eme

ac_add_options --enable-proxy-bypass-protection

# Architecture flags for armhf
ac_add_options --with-arch=armv7-a
ac_add_options --with-fpu=vfpv3-d16
ac_add_options --with-float-abi=hard
ac_add_options --with-thumb=yes

# From Arch Linux ARM for ESR68
# https://github.com/archlinuxarm/PKGBUILDs/blob/001eccbae9dcac00b6bf29b032f28786aba9afdd/extra/firefox/PKGBUILD
ac_add_options --enable-optimize="-O2"
ac_add_options --disable-elf-hack
ac_add_options --disable-av1
