From 474b232b3a998f76b09e249c18ce7283593c2b5b Mon Sep 17 00:00:00 2001 From: Emile Clark-Boman Date: Sat, 27 Sep 2025 20:56:22 +1000 Subject: [PATCH] init gmake --- Makefile | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ config.mk | 23 +++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 Makefile create mode 100644 config.mk diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..56a363a --- /dev/null +++ b/Makefile @@ -0,0 +1,49 @@ +.DEFAULT_GOAL := all + +include config.mk + +# === BUILD ENVIRONMENT === +SRC := src +BIN := bin +BUILD := build + +# === MACRO DEFINITIONS === +define objpath +$(addprefix $(BUILD)/, + $(addsuffix .o, + $(basename $(1)))) +endef +define mkobj +$(foreach DEP, $?, + mkdir -p $(dir $(call objpath, $(DEP))) + $(CC) $(CFLAGS) $1 -o $(call objpath, $(DEP)) -c $(DEP)) + +$(LD) -r $(LDFLAGS) -o $@ $(call objpath, $?) +endef + +# === BUILD TARGETS === +all: tests + +.PHONY: tests +tests: $(BIN) $(BIN)/ct_test + +$(BIN)/ct_test: $(BUILD) $(addprefix $(BUILD)/, ct_test.o term.o surface.o) + $(LD) -o $@ $(filter %.o, $^) + +$(BUILD)/%.o: $(SRC)/%.c + $(CC) $(CFLAGS) -o $@ -c $^ + +$(BUILD) $(BIN): + mkdir -p $@ + +# === DEVELOPMENT TARGETS === +.PHONY: debug +debug: + $(MAKE) all \ + CFLAGS="$(CFLAGS) $(CDEBUG)" \ + CLDFLAGS="$(LDFLAGS) $(LDDEBUG)" + +# === UTILITY TARGETS === +.PHONY: clean +clean: + - rm -rf $(BUILD) $(BIN) vgcore.* 2>/dev/null diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..0e551a9 --- /dev/null +++ b/config.mk @@ -0,0 +1,23 @@ +# -*- make -*- + +# === C Compiler Configuration === +CC := gcc -xc -std=gnu23 +CFLAGS := -Wall -Wextra -O +CDEBUG := -g + +# === Linker Configuration === +LD := ld +LDFLAGS := + +# === GNU Make Configuration === +# GMAKE_JOBS defaults to the number of available logical processors +GMAKE_JOBS := $(shell nproc) +MAKEFLAGS := --jobs=$(GMAKE_JOBS) --output-sync=target + +# === Platform Configuration === +ifeq ($(OS),Windows_NT) # Windows_NT -> XP, 2000, 7, Vista, 10... + PLATFORM := WINDOWS_NT +else + PLATFORM := $(shell uname) +endif +