Skip to content

Commit

Permalink
make: multi-os
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesob committed Jan 27, 2025
1 parent ce3ae20 commit f9fa92e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ jobs:
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install secp256k1 libsodium python3 go
sudo mkdir -p /usr/local/{lib,include}
sudo chmod 755 /usr/local/{lib,include}
echo "LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH" >> $GITHUB_ENV
echo "CPATH=/usr/local/include:$CPATH" >> $GITHUB_ENV
fi
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.uv/bin" >> $GITHUB_PATH
Expand Down
45 changes: 40 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
CC := $(shell command -v clang 2>/dev/null || command -v $(CC) 2>/dev/null || echo cc)
CFLAGS = -DDEBUG -Wall -Werror
LDFLAGS = -lsecp256k1 -lsodium

CFLAGS = -Wall -Werror
ifdef DEBUG
CFLAGS += -g -DDEBUG
else
CFLAGS += -O2
endif

LDCONFIG := ldconfig
INSTALL_PREFIX := /usr/local

UNAME_S := $(shell uname -s)

# Set default paths
STD_INCLUDE_PATHS := /usr/local/include
STD_LIB_PATHS := /usr/local/lib

# Add Homebrew paths for macOS
ifeq ($(UNAME_S),Darwin)
UNAME_MACHINE := $(shell uname -m)
LDCONFIG := test 1
INSTALL_PREFIX := /usr
ifeq ($(UNAME_MACHINE),arm64)
BREW_PREFIX := /opt/homebrew
else
BREW_PREFIX := /usr/local
endif
INCLUDE_PATHS := $(BREW_PREFIX)/include $(STD_INCLUDE_PATHS)
LIB_PATHS := $(BREW_PREFIX)/lib $(STD_LIB_PATHS)
else
INCLUDE_PATHS := $(STD_INCLUDE_PATHS)
LIB_PATHS := $(STD_LIB_PATHS)
endif

# Convert paths to compiler flags
CFLAGS += $(foreach path,$(INCLUDE_PATHS),-I$(path))
LDFLAGS += $(foreach path,$(LIB_PATHS),-L$(path)) -lsecp256k1 -lsodium

all: libbip32.so
$(CC) $(CFLAGS) -o bip32-cli cli.c libbip32.so $(LDFLAGS)
Expand All @@ -22,9 +57,9 @@ fuzz: fuzz_target

.PHONY: install
install: libbip32.so
install -m755 libbip32.so /usr/local/lib/
install -m755 bip32.h /usr/local/include/
ldconfig
install -m755 libbip32.so $(INSTALL_PREFIX)/lib/
install -m755 bip32.h $(INSTALL_PREFIX)/include/
$(LDCONFIG)

.PHONY: clean
clean:
Expand Down

0 comments on commit f9fa92e

Please sign in to comment.