build: add hand-rolled make scaffold (gmake/bmake/build.sh/build.bat)

Static-lib-only build (libfpk.a, no shared/dynamic target), plus a
tools/ build path for fpack/funpack linked against the just-built
static lib. Matches stk's C89 build style; no library source yet.
This commit is contained in:
2026-09-13 14:38:23 +02:00
parent 59e8af1517
commit d5e48c4019
6 changed files with 238 additions and 0 deletions
+101
View File
@@ -0,0 +1,101 @@
include config.mk
ifeq ($(OS),Windows_NT)
SHELL := cmd.exe
STATIC_LIB := lib$(LIB_NAME).a
CFLAGS_PLAT :=
MKDIR = if not exist $(subst /,\,$(1)) mkdir $(subst /,\,$(1))
RMDIR = if exist $(subst /,\,$(1)) rd /s /q $(subst /,\,$(1))
TOOL_EXT := .exe
else
STATIC_LIB := lib$(LIB_NAME).a
CFLAGS_PLAT :=
MKDIR = mkdir -p $(1)
RMDIR = rm -rf $(1)
TOOL_EXT :=
endif
RELEASE_LDFLAGS := -s
CFLAGS_BASE := -Wall -Wpedantic -I$(INC_DIR) -std=c89 $(CFLAGS_PLAT)
PREFIX ?= /usr
LIBDIR ?= $(PREFIX)/lib
INCDIR ?= $(PREFIX)/include
TOOL_DEBUG_BINS := $(TOOL_SRCS:tools/%.c=$(BIN_DIR)/debug/tools/%$(TOOL_EXT))
TOOL_RELEASE_BINS := $(TOOL_SRCS:tools/%.c=$(BIN_DIR)/release/tools/%$(TOOL_EXT))
.PHONY: all debug release tools clean test install uninstall
all: debug tools
debug: $(BIN_DIR)/debug/$(STATIC_LIB)
release: $(BIN_DIR)/release/$(STATIC_LIB)
tools: $(TOOL_DEBUG_BINS)
$(BIN_DIR)/debug/$(STATIC_LIB): $(SRCS:src/%.c=obj/debug/%.o)
@$(call MKDIR,$(@D))
ar rcs $@ $^
obj/debug/%.o: src/%.c
@$(call MKDIR,$(@D))
$(CC) $(CFLAGS_BASE) -g -O0 -MMD -MP -c $< -o $@
$(BIN_DIR)/release/$(STATIC_LIB): $(SRCS:src/%.c=obj/release/%.o)
@$(call MKDIR,$(@D))
ar rcs $@ $^
obj/release/%.o: src/%.c
@$(call MKDIR,$(@D))
$(CC) $(CFLAGS_BASE) -O2 -MMD -MP -c $< -o $@
obj/debug/tools/%.o: tools/%.c
@$(call MKDIR,$(@D))
$(CC) $(CFLAGS_BASE) -g -O0 -MMD -MP -c $< -o $@
$(BIN_DIR)/debug/tools/%$(TOOL_EXT): obj/debug/tools/%.o $(BIN_DIR)/debug/$(STATIC_LIB)
@$(call MKDIR,$(@D))
$(CC) -o $@ $< -L$(BIN_DIR)/debug -l$(LIB_NAME)
obj/release/tools/%.o: tools/%.c
@$(call MKDIR,$(@D))
$(CC) $(CFLAGS_BASE) -O2 -MMD -MP -c $< -o $@
$(BIN_DIR)/release/tools/%$(TOOL_EXT): obj/release/tools/%.o $(BIN_DIR)/release/$(STATIC_LIB)
@$(call MKDIR,$(@D))
$(CC) $(RELEASE_LDFLAGS) -o $@ $< -L$(BIN_DIR)/release -l$(LIB_NAME)
-include $(wildcard obj/debug/*.d)
-include $(wildcard obj/debug/tools/*.d)
-include $(wildcard obj/release/*.d)
-include $(wildcard obj/release/tools/*.d)
clean:
@$(call RMDIR,$(OBJ_DIR))
@$(call RMDIR,$(BIN_DIR))
test: debug
@echo "=== Building and running fpk tests ==="
@$(MAKE) -C test -f gmake.mk
ifneq ($(OS),Windows_NT)
install:
@test -f $(BIN_DIR)/release/$(STATIC_LIB) || { echo "Run 'make -f gmake.mk release' before installing."; exit 1; }
install -d $(LIBDIR) $(INCDIR)/fpk
install -m 644 $(BIN_DIR)/release/$(STATIC_LIB) $(LIBDIR)/
install -m 644 $(INC_DIR)/fpk.h $(INCDIR)/fpk/
install -m 644 $(INC_DIR)/fpk_version.h $(INCDIR)/fpk/
uninstall:
rm -f $(LIBDIR)/$(STATIC_LIB)
rm -rf $(INCDIR)/fpk
else
install:
@echo "make install is not supported on Windows."
@echo "Copy include/ directory contents to your_project/include/fpk/"
@echo "Copy bin/release/libfpk.a to your project's lib directory."
uninstall:
@echo "make uninstall is not supported on Windows."
endif