63 lines
1.8 KiB
Makefile
Raw Normal View History

2025-10-14 14:16:15 +02:00
# Destination folder for the downloaded libraries
LIBS_DIR := $(abspath ./libs)
2025-10-15 08:34:44 +02:00
# Flags for CGO to find the headers and the shared library
2025-10-15 14:56:54 +02:00
UNAME_S := $(shell uname -s)
2025-10-15 12:16:26 +02:00
ifeq ($(UNAME_S),Darwin)
CGO_CFLAGS := -I$(LIBS_DIR)
2025-10-15 19:06:19 +02:00
CGO_LDFLAGS := -L$(LIBS_DIR) -lcodex -Wl,-rpath,@executable_path
2025-10-15 12:16:26 +02:00
else
CGO_CFLAGS := -I$(LIBS_DIR)
CGO_LDFLAGS := -L$(LIBS_DIR) -lcodex -Wl,-rpath,$(LIBS_DIR)
endif
ifeq ($(OS),Windows_NT)
2025-10-15 09:30:41 +02:00
BIN_NAME := example.exe
2025-10-15 08:24:14 +02:00
else
BIN_NAME := example
endif
2025-10-14 14:16:15 +02:00
# Configuration for fetching the right binary
OS ?= "linux"
ARCH ?= "amd64"
2025-10-15 11:10:53 +02:00
VERSION ?= "v0.0.17"
2025-10-15 14:56:54 +02:00
DOWNLOAD_URL ?= "https://github.com/codex-storage/codex-go-bindings/releases/latest/download/codex-${OS}-${ARCH}.zip"
ifneq ($(VERSION),)
DOWNLOAD_URL := "https://github.com/codex-storage/codex-go-bindings/releases/download/$(VERSION)/codex-${OS}-${ARCH}.zip"
endif
2025-10-14 14:16:15 +02:00
all: run
fetch:
2025-10-15 14:56:54 +02:00
@echo "Fetching libcodex from GitHub Actions from: ${DOWNLOAD_URL}"
curl -fSL --create-dirs -o $(LIBS_DIR)/codex-${OS}-${ARCH}.zip ${DOWNLOAD_URL}
2025-10-15 09:12:27 +02:00
unzip -o -qq $(LIBS_DIR)/codex-${OS}-${ARCH}.zip -d $(LIBS_DIR)
rm -f $(LIBS_DIR)/*.zip
2025-10-15 12:18:51 +02:00
# Update the path to the shared library on macOS
2025-10-15 15:02:33 +02:00
ifeq ($(UNAME_S),Darwin)
2025-10-15 14:58:00 +02:00
# install_name_tool -id @rpath/libcodex.dylib $(LIBS_DIR)/libcodex.dylib
2025-10-15 15:02:33 +02:00
otool -L libs/libcodex.dylib
endif
2025-10-15 12:18:51 +02:00
2025-10-14 14:16:15 +02:00
build:
2025-10-15 16:21:28 +02:00
ifeq ($(UNAME_S),Darwin)
# install_name_tool -id @rpath/libcodex.dylib $(LIBS_DIR)/libcodex.dylib
otool -L libs/libcodex.dylib
endif
2025-10-15 08:25:41 +02:00
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go build -o $(BIN_NAME) main.go
2025-10-15 12:18:51 +02:00
2025-10-14 14:16:15 +02:00
run:
2025-10-15 08:45:48 +02:00
ifeq ($(OS),Windows_NT)
2025-10-15 21:55:52 +11:00
pwsh -File $(CURDIR)/.github/scripts/run-windows.ps1 -BinaryName $(BIN_NAME)
2025-10-15 12:07:28 +02:00
else ifeq ($(UNAME_S),Darwin)
2025-10-15 12:18:51 +02:00
# Instead of relying on install_name_tool, we can define DYLD_LIBRARY_PATH
# DYLD_LIBRARY_PATH=$(LIBS_DIR) ./$(BIN_NAME)
2025-10-15 12:12:23 +02:00
./$(BIN_NAME)
2025-10-15 08:45:48 +02:00
else
2025-10-15 08:24:14 +02:00
./$(BIN_NAME)
2025-10-15 08:45:48 +02:00
endif
2025-10-14 14:16:15 +02:00
clean:
2025-10-15 08:24:14 +02:00
rm -f $(BIN_NAME)
2025-10-14 14:16:15 +02:00
rm -Rf $(LIBS_DIR)/*