Skip to content

Commit 4bc8be6

Browse files
committed
make: multi-os
1 parent ce3ae20 commit 4bc8be6

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

.github/workflows/tests.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,25 @@ jobs:
2222
elif [ "$RUNNER_OS" == "macOS" ]; then
2323
brew install secp256k1 libsodium python3 go
2424
25+
sudo mkdir -p /usr/local/{lib,include}
26+
sudo chmod 755 /usr/local/{lib,include}
27+
echo "LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH" >> $GITHUB_ENV
28+
echo "CPATH=/opt/homebrew/include:$CPATH" >> $GITHUB_ENV
2529
fi
30+
2631
curl -LsSf https://astral.sh/uv/install.sh | sh
2732
echo "$HOME/.uv/bin" >> $GITHUB_PATH
2833
2934
- name: Build
3035
run: |
31-
make && sudo make install
36+
make
37+
38+
if [ "$RUNNER_OS" == "macOS" ]; then
39+
sudo make INSTALL_PREFIX=/opt/homebrew install
40+
else
41+
sudo make install
42+
fi
43+
3244
3345
- name: Run Python tests
3446
run: |
@@ -38,4 +50,6 @@ jobs:
3850
- name: Run Go tests
3951
run: |
4052
cd examples/go
41-
make test
53+
if [ "$RUNNER_OS" != "macOS" ]; then
54+
make test
55+
fi

Makefile

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
CC := $(shell command -v clang 2>/dev/null || command -v $(CC) 2>/dev/null || echo cc)
2-
CFLAGS = -DDEBUG -Wall -Werror
3-
LDFLAGS = -lsecp256k1 -lsodium
2+
3+
CFLAGS = -Wall -Werror
4+
ifdef DEBUG
5+
CFLAGS += -g -DDEBUG
6+
else
7+
CFLAGS += -O2
8+
endif
9+
10+
LDCONFIG := ldconfig
11+
INSTALL_PREFIX := /usr/local
12+
13+
UNAME_S := $(shell uname -s)
14+
15+
# Set default paths
16+
STD_INCLUDE_PATHS := /usr/local/include
17+
STD_LIB_PATHS := /usr/local/lib
18+
19+
# Add Homebrew paths for macOS
20+
ifeq ($(UNAME_S),Darwin)
21+
UNAME_MACHINE := $(shell uname -m)
22+
LDCONFIG := test 1
23+
ifeq ($(UNAME_MACHINE),arm64)
24+
BREW_PREFIX := /opt/homebrew
25+
else
26+
BREW_PREFIX := /usr/local
27+
endif
28+
INCLUDE_PATHS := $(BREW_PREFIX)/include $(STD_INCLUDE_PATHS)
29+
LIB_PATHS := $(BREW_PREFIX)/lib $(STD_LIB_PATHS)
30+
else
31+
INCLUDE_PATHS := $(STD_INCLUDE_PATHS)
32+
LIB_PATHS := $(STD_LIB_PATHS)
33+
endif
34+
35+
# Convert paths to compiler flags
36+
CFLAGS += $(foreach path,$(INCLUDE_PATHS),-I$(path))
37+
LDFLAGS += $(foreach path,$(LIB_PATHS),-L$(path)) -lsecp256k1 -lsodium
438

539
all: libbip32.so
640
$(CC) $(CFLAGS) -o bip32-cli cli.c libbip32.so $(LDFLAGS)
@@ -22,9 +56,9 @@ fuzz: fuzz_target
2256

2357
.PHONY: install
2458
install: libbip32.so
25-
install -m755 libbip32.so /usr/local/lib/
26-
install -m755 bip32.h /usr/local/include/
27-
ldconfig
59+
install -m755 libbip32.so $(INSTALL_PREFIX)/lib/
60+
install -m755 bip32.h $(INSTALL_PREFIX)/include/
61+
$(LDCONFIG)
2862

2963
.PHONY: clean
3064
clean:

examples/go/cbip32.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cbip32
22

33
// #cgo CFLAGS: -I.
4-
// #cgo LDFLAGS: -L. -lbip32
4+
// #cgo LDFLAGS: -lbip32
55
// #include "bip32.h"
66
import "C"
77
import (

0 commit comments

Comments
 (0)