aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-08-10 18:11:05 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-08-11 00:19:59 +0200
commitcf19f8287547c523f65879b9e9477950c81a9eed (patch)
treec6be8ae4f6e0b24da953633d5cae77c8b91e5cb1
parent9c9453172a3941b6e43ceac0f86ecd96ead1ffb2 (diff)
downloadfiv-cf19f8287547c523f65879b9e9477950c81a9eed.tar.gz
fiv-cf19f8287547c523f65879b9e9477950c81a9eed.tar.xz
fiv-cf19f8287547c523f65879b9e9477950c81a9eed.zip
Automate Windows builds, add icons to executables
Scripts have been ported from sdtui, and adjusted for Meson. The port is broken through and through on WINE, but sort-of works natively.
-rw-r--r--README.adoc13
-rw-r--r--fiv.manifest11
-rw-r--r--fiv.rc3
-rw-r--r--meson.build47
-rwxr-xr-xmsys2-cross-configure.sh111
-rwxr-xr-xmsys2-cross-install.sh65
6 files changed, 245 insertions, 5 deletions
diff --git a/README.adoc b/README.adoc
index 13d92ba..031b110 100644
--- a/README.adoc
+++ b/README.adoc
@@ -56,6 +56,19 @@ direct installations via `ninja install`. To test the program:
The lossless JPEG cropper is intended to be invoked from a context menu.
+Windows
+~~~~~~~
+'fiv' can be cross-compiled for Windows, provided that you install a bunch of
+dependencies listed at the beginning of 'msys2-cross-configure.sh',
+plus rsvg-convert from librsvg2, and icotool from icoutils.
+Beware that the build will take up close to a gigabyte of disk space.
+
+ $ sh msys2-cross-configure.sh builddir
+ $ meson install -C builddir
+
+If everything succeeds, you will find a portable build of the application
+in the 'builddir/package' subdirectory. Keep your expectations low.
+
Documentation
-------------
For information concerning usage, refer to link:docs/fiv.html[the user guide],
diff --git a/fiv.manifest b/fiv.manifest
new file mode 100644
index 0000000..6009f3c
--- /dev/null
+++ b/fiv.manifest
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <assemblyIdentity name="fiv" version="1.0.0.0" type="win32" />
+ <dependency>
+ <dependentAssembly>
+ <assemblyIdentity name="Microsoft.Windows.Common-Controls"
+ version="6.0.0.0" type="win32" processorArchitecture="*"
+ publicKeyToken="6595b64144ccf1df" language="*" />
+ </dependentAssembly>
+ </dependency>
+</assembly>
diff --git a/fiv.rc b/fiv.rc
new file mode 100644
index 0000000..7e029f5
--- /dev/null
+++ b/fiv.rc
@@ -0,0 +1,3 @@
+#include <windows.h>
+LD_ICON ICON "fiv.ico"
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "fiv.manifest"
diff --git a/meson.build b/meson.build
index 9c40889..d646a2a 100644
--- a/meson.build
+++ b/meson.build
@@ -91,8 +91,32 @@ configure_file(
configuration : conf,
)
+rc = []
+if host_machine.system() == 'windows'
+ windows = import('windows')
+ rsvg_convert = find_program('rsvg-convert')
+ icotool = find_program('icotool')
+
+ # Meson is brain-dead and retarded, so these PNGs cannot be installed,
+ # only because they must all have the same name when installed.
+ # The largest size is mainly for an appropriately sized Windows icon.
+ icon_png_list = []
+ foreach size : ['16', '32', '48', '256']
+ icon_dimensions = size + 'x' + size
+ icon_png_list += custom_target(icon_dimensions + ' icon',
+ input : 'fiv.svg',
+ output : 'fiv.' + icon_dimensions + '.png',
+ command : [rsvg_convert, '--output', '@OUTPUT@',
+ '--width', size, '--height', size, '@INPUT@'])
+ endforeach
+
+ icon_ico = custom_target(input : icon_png_list, output : 'fiv.ico',
+ command : [icotool, '-c', '-o', '@OUTPUT@', '@INPUT@'])
+ rc += windows.compile_resources('fiv.rc', depends : icon_ico)
+endif
+
gnome = import('gnome')
-resources = gnome.compile_resources('resources',
+gresources = gnome.compile_resources('resources',
'resources/resources.gresource.xml',
source_dir : 'resources',
c_name : 'resources',
@@ -108,9 +132,11 @@ tiff_tables = custom_target('tiff-tables.h',
desktops = ['fiv.desktop', 'fiv-browse.desktop']
exe = executable('fiv', 'fiv.c', 'fiv-view.c', 'fiv-io.c', 'fiv-context-menu.c',
'fiv-browser.c', 'fiv-sidebar.c', 'fiv-thumbnail.c', 'fiv-collection.c',
- 'xdg.c', resources,
+ 'xdg.c', gresources, rc,
install : true,
- dependencies : dependencies)
+ dependencies : dependencies,
+ win_subsystem : 'windows',
+)
if gdkpixbuf.found()
executable('io-benchmark', 'fiv-io-benchmark.c', 'fiv-io.c', 'xdg.c',
build_by_default : false,
@@ -118,12 +144,14 @@ if gdkpixbuf.found()
endif
desktops += 'fiv-jpegcrop.desktop'
-jpegcrop = executable('fiv-jpegcrop', 'fiv-jpegcrop.c',
+jpegcrop = executable('fiv-jpegcrop', 'fiv-jpegcrop.c', rc,
install : true,
dependencies : [
dependency('gtk+-3.0'),
dependency('libturbojpeg'),
- ])
+ ],
+ win_subsystem : 'windows',
+)
if get_option('tools').enabled()
# libjq 1.6 lacks a pkg-config file, and there is no release in sight.
@@ -170,6 +198,15 @@ if host_machine.system() != 'windows'
if not meson.is_cross_build()
meson.add_install_script(updater, skip_if_destdir : dynamic_desktops)
endif
+elif meson.is_cross_build()
+ msys2_root = meson.get_external_property('msys2_root')
+ meson.add_install_script('msys2-cross-install.sh', msys2_root)
+
+ # This is the minimum to run targets from msys2-cross-configure.sh builds.
+ meson.add_devenv({
+ 'WINEPATH' : msys2_root / 'bin',
+ 'XDG_DATA_DIRS' : msys2_root / 'share',
+ })
endif
install_data('fiv.svg',
diff --git a/msys2-cross-configure.sh b/msys2-cross-configure.sh
new file mode 100755
index 0000000..602548e
--- /dev/null
+++ b/msys2-cross-configure.sh
@@ -0,0 +1,111 @@
+#!/bin/sh -e
+# msys2-cross-configure.sh: set up an MSYS2-based cross-compiled Meson build.
+# Dependencies: AWK, sed, sha256sum, cURL, bsdtar,
+# wine64, Meson, mingw-w64-binutils, mingw-w64-gcc, pkg-config
+repository=https://repo.msys2.org/mingw/mingw64/
+
+status() {
+ echo "$(tput bold)-- $*$(tput sgr0)"
+}
+
+dbsync() {
+ status Fetching repository DB
+ [ -f db.tsv ] || curl -# "$repository/mingw64.db" | bsdtar -xOf- | awk '
+ function flush() { print f["%NAME%"] f["%FILENAME%"] f["%DEPENDS%"] }
+ NR > 1 && $0 == "%FILENAME%" { flush(); for (i in f) delete f[i] }
+ !/^[^%]/ { field = $0; next } { f[field] = f[field] $0 "\t" }
+ field == "%SHA256SUM%" { path = "*packages/" f["%FILENAME%"]
+ sub(/\t$/, "", path); print $0, path > "db.sums" } END { flush() }
+ ' > db.tsv
+}
+
+fetch() {
+ status Resolving "$@"
+ mkdir -p packages
+ awk -F'\t' 'function get(name, i, a) {
+ if (visited[name]++ || !(name in filenames)) return
+ print filenames[name]; split(deps[name], a); for (i in a) get(a[i])
+ } BEGIN { while ((getline < "db.tsv") > 0) {
+ filenames[$1] = $2; deps[$1] = ""; for (i = 3; i <= NF; i++) {
+ gsub(/[<=>].*/, "", $i); deps[$1] = deps[$1] $i FS }
+ } for (i = 0; i < ARGC; i++) get(ARGV[i]) }' "$@" | while IFS= read -r name
+ do
+ status Fetching "$name"
+ [ -f "packages/$name" ] || curl -#o "packages/$name" "$repository/$name"
+ done
+}
+
+verify() {
+ status Verifying checksums
+ sha256sum --ignore-missing --quiet -c db.sums
+}
+
+extract() {
+ status Extracting packages
+ for subdir in *
+ do [ -d "$subdir" -a "$subdir" != packages ] && rm -rf -- "$subdir"
+ done
+ for i in packages/*
+ do bsdtar -xf "$i" --strip-components 1 mingw64
+ done
+}
+
+configure() {
+ # Don't let GLib programs inherit wrong paths from the environment.
+ export XDG_DATA_DIRS=$msys2_root/share
+
+ status Configuring packages
+ wine64 bin/update-mime-database.exe share/mime
+ wine64 bin/glib-compile-schemas.exe share/glib-2.0/schemas
+ wine64 bin/gdk-pixbuf-query-loaders.exe \
+ > lib/gdk-pixbuf-2.0/2.10.0/loaders.cache
+}
+
+setup() {
+ status Setting up Meson
+ cat >"$toolchain" <<-EOF
+ [binaries]
+ c = 'x86_64-w64-mingw32-gcc'
+ cpp = 'x86_64-w64-mingw32-g++'
+ ar = 'x86_64-w64-mingw32-gcc-ar'
+ ranlib = 'x86_64-w64-mingw32-gcc-ranlib'
+ strip = 'x86_64-w64-mingw32-strip'
+ windres = 'x86_64-w64-mingw32-windres'
+ pkgconfig = 'pkg-config'
+
+ [properties]
+ sys_root = '$builddir'
+ msys2_root = '$msys2_root'
+ pkg_config_libdir = '$msys2_root/share/pkgconfig:$msys2_root/lib/pkgconfig'
+ needs_exe_wrapper = true
+
+ [host_machine]
+ system = 'windows'
+ cpu_family = 'x86_64'
+ cpu = 'x86_64'
+ endian = 'little'
+ EOF
+
+ meson --buildtype=debugoptimized --prefix="$packagedir" \
+ --bindir . --libdir . --cross-file="$toolchain" "$builddir" "$sourcedir"
+}
+
+sourcedir=$(realpath "${2:-$(dirname "$0")}")
+builddir=$(realpath "${1:-builddir}")
+packagedir=$builddir/package
+toolchain=$builddir/msys2-cross-toolchain.meson
+
+# This directory name matches the prefix in .pc files, so we don't need to
+# modify them (pkgconf has --prefix-variable, but Meson can't pass that option).
+msys2_root=$builddir/mingw64
+
+mkdir -p "$msys2_root"
+cd "$msys2_root"
+dbsync
+fetch mingw-w64-x86_64-gtk3 mingw-w64-x86_64-lcms2 \
+ mingw-w64-x86_64-libraw mingw-w64-x86_64-libheif \
+ mingw-w64-x86_64-libwinpthread-git # Because we don't do "provides"?
+verify
+extract
+configure
+setup
diff --git a/msys2-cross-install.sh b/msys2-cross-install.sh
new file mode 100755
index 0000000..f349e86
--- /dev/null
+++ b/msys2-cross-install.sh
@@ -0,0 +1,65 @@
+#!/bin/sh -e
+export LC_ALL=C
+cd "$MESON_INSTALL_DESTDIR_PREFIX"
+msys2_root=$1
+
+# Copy libraries we depend on, and a few files required by GTK+.
+cp -p "$msys2_root"/bin/*.dll .
+cp -pR "$msys2_root"/etc/ .
+
+mkdir -p lib
+cp -pR "$msys2_root"/lib/gdk-pixbuf-2.0/ lib
+mkdir -p share/glib-2.0
+cp -pR "$msys2_root"/share/glib-2.0/schemas/ share/glib-2.0
+mkdir -p share
+cp -pR "$msys2_root"/share/mime/ share
+mkdir -p share/icons
+cp -pR "$msys2_root"/share/icons/Adwaita/ share/icons
+mkdir -p share/icons/hicolor
+cp -p "$msys2_root"/share/icons/hicolor/index.theme share/icons/hicolor
+
+# Remove unreferenced libraries.
+find lib -name '*.a' -exec rm -- {} +
+awk 'function whitelist(binary) {
+ if (seen[binary]++)
+ return
+
+ delete orphans[binary]
+ while (("strings -a \"" binary "\" 2>/dev/null" | getline string) > 0)
+ if (match(string, /[-.+_a-zA-Z0-9]+[.][Dd][Ll][Ll]$/))
+ whitelist("./" substr(string, RSTART, RLENGTH))
+} BEGIN {
+ while (("find . -type f -path \"./*.[Dd][Ll][Ll]\"" | getline) > 0)
+ orphans[$0]++
+ while (("find . -type f -path \"./*.[Ee][Xx][Ee]\"" | getline) > 0)
+ whitelist($0)
+ while (("find ./lib/gdk-pixbuf-2.0 -type f " \
+ "-path \"./*.[Dd][Ll][Ll]\"" | getline) > 0)
+ whitelist($0)
+ for (library in orphans)
+ print library
+}' | xargs rm --
+
+# Removes unused icons from the Adwaita theme. It could be even more aggressive,
+# since it keeps around lots of sizes and all the GTK+ stock icons.
+find share/icons/Adwaita -type f | awk 'BEGIN {
+ while (("grep -aho \"[a-z][a-z-]*\" *.dll *.exe" | getline) > 0)
+ good[$0] = 1
+} /[.](png|svg|cur|ani)$/ {
+ # Cut out the basename without extensions.
+ match($0, /[^\/]+$/)
+ base = substr($0, RSTART)
+ sub(/[.].+$/, "", base)
+
+ # Try matching while cutting off suffixes.
+ # Disregarding the not-much-used GTK_ICON_LOOKUP_GENERIC_FALLBACK.
+ while (!(keep = good[base]) &&
+ sub(/-(ltr|rtl|symbolic)$/, "", base)) {}
+ if (!keep)
+ print
+}' | xargs rm --
+
+wine64 "$msys2_root"/bin/glib-compile-schemas.exe share/glib-2.0/schemas
+
+# This may speed up program start-up a little bit.
+wine64 "$msys2_root"/bin/gtk-update-icon-cache-3.0.exe share/icons/Adwaita