diff --git a/templates/hl/mac-launch.sh b/templates/hl/mac-launch.sh new file mode 100644 index 000000000..7f3b77fca --- /dev/null +++ b/templates/hl/mac-launch.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +# HashLink needs a specific working directory to find hlboot.dat and libraries +cd "$(dirname "$0")" +exec ./hl \ No newline at end of file diff --git a/tools/platforms/MacPlatform.hx b/tools/platforms/MacPlatform.hx index 8829ac3ad..4f80be65a 100644 --- a/tools/platforms/MacPlatform.hx +++ b/tools/platforms/MacPlatform.hx @@ -207,6 +207,20 @@ class MacPlatform extends PlatformTarget if (noOutput) return; HashlinkHelper.copyHashlink(project, targetDirectory, executableDirectory, executablePath, is64); + + // HashLink looks for hlboot.dat and libraries in the current + // working directory, so the .app file won't work properly if it + // tries to run the HashLink executable directly. + // when the .app file is launched, we can tell it to run a shell + // script instead of the HashLink executable. the shell script will + // adjusts the working directory before running the HL executable. + + // unlike other platforms, we want to use the original "hl" name + var hlExecutablePath = Path.combine(executableDirectory, "hl"); + System.renameFile(executablePath, hlExecutablePath); + System.runCommand("", "chmod", ["755", hlExecutablePath]); + // then we can use the executable name for the shell script + System.copyFileTemplate(project.templatePaths, 'hl/mac-launch.sh', executablePath); } else if (targetType == "java") {