Skip to content

Instantly share code, notes, and snippets.

@cwchentw
Last active June 18, 2021 07:47
Show Gist options
  • Save cwchentw/ba2d95ee3bab69ccdff60c8aa1ed742f to your computer and use it in GitHub Desktop.
Save cwchentw/ba2d95ee3bab69ccdff60c8aa1ed742f to your computer and use it in GitHub Desktop.
Depoly a MSYS2 Executable to Native Windows Environment
#!/bin/sh
# deploy2win - Deploy a MSYS2 executable to native Windows environment
#
# Copyright (c) 2020, Michelle Chen. Licensed under MIT.
target="$1"
# Check whether `$target` is an executable.
if ! [ -x "$target" ];
then
echo "Not a valid executable: ${target}" >&2
exit 1
fi
# Get the destination directory.
dest="$(dirname $(realpath $target))"
# Iterate over the required DLLs, excluding those in system directories.
for dll in `ldd $target | grep -i -v WINDOWS | cut -d ' ' -f 3`;
do
src="$(dirname $(realpath $dll))"
# If the `$src` of the `$dll` is not the same as `$dest`,
# copy the `$dll` to `$dest`.
if [ "$src" != "$dest" ];
then
cp "$dll" "$dest" || (
echo "Fail to copy $dll to $dest" >&2
)
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment