From c25d8a7f1813feb8ea742da17d285f3fa4e9f48e Mon Sep 17 00:00:00 2001 From: Zeta <53486764+Apprentice-Alchemist@users.noreply.github.com> Date: Wed, 31 Jan 2024 11:39:58 +0100 Subject: [PATCH] [mac] Fix resolution of libhl.dylib when globally installed. (#646) --- .github/workflows/build.yml | 6 ++++++ Makefile | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 822ed9686..bc3f00f95 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -248,6 +248,12 @@ jobs: haxe -hl src/_main.c -cp other/tests -main HelloWorld make hlc ./hlc + + # ensure the executable still works when installed globally + cp hello.hl /tmp + pushd /tmp + hl hello.hl + popd ;; esac diff --git a/Makefile b/Makefile index eca16c3da..3d553707d 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,8 @@ HLFLAGS = -ldl LIBEXT = so LIBTURBOJPEG = -lturbojpeg +LHL_LINK_FLAGS = + PCRE_FLAGS = -I include/pcre -D HAVE_CONFIG_H -D PCRE2_CODE_UNIT_WIDTH=16 PCRE = include/pcre/pcre2_auto_possess.o include/pcre/pcre2_chartables.o include/pcre/pcre2_compile.o \ @@ -136,6 +138,9 @@ endif CFLAGS += -arch $(ARCH) LFLAGS += -arch $(ARCH) +LFLAGS += -rpath @executable_path -rpath $(INSTALL_LIB_DIR) +LIBFLAGS += -rpath @executable_path -rpath $(INSTALL_LIB_DIR) +LHL_LINK_FLAGS += -install_name @rpath/libhl.dylib else # Linux @@ -189,7 +194,7 @@ src/std/regexp.o: src/std/regexp.c ${CC} ${CFLAGS} -o $@ -c $< ${PCRE_FLAGS} libhl: ${LIB} - ${CC} ${CFLAGS} -o libhl.$(LIBEXT) -m${MARCH} ${LIBFLAGS} -shared ${LIB} -lpthread -lm + ${CC} ${CFLAGS} -o libhl.$(LIBEXT) -m${MARCH} ${LIBFLAGS} ${LHL_LINK_FLAGS} -shared ${LIB} -lpthread -lm hlc: ${BOOT} ${CC} ${CFLAGS} -o hlc ${BOOT} ${LFLAGS} ${EXTRA_LFLAGS}