From ec713b633e0add828cdf410c10eee7b48717ba55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Mon, 26 Jun 2023 15:31:28 +0200 Subject: Package the MSI from within a custom target --- README.adoc | 2 +- meson.build | 16 +++++++++++----- msys2-configure.sh | 3 +-- msys2-package.sh | 30 +++++++++++++++++------------- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/README.adoc b/README.adoc index 5c8def4..e671a1d 100644 --- a/README.adoc +++ b/README.adoc @@ -69,7 +69,7 @@ plus rsvg-convert from librsvg2, icotool from icoutils, and msitools ≥ 0.102. Beware that the build will take up about a gigabyte of disk space. $ sh -e msys2-configure.sh builddir - $ meson install -C builddir + $ meson compile package -C builddir If everything succeeds, you will find a portable build of the application in the 'builddir/package' subdirectory, and a very basic MSI installation diff --git a/meson.build b/meson.build index 4a9b411..f809ebd 100644 --- a/meson.build +++ b/meson.build @@ -338,11 +338,7 @@ elif meson.is_cross_build() msys2_root = meson.get_external_property('msys2_root') meson.add_install_script('msys2-install.sh', msys2_root) - # TODO: If we used DESTDIR instead of the prefix, this could probably - # be a custom target that invokes "meson install --destdir $(pwd)/package" - # through "meson compile -C builddir msi". Try it out, also in MSYS2. - meson.add_install_script('msys2-package.sh', host_machine.cpu()) - configure_file( + wxs = configure_file( input : 'fiv.wxs.in', output : 'fiv.wxs', configuration : configuration_data({ @@ -350,6 +346,16 @@ elif meson.is_cross_build() 'ProjectVersion' : meson.project_version(), }), ) + custom_target('package', + output : 'fiv.msi', + command : [meson.current_source_dir() / 'msys2-package.sh', + host_machine.cpu(), 'fiv.msi', wxs], + env : ['MESON_BUILD_ROOT=' + meson.current_build_dir(), + 'MESON_SOURCE_ROOT=' + meson.current_source_dir()], + console : true, + build_always_stale : true, + build_by_default : false, + ) # This is the minimum to run targets from msys2-configure.sh builds. meson.add_devenv({ diff --git a/msys2-configure.sh b/msys2-configure.sh index 9554e4f..c8c8eea 100755 --- a/msys2-configure.sh +++ b/msys2-configure.sh @@ -120,13 +120,12 @@ setup() { endian = 'little' EOF - meson setup --buildtype=debugoptimized --prefix="$packagedir" \ + meson setup --buildtype=debugoptimized --prefix=/ \ --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 diff --git a/msys2-package.sh b/msys2-package.sh index 419ee21..f403769 100755 --- a/msys2-package.sh +++ b/msys2-package.sh @@ -1,9 +1,17 @@ #!/bin/sh -e -export LC_ALL=C.UTF-8 +export LC_ALL=C cd "$MESON_BUILD_ROOT" +arch=$1 msi=$2 files=package-files.wxs destdir=$(pwd)/package +shift 2 + +# We're being passed host_machine.cpu(), which will be either x86 or x86_64. +[ "$arch" = "x86" ] || arch=x64 + +rm -rf "$destdir" +meson install --destdir "$destdir" txt2rtf() { - iconv -f utf-8 -t ascii//translit "$@" | awk 'BEGIN { + LC_CTYPE=C.UTF-8 iconv -f utf-8 -t ascii//translit "$@" | awk 'BEGIN { print "{\\rtf1\\ansi\\ansicpg1252\\deff0{\\fonttbl{\\f0 Tahoma;}}" print "\\f0\\fs24{\\pard\\sa240" } { @@ -15,16 +23,12 @@ txt2rtf() { }' } -# We're being passed host_machine.cpu(), which will be either x86 or x86_64. -[ "$1" = "x86" ] && arch=x86 || arch=x64 - -wxs=fiv.wxs files=fiv-files.wxs msi=fiv.msi - +# msitools have this filename hardcoded in UI files, and it's required. txt2rtf "$MESON_SOURCE_ROOT/LICENSE" > License.rtf -find "$MESON_INSTALL_DESTDIR_PREFIX" -type f \ - | wixl-heat --prefix "$MESON_INSTALL_DESTDIR_PREFIX/" \ - --directory-ref INSTALLDIR --component-group CG.fiv \ - --var var.SourceDir > "$files" -wixl --verbose --arch "$arch" -D SourceDir="$MESON_INSTALL_DESTDIR_PREFIX" \ - --ext ui --output "$msi" "$wxs" "$files" +find "$destdir" -type f \ + | wixl-heat --prefix "$destdir/" --directory-ref INSTALLDIR \ + --component-group CG.fiv --var var.SourceDir > "$files" + +wixl --verbose --arch "$arch" -D SourceDir="$destdir" --ext ui \ + --output "$msi" "$@" "$files" -- cgit v1.2.3