Skip to content

Instantly share code, notes, and snippets.

@munshkr
Last active June 13, 2020 17:00
Show Gist options
  • Save munshkr/42f8c69bd8e6f11900f034fa6aeb8ba7 to your computer and use it in GitHub Desktop.
Save munshkr/42f8c69bd8e6f11900f034fa6aeb8ba7 to your computer and use it in GitHub Desktop.
Package dynamically-linked Haskell binary on OSX
#!/bin/bash
# Based on http://gelisam.blogspot.com/2014/12/how-to-package-up-binaries-for.html
# This assumes binary file is called `hello-world-exe`
#
# You can test this by creatiung a new stack project:
# $ stack new hello-world
#
# Copy this file on the directory and run:
# $ chmod +x build-osx.sh
# $ ./build-osx.sh
BIN=hello-world-exe
LIBS_DIR=libs/
stack build
stack install --lobal-bin-path .
dynlibs=$(otool -L $BIN | tail +2 | cut -f1 -d' ' | xargs)
echo "Dynamic libraries: $dynlibs"
rm -r $LIBS_DIR
mkdir -p $LIBS_DIR
cp $dynlibs $LIBS_DIR
for dynlib in $dynlibs; do
install_name_tool -change "$dynlib" "@executable_path/$LIBS_DIR/$(basename $dynlib)" $BIN
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment