# One config to rule them all

# macOS Specific Options
if test $(uname -s) = Darwin; then
	export CXXFLAGS="-stdlib=libc++"
	ac_add_options --enable-optimize="-O3 -march=core2 -mtune=core2 -flto=thin -w"
	ac_add_options --enable-macos-target=10.7
	ac_add_options --with-macos-sdk=$PWD/../MacOSX10.12.sdk
	mk_add_options AUTOCONF=/usr/local/Cellar/autoconf213/2.13/bin/autoconf213
# Windows 10 Specific Options
elif test $(uname -s) = MINGW32_NT-6.2; then
	export LINKER=lld-link
	export CC=clang-cl
	export CXX=clang-cl
	ac_add_options --enable-optimize="-O2 -Qvec -w -clang:-arch:SSE3"
	ac_add_options --host=x86_64-pc-mingw32
	ac_add_options --target=x86_64-pc-mingw32
    if test -d "/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise"; then
        export WIN32_REDIST_DIR="/c/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Redist/MSVC/14.16.27012/x64/Microsoft.VC141.CRT"
    else
    	ac_add_options --with-visual-studio-version=2017
        export WIN32_REDIST_DIR="/c/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Redist/MSVC/14.16.27012/x64/Microsoft.VC141.CRT"
    fi
	export WIN_UCRT_REDIST_DIR="/c/Program Files (x86)/Windows Kits/10/Redist/ucrt/DLLs/x64"
# Linux Specific Options
elif test $(uname -s) = Linux; then
	if test -d "$HOME/.mozbuild/clang/bin"; then
		export CC=$HOME/.mozbuild/clang/bin/clang
		export CXX=$HOME/.mozbuild/clang/bin/clang++
	else
		export CC=clang
		export CXX=clang++
	fi
    if test -f "/usr/lib/nasm-mozilla/bin/nasm"; then
        export NASM="/usr/lib/nasm-mozilla/bin/nasm"
    fi
	ac_add_options --enable-optimize="-O2 -march=nocona -mtune=nocona -w"
	ac_add_options --target=x86_64-pc-linux-gnu
	ac_add_options --enable-pulseaudio
	ac_add_options --enable-alsa
fi

ac_add_options --disable-crashreporter
ac_add_options --disable-js-shell
ac_add_options --disable-maintenance-service
ac_add_options --disable-profiling
ac_add_options --disable-signmar
ac_add_options --disable-stylo
ac_add_options --disable-tests
ac_add_options --disable-verify-mar

if [ -x "$(command -v sccache)" ]; then
	ac_add_options --with-ccache=sccache
elif [ -x "$(command -v ccache)" ]; then
    ac_add_options --with-ccache=ccache
elif [ -f "$HOME/.mozbuild/sccache/sccache" ]; then
	ac_add_options --with-ccache=$HOME/.mozbuild/sccache/sccache
fi

ac_add_options --enable-application=browser
ac_add_options --enable-eme=widevine
ac_add_options --enable-release
ac_add_options --enable-rust-simd # on x86 requires SSE2
ac_add_options --enable-update-channel=release
ac_add_options --enable-updater

ac_add_options --with-app-name=waterfox
ac_add_options --with-app-basename=Waterfox
ac_add_options --with-branding=browser/branding/unofficial
ac_add_options --with-distribution-id=org.waterfoxproject

if test $(uname -s) = MINGW32_NT-6.2; then
	X=$(wmic cpu get NumberOfLogicalProcessors /Format:List | cut -d'=' -f2 | xargs)
    mk_add_options MOZ_MAKE_FLAGS=-j${X%.*}
else
	X=$(getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)
	mk_add_options MOZ_MAKE_FLAGS=-j${X%.*}
fi

mk_add_options AUTOCLOBBER=1
mk_add_options MOZ_OBJDIR=objdir-classic

export MOZ_GECKO_PROFILER=
export MOZ_ENABLE_PROFILER_SPS=
export MOZ_PROFILING=
export MOZ_INCLUDE_SOURCE_INFO=1
