From f2f9ec041b51b9123c0b9bae892dc853210a23c3 Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Fri, 31 Jan 2025 09:57:20 +0100
Subject: [PATCH] util-linux: build for cygwin

---
 util-linux/2.24.2-msysize.patch | 81 ---------------------------------
 util-linux/PKGBUILD             | 13 +++---
 2 files changed, 6 insertions(+), 88 deletions(-)
 delete mode 100644 util-linux/2.24.2-msysize.patch

diff --git a/util-linux/2.24.2-msysize.patch b/util-linux/2.24.2-msysize.patch
deleted file mode 100644
index 5e2cfe15273..00000000000
--- a/util-linux/2.24.2-msysize.patch
+++ /dev/null
@@ -1,81 +0,0 @@
-diff -Naur util-linux-2.24.2-orig/config/compile util-linux-2.24.2/config/compile
---- util-linux-2.24.2-orig/config/compile	2013-08-05 14:10:38.000000000 +0400
-+++ util-linux-2.24.2/config/compile	2014-10-13 12:04:25.132000000 +0400
-@@ -53,7 +53,7 @@
- 	  MINGW*)
- 	    file_conv=mingw
- 	    ;;
--	  CYGWIN*)
-+	  CYGWIN*|MSYS*)
- 	    file_conv=cygwin
- 	    ;;
- 	  *)
-@@ -67,7 +67,7 @@
- 	mingw/*)
- 	  file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
- 	  ;;
--	cygwin/*)
-+	cygwin/*|msys*/)
- 	  file=`cygpath -m "$file" || echo "$file"`
- 	  ;;
- 	wine/*)
-diff -Naur util-linux-2.24.2-orig/config/config.guess util-linux-2.24.2/config/config.guess
---- util-linux-2.24.2-orig/config/config.guess	2013-08-05 14:10:38.000000000 +0400
-+++ util-linux-2.24.2/config/config.guess	2014-10-13 12:04:57.736000000 +0400
-@@ -849,6 +849,9 @@
-     amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
- 	echo x86_64-unknown-cygwin
- 	exit ;;
-+    amd64:MSYS*:*:* | x86_64:MSYS*:*:*)
-+	echo x86_64-unknown-msys
-+	exit ;;
-     prep*:SunOS:5.*:*)
- 	echo powerpcle-unknown-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`"
- 	exit ;;
---- util-linux-2.25.1/config/config.rpath.orig	2014-11-04 20:24:30.957200000 +0300
-+++ util-linux-2.25.1/config/config.rpath	2014-11-04 20:25:44.766400000 +0300
-@@ -57,7 +57,7 @@
-     aix*)
-       wl='-Wl,'
-       ;;
--    mingw* | cygwin* | pw32* | os2* | cegcc*)
-+    mingw* | cygwin* | msys* | pw32* | os2* | cegcc*)
-       ;;
-     hpux9* | hpux10* | hpux11*)
-       wl='-Wl,'
-@@ -149,7 +149,7 @@
- hardcode_minus_L=no
- 
- case "$host_os" in
--  cygwin* | mingw* | pw32* | cegcc*)
-+  cygwin* | msys* | mingw* | pw32* | cegcc*)
-     # FIXME: the MSVC++ port hasn't been tested in a loooong time
-     # When not using gcc, we currently assume that we are using
-     # Microsoft Visual C++.
-@@ -198,7 +198,7 @@
-         ld_shlibs=no
-       fi
-       ;;
--    cygwin* | mingw* | pw32* | cegcc*)
-+    cygwin* | msys* | mingw* | pw32* | cegcc*)
-       # hardcode_libdir_flag_spec is actually meaningless, as there is
-       # no search path for DLLs.
-       hardcode_libdir_flag_spec='-L$libdir'
-@@ -348,7 +348,7 @@
-       ;;
-     bsdi[45]*)
-       ;;
--    cygwin* | mingw* | pw32* | cegcc*)
-+    cygwin* | msys* | mingw* | pw32* | cegcc*)
-       # When not using gcc, we currently assume that we are using
-       # Microsoft Visual C++.
-       # hardcode_libdir_flag_spec is actually meaningless, as there is
-@@ -537,7 +537,7 @@
-   bsdi[45]*)
-     library_names_spec='$libname$shrext'
-     ;;
--  cygwin* | mingw* | pw32* | cegcc*)
-+  cygwin* | msys* | mingw* | pw32* | cegcc*)
-     shrext=.dll
-     library_names_spec='$libname.dll.a $libname.lib'
-     ;;
diff --git a/util-linux/PKGBUILD b/util-linux/PKGBUILD
index 8b0bb8dfa66..cc6dd2576fd 100644
--- a/util-linux/PKGBUILD
+++ b/util-linux/PKGBUILD
@@ -3,7 +3,7 @@
 pkgname=("util-linux" "libutil-linux" "libutil-linux-devel")
 _pkgmajor=2.35
 pkgver=${_pkgmajor}.2
-pkgrel=4
+pkgrel=5
 pkgdesc="Miscellaneous system utilities for Linux"
 arch=('i686' 'x86_64')
 license=('GPL3')
@@ -25,8 +25,7 @@ source=(https://www.kernel.org/pub/linux/utils/$pkgname/v${_pkgmajor}/${pkgname}
         2.33.1-cygwin-ionice.patch
         2.33.1-cygwin-taskset.patch
         2.32.1-testsuite.patch
-        2.25.1-relocate-sbin-to-usr-bin.patch
-        2.24.2-msysize.patch)
+        2.25.1-relocate-sbin-to-usr-bin.patch)
 sha256sums=('21b7431e82f6bcd9441a01beeec3d57ed33ee948f8a5b41da577073c372eb58a'
             '0d6c812fab3deb34842dfb4313ce626e389c0961fe863a653ee1799a16614200'
             '347ff26c7750ef586dd50c3ac0be0b86604f8c4a4f148a0fc4e49d9ec55e2198'
@@ -36,8 +35,7 @@ sha256sums=('21b7431e82f6bcd9441a01beeec3d57ed33ee948f8a5b41da577073c372eb58a'
             'e8ee1a1577899d00c6e198cf81cd11af445eb6c906a602559a751c0f4878f248'
             'e355a7c05ad4abc5e6076e047e470b12104f1da1404313258470d404c7c26b38'
             'ea33be334f966df7b08b9d4d7b1f10df1c3f3cd08eade156d1f6969f913658d9'
-            'd6bfc7e34349a98c8d110f1e216bd16d6f1edf45c369cda8c6301fb994986d13'
-            '11563826de30d5e7e372e2901f3fd9d5b86539ae0c38c3d709c16b894b3034e5')
+            'd6bfc7e34349a98c8d110f1e216bd16d6f1edf45c369cda8c6301fb994986d13')
 
 prepare() {
   cd ${srcdir}/${pkgname}-${pkgver}
@@ -50,7 +48,6 @@ prepare() {
   patch -p2 -i ${srcdir}/2.33.1-cygwin-ionice.patch
   patch -p2 -i ${srcdir}/2.33.1-cygwin-taskset.patch
   patch -p2 -i ${srcdir}/2.32.1-testsuite.patch
-  patch -p1 -i ${srcdir}/2.24.2-msysize.patch
   patch -p1 -i ${srcdir}/2.25.1-relocate-sbin-to-usr-bin.patch
   autoreconf -fi
 }
@@ -61,8 +58,10 @@ build() {
 
   CPPFLAGS+=" -D__USE_LINUX_IOCTL_DEFS"
 
+  export MSYSTEM=CYGWIN
+  local CYGWIN_CHOST="${CHOST/-msys/-cygwin}"
   ../${pkgname}-${pkgver}/configure \
-    --build=${CHOST} \
+    --build=${CYGWIN_CHOST} \
     --prefix=/usr \
     --bindir=/usr/bin \
     --sbindir=/usr/bin \