aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElse <else@localhost>2026-03-18 11:01:36 +0100
committerfrosty <gabriel@bwaaa.monster>2026-03-18 06:21:05 -0400
commit38aa54bb91597bd15ecd1dca1da6194c80249039 (patch)
tree6756df3fabbc206264a15b35879b2ad175aec758
parentf17698c08030b64e5106465525b73735516d567e (diff)
downloadbeaker-38aa54bb91597bd15ecd1dca1da6194c80249039.tar.gz
Add macOS build and install support
-rw-r--r--Makefile49
-rw-r--r--README.md8
2 files changed, 42 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index eb44468..071f923 100644
--- a/Makefile
+++ b/Makefile
@@ -1,32 +1,44 @@
-CC ?= cc
-INSTALL_PREFIX ?= /usr/
-LDCONFIG := ldconfig
+CC ?= cc
+UNAME_S := $(shell uname -s)
-AR := ar
-CFLAGS := -Wall -fPIC -I. -Isrc
-LDFLAGS := -shared -lpthread
+AR := ar
+CFLAGS := -Wall -fPIC -I. -Isrc
BUILD_DIR ?= build
-OBJ_DIR := $(BUILD_DIR)/obj
+OBJ_DIR := $(BUILD_DIR)/obj
+
+ifeq ($(UNAME_S),Darwin)
+INSTALL_PREFIX ?= /usr/local/
+SHARED_EXT := dylib
+LDCONFIG := true
+LDFLAGS := -dynamiclib -lpthread -Wl,-install_name,$(INSTALL_PREFIX)lib/libbeaker.$(SHARED_EXT)
+else
+INSTALL_PREFIX ?= /usr/
+SHARED_EXT := so
+LDCONFIG := ldconfig
+LDFLAGS := -shared -lpthread
+endif
SRCS := $(wildcard src/*.c)
OBJS := $(patsubst src/%.c,$(OBJ_DIR)/%.o,$(SRCS))
-LIB := $(BUILD_DIR)/libbeaker
-HEADER := beaker.h
+LIB_BASE := $(BUILD_DIR)/libbeaker
+STATIC_LIB := $(LIB_BASE).a
+SHARED_LIB := $(LIB_BASE).$(SHARED_EXT)
+HEADER := beaker.h
.PHONY: all clean install uninstall info
-all: $(LIB).so $(LIB).a
+all: $(SHARED_LIB) $(STATIC_LIB)
$(OBJ_DIR):
@mkdir -p $(OBJ_DIR)
-$(LIB).a: $(OBJS)
+$(STATIC_LIB): $(OBJS)
@echo "Linking static library $@..."
$(AR) rcs $@ $^
@echo "Successfully built $@"
-$(LIB).so: $(OBJS)
+$(SHARED_LIB): $(OBJS)
@echo "Linking shared library $@..."
$(CC) $(LDFLAGS) $(OBJS) -o $@ -lm
@echo "Successfully built $@"
@@ -43,7 +55,10 @@ clean:
install: all
@echo "Installing libraries to $(INSTALL_PREFIX)lib"
@mkdir -p $(INSTALL_PREFIX)lib
- @cp $(LIB).so $(LIB).a $(INSTALL_PREFIX)lib/
+ifeq ($(UNAME_S),Darwin)
+ @rm -f $(INSTALL_PREFIX)lib/libbeaker.so
+endif
+ @cp $(SHARED_LIB) $(STATIC_LIB) $(INSTALL_PREFIX)lib/
@$(LDCONFIG) || true
@echo "Installing $(HEADER) to $(INSTALL_PREFIX)include"
@mkdir -p $(INSTALL_PREFIX)include
@@ -52,14 +67,18 @@ install: all
uninstall:
@echo "Uninstalling from $(INSTALL_PREFIX)..."
- @rm -f $(INSTALL_PREFIX)lib/libbeaker.so
+ @rm -f $(INSTALL_PREFIX)lib/libbeaker.$(SHARED_EXT)
@rm -f $(INSTALL_PREFIX)lib/libbeaker.a
+ifeq ($(UNAME_S),Darwin)
+ @rm -f $(INSTALL_PREFIX)lib/libbeaker.so
+endif
@rm -f $(INSTALL_PREFIX)include/$(HEADER)
@$(LDCONFIG) || true
@echo "Uninstallation complete."
info:
- @echo "Detected OS: '$(OS)'"
+ @echo "Detected OS: '$(UNAME_S)'"
@echo "Compiler: $(CC)"
@echo "Install Prefix: $(INSTALL_PREFIX)"
+ @echo "Shared Library: $(SHARED_LIB)"
@echo "Source Files: $(SRCS)"
diff --git a/README.md b/README.md
index 8b8190c..a345f42 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,14 @@ Look at the files in examples for usage
$ cd beaker
# make install
```
+
+On macOS the default install prefix is `/usr/local/`, because `/usr/lib` is protected by System Integrity Protection.
+The install step produces `libbeaker.dylib` and removes any stale `libbeaker.so` from older installs.
+You can always override the destination:
+
+```bash
+$ make install INSTALL_PREFIX=/some/prefix/
+```
## Roadmap