SDL: mingw: use DESTDIR to change the install location of the mingw package

From 4d6b23b68fd1726873dfd84071478fc007563da2 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sat, 6 Jul 2024 17:10:02 +0200
Subject: [PATCH] mingw: use DESTDIR to change the install location of the
 mingw package

---
 mingw/pkg-support/INSTALL.txt | 21 +++++++++++------
 mingw/pkg-support/Makefile    | 43 ++++++++++++++++++++++-------------
 2 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/mingw/pkg-support/INSTALL.txt b/mingw/pkg-support/INSTALL.txt
index 607dafd0ee0a7..61dc062e86dc7 100644
--- a/mingw/pkg-support/INSTALL.txt
+++ b/mingw/pkg-support/INSTALL.txt
@@ -2,17 +2,24 @@
 The 32-bit files are in i686-w64-mingw32
 The 64-bit files are in x86_64-w64-mingw32
 
-To install SDL for native development:
-    make native
+To install SDL for 32-bit x86 executables (i686):
+    make install-i686
 
-To install SDL for cross-compiling development:
-    make cross
+To install SDL for 64-bit x86 executables (x86_64):
+    make install-x86_64
+
+To install both:
+    make install-all
+
+Use DESTDIR to change the target location
+    mkdir $HOME/mingw32-prefix
+    make install-i686 DESTDIR=$HOME/mingw32-prefix
 
 Look at the example programs in ./test, and check out online documentation:
-    http://wiki.libsdl.org/
+    https://wiki.libsdl.org/SDL3/FrontPage
 
-Join the SDL developer mailing list if you want to join the community:
-    http://www.libsdl.org/mailing-list.php
+Join the SDL discourse server if you want to join the community:
+    https://discourse.libsdl.org/
 
 That's it!
 Sam Lantinga <slouken@libsdl.org>
diff --git a/mingw/pkg-support/Makefile b/mingw/pkg-support/Makefile
index 19732d7d24c61..ff8d01f81eef2 100644
--- a/mingw/pkg-support/Makefile
+++ b/mingw/pkg-support/Makefile
@@ -1,26 +1,37 @@
 #
 # Makefile for installing the mingw32 version of the SDL library
 
-CROSS_PATH := /usr/local
+DESTDIR = /usr/local
 ARCHITECTURES := i686-w64-mingw32 x86_64-w64-mingw32
 
-all install:
-	@echo "Type \"make native\" to install 32-bit to /usr"
-	@echo "Type \"make cross\" to install 32-bit and 64-bit to $(CROSS_PATH)"
+default:
+	@echo "Run \"make install-i686\" to install 32-bit"
+	@echo "Run \"make install-x86_64\" to install 64-bit"
+	@echo "Run \"make install-all\" to install both"
+	@echo "Add DESTDIR=/custom/path to change the destination folder"
 
-native:
-	make install-package arch=i686-w64-mingw32 prefix=/usr
+install:
+	@if test -d $(ARCH) && test -d $(DESTDIR); then \
+		(cd $(ARCH) && cp -rv bin include lib share $(DESTDIR)/); \
+	else \
+		echo "*** ERROR: $(ARCH) or $(DESTDIR) does not exist!"; \
+		exit 1; \
+	fi
 
-cross:
-	for arch in $(ARCHITECTURES); do \
-	    make install-package arch=$$arch prefix=$(CROSS_PATH)/$$arch; \
-	done
+install-i686:
+	$(MAKE) install ARCH=i686-w64-mingw32
 
-install-package:
-	@if test -d $(arch) && test -d $(prefix); then \
-	    (cd $(arch) && cp -rv bin include lib share $(prefix)/); \
-	    sed "s|^prefix=.*|prefix=$(prefix)|" <$(arch)/lib/pkgconfig/sdl3.pc >$(prefix)/lib/pkgconfig/sdl3.pc; \
+install-x86_64:
+	$(MAKE) install ARCH=x86_64-w64-mingw32
+
+install-all:
+	@if test -d $(DESTDIR); then \
+		for arch in $(ARCHITECTURES); do \
+			$(MAKE) install ARCH=$$arch DESTDIR=$(DESTDIR)/$$arch; \
+		done \
 	else \
-	    echo "*** ERROR: $(arch) or $(prefix) does not exist!"; \
-	    exit 1; \
+		echo "*** ERROR: $(DESTDIR) does not exist!"; \
+		exit 1; \
 	fi
+
+.PHONY: default install install-i686 install-x86_64 install-all