From 25059bfb6bcfc0c47aee8f8a30855dc29502e53b Mon Sep 17 00:00:00 2001
From: Cameron Cawley <ccawley2011@gmail.com>
Date: Wed, 16 Feb 2022 00:26:44 +0000
Subject: [PATCH] Update the x86_64-w64-mingw32 toolchain

---
 sdk/Makefile                                  |  9 ++++++
 .../openssl/Configurations-50-windows.conf.p  | 28 +++++++++++++++++--
 x86_64-w64-mingw32/Makefile                   | 23 +++++++++------
 .../recipes/patches/gcc4/cp_cfns_gperf.p      | 17 +++++++++++
 .../recipes/patches/gcc4/cp_cfns_h.p          | 17 +++++++++++
 .../recipes/patches/gcc4/gcc_texi.p           | 20 +++++++++++++
 6 files changed, 103 insertions(+), 11 deletions(-)
 create mode 100644 x86_64-w64-mingw32/recipes/patches/gcc4/cp_cfns_gperf.p
 create mode 100644 x86_64-w64-mingw32/recipes/patches/gcc4/cp_cfns_h.p
 create mode 100644 x86_64-w64-mingw32/recipes/patches/gcc4/gcc_texi.p

diff --git a/sdk/Makefile b/sdk/Makefile
index 6870546..b33a87f 100644
--- a/sdk/Makefile
+++ b/sdk/Makefile
@@ -12,6 +12,7 @@
 #			m5475-atari-mint
 #                       ppc-amigaos 
 #                       i686-w64-mingw32    
+#                       x86_64-w64-mingw32
 #                       m68k-unknown-amigaos
 
 ifeq ($(GCCSDK_INSTALL_ENV),)
@@ -139,6 +140,14 @@ ifeq ($(TARGET),i686-w64-mingw32)
   EXTRAARGS_OPENSSL := no-asm enable-capieng
 endif
 
+ifeq ($(TARGET),x86_64-w64-mingw32)
+  SDK_ITEMS := $(addprefix $(BUILDSTEPS)/, libiconv.d libgnurx.d $(COMMON_SDK_ITEMS) libjpeg.d libwebp.d)
+  EXTRAARGS_LIBCARES := --disable-shared
+  EXTRAARGS_LIBCURL := --enable-nonblocking --enable-ares --disable-ldap --without-random
+  LIBCURL_ENV := CFLAGS="-DCARES_STATICLIB" LIBS="-lgdi32 -lcrypt32"
+  EXTRAARGS_OPENSSL := no-asm enable-capieng
+endif
+
 ifeq ($(TARGET),m68k-unknown-amigaos)
   SDK_ITEMS := $(addprefix $(BUILDSTEPS)/, roadshow.d libiconv.d libtre.d libpbl.d $(COMMON_SDK_ITEMS) libjpeg.d)
   EXTRAARGS_LIBCARES := --disable-shared --without-random
diff --git a/sdk/recipes/patches/openssl/Configurations-50-windows.conf.p b/sdk/recipes/patches/openssl/Configurations-50-windows.conf.p
index c492c01..9078348 100644
--- a/sdk/recipes/patches/openssl/Configurations-50-windows.conf.p
+++ b/sdk/recipes/patches/openssl/Configurations-50-windows.conf.p
@@ -1,6 +1,6 @@
---- /dev/null	2017-10-10 15:19:45.611896396 +0100
-+++ Configurations/50-windows.conf	2017-10-17 15:42:25.304921197 +0100
-@@ -0,0 +1,25 @@
+--- /dev/null	2022-02-14 15:37:52.105293873 +0000
++++ Configurations/50-windows.conf	2022-02-14 21:08:53.051895233 +0000
+@@ -0,0 +1,47 @@
 +%targets = (
 +
 +    "i686-w64-mingw32" => {
@@ -25,4 +25,26 @@
 +        multilib         => "",
 +        apps_aux_src     => add("win32_init.c"),
 +    },
++
++    "x86_64-w64-mingw32" => {
++        inherit_from     => [ "BASE_unix", asm("x86_64_asm") ],
++        cc               => "gcc",
++        cflags           => combine(picker(default => "-DL_ENDIAN -DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE -m64 -Wall",
++                                           debug   => "-g -O0",
++                                           release => "-O3"),
++                                    threads("-D_MT")),
++        sys_id           => "MINGW64",
++        ex_libs          => add("-lws2_32 -lgdi32 -lcrypt32"),
++        bn_ops           => "SIXTY_FOUR_BIT EXPORT_VAR_AS_FN",
++        thread_scheme    => "winthreads",
++        perlasm_scheme   => "mingw64",
++        dso_scheme       => "win32",
++        shared_target    => "mingw-shared",
++        shared_cflag     => add("-D_WINDLL"),
++        shared_ldflag    => "-static-libgcc",
++        shared_rcflag    => "--target=pe-x86-64",
++        shared_extension => ".dll",
++        multilib         => "64",
++        apps_aux_src     => add("win32_init.c"),
++    },
 +);
diff --git a/x86_64-w64-mingw32/Makefile b/x86_64-w64-mingw32/Makefile
index 240411b..c3b174d 100644
--- a/x86_64-w64-mingw32/Makefile
+++ b/x86_64-w64-mingw32/Makefile
@@ -1,6 +1,6 @@
-#!/bin/make
+#!/usr/bin/make
 
-# mingw toolchain
+# Build cross toolchain for x86_64 processor with a win32 (mingw) ABI
 
 UPSTREAM_GCC_VERSION := 4.8.4
 UPSTREAM_GCC_TARBALL := gcc-$(UPSTREAM_GCC_VERSION).tar.bz2
@@ -10,9 +10,9 @@ UPSTREAM_BINUTILS_VERSION := 2.25
 UPSTREAM_BINUTILS_TARBALL := binutils-$(UPSTREAM_BINUTILS_VERSION).tar.bz2
 UPSTREAM_BINUTILS_URI := http://ftpmirror.gnu.org/binutils/$(UPSTREAM_BINUTILS_TARBALL)
 
-UPSTREAM_GMP_VERSION := 4.3.2
+UPSTREAM_GMP_VERSION := 5.0.5
 UPSTREAM_GMP_TARBALL := gmp-$(UPSTREAM_GMP_VERSION).tar.bz2
-UPSTREAM_GMP_URI := http://ftp.gnu.org/gnu/gmp/$(UPSTREAM_GMP_TARBALL)
+UPSTREAM_GMP_URI := https://gmplib.org/download/gmp-$(UPSTREAM_GMP_VERSION)/$(UPSTREAM_GMP_TARBALL)
 
 # Would use 3.0.0, but that dislikes in-tree gmp sources
 UPSTREAM_MPFR_VERSION := 2.4.2
@@ -62,7 +62,7 @@ $(BUILDSTEPS)/gcc-core.d: $(BUILDSTEPS)/srcdir-step3.d $(BUILDSTEPS)/binutils.d
 		--prefix=$(PREFIX) --target=$(TARGET_NAME) \
 		--enable-languages=c,c++ --with-system-zlib --disable-multilib \
 		--enable-shared --enable-fully-dynamic-string
-	cd $(BUILDDIR)/gcc && PATH="$(PREFIX)/bin:$(PATH)" make all-gcc -j 4
+	cd $(BUILDDIR)/gcc && PATH="$(PREFIX)/bin:$(PATH)" make all-gcc 
 	cd $(BUILDDIR)/gcc && PATH="$(PREFIX)/bin:$(PATH)" make install-gcc
 	touch $@
 
@@ -104,6 +104,7 @@ $(BUILDSTEPS)/mingw-srcdir.d: $(SOURCESDIR)/$(UPSTREAM_MINGW_TARBALL)
 ###
 
 $(BUILDSTEPS)/srcdir-step3.d: $(BUILDSTEPS)/srcdir-step2.d
+	for p in `ls $(RECIPES)/patches/gcc4/*.p` ; do patch -d $(GCC_SRCDIR) -p0 <$$p ; done
 	touch $@
 
 $(BUILDSTEPS)/srcdir-step2.d: $(BUILDSTEPS)/srcdir-step1.d $(SOURCESDIR)/$(UPSTREAM_GMP_TARBALL) $(SOURCESDIR)/$(UPSTREAM_MPFR_TARBALL) $(SOURCESDIR)/$(UPSTREAM_MPC_TARBALL)
@@ -143,22 +144,28 @@ $(BUILDSTEPS)/binutils-srcdir.d: $(SOURCESDIR)/$(UPSTREAM_BINUTILS_TARBALL)
 ###
 
 $(SOURCESDIR)/$(UPSTREAM_GCC_TARBALL):
-	wget -q -O $@ $(UPSTREAM_GCC_URI) 
+	wget -q -O $@ $(UPSTREAM_GCC_URI)
+	touch $@
 
 $(SOURCESDIR)/$(UPSTREAM_GMP_TARBALL):
 	wget -q -O $@ $(UPSTREAM_GMP_URI)
+	touch $@
 
 $(SOURCESDIR)/$(UPSTREAM_MPFR_TARBALL):
 	wget -q -O $@ $(UPSTREAM_MPFR_URI)
+	touch $@
 
 $(SOURCESDIR)/$(UPSTREAM_MPC_TARBALL):
 	wget -q -O $@ $(UPSTREAM_MPC_URI)
+	touch $@
 
 $(SOURCESDIR)/$(UPSTREAM_BINUTILS_TARBALL):
 	wget -q -O $@ $(UPSTREAM_BINUTILS_URI) 
+	touch $@
 
 $(SOURCESDIR)/$(UPSTREAM_MINGW_TARBALL):
 	wget -q -O $@ $(UPSTREAM_MINGW_URI)
+	touch $@
 
 ###
 # Rule to create buildsteps dir
@@ -169,7 +176,7 @@ $(BUILDSTEPS)/buildsteps.d: $(SOURCESDIR) $(SRCDIR)
 	touch $@
 
 $(SOURCESDIR):
-	mkdir -p $(SOURCESDIR)
+	mkdir -p $@
 
 $(SRCDIR):
-	mkdir -p $(SRCDIR)
+	mkdir -p $@
diff --git a/x86_64-w64-mingw32/recipes/patches/gcc4/cp_cfns_gperf.p b/x86_64-w64-mingw32/recipes/patches/gcc4/cp_cfns_gperf.p
new file mode 100644
index 0000000..f0598e5
--- /dev/null
+++ b/x86_64-w64-mingw32/recipes/patches/gcc4/cp_cfns_gperf.p
@@ -0,0 +1,17 @@
+--- gcc/cp/cfns.gperf.orig	2017-09-15 16:17:49.249145794 +0100
++++ gcc/cp/cfns.gperf	2017-09-15 16:18:26.468005263 +0100
+@@ -16,14 +16,6 @@
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3.  If not see
+ <http://www.gnu.org/licenses/>.  */
+-#ifdef __GNUC__
+-__inline
+-#endif
+-static unsigned int hash (const char *, unsigned int);
+-#ifdef __GNUC__
+-__inline
+-#endif
+-const char * libc_name_p (const char *, unsigned int);
+ %}
+ %%
+ # The standard C library functions, for feeding to gperf; the result is used
diff --git a/x86_64-w64-mingw32/recipes/patches/gcc4/cp_cfns_h.p b/x86_64-w64-mingw32/recipes/patches/gcc4/cp_cfns_h.p
new file mode 100644
index 0000000..8f89f8a
--- /dev/null
+++ b/x86_64-w64-mingw32/recipes/patches/gcc4/cp_cfns_h.p
@@ -0,0 +1,17 @@
+--- gcc/cp/cfns.h.orig	2017-09-15 16:50:55.872127506 +0100
++++ gcc/cp/cfns.h	2017-09-15 16:51:18.147443810 +0100
+@@ -47,14 +47,6 @@
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING3.  If not see
+ <http://www.gnu.org/licenses/>.  */
+-#ifdef __GNUC__
+-__inline
+-#endif
+-static unsigned int hash (const char *, unsigned int);
+-#ifdef __GNUC__
+-__inline
+-#endif
+-const char * libc_name_p (const char *, unsigned int);
+ /* maximum key range = 391, duplicates = 0 */
+ 
+ #ifdef __GNUC__
diff --git a/x86_64-w64-mingw32/recipes/patches/gcc4/gcc_texi.p b/x86_64-w64-mingw32/recipes/patches/gcc4/gcc_texi.p
new file mode 100644
index 0000000..056edfa
--- /dev/null
+++ b/x86_64-w64-mingw32/recipes/patches/gcc4/gcc_texi.p
@@ -0,0 +1,20 @@
+--- gcc/doc/gcc.texi.orig	2017-09-15 17:46:47.157490325 +0100
++++ gcc/doc/gcc.texi	2017-09-15 17:47:58.714929743 +0100
+@@ -85,9 +85,15 @@
+ @item GNU Press
+ @tab Website: www.gnupress.org
+ @item a division of the
+-@tab General: @tex press@@gnu.org @end tex
++@tab General:
++@tex
++press@@gnu.org
++@end tex
+ @item Free Software Foundation
+-@tab Orders:  @tex sales@@gnu.org @end tex
++@tab Orders:
++@tex
++sales@@gnu.org
++@end tex
+ @item 51 Franklin Street, Fifth Floor
+ @tab Tel 617-542-5942
+ @item Boston, MA 02110-1301 USA
-- 
2.30.2

