From cc5b7b05c04630cc1cb3f396604630c98d3b3141 Mon Sep 17 00:00:00 2001
From: psykose <alice@ayaya.dev>
Date: Mon, 12 Sep 2022 07:56:28 +0000
Subject: [PATCH] community/wxwidgets: upgrade to 3.2.1, rename from wxgtk

---
 community/wxwidgets/APKBUILD                  | 154 ++++++++++++++++++
 .../wxwidgets/invalid-header-syntax.patch     |  17 ++
 community/wxwidgets/largefile.patch           |  14 ++
 community/wxwidgets/musl-locale-l.patch       |  32 ++++
 community/wxwidgets/no-glvnd.patch            |  40 +++++
 community/wxwidgets/no-langinfo-h.patch       |  27 +++
 community/wxwidgets/wxgtk-abicheck.patch      |  38 +++++
 7 files changed, 322 insertions(+)
 create mode 100644 community/wxwidgets/APKBUILD
 create mode 100644 community/wxwidgets/invalid-header-syntax.patch
 create mode 100644 community/wxwidgets/largefile.patch
 create mode 100644 community/wxwidgets/musl-locale-l.patch
 create mode 100644 community/wxwidgets/no-glvnd.patch
 create mode 100644 community/wxwidgets/no-langinfo-h.patch
 create mode 100644 community/wxwidgets/wxgtk-abicheck.patch

diff --git a/community/wxwidgets/APKBUILD b/community/wxwidgets/APKBUILD
new file mode 100644
index 000000000000..cdf72365fbd2
--- /dev/null
+++ b/community/wxwidgets/APKBUILD
@@ -0,0 +1,154 @@
+# Contributor: Rasmus Thonsen <oss@cogitri.dev>
+# Contributor: Pavel Kalian <pavel@kalian.cz>
+# Contributor: ScrumpyJack <scrumpyjack@st.ilet.to>
+# Maintainer: psykose <alice@ayaya.dev>
+pkgname=wxwidgets
+pkgver=3.2.1
+pkgrel=0
+pkgdesc="wxWidgets GUI library"
+url="https://www.wxwidgets.org/"
+arch="all"
+license="custom:wxWidgets"
+depends_dev="
+	expat-dev
+	libjpeg-turbo-dev
+	libsecret-dev
+	libsm-dev
+	curl-dev
+	glu-dev
+	gst-plugins-base-dev
+	gstreamer-dev
+	libnotify-dev
+	pcre2-dev
+	gtk+3.0-dev
+	mesa-dev
+	sdl2-dev
+	webkit2gtk-dev
+	tiff-dev
+	qt5-qtbase-dev
+	xz-dev
+	zlib-dev
+	"
+makedepends="
+	$depends_dev
+	cmake
+	samurai
+	"
+subpackages="
+	$pkgname-dbg
+	$pkgname-dev
+	$pkgname-webview:_webview
+	$pkgname-gtk3:_gtk3
+	$pkgname-qt5:_qt5
+	"
+source="https://github.com/wxWidgets/wxWidgets/releases/download/v$pkgver/wxWidgets-$pkgver.tar.bz2
+	invalid-header-syntax.patch
+	largefile.patch
+	musl-locale-l.patch
+	no-glvnd.patch
+	no-langinfo-h.patch
+	"
+builddir="$srcdir/wxWidgets-$pkgver"
+# tests test meaningless locale stuff that fails on musl
+options="!check !spdx"
+
+build() {
+	export CFLAGS="$CFLAGS -g1 -O2 -flto=auto"
+	export CXXFLAGS="$CXXFLAGS -g1 -O2 -flto=auto"
+
+	cmake -B build-gtk3 -G Ninja -Wno-dev \
+		-DCMAKE_INSTALL_PREFIX=/usr \
+		-DCMAKE_BUILD_TYPE=None \
+		-DwxBUILD_PRECOMP=OFF \
+		-DwxBUILD_TESTS="$(want_check && echo CONSOLE_ONLY || echo OFF)" \
+		-DwxBUILD_TOOLKIT=gtk3 \
+		-DwxUSE_EXPAT=sys \
+		-DwxUSE_GLCANVAS_EGL=ON \
+		-DwxUSE_GTKPRINT=ON \
+		-DwxUSE_LIBJPEG=sys \
+		-DwxUSE_LIBLZMA=sys \
+		-DwxUSE_LIBPNG=sys \
+		-DwxUSE_LIBTIFF=sys \
+		-DwxUSE_OPENGL=ON \
+		-DwxUSE_PRIVATE_FONTS=ON \
+		-DwxUSE_REGEX=sys \
+		-DwxUSE_ZLIB=sys
+
+	cmake --build build-gtk3
+
+	cmake -B build-qt5 -G Ninja -Wno-dev \
+		-DCMAKE_INSTALL_PREFIX=/usr \
+		-DCMAKE_BUILD_TYPE=None \
+		-DwxBUILD_PRECOMP=OFF \
+		-DwxBUILD_TOOLKIT=qt \
+		-DwxUSE_EXPAT=sys \
+		-DwxUSE_GLCANVAS_EGL=ON \
+		-DwxUSE_LIBJPEG=sys \
+		-DwxUSE_LIBLZMA=sys \
+		-DwxUSE_LIBPNG=sys \
+		-DwxUSE_LIBTIFF=sys \
+		-DwxUSE_OPENGL=ON \
+		-DwxUSE_PRIVATE_FONTS=ON \
+		-DwxUSE_REGEX=sys \
+		-DwxUSE_ZLIB=sys
+
+	cmake --build build-qt5
+}
+
+check() {
+	ctest --test-dir build-gtk3 --output-on-failure
+}
+
+package() {
+	DESTDIR="$pkgdir" cmake --install build-qt5
+
+	# Rename qt5 cmake files to allow dual use
+	mv "$pkgdir"/usr/lib/cmake/wxWidgets "$pkgdir"/usr/lib/cmake/wxWidgetsQt
+	local f
+	for f in "$pkgdir"/usr/lib/cmake/wxWidgetsQt/*; do
+		local target="$(dirname $f)/$(basename $f | sed -e 's/wxWidgets/wxWidgetsQt/')"
+		mv "$f" "$target"
+	done
+	mv "$pkgdir"/usr/bin/wx-config "$pkgdir"/usr/bin/wx-config-qt
+
+	DESTDIR="$pkgdir" cmake --install build-gtk3
+
+	install -Dm644 wxwin.m4 -t "$pkgdir"/usr/share/aclocal
+	install -Dm644 docs/licence.txt -t "$pkgdir"/usr/share/licenses/$pkgname
+}
+
+dev() {
+	replaces="wxgtk-base-dev"
+	amove usr/bin
+	default_dev
+	amove usr/lib/wx/config
+}
+
+_webview() {
+	pkgdesc="$pkgdesc (WebView component)"
+	depends="$pkgname=$pkgver-r$pkgrel $pkgname-gtk3=$pkgver-r$pkgrel"
+
+	amove usr/lib/wx/3.2/web-extensions
+	amove usr/lib/libwx_gtk3u_webview*
+}
+
+_gtk3() {
+	pkgdesc="$pkgdesc (GTK3 components)"
+
+	amove usr/lib/libwx_gtk3u*
+}
+
+_qt5() {
+	pkgdesc="$pkgdesc (Qt5 components)"
+
+	amove usr/lib/libwx_qtu*
+}
+
+sha512sums="
+d0294788891014672d8eb4501ae257598972407b53f38471e4f11dd20f517d0145d510c5bce006b09c5d63113fed844bdf6124b3c80453c1d37b402abc89202b  wxWidgets-3.2.1.tar.bz2
+90efa1007b6f4aa7a80a8e78a767ba953cd3f260f36111e507fc4b1ce7ef702682bda0c92dcd4e07d54aaf719f9b1ff380f5a4a2d7532a8cf79bf25eb257c7ab  invalid-header-syntax.patch
+f41162f574ddce14c64b0c052c181dd490d0e5464e03e800d08e04ca0699392820ce7e01c70d59c9eb2ffdc75af9abf0c75e59b680abee7d06571840480321e7  largefile.patch
+07f40cbeefdc19aa6bd8e71826409a8e2ea04f19e70e895623d887eaf1b6f2a9ddce9a804d8c66de138431131f8c4e5b910dd4c71a38cd84587ff4cf53804339  musl-locale-l.patch
+242b61fbbccffa2aa1ee471d957d2284ca8e52d26596063f37292a9f4206a27a133d4d96fb470ac6418eab1b2627e93e132416950b13c712577ddf7062f66b3f  no-glvnd.patch
+2a6f6e51d973039a58510ca52466c680b2c7f68dc4893b64534cabc5d16363994fa5322e350b5e06b8ec09f974f437813f92ed0ac26e7f5d156325029c2e4d5f  no-langinfo-h.patch
+"
diff --git a/community/wxwidgets/invalid-header-syntax.patch b/community/wxwidgets/invalid-header-syntax.patch
new file mode 100644
index 000000000000..b66c3e7b876e
--- /dev/null
+++ b/community/wxwidgets/invalid-header-syntax.patch
@@ -0,0 +1,17 @@
+diff --git a/include/wx/matrix.h b/include/wx/matrix.h
+index d18a0d2..f24b583 100644
+--- a/include/wx/matrix.h
++++ b/include/wx/matrix.h
+@@ -37,11 +37,10 @@
+ //  at a certain coordinate and angle within another parent picture.
+ //  At all times m_isIdentity is set if the matrix itself is an Identity matrix.
+ //  It is used where possible to optimize calculations.
+-class
+ #ifndef WXBUILDING
+ wxDEPRECATED_MSG("use wxAffineMatrix2D instead")
+ #endif
+-WXDLLIMPEXP_CORE wxTransformMatrix: public wxObject
++WXDLLIMPEXP_CORE class wxTransformMatrix: public wxObject
+ {
+ public:
+     wxTransformMatrix();
diff --git a/community/wxwidgets/largefile.patch b/community/wxwidgets/largefile.patch
new file mode 100644
index 000000000000..3b52f8d1dfbf
--- /dev/null
+++ b/community/wxwidgets/largefile.patch
@@ -0,0 +1,14 @@
+nothing sets this to 0, but for some reason it gets undef'd
+diff --git a/build/cmake/setup.h.in b/build/cmake/setup.h.in
+index d4ef1fc..69ecd6c 100644
+--- a/build/cmake/setup.h.in
++++ b/build/cmake/setup.h.in
+@@ -869,7 +869,7 @@
+ /*
+  * Define if large (64 bit file offsets) files are supported.
+  */
+-#cmakedefine HAVE_LARGEFILE_SUPPORT 1
++#define HAVE_LARGEFILE_SUPPORT 1
+ 
+ /*
+  * Use OpenGL
diff --git a/community/wxwidgets/musl-locale-l.patch b/community/wxwidgets/musl-locale-l.patch
new file mode 100644
index 000000000000..f83d2d4458c1
--- /dev/null
+++ b/community/wxwidgets/musl-locale-l.patch
@@ -0,0 +1,32 @@
+these macro'd away functions don't exist in musl (yet)
+diff --git a/include/wx/xlocale.h b/include/wx/xlocale.h
+index c433d25..3ab9d84 100644
+--- a/include/wx/xlocale.h
++++ b/include/wx/xlocale.h
+@@ -33,6 +33,26 @@
+ #include "wx/crt.h"     // Includes wx/chartype.h, wx/wxcrt.h(wx/string.h)
+ #include "wx/intl.h"    // wxLanguage
+ 
++#ifndef strtol_l
++#define strtol_l(s, p, base, l) strtol(s, p, base)
++#endif
++
++#ifndef strtoul_l
++#define strtoul_l(s, p, base, l) strtoul(s, p, base)
++#endif
++
++#ifndef wcstod_l
++#define wcstod_l(s, p, l) wcstod(s, p)
++#endif
++
++#ifndef wcstol_l
++#define wcstol_l(s, p, base, l) wcstol(s, p, base)
++#endif
++
++#ifndef wcstoul_l
++#define wcstoul_l(s, p, base, l) wcstoul(s, p, base)
++#endif
++
+ // The platform-specific locale type
+ // If wxXLocale_t is not defined, then only "C" locale support is provided
+ #ifdef wxHAS_XLOCALE_SUPPORT
diff --git a/community/wxwidgets/no-glvnd.patch b/community/wxwidgets/no-glvnd.patch
new file mode 100644
index 000000000000..a4b38fb93377
--- /dev/null
+++ b/community/wxwidgets/no-glvnd.patch
@@ -0,0 +1,40 @@
+find_package(OpenGL) only works with glvnd and hardcodes glvnd paths, even
+though all these components are easily found with pkgconfig..
+diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake
+index ef28c99..0840447 100644
+--- a/build/cmake/init.cmake
++++ b/build/cmake/init.cmake
+@@ -408,15 +408,24 @@ if(wxUSE_GUI)
+             set(OPENGL_FOUND TRUE)
+             set(OPENGL_LIBRARIES "-framework OpenGLES" "-framework QuartzCore" "-framework GLKit")
+         else()
+-            find_package(OpenGL)
+-            if(OPENGL_FOUND)
+-                foreach(gltarget OpenGL::GL OpenGL::GLU OpenGL::OpenGL)
+-                    if(TARGET ${gltarget})
+-                        set(OPENGL_LIBRARIES ${gltarget} ${OPENGL_LIBRARIES})
+-                    endif()
+-                endforeach()
+-            endif()
+-            if(WXGTK3 AND OpenGL_EGL_FOUND AND wxUSE_GLCANVAS_EGL)
++            # find_package(OpenGL)
++            # if(OPENGL_FOUND)
++            #     foreach(gltarget OpenGL::GL OpenGL::GLU OpenGL::OpenGL)
++            #         if(TARGET ${gltarget})
++            #             set(OPENGL_LIBRARIES ${gltarget} ${OPENGL_LIBRARIES})
++            #         endif()
++            #     endforeach()
++            # endif()
++            find_package(PkgConfig REQUIRED)
++            pkg_check_modules(GLU REQUIRED glu IMPORTED_TARGET GLOBAL)
++            add_library(OpenGL::GLU ALIAS PkgConfig::GLU)
++            pkg_check_modules(GL REQUIRED gl IMPORTED_TARGET GLOBAL)
++            add_library(OpenGL::GL ALIAS PkgConfig::GL)
++            pkg_check_modules(EGL REQUIRED egl IMPORTED_TARGET GLOBAL)
++            add_library(OpenGL::EGL ALIAS PkgConfig::EGL)
++            set(OPENGL_FOUND TRUE)
++            set(OpenGL_EGL_FOUND TRUE)
++            if(WXGTK3 AND wxUSE_GLCANVAS_EGL)
+                 if(TARGET OpenGL::EGL)
+                     set(OPENGL_LIBRARIES OpenGL::EGL ${OPENGL_LIBRARIES})
+                 endif()
diff --git a/community/wxwidgets/no-langinfo-h.patch b/community/wxwidgets/no-langinfo-h.patch
new file mode 100644
index 000000000000..fd7ba5d5b740
--- /dev/null
+++ b/community/wxwidgets/no-langinfo-h.patch
@@ -0,0 +1,27 @@
+requires langinfo.h support not present in musl, so use the embedded
+localisation facilities instead
+diff --git a/build/cmake/setup.cmake b/build/cmake/setup.cmake
+index 365c1f3..89a1610 100644
+--- a/build/cmake/setup.cmake
++++ b/build/cmake/setup.cmake
+@@ -604,7 +604,7 @@ if(NOT MSVC_VERSION LESS 1600)
+     check_include_file_cxx(type_traits HAVE_TYPE_TRAITS)
+ endif()
+ check_include_file(fcntl.h HAVE_FCNTL_H)
+-check_include_file(langinfo.h HAVE_LANGINFO_H)
++#check_include_file(langinfo.h HAVE_LANGINFO_H)
+ check_include_file(sched.h HAVE_SCHED_H)
+ check_include_file(unistd.h HAVE_UNISTD_H)
+ check_include_file(wchar.h HAVE_WCHAR_H)
+diff --git a/build/cmake/setup.h.in b/build/cmake/setup.h.in
+index bce33a7..9ba4d76 100644
+--- a/build/cmake/setup.h.in
++++ b/build/cmake/setup.h.in
+@@ -1183,7 +1183,6 @@
+ #cmakedefine ICONV_CONST @ICONV_CONST@
+ 
+ /* Define if you have the <langinfo.h> header file.  */
+-#cmakedefine HAVE_LANGINFO_H 1
+ 
+ /* Define if you have the <sys/soundcard.h> header file. */
+ #cmakedefine HAVE_SYS_SOUNDCARD_H 1
diff --git a/community/wxwidgets/wxgtk-abicheck.patch b/community/wxwidgets/wxgtk-abicheck.patch
new file mode 100644
index 000000000000..e54b404cd2ee
--- /dev/null
+++ b/community/wxwidgets/wxgtk-abicheck.patch
@@ -0,0 +1,38 @@
+Description: Suppress error about mismatching C++ ABI version
+ In practice, the differences between recent ABI versions don't seem to be
+ incompatible since they apparently only affect obscure corner cases.  So
+ suppress this error so we don't have to rebuild the entire wx world in one
+ go.
+Author: Olly Betts <olly@survex.com>
+Forwarded: no
+Last-Update: 2017-07-26
+
+--- a/src/common/appbase.cpp
++++ b/src/common/appbase.cpp
+@@ -766,6 +766,26 @@
+         msg.Printf(wxT("Mismatch between the program and library build versions detected.\nThe library used %s,\nand %s used %s."),
+                    lib.c_str(), progName.c_str(), prog.c_str());
+ 
++	int l_off = lib.Find("compiler with C++ ABI ");
++	int p_off = prog.Find("compiler with C++ ABI ");
++	if (l_off != wxNOT_FOUND && p_off != wxNOT_FOUND) {
++	    int space;
++	    space = lib.find(',', l_off + 22);
++	    lib.erase(l_off, space - l_off);
++	    space = prog.find(',', p_off + 22);
++	    prog.erase(p_off, space - p_off);
++	    if (lib == prog) {
++		// The only difference is the ABI version, which apparently only
++		// affect obscure cases.  We used to warn here, so at least
++		// there was an indication of what's up if there is a problem
++		// due to ABI incompatibilities, but wxLogWarning() can result
++		// in a pop up dialog with some applications, which is just too
++		// intrusive, so just quietly ignore instead.
++		//wxLogWarning(msg.c_str());
++		return false;
++	    }
++	}
++
+         wxLogFatalError(msg.c_str());
+ 
+         // normally wxLogFatalError doesn't return
-- 
GitLab