diff options
| -rw-r--r-- | Makefile | 49 | ||||
| -rw-r--r-- | README.md | 8 |
2 files changed, 42 insertions, 15 deletions
@@ -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)" @@ -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 |
