2021-09-13 13:09:23 +02:00
|
|
|
.PHONY: build-lib
|
|
|
|
|
2021-10-15 10:50:58 +02:00
|
|
|
BUILD_PATH=$(realpath .)/build
|
2021-09-13 13:09:23 +02:00
|
|
|
|
2021-09-27 16:00:56 +02:00
|
|
|
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
|
|
|
|
detected_OS := Windows
|
|
|
|
else
|
|
|
|
detected_OS := $(strip $(shell uname))
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(detected_OS),Darwin)
|
|
|
|
LIB_EXT := dylib
|
2021-10-06 09:13:02 -04:00
|
|
|
ifeq ("$(shell sysctl -nq hw.optional.arm64)","1")
|
|
|
|
# Building on M1 is still not supported, so in the meantime we crosscompile to amd64
|
|
|
|
CGOFLAGS=CGO_ENABLED=1 GOOS=darwin GOARCH=amd64
|
|
|
|
endif
|
2021-09-27 16:00:56 +02:00
|
|
|
else ifeq ($(detected_OS),Windows)
|
|
|
|
LIB_EXT:= dll
|
|
|
|
LIBKEYCARD_EXT := dll
|
|
|
|
else
|
|
|
|
LIB_EXT := so
|
|
|
|
endif
|
|
|
|
|
2021-09-13 13:09:23 +02:00
|
|
|
build-lib:
|
2021-10-15 10:34:19 +02:00
|
|
|
mkdir -p $(BUILD_PATH)/libkeycard
|
2021-09-13 13:09:23 +02:00
|
|
|
@echo "Building static library..."
|
2021-10-15 10:34:19 +02:00
|
|
|
cd shared && \
|
|
|
|
$(CGOFLAGS) go build -buildmode=c-shared -o $(BUILD_PATH)/libkeycard/libkeycard.$(LIB_EXT) .
|
2021-09-13 13:09:23 +02:00
|
|
|
@echo "Static library built:"
|
2021-10-15 10:34:19 +02:00
|
|
|
@ls -la $(BUILD_PATH)/libkeycard/*
|
|
|
|
|
|
|
|
build-example-shared: build-lib
|
|
|
|
mkdir -p $(BUILD_PATH)
|
|
|
|
@echo "Building example-c..."
|
|
|
|
cd examples/example-shared && \
|
|
|
|
go build -o $(BUILD_PATH)/example-shared
|
|
|
|
|
|
|
|
run-example-shared: build-example-shared
|
|
|
|
LD_LIBRARY_PATH=$(BUILD_PATH)/libkeycard $(BUILD_PATH)/example-shared
|
|
|
|
|
2021-10-19 10:21:09 +02:00
|
|
|
build-example-go:
|
2021-10-15 10:34:19 +02:00
|
|
|
mkdir -p $(BUILD_PATH)
|
|
|
|
@echo "Building example-c..."
|
|
|
|
cd examples/example-go && \
|
|
|
|
go build -o $(BUILD_PATH)/example-go
|
|
|
|
|
|
|
|
run-example-go: build-example-go
|
|
|
|
$(BUILD_PATH)/example-go
|