From 58f6a5807b026abebbaa0fbacf22d606c3884070 Mon Sep 17 00:00:00 2001
From: Cameron Cawley <ccawley2011@gmail.com>
Date: Wed, 16 Feb 2022 00:56:23 +0000
Subject: [PATCH] Fix build and warnings with 64-bit Windows

---
 content/fetchers/about/chart.c      |  1 +
 content/handlers/html/interaction.c |  2 ++
 content/llcache.c                   |  2 +-
 frontends/windows/Makefile.tools    |  9 +++++++--
 frontends/windows/about.c           |  2 +-
 frontends/windows/download.c        |  5 +++--
 frontends/windows/font.c            |  4 ++--
 frontends/windows/prefs.c           | 27 +++++++++++++++------------
 frontends/windows/windbg.h          |  2 +-
 tools/jenkins-build.sh              | 13 +++++++++++++
 10 files changed, 46 insertions(+), 21 deletions(-)

diff --git a/content/fetchers/about/chart.c b/content/fetchers/about/chart.c
index 1565c54d8..f67598a84 100644
--- a/content/fetchers/about/chart.c
+++ b/content/fetchers/about/chart.c
@@ -34,6 +34,7 @@
 #include <stdio.h>
 
 #include "netsurf/inttypes.h"
+#include "utils/config.h"
 #include "utils/utils.h"
 #include "utils/errors.h"
 #include "utils/nsurl.h"
diff --git a/content/handlers/html/interaction.c b/content/handlers/html/interaction.c
index 026ef1ee7..cef09fcda 100644
--- a/content/handlers/html/interaction.c
+++ b/content/handlers/html/interaction.c
@@ -1499,6 +1499,8 @@ html_mouse_action(struct content *c,
 	default:
 		/* Unknown content related drag type */
 		assert(0 && "Unknown content related drag type");
+		res = NSERROR_BAD_PARAMETER;
+		break;
 	}
 
 	if (res != NSERROR_OK) {
diff --git a/content/llcache.c b/content/llcache.c
index 81e08383c..a64900a77 100644
--- a/content/llcache.c
+++ b/content/llcache.c
@@ -2966,7 +2966,7 @@ static void llcache_persist(void *p)
 		total_bandwidth = (total_written * 1000) / total_elapsed;
 
 		NSLOG(llcache, DEBUG,
-		      "Wrote %"PRIssizet" bytes in %lums bw:%lu %s",
+		      "Wrote %"PRIssizet" bytes in %lums bw:%"PRIsizet" %s",
 		      written, elapsed, (written * 1000) / elapsed,
 		      nsurl_access(lst[idx]->url) );
 
diff --git a/frontends/windows/Makefile.tools b/frontends/windows/Makefile.tools
index 24f0f7fbd..38e856eb0 100644
--- a/frontends/windows/Makefile.tools
+++ b/frontends/windows/Makefile.tools
@@ -5,8 +5,13 @@
 
 ifneq ($(HOST),windows)
   # Set Mingw defaults
-  GCCSDK_INSTALL_ENV ?= /opt/netsurf/i686-w64-mingw32/env
-  GCCSDK_INSTALL_CROSSBIN ?= /opt/netsurf/i686-w64-mingw32/cross/bin
+  ifeq ($(findstring -w64-mingw32,$(HOST)),-w64-mingw32)
+    GCCSDK_INSTALL_ENV ?= /opt/netsurf/$(HOST)/env
+    GCCSDK_INSTALL_CROSSBIN ?= /opt/netsurf/$(HOST)/cross/bin
+  else
+    GCCSDK_INSTALL_ENV ?= /opt/netsurf/i686-w64-mingw32/env
+    GCCSDK_INSTALL_CROSSBIN ?= /opt/netsurf/i686-w64-mingw32/cross/bin
+  endif
 
   CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
   WINDRES := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*windres)
diff --git a/frontends/windows/about.c b/frontends/windows/about.c
index 325587d8a..730751f34 100644
--- a/frontends/windows/about.c
+++ b/frontends/windows/about.c
@@ -94,7 +94,7 @@ static BOOL destroy_about_dialog(HWND hwnd)
 
 }
 
-static BOOL CALLBACK 
+static INT_PTR CALLBACK
 nsws_about_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
 {
 
diff --git a/frontends/windows/download.c b/frontends/windows/download.c
index f0163cef7..86ab51bea 100644
--- a/frontends/windows/download.c
+++ b/frontends/windows/download.c
@@ -37,6 +37,7 @@
 #include "utils/string.h"
 #include "content/fetch.h"
 #include "netsurf/download.h"
+#include "netsurf/inttypes.h"
 #include "desktop/download.h"
 
 #include "windows/download.h"
@@ -155,7 +156,7 @@ static void nsws_download_clear_data(struct gui_download_window *w)
 }
 
 
-static BOOL CALLBACK
+static INT_PTR CALLBACK
 nsws_download_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
 {
 	switch(msg) {
@@ -314,7 +315,7 @@ gui_download_window_data(struct gui_download_window *w, const char *data,
 	struct timeval val;
 	res = fwrite((void *)data, 1, size, w->file);
 	if (res != size)
-		NSLOG(netsurf, INFO, "file write error %d of %d", size - res,
+		NSLOG(netsurf, INFO, "file write error %"PRIsizet" of %d", size - res,
 		      size);
 	w->downloaded += res;
 	w->progress = (unsigned int)(((long long)(w->downloaded) * 10000)
diff --git a/frontends/windows/font.c b/frontends/windows/font.c
index 3e81a80a1..da2fe9735 100644
--- a/frontends/windows/font.c
+++ b/frontends/windows/font.c
@@ -335,8 +335,8 @@ win32_font_split(const plot_font_style_t *style,
 	res = win32_font_width(style, string, *offset, actual_x);
 
 	NSLOG(netsurf, DEEPDEBUG,
-	      "ret %d Split %u chars at %ipx: Split at char %i (%ipx) - %.*s",
-	      res, length, x, *offset, *actual_x, *offset, string);
+	      "ret %d Split %"PRIsizet" chars at %ipx: Split at char %"PRIsizet" (%ipx) - %.*s",
+	      res, length, x, *offset, *actual_x, (int)*offset, string);
 
 	return res;
 }
diff --git a/frontends/windows/prefs.c b/frontends/windows/prefs.c
index 37f558477..cd196a1ab 100644
--- a/frontends/windows/prefs.c
+++ b/frontends/windows/prefs.c
@@ -145,10 +145,11 @@ static void change_spinner(HWND sub, double change, double minval, double maxval
  * \param lParam The message l parameter
  * \return result appropriate for message
  */
-static BOOL CALLBACK options_appearance_dialog_handler(HWND hwnd,
-						       UINT msg,
-						       WPARAM wparam,
-						       LPARAM lParam)
+static INT_PTR CALLBACK
+options_appearance_dialog_handler(HWND hwnd,
+				  UINT msg,
+				  WPARAM wparam,
+				  LPARAM lParam)
 {
 	int len;
 	char *temp, number[6];
@@ -427,10 +428,11 @@ static BOOL CALLBACK options_appearance_dialog_handler(HWND hwnd,
  * \param lParam The message l parameter
  * \return result appropriate for message
  */
-static BOOL CALLBACK options_connections_dialog_handler(HWND hwnd,
-							UINT msg,
-							WPARAM wparam,
-							LPARAM lParam)
+static INT_PTR CALLBACK
+options_connections_dialog_handler(HWND hwnd,
+				   UINT msg,
+				   WPARAM wparam,
+				   LPARAM lParam)
 {
 	int len;
 	char *temp, number[6];
@@ -598,10 +600,11 @@ static BOOL CALLBACK options_connections_dialog_handler(HWND hwnd,
  * \param lParam The message l parameter
  * \return result appropriate for message
  */
-static BOOL CALLBACK options_general_dialog_handler(HWND hwnd,
-						    UINT msg,
-						    WPARAM wparam,
-						    LPARAM lParam)
+static INT_PTR CALLBACK
+options_general_dialog_handler(HWND hwnd,
+			       UINT msg,
+			       WPARAM wparam,
+			       LPARAM lParam)
 {
 	HWND sub;
 
diff --git a/frontends/windows/windbg.h b/frontends/windows/windbg.h
index f09cea9e6..8ad3ee24a 100644
--- a/frontends/windows/windbg.h
+++ b/frontends/windows/windbg.h
@@ -35,7 +35,7 @@ void win_perror(const char *lpszFunction);
 	    ((m) != WM_NCHITTEST) &&					\
 	    ((m) != WM_ENTERIDLE))					\
 		NSLOG(netsurf, DEBUG,					\
-		      "%s, hwnd %p, w 0x%x, l 0x%Ix",			\
+		      "%s, hwnd %p, w 0x%Ix, l 0x%Ix",			\
 		      msg_num_to_name(m), h, w, l)
 
 #endif
diff --git a/tools/jenkins-build.sh b/tools/jenkins-build.sh
index d31b233b4..b8eaf357a 100755
--- a/tools/jenkins-build.sh
+++ b/tools/jenkins-build.sh
@@ -95,6 +95,9 @@ case ${TARGET} in
 	    "i686-w64-mingw32")
 		;;
 
+	    "x86_64-w64-mingw32")
+		;;
+
 	    *)
 		echo "Target \"${TARGET}\" cannot be built on \"${HOST})\""
 		exit 1
@@ -306,6 +309,11 @@ case ${TARGET} in
 		export GCCSDK_INSTALL_CROSSBIN=/opt/netsurf/${HOST}/cross/bin
 		;;
 
+	    "x86_64-w64-mingw32")
+		export GCCSDK_INSTALL_ENV=/opt/netsurf/${HOST}/env
+		export GCCSDK_INSTALL_CROSSBIN=/opt/netsurf/${HOST}/cross/bin
+		;;
+
 	    "ppc-amigaos")
 		export GCCSDK_INSTALL_ENV=/opt/netsurf/${HOST}/env
 		export GCCSDK_INSTALL_CROSSBIN=/opt/netsurf/${HOST}/cross/bin
@@ -365,6 +373,11 @@ case ${TARGET} in
 		export GCCSDK_INSTALL_CROSSBIN=/opt/netsurf/${HOST}/cross/bin
 		;;
 
+	    "x86_64-w64-mingw32")
+		export GCCSDK_INSTALL_ENV=/opt/netsurf/${HOST}/env
+		export GCCSDK_INSTALL_CROSSBIN=/opt/netsurf/${HOST}/cross/bin
+		;;
+
 	    "ppc-amigaos")
 		export GCCSDK_INSTALL_ENV=/opt/netsurf/${HOST}/env
 		export GCCSDK_INSTALL_CROSSBIN=/opt/netsurf/${HOST}/cross/bin
-- 
2.30.2

