22LIBS_DIR := $(abspath ./libs)
33
44UNAME_S := $(shell uname -s)
5-
65# Flags for CGO to find the headers and the shared library
76ifeq ($(UNAME_S ) ,Darwin)
87 CGO_CFLAGS := -I$(LIBS_DIR)
9- CGO_LDFLAGS := -L$(LIBS_DIR) -lcodex -Wl,-rpath,@executable_path/./ libs
8+ CGO_LDFLAGS := -L$(LIBS_DIR) -lcodex -Wl,-rpath,@executable_path/libs
109else
1110 CGO_CFLAGS := -I$(LIBS_DIR)
1211 CGO_LDFLAGS := -L$(LIBS_DIR) -lcodex -Wl,-rpath,$(LIBS_DIR)
@@ -29,9 +28,13 @@ all: run
2928
3029fetch :
3130 @echo " Fetching libcodex from GitHub Actions: ${LATEST_URL} "
32- @ curl -fSL --create-dirs -o $(LIBS_DIR ) /codex-${OS} -${ARCH} .zip ${LATEST_URL}
31+ curl -fSL --create-dirs -o $(LIBS_DIR ) /codex-${OS} -${ARCH} .zip ${LATEST_URL}
3332 unzip -o -qq $(LIBS_DIR ) /codex-${OS} -${ARCH} .zip -d $(LIBS_DIR )
3433 rm -f $(LIBS_DIR ) /* .zip
34+ # Update the path to the shared library on macOS
35+ ifeq ($(UNAME_S ) ,Darwin)
36+ install_name_tool -id @rpath/libcodex.dylib $(LIBS_DIR)/libcodex.dylib
37+ endif
3538
3639build :
3740 CGO_ENABLED=1 CGO_CFLAGS=" $( CGO_CFLAGS) " CGO_LDFLAGS=" $( CGO_LDFLAGS) " go build -o $(BIN_NAME ) main.go
4043ifeq ($(OS ) ,Windows_NT)
4144 pwsh -Command "Copy-Item libs\libcodex.dll ."
4245 pwsh -Command ".\$(BIN_NAME)"
46+ else ifeq ($(UNAME_S),Darwin)
47+ # Instead of relying on install_name_tool, we can define DYLD_LIBRARY_PATH
48+ # DYLD_LIBRARY_PATH=$(LIBS_DIR) ./$(BIN_NAME)
49+ ./$(BIN_NAME)
4350else
4451 ./$(BIN_NAME)
4552endif
0 commit comments