CROSS_COMPILE=1

ac_add_options --enable-application=browser

# Talospace recommends GCC instead of Clang.
CC="/var/tmp/dist/gcc-cross/bin/powerpc64-linux-gnu-gcc"
CXX="/var/tmp/dist/gcc-cross/bin/powerpc64-linux-gnu-g++"
HOST_CC="/var/tmp/dist/gcc/bin/gcc"
HOST_CXX="/var/tmp/dist/gcc/bin/g++"

# Note: the C++ -I path should be updated when GCC version is bumped.
export BINDGEN_CFLAGS='--gcc-toolchain=/var/tmp/dist/gcc-cross -I/var/tmp/dist/gcc-cross/powerpc64-linux-gnu/include/c++/10.3.0 -I/var/tmp/dist/gcc-cross/powerpc64-linux-gnu/include'

export LDFLAGS="-Wl,-rpath-link=/lib/powerpc64-linux-gnu -Wl,-rpath-link=/usr/lib/powerpc64-linux-gnu"

ac_add_options --target=powerpc64-linux-gnu
ac_add_options --with-toolchain-prefix=powerpc64-linux-gnu-
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-ppc64

mk_add_options MOZ_APP_DISPLAYNAME="Tor Browser"
export MOZILLA_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-verify-mar

ac_add_options --disable-tests
ac_add_options --disable-debug
ac_add_options --disable-crashreporter
ac_add_options --disable-webrtc
ac_add_options --disable-parental-controls

# 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/ppc64. 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/ppc64. 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/ppc64. Someone should report this to Mozilla and
# get it fixed upstream.
#ac_add_options --disable-eme

ac_add_options --enable-proxy-bypass-protection

# Bug 31448: ld.gold fails if we don't disable debug-symbols
ac_add_options --disable-debug-symbols

# Disable telemetry
ac_add_options MOZ_TELEMETRY_REPORTING=

# From Talospace
# https://www.talospace.com/2021/08/firefox-91-on-power-fur-fowk.html
# https://www.talospace.com/2021/07/firefox-90-on-power-and-jit-progress.html
# https://www.talospace.com/2020/10/firefox-82-on-power-goes-pgo.html
ac_add_options --enable-optimize="-O3 -mcpu=power9"
ac_add_options --enable-linker=bfd
