From 79caa11f84ff4c7475238d4474945c8393b3edf9 Mon Sep 17 00:00:00 2001 From: Emile Clark-Boman Date: Wed, 3 Sep 2025 02:32:13 +1000 Subject: [PATCH] configure GNU Make for C library --- Makefile | 31 +++++++++++++++++++++++++++++++ config.mk | 4 ++++ 2 files changed, 35 insertions(+) create mode 100644 Makefile create mode 100644 config.mk diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0002590 --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +.DEFAULT_GOAL := all + +include config.mk + +# === BUILD ENVIRONMENT === +BIN := bin +BUILD := build +LIB := lib +PATHS := $(BUILD) $(BIN) $(LIB) + +# Macro definitions +define mkbin +$(addprefix $(BIN)/,$1) +endef +define mkbuild +$(addprefix $(BUILD)/,$1) +endef +define mklib +$(addprefix $(LIB)/,$1) +endef + +all: $(PATHS) $(BIN)/pw-test +$(BIN)/pw-test: $(call mklib, main.c) + $(CC) $(CFLAGS) -o $(BUILD)/pw-test.o -c $^ + $(LD) -o $@ $(BUILD)/pw-test.o + +$(PATHS): + mkdir -p $@ +.PHONY: clean +clean: + rm -rf $(PATHS) diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..3591f5d --- /dev/null +++ b/config.mk @@ -0,0 +1,4 @@ +# === C Compiler+Linker === +LD = ld +CC = gcc +CFLAGS =