aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile67
1 files changed, 42 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index 66e5016..923212d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,27 +1,36 @@
-CC = gcc
-AR = ar
-CFLAGS = -Wall -fPIC -I. -Isrc
-LDFLAGS = -shared
+S := $(shell uname -s | tr -d ' ')
+
+ifeq ($(OS), FreeBSD)
+ CC := clang
+ INSTALL_PREFIX ?= /usr/local/
+ LDCONFIG := true
+else
+ CC := gcc
+ INSTALL_PREFIX ?= /usr/
+ LDCONFIG := ldconfig
+endif
+
+AR := ar
+CFLAGS := -Wall -fPIC -I. -Isrc
+LDFLAGS := -shared
BUILD_DIR ?= build
-OBJ_DIR = $(BUILD_DIR)/obj
-INSTALL_PREFIX ?= /usr/
+OBJ_DIR := $(BUILD_DIR)/obj
-SRCS = $(wildcard src/*.c)
-OBJS = $(patsubst src/%.c,$(OBJ_DIR)/%.o,$(SRCS))
+SRCS := $(wildcard src/*.c)
+OBJS := $(patsubst src/%.c,$(OBJ_DIR)/%.o,$(SRCS))
-LIB = $(BUILD_DIR)/libbeaker
-HEADER = beaker.h
+LIB := $(BUILD_DIR)/libbeaker
+HEADER := beaker.h
-.PHONY: all clean install uninstall
+.PHONY: all clean install uninstall info
all: $(LIB).so $(LIB).a
-
$(OBJ_DIR):
@mkdir -p $(OBJ_DIR)
$(LIB).a: $(OBJS)
- @echo "Linking shared library $@..."
+ @echo "Linking static library $@..."
$(AR) rcs $@ $^
@echo "Successfully built $@"
@@ -35,22 +44,30 @@ $(OBJ_DIR)/%.o: src/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
clean:
- @echo "Cleaning up object files and shared library..."
- @rm -rf $(OBJ_DIR) $(LIB)
+ @echo "Cleaning up object files and libraries..."
+ @rm -rf $(BUILD_DIR)
@echo "Clean complete."
install: all
- @echo "Installing $(LIB) to $(INSTALL_PREFIX)/lib"
- @cp $(LIB).so $(INSTALL_PREFIX)/lib/
- @ldconfig
- @echo "Installing $(HEADER) to $(INSTALL_PREFIX)/include"
- @cp $(HEADER) $(INSTALL_PREFIX)/include
+ @echo "Installing libraries to $(INSTALL_PREFIX)lib"
+ @mkdir -p $(INSTALL_PREFIX)lib
+ @cp $(LIB).so $(LIB).a $(INSTALL_PREFIX)lib/
+ @$(LDCONFIG) || true
+ @echo "Installing $(HEADER) to $(INSTALL_PREFIX)include"
+ @mkdir -p $(INSTALL_PREFIX)include
+ @cp $(HEADER) $(INSTALL_PREFIX)include
@echo "Installation complete."
uninstall:
- @echo "Uninstalling $(LIB) from $(INSTALL_PREFIX)/lib..."
- @rm -f $(INSTALL_PREFIX)/lib/$(LIB)
- @ldconfig
- @echo "Removing $(HEADER) from $(INSTALL_PREFIX)/include"
- @rm -f $(INSTALL_PREFIX)/include/$(HEADER)
+ @echo "Uninstalling from $(INSTALL_PREFIX)..."
+ @rm -f $(INSTALL_PREFIX)lib/libbeaker.so
+ @rm -f $(INSTALL_PREFIX)lib/libbeaker.a
+ @rm -f $(INSTALL_PREFIX)include/$(HEADER)
+ @$(LDCONFIG) || true
@echo "Uninstallation complete."
+
+info:
+ @echo "Detected OS: '$(OS)'"
+ @echo "Compiler: $(CC)"
+ @echo "Install Prefix: $(INSTALL_PREFIX)"
+ @echo "Source Files: $(SRCS)"