From 12f56f81029c0c0720730d2edc85b0c13b00b645 Mon Sep 17 00:00:00 2001
From: "A. Wilcox" <AWilcox@Wilcox-Tech.com>
Date: Tue, 19 Nov 2024 00:55:22 -0600
Subject: user/arcticfox: New package

This browser would not be necessary if Firefox worked on the PPCs.

Tested on 32-bit and 64-bit PowerPC.
---
 user/arcticfox/APKBUILD                   | 131 ++++++++++++++++++++++++++++++
 user/arcticfox/arcticfox.desktop          |  76 +++++++++++++++++
 user/arcticfox/hunspell.patch             |  15 ++++
 user/arcticfox/mozconfig                  |  28 +++++++
 user/arcticfox/override-cxx-version.patch |  17 ++++
 user/arcticfox/stackwalk-x86-ppc.patch    |  14 ++++
 6 files changed, 281 insertions(+)
 create mode 100644 user/arcticfox/APKBUILD
 create mode 100644 user/arcticfox/arcticfox.desktop
 create mode 100644 user/arcticfox/hunspell.patch
 create mode 100644 user/arcticfox/mozconfig
 create mode 100644 user/arcticfox/override-cxx-version.patch
 create mode 100644 user/arcticfox/stackwalk-x86-ppc.patch

diff --git a/user/arcticfox/APKBUILD b/user/arcticfox/APKBUILD
new file mode 100644
index 000000000..da5bce014
--- /dev/null
+++ b/user/arcticfox/APKBUILD
@@ -0,0 +1,131 @@
+# Maintainer: A. Wilcox <awilfox@adelielinux.org>
+pkgname=arcticfox
+pkgver=45.1
+pkgrel=0
+pkgdesc="Arctic Fox web browser (fork of Firefox with PPC support)"
+url="https://github.com/rmottola/Arctic-Fox/wiki"
+arch="pmmx ppc ppc64 x86"
+options="!check"  # Disable tests.
+license="MPL-2.0"
+depends=""
+makedepends="alsa-lib-dev bzip2-dev dbus-glib-dev gconf-dev gtk+2.0-dev
+	gtk+3.0-dev hunspell-dev icu-dev libevent-dev libidl-dev
+	libjpeg-turbo-dev libnotify-dev libogg-dev libtheora-dev libvorbis-dev
+	libxt-dev libxcomposite-dev mesa-dev nspr-dev automake libtool
+	pulseaudio-dev sqlite-dev startup-notification-dev autoconf2.13
+	bsd-compat-headers cmd:which openssl-dev sed yasm zip"
+subpackages="$pkgname-dev"
+source="arcticfox-$pkgver.tar.gz::https://github.com/rmottola/Arctic-Fox/archive/refs/tags/v$pkgver.tar.gz
+	mozconfig
+	https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tar.xz
+	arcticfox.desktop
+
+	hunspell.patch
+	override-cxx-version.patch
+	stackwalk-x86-ppc.patch
+	"
+builddir="$srcdir/Arctic-Fox-$pkgver"
+_mozappdir="/usr/lib/$pkgname-$pkgver"
+ldpath="$_mozappdir"
+
+unpack() {
+	default_unpack
+
+	[ -z $SKIP_PYTHON ] || return 0
+	msg "Killing all remaining hope for humanity and building Python 2..."
+	cd "$srcdir"
+	[ -d python ] && rm -r python
+	mkdir python
+	# 19:39 <+solar> just make the firefox build process build its own py2 copy
+	# 20:03 <calvin> TheWilfox: there's always violence
+	cd Python-2.7.15
+	./configure --prefix="$srcdir/python"
+	make -j $JOBS
+	# 6 tests failed:
+	#    test__locale test_os test_posix test_re test_strptime test_time
+	# make test
+	make -j $JOBS install
+}
+
+prepare() {
+	default_prepare
+
+	cp "$srcdir"/mozconfig "$builddir"/mozconfig
+	echo "ac_add_options --host=\"$CHOST\"" >> "$builddir"/mozconfig
+	echo "ac_add_options --target=\"$CTARGET\"" >> "$builddir"/mozconfig
+	echo "mk_add_options MOZ_MAKE_FLAGS=\"-j$JOBS\"" >> "$builddir"/mozconfig
+	# Needed, see upstream https://github.com/rmottola/Arctic-Fox/issues/125
+	# on ppc, fails in NSFrameState::operator& without these flags
+	export CFLAGS="$CFLAGS -O1 -fno-delete-null-pointer-checks -fno-lifetime-dse -fno-schedule-insns2"
+	export LDFLAGS="$LDFLAGS -Wl,-rpath,$_mozappdir"
+
+	# arch-specific configuration
+	case "$CARCH" in
+	pmmx|x86*|arm*)
+		echo "ac_add_options --disable-elf-hack" >> "$builddir"/mozconfig
+		;;
+	ppc)
+		export LDFLAGS="$LDFLAGS -latomic"
+		;;
+	ppc64)
+		echo "ac_add_options --enable-altivec" >> "$builddir"/mozconfig
+		;;
+	s390x)
+		echo "ac_add_options --disable-startupcache" >> "$builddir"/mozconfig
+		;;
+	esac
+
+	echo "ac_add_options --enable-optimize=\"$CFLAGS\"" >> "$builddir"/mozconfig
+}
+
+build() {
+	export CFLAGS="$CFLAGS -Wno-dangling-pointer -Wno-array-bounds -Wno-comment -Wno-maybe-uninitialized -Wno-misleading-indentation -Wno-multistatement-macros -Wno-stringop-overflow -Wno-unused-function -Wno-unused-value -Wno-ignored-qualifiers -Wno-deprecated-declarations -Wno-implicit-fallthrough -Wno-unused-but-set-variable -Wno-int-in-bool-context -Wno-stringop-overread -Wno-address -Wno-use-after-free"
+	export CXXFLAGS="$CFLAGS -Wno-class-memaccess -Wno-changes-meaning -Wno-subobject-linkage -Wno-return-local-addr -Wno-unused-local-typedefs"
+	export SHELL=/bin/sh
+	export BUILD_OFFICIAL=1
+	export MOZILLA_OFFICIAL=1
+	export USE_SHORT_LIBNAME=1
+	export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=system
+	export PATH="$PATH:$srcdir/python/bin"
+	export CXX="/usr/bin/g++ -std=gnu++17"
+
+	# set rpath so linker finds the libs
+	export UNIXCONFDIR="$srcdir"
+
+	./mach configure
+	# parallel make bug hit on gwyn (64 threads)
+	./mach build -j1 export
+	./mach build
+}
+
+package() {
+	export PATH="$PATH:$srcdir/python/bin"
+	DESTDIR="$pkgdir" ./mach install
+
+	for pngsize in 16 32 48; do
+		install -D -m644 \
+			"browser/branding/$pkgname/default$pngsize.png" \
+			"$pkgdir"/usr/share/icons/hicolor/${pngsize}x${pngsize}/apps/$pkgname.png
+	done
+
+	install -D -m644 "browser/branding/$pkgname/mozicon128.png" \
+		"$pkgdir"/usr/share/pixmaps/$pkgname.png
+	install -D -m644 $srcdir/$pkgname.desktop \
+		"$pkgdir"/usr/share/applications/$pkgname.desktop
+}
+
+dev() {
+	mkdir -p "$subpkgdir"/usr/lib "$subpkgdir"/usr/share
+	mv "$pkgdir"/usr/lib/$pkgname-devel-$pkgver \
+		"$subpkgdir"/usr/lib/
+	mv "$pkgdir"/usr/share/idl "$subpkgdir"/usr/share/
+	default_dev
+}
+
+sha512sums="0b24bc8cf201a78517c7934c119b1e21d511068e8ea06c8b7f5ce65e5867e9f091cc0c8c65b0f8c78e8637d27dd3d505126d355c8ca5693f1b0417020b838800  arcticfox-45.1.tar.gz
+ce5312b4fcf07d0dd0496366f6e3be406ef19a389f67a3eb8e3df62232d9eb08ed1a5e212dee1725d907bb025bc3da19b6d0b0d97210893846eb8206890fe8de  mozconfig
+27ea43eb45fc68f3d2469d5f07636e10801dee11635a430ec8ec922ed790bb426b072da94df885e4dfa1ea8b7a24f2f56dd92f9b0f51e162330f161216bd6de6  Python-2.7.15.tar.xz
+d4f9a2a64cb8c1e679a13429e62cfd2e8a44cf54896c2999258571ab990711fbc3d078ce655efd90437e60ef113af1e5277f416f5cf78dfea21f82c481f6929b  arcticfox.desktop
+50cc077df6d17358f5dcffcabb1a75087b58ac46f60d9d5fc8f2d407e93a26d89778e4c09a5203f2a55bc9f9ddb247f4482483d30f495bc9e3393fad37a322d7  hunspell.patch
+bf63b06c030b388711554a4eff36fc50f2af802b59a9f1d7c5b42f11fcc1dd806d53980bdd89bf9518fc51ba25a812c892dfaf47e9d50b33a82ebad9462da92a  override-cxx-version.patch
+a0f97b8b3e5b0d93b155f1678a3d5984b52ede440202656d35237a6e7025b4a1315c114a1a87c3974d0d43b0f637e186b2be6422c44ba5f111ede53893e39c54  stackwalk-x86-ppc.patch"
diff --git a/user/arcticfox/arcticfox.desktop b/user/arcticfox/arcticfox.desktop
new file mode 100644
index 000000000..9e09c4abd
--- /dev/null
+++ b/user/arcticfox/arcticfox.desktop
@@ -0,0 +1,76 @@
+[Desktop Entry]
+Exec=arcticfox %u
+Icon=arcticfox
+Type=Application
+Terminal=false
+Name=Arctic Fox
+GenericName=Web Browser
+GenericName[af]=Web Blaaier
+GenericName[ar]=متصفح ويب
+GenericName[az]=Veb Səyyahı
+GenericName[bg]=Браузър
+GenericName[bn]=ওয়েব ব্রাউজার
+GenericName[br]=Furcher ar Gwiad
+GenericName[bs]=WWW Preglednik
+GenericName[ca]=Fullejador web
+GenericName[cs]=WWW prohlížeč
+GenericName[cy]=Porydd Gwe
+GenericName[da]=Browser
+GenericName[de]=Web-Browser
+GenericName[el]=Περιηγητής Ιστού
+GenericName[eo]=TTT-legilo
+GenericName[es]=Navegador web
+GenericName[et]=Veebilehitseja
+GenericName[eu]=Web arakatzailea
+GenericName[fa]=مرورگر وب
+GenericName[fi]=WWW-selain
+GenericName[fo]=Alnótsfar
+GenericName[fr]=Navigateur web
+GenericName[gl]=Navegador Web
+GenericName[he]=דפדפן אינטרנט
+GenericName[hi]=वेब ब्राउज़र
+GenericName[hr]=Web preglednik
+GenericName[hu]=Webböngésző
+GenericName[is]=Vafri
+GenericName[it]=Browser Web
+GenericName[ja]=ウェブブラウザ
+GenericName[ko]=웹 브라우저
+GenericName[lo]=ເວັບບຣາວເຊີ
+GenericName[lt]=Žiniatinklio naršyklė
+GenericName[lv]=Web Pārlūks
+GenericName[mk]=Прелистувач на Интернет 
+GenericName[mn]=Веб-Хөтөч
+GenericName[nb]=Nettleser
+GenericName[nds]=Nettkieker
+GenericName[nl]=Webbrowser
+GenericName[nn]=Nettlesar
+GenericName[nso]=Seinyakisi sa Web
+GenericName[pa]=ਵੈਬ ਝਲਕਾਰਾ
+GenericName[pl]=Przeglądarka WWW
+GenericName[pt]=Navegador Web
+GenericName[pt_BR]=Navegador Web
+GenericName[ro]=Navigator de web
+GenericName[ru]=Веб-браузер
+GenericName[se]=Fierpmádatlogan
+GenericName[sk]=Webový prehliadač
+GenericName[sl]=Spletni brskalnik
+GenericName[sr]=Веб претраживач
+GenericName[sr@Latn]=Veb pretraživač
+GenericName[ss]=Ibrawuza yeWeb 
+GenericName[sv]=Webbläsare
+GenericName[ta]=வலை உலாவி
+GenericName[tg]=Тафсиргари вэб
+GenericName[th]=เว็บบราวเซอร์
+GenericName[tr]=Web Tarayıcı
+GenericName[uk]=Навігатор Тенет
+GenericName[uz]=Веб-браузер
+GenericName[ven]=Buronza ya Webu
+GenericName[vi]=Trình duyệt Web
+GenericName[wa]=Betchteu waibe
+GenericName[xh]=Umkhangeli zincwadi we Web
+GenericName[zh_CN]=网页浏览器
+GenericName[zh_TW]=網頁瀏覽器
+GenericName[zu]=Umcingi we-Web
+MimeType=text/html;
+StartupNotify=true
+Categories=Network;WebBrowser;
diff --git a/user/arcticfox/hunspell.patch b/user/arcticfox/hunspell.patch
new file mode 100644
index 000000000..9fa23eeb5
--- /dev/null
+++ b/user/arcticfox/hunspell.patch
@@ -0,0 +1,15 @@
+On musl libc, #define free is dangerous.
+
+Upstream-URL: https://github.com/rmottola/Arctic-Fox/issues/100
+
+--- Arctic-Fox-45.1/extensions/spellcheck/hunspell/glue/hunspell_alloc_hooks.h.old	2024-09-30 19:54:44.000000000 +0000
++++ Arctic-Fox-45.1/extensions/spellcheck/hunspell/glue/hunspell_alloc_hooks.h	2024-10-22 21:46:00.494798524 +0000
+@@ -47,6 +47,8 @@
+  * allocated using C memory allocation functions.
+  */
+ 
++#include <sched.h>
++#include "mozilla/Logging.h"
+ #include "mozilla/mozalloc.h"
+ #include "mozHunspellAllocator.h"
+ 
diff --git a/user/arcticfox/mozconfig b/user/arcticfox/mozconfig
new file mode 100644
index 000000000..e19a24be1
--- /dev/null
+++ b/user/arcticfox/mozconfig
@@ -0,0 +1,28 @@
+ac_add_options --prefix=/usr
+ac_add_options --disable-crashreporter
+ac_add_options --disable-eme
+ac_add_options --disable-install-strip
+ac_add_options --disable-jemalloc
+ac_add_options --disable-mozril-geoloc
+ac_add_options --disable-necko-wifi
+ac_add_options --disable-precompiled-startupcache
+ac_add_options --disable-profiling
+ac_add_options --disable-strip
+ac_add_options --disable-tests
+ac_add_options --disable-updater
+ac_add_options --disable-webrtc
+ac_add_options --enable-alsa
+ac_add_options --enable-application=browser
+ac_add_options --enable-dbus
+ac_add_options --enable-default-toolkit=cairo-gtk3
+ac_add_options --enable-pulseaudio
+ac_add_options --enable-system-ffi
+ac_add_options --enable-system-hunspell
+ac_add_options --with-branding=browser/branding/arcticfox
+ac_add_options --with-system-icu
+ac_add_options --with-system-jpeg
+ac_add_options --with-system-nspr
+ac_add_options --with-system-pixman
+ac_add_options --with-system-png
+ac_add_options --with-system-zlib
+ac_add_options --without-system-nss
diff --git a/user/arcticfox/override-cxx-version.patch b/user/arcticfox/override-cxx-version.patch
new file mode 100644
index 000000000..6486c702e
--- /dev/null
+++ b/user/arcticfox/override-cxx-version.patch
@@ -0,0 +1,17 @@
+ICU 75 requires C++17 mode as a bare minimum.
+
+--- Arctic-Fox-45.1/build/moz.configure/toolchain.configure.old	2024-09-30 14:54:44.000000000 -0500
++++ Arctic-Fox-45.1/build/moz.configure/toolchain.configure	2024-11-19 00:21:31.792210428 -0600
+@@ -339,9 +339,9 @@
+     # Note: MSVC, while supporting C++11, still reports 199711L for __cplusplus.
+     # Note: this is a strict version check because we used to always add
+     # -std=gnu++11.
+-    if info.language == 'C++' and info.language_version != 201103:
+-        if info.type in ('clang-cl', 'clang', 'gcc'):
+-            append_flag('-std=gnu++11')
++    if info.language == 'C++' and info.language_version < 201703:
++        if info.type in ('clang', 'gcc'):
++            append_flag('-std=gnu++17')
+ 
+     # We force clang-cl to emulate Visual C++ 2013 Update 3 with fallback to
+     # cl.exe.
diff --git a/user/arcticfox/stackwalk-x86-ppc.patch b/user/arcticfox/stackwalk-x86-ppc.patch
new file mode 100644
index 000000000..377edabb6
--- /dev/null
+++ b/user/arcticfox/stackwalk-x86-ppc.patch
@@ -0,0 +1,14 @@
+--- Arctic-Fox-45.1/mozglue/misc/StackWalk.cpp.old	2024-09-30 19:54:44.000000000 +0000
++++ Arctic-Fox-45.1/mozglue/misc/StackWalk.cpp	2024-10-21 11:28:48.295293788 +0000
+@@ -42,10 +42,7 @@
+   (defined(XP_DARWIN) && \
+    (defined(__i386) || defined(__ppc__) || defined(HAVE__UNWIND_BACKTRACE)))
+ 
+-#define MOZ_STACKWALK_SUPPORTS_LINUX \
+-  (defined(linux) && \
+-   ((defined(__GNUC__) && (defined(__i386) || defined(PPC))) || \
+-    defined(HAVE__UNWIND_BACKTRACE)))
++#define MOZ_STACKWALK_SUPPORTS_LINUX 0
+ 
+ #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
+ #define HAVE___LIBC_STACK_END 1
-- 
cgit v1.2.3-70-g09d2