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
+77
View File
@@ -0,0 +1,77 @@
.include "config.mk"
PREFIX ?= /usr/local
LIBDIR ?= ${PREFIX}/lib
INCDIR ?= ${PREFIX}/include
STATIC_LIB = lib${LIB_NAME}.a
CFLAGS_BASE = -Wall -Wpedantic -I${.CURDIR}/${INC_DIR} -std=c89
.PHONY: all debug release tools clean test install uninstall
all: debug tools
OBJS_DEBUG = ${SRCS:S|^src/|${.CURDIR}/obj/debug/|:S/.c$/.o/}
OBJS_RELEASE = ${SRCS:S|^src/|${.CURDIR}/obj/release/|:S/.c$/.o/}
TOOL_DEBUG_BINS = ${TOOL_SRCS:S|^tools/|${.CURDIR}/${BIN_DIR}/debug/tools/|:S/.c$//}
TOOL_RELEASE_BINS = ${TOOL_SRCS:S|^tools/|${.CURDIR}/${BIN_DIR}/release/tools/|:S/.c$//}
debug: ${.CURDIR}/${BIN_DIR}/debug/${STATIC_LIB}
release: ${.CURDIR}/${BIN_DIR}/release/${STATIC_LIB}
tools: ${TOOL_DEBUG_BINS}
${.CURDIR}/${BIN_DIR}/debug/${STATIC_LIB}: ${OBJS_DEBUG}
@mkdir -p ${.TARGET:H}
ar rcs ${.TARGET} ${.ALLSRC}
${.CURDIR}/${BIN_DIR}/release/${STATIC_LIB}: ${OBJS_RELEASE}
@mkdir -p ${.TARGET:H}
ar rcs ${.TARGET} ${.ALLSRC}
.for _src in ${SRCS}
${.CURDIR}/obj/debug/${_src:S|^src/||:S/.c$/.o/}: ${.CURDIR}/${_src}
@mkdir -p ${.TARGET:H}
${CC} ${CFLAGS_BASE} -g -O0 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
${.CURDIR}/obj/release/${_src:S|^src/||:S/.c$/.o/}: ${.CURDIR}/${_src}
@mkdir -p ${.TARGET:H}
${CC} ${CFLAGS_BASE} -O2 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
.endfor
.for _src in ${TOOL_SRCS}
${.CURDIR}/obj/debug/tools/${_src:S|^tools/||:S/.c$/.o/}: ${.CURDIR}/${_src}
@mkdir -p ${.TARGET:H}
${CC} ${CFLAGS_BASE} -g -O0 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
${.CURDIR}/${BIN_DIR}/debug/tools/${_src:S|^tools/||:S/.c$//}: ${.CURDIR}/obj/debug/tools/${_src:S|^tools/||:S/.c$/.o/} ${.CURDIR}/${BIN_DIR}/debug/${STATIC_LIB}
@mkdir -p ${.TARGET:H}
${CC} -o ${.TARGET} ${.CURDIR}/obj/debug/tools/${_src:S|^tools/||:S/.c$/.o/} -L${.CURDIR}/${BIN_DIR}/debug -l${LIB_NAME}
${.CURDIR}/obj/release/tools/${_src:S|^tools/||:S/.c$/.o/}: ${.CURDIR}/${_src}
@mkdir -p ${.TARGET:H}
${CC} ${CFLAGS_BASE} -O2 -MMD -MP -MT ${.TARGET} -MF ${.TARGET:S/.o$/.d/} -c ${.ALLSRC} -o ${.TARGET}
${.CURDIR}/${BIN_DIR}/release/tools/${_src:S|^tools/||:S/.c$//}: ${.CURDIR}/obj/release/tools/${_src:S|^tools/||:S/.c$/.o/} ${.CURDIR}/${BIN_DIR}/release/${STATIC_LIB}
@mkdir -p ${.TARGET:H}
${CC} -O2 -s -o ${.TARGET} ${.CURDIR}/obj/release/tools/${_src:S|^tools/||:S/.c$/.o/} -L${.CURDIR}/${BIN_DIR}/release -l${LIB_NAME}
.endfor
clean:
rm -rf ${.CURDIR}/${OBJ_DIR} ${.CURDIR}/${BIN_DIR}
test: debug
@echo "=== Building and running fpk tests ==="
cd ${.CURDIR}/test && ${MAKE} -f bmake.mk
install:
@test -f ${.CURDIR}/${BIN_DIR}/release/${STATIC_LIB} || { echo "Run 'make -f bmake.mk release' before installing."; exit 1; }
install -d ${LIBDIR} ${INCDIR}/fpk
install -m 644 ${.CURDIR}/${BIN_DIR}/release/${STATIC_LIB} ${LIBDIR}/
install -m 644 ${.CURDIR}/${INC_DIR}/fpk.h ${INCDIR}/fpk/
install -m 644 ${.CURDIR}/${INC_DIR}/fpk_version.h ${INCDIR}/fpk/
uninstall:
rm -f ${LIBDIR}/${STATIC_LIB}
rm -rf ${INCDIR}/fpk
Executable
+2
View File
@@ -0,0 +1,2 @@
@echo off
make -f gmake.mk %*
Executable
+39
View File
@@ -0,0 +1,39 @@
#!/bin/sh
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
if [ "$OS" = "linux" ]; then
MK_FILE="gmake.mk"
else
MK_FILE="bmake.mk"
fi
HAS_INSTALL=0
HAS_UNINSTALL=0
for arg in "$@"; do
case "$arg" in
install) HAS_INSTALL=1 ;;
uninstall) HAS_UNINSTALL=1 ;;
esac
done
if [ "$HAS_INSTALL" = "1" ] || [ "$HAS_UNINSTALL" = "1" ]; then
if [ "$HAS_INSTALL" = "1" ]; then
make -f "$MK_FILE" release
fi
if [ "$(id -u)" = "0" ]; then
PRIV=""
elif command -v doas > /dev/null 2>&1; then
PRIV="doas"
elif command -v sudo > /dev/null 2>&1; then
PRIV="sudo"
else
echo "error: install requires root. neither doas nor sudo found." >&2
exit 1
fi
$PRIV make -f "$MK_FILE" "$@"
else
make -f "$MK_FILE" "$@"
fi
+6
View File
@@ -0,0 +1,6 @@
-xc
-std=c89
-Wall
-Wpedantic
-Iinclude
+13
View File
@@ -0,0 +1,13 @@
SRC_DIR = src
INC_DIR = include
OBJ_DIR = obj
BIN_DIR = bin
LIB_NAME = fpk
STATIC_LIB = lib$(LIB_NAME).a
SRCS = src/fpk.c
TOOL_SRCS = \
tools/fpack.c \
tools/funpack.c
+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