64f7260b3a
- Add PREFIX, LIBDIR, and INCDIR variables (default: /usr/local) - Implement install target that builds release and installs to system paths - Implement uninstall target to cleanly remove installed files - Support custom install locations via PREFIX variable - Add helpful message on Windows directing users to manual installation Both gmake.mk and bmake.mk now support standard installation workflow on Unix-like systems (Linux, BSD, macOS). Windows users are instructed to copy files manually as per platform conventions. Usage: make install # Install to /usr/local (requires root) make PREFIX=$HOME install # Install to custom location make uninstall # Remove installed files
79 lines
1.9 KiB
Makefile
79 lines
1.9 KiB
Makefile
include config.mk
|
|
|
|
ifeq ($(OS),Windows_NT)
|
|
SHELL := cmd.exe
|
|
FULL_LIB := $(LIB_NAME).dll
|
|
LDFLAGS_PLAT :=
|
|
CFLAGS_PLAT :=
|
|
MKDIR = if not exist $(subst /,\,$(1)) mkdir $(subst /,\,$(1))
|
|
RMDIR = if exist $(subst /,\,$(1)) rd /s /q $(subst /,\,$(1))
|
|
else
|
|
FULL_LIB := lib$(LIB_NAME).so
|
|
LDFLAGS_PLAT := -ldl
|
|
CFLAGS_PLAT := -fPIC
|
|
MKDIR = mkdir -p $(1)
|
|
RMDIR = rm -rf $(1)
|
|
endif
|
|
|
|
RELEASE_LDFLAGS := -s
|
|
CFLAGS_BASE := -Wall -Wpedantic -I$(INC_DIR) -std=c89 $(CFLAGS_PLAT)
|
|
|
|
PREFIX ?= /usr/local
|
|
LIBDIR ?= $(PREFIX)/lib
|
|
INCDIR ?= $(PREFIX)/include
|
|
|
|
.PHONY: all debug release clean test install uninstall
|
|
|
|
all: debug
|
|
|
|
debug: $(BIN_DIR)/debug/$(FULL_LIB)
|
|
release: $(BIN_DIR)/release/$(FULL_LIB)
|
|
|
|
# Debug Rules
|
|
$(BIN_DIR)/debug/$(FULL_LIB): $(SRCS:src/%.c=obj/debug/%.o)
|
|
@$(call MKDIR,$(@D))
|
|
$(CC) -shared -o $@ $^ $(LDFLAGS_PLAT)
|
|
|
|
obj/debug/%.o: src/%.c
|
|
@$(call MKDIR,$(@D))
|
|
$(CC) $(CFLAGS_BASE) -g -O0 -MMD -MP -c $< -o $@
|
|
|
|
# Release Rules
|
|
$(BIN_DIR)/release/$(FULL_LIB): $(SRCS:src/%.c=obj/release/%.o)
|
|
@$(call MKDIR,$(@D))
|
|
$(CC) -shared $(RELEASE_LDFLAGS) -o $@ $^ $(LDFLAGS_PLAT)
|
|
|
|
obj/release/%.o: src/%.c
|
|
@$(call MKDIR,$(@D))
|
|
$(CC) $(CFLAGS_BASE) -O2 -MMD -MP -c $< -o $@
|
|
|
|
-include $(wildcard obj/debug/*.d)
|
|
-include $(wildcard obj/release/*.d)
|
|
|
|
clean:
|
|
@$(call RMDIR,$(OBJ_DIR))
|
|
@$(call RMDIR,$(BIN_DIR))
|
|
|
|
test: debug
|
|
@echo "=== Building and running stk tests ==="
|
|
@$(MAKE) -C test -f gmake.mk
|
|
|
|
# Installation (Unix only)
|
|
ifneq ($(OS),Windows_NT)
|
|
install: release
|
|
install -d $(LIBDIR) $(INCDIR)
|
|
install -m 755 $(BIN_DIR)/release/$(FULL_LIB) $(LIBDIR)/
|
|
install -m 644 $(INC_DIR)/stk.h $(INCDIR)/
|
|
|
|
uninstall:
|
|
rm -f $(LIBDIR)/$(FULL_LIB)
|
|
rm -f $(INCDIR)/stk.h
|
|
else
|
|
install:
|
|
@echo "make install is not supported on Windows."
|
|
@echo "Copy include/stk.h and bin/release/stk.dll to your project."
|
|
|
|
uninstall:
|
|
@echo "make uninstall is not supported on Windows."
|
|
endif
|