shithub: rgbds

Download patch

ref: 8ccbd9dc36c9fd672225ba91e50d022f166acd73
parent: b8307432b896deb73785ec3f0e08930b7bea7691
author: ISSOtm <[email protected]>
date: Sat Oct 1 14:55:01 EDT 2022

Properly build and link against libpng

Doing it right this time.
Also bundling the newly required DLLs.

--- a/.github/actions/mingw-configure.sh
+++ /dev/null
@@ -1,17 +1,0 @@
-#!/bin/bash
-
-source mingw-env @TRIPLE@
-echo LAST IS: $last
-
-# check if last arg is a path to configure, else use parent
-for last; do true; done
-if test -x "${last}/configure"; then
-  config_path="$last"
-else
-  config_path=".."
-fi
-
-${config_path}/configure \
-  --host=@TRIPLE@ --target=@TRIPLE@ --build="$CHOST" \
-  --prefix=/usr/@TRIPLE@ --libdir=/usr/@TRIPLE@/lib --includedir=/usr/@TRIPLE@/include \
-  --enable-shared --enable-static "$@"
--- a/.github/actions/mingw-env.sh
+++ /dev/null
@@ -1,16 +1,0 @@
-#!/bin/sh
-
-_arch=$1
-
-default_mingw_pp_flags="-D_FORTIFY_SOURCE=2"
-default_mingw_compiler_flags="$default_mingw_pp_flags -O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4"
-default_mingw_linker_flags="-Wl,-O1,--sort-common,--as-needed -fstack-protector"
-
-export CPPFLAGS="${MINGW_CPPFLAGS:-$default_mingw_pp_flags $CPPFLAGS}"
-export CFLAGS="${MINGW_CFLAGS:-$default_mingw_compiler_flags $CFLAGS}"
-export CXXFLAGS="${MINGW_CXXFLAGS:-$default_mingw_compiler_flags $CXXFLAGS}"
-export LDFLAGS="${MINGW_LDFLAGS:-$default_mingw_linker_flags $LDFLAGS}"
-
-mingw_prefix=/usr/${_arch}
-export PKG_CONFIG_SYSROOT_DIR="${mingw_prefix}"
-export PKG_CONFIG_LIBDIR="${mingw_prefix}/lib/pkgconfig:${mingw_prefix}/share/pkgconfig"
--- a/.github/actions/mingw-w64-libpng-dev.sh
+++ b/.github/actions/mingw-w64-libpng-dev.sh
@@ -1,44 +1,34 @@
 #!/bin/sh
 
-# This script was written by ISSOtm while looking at Arch Linux's PKGBUILD for
-# the corresponding package. (And its dependencies)
-# https://aur.archlinux.org/packages/mingw-w64-libpng/
-
 set -e
 
 pngver=1.6.37
-_apngver=$pngver
-_arch="$1"
+arch="$1"
 
-
-## Install mingw-configure and mingw-env (both build dependencies)
-
-install -m 755 .github/actions/mingw-env.sh /usr/bin/mingw-env
-
-sed "s|@TRIPLE@|${_arch}|g" .github/actions/mingw-configure.sh > ${_arch}-configure
-install -m 755 ${_arch}-configure /usr/bin/
-
-
 ## Grab sources and check them
 
-wget http://downloads.sourceforge.net/sourceforge/libpng/libpng-$pngver.tar.xz
-wget http://downloads.sourceforge.net/project/apng/libpng/libpng16/libpng-$_apngver-apng.patch.gz
+wget http://downloads.sourceforge.net/project/libpng/libpng16/$pngver/libpng-$pngver.tar.xz
+wget http://downloads.sourceforge.net/project/apng/libpng/libpng16/libpng-$pngver-apng.patch.gz
 sha256sum -c .github/actions/mingw-w64-libpng-dev.sha256sums
 
-## Extract sources
+## Extract sources and patch them
 
 tar -xf libpng-$pngver.tar.xz
-gunzip libpng-$_apngver-apng.patch.gz
+gunzip libpng-$pngver-apng.patch.gz
 
+# Patch in apng support
+env -C libpng-$pngver patch -p0 ../libpng-$pngver-apng.patch
 
 ## Start building!
 
-cd libpng-$pngver
-# Patch in apng support
-patch -p0 ../libpng-$_apngver-apng.patch
-
-mkdir -p build-${_arch}
-cd build-${_arch}
-${_arch}-configure LDFLAGS=-static-libgcc
-make
+mkdir -p build
+cd build
+../libpng-$pngver/configure \
+	--host="$arch" --target="$arch" \
+	--prefix="/usr/$arch" \
+	--enable-shared --disable-static \
+	CPPFLAGS="-D_FORTIFY_SOURCE=2" \
+	CFLAGS="-O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4" \
+	LDFLAGS="-Wl,-O1,--sort-common,--as-needed -fstack-protector"
+make -kj
 make install
--- a/.github/workflows/testing.yml
+++ b/.github/workflows/testing.yml
@@ -158,7 +158,7 @@
             arch: x86-64
             triplet: x86_64-w64-mingw32
       fail-fast: false
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-22.04
     env:
       DIST_DIR: win${{ matrix.bits }}
     steps:
@@ -168,8 +168,8 @@
         run: |
           ./.github/actions/install_deps.sh ${{ matrix.os }}
       - name: Install MinGW
-        run: |
-          sudo apt-get install {gcc,g++}-mingw-w64-${{ matrix.arch }} mingw-w64-tools libz-mingw-w64-dev
+        run: | # dpkg-dev is apparently required for pkg-config for cross-building
+          sudo apt-get install {gcc,g++}-mingw-w64-${{ matrix.arch }}-win32 mingw-w64-tools libz-mingw-w64-dev dpkg-dev
       - name: Install libpng dev headers for MinGW
         run: |
           sudo ./.github/actions/mingw-w64-libpng-dev.sh ${{ matrix.triplet }}
@@ -177,17 +177,12 @@
         run: |
           make mingw${{ matrix.bits }} -j Q=
       - name: Package binaries
-        run: |
+        run: | # DLL dependencies can be figured out using e.g. Dependency Walker
           mkdir bins
-          mv rgbasm bins/rgbasm.exe
-          mv rgblink bins/rgblink.exe
-          mv rgbfix bins/rgbfix.exe
-          mv rgbgfx bins/rgbgfx.exe
-          cp /usr/${{ matrix.triplet }}/lib/zlib1.dll bins
-          cp /usr/${{ matrix.triplet }}/bin/libpng16-16.dll bins
-          if [ ${{ matrix.bits }} -eq 32 ]; then cp /usr/lib/gcc/${{ matrix.triplet }}/7.3-win32/lib{gcc_s_sjlj-1,stdc++-6}.dll bins; fi
-          mv test/gfx/randtilegen{,.exe}
-          mv test/gfx/rgbgfx_test{,.exe}
+          mv -v rgb{asm,link,fix,gfx}.exe bins/
+          cp -v /usr/${{ matrix.triplet }}/lib/zlib1.dll bins
+          cp -v /usr/${{ matrix.triplet }}/bin/libpng16-16.dll bins
+          [ "${{ matrix.bits }}" -ne 32 ] || cp -v /usr/lib/gcc/${{ matrix.triplet }}/10-win32/lib{gcc_s_dw2-1,ssp-0,stdc++-6}.dll bins
       - name: Upload Windows binaries
         uses: actions/upload-artifact@v3
         with:
--- a/Makefile
+++ b/Makefile
@@ -267,12 +267,12 @@
 mingw32:
 	$Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test \
 		CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ \
-		BISON=bison PKG_CONFIG=i686-w64-mingw32-pkg-config -j
+		BISON=bison PKG_CONFIG="PKG_CONFIG_SYSROOT_DIR=/usr/i686-w64-mingw32 pkg-config"
 
 mingw64:
 	$Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test \
 		CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ \
-		BISON=bison PKG_CONFIG=x86_64-w64-mingw32-pkg-config -j
+		BISON=bison PKG_CONFIG="PKG_CONFIG_SYSROOT_DIR=/usr/x86_64-w64-mingw32 pkg-config"
 
 wine-shim:
 	$Qecho '#!/bin/bash' > rgbshim.sh