From c1d82b504627a6a34aca8776ecbab52ec14f05d5 Mon Sep 17 00:00:00 2001 From: Emile Clark-Boman Date: Tue, 9 Sep 2025 11:12:09 +1000 Subject: [PATCH] restructure Make --- Makefile | 27 +++++++++++++++------------ config.mk | 38 ++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index bfa5689..dd17e94 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,6 @@ BIN := bin BUILD := build LIB := lib -LDLIBS := -lm -lc -lpipewire-0.3 - # Macro definitions define mkbin $(addprefix $(BIN)/,$1) @@ -20,21 +18,26 @@ define mklib $(addprefix $(LIB)/,$1) endef -all: $(BUILD) $(BIN) $(BIN)/pw-test +# === BUILD TARGETS === +all: $(BUILD) $(BIN) $(call mkbin,pw-test graph sine) $(BIN)/pw-test: $(call mklib, main.c) - $(CC) $(CFLAGS) -o $(BUILD)/pw-test.o -c $^ - $(LD) $(LDFLAGS) $(LDLIBS) -o $@ $(BUILD)/pw-test.o + $(CCOMPILER) $(CFLAGS) -o $(BUILD)/pw-test.o -c $^ + $(CLINKER) $(LDFLAGS) -o $@ $(BUILD)/pw-test.o $(BUILD) $(BIN): mkdir -p $@ -.PHONY: run -run: - command $(BIN)/pw-test +# === DEVELOPMENT TARGETS === +.PHONY: debug run test +debug: + $(MAKE) all \ + CFLAGS="$(CFLAGS) $(CFLAGS_DBG)" \ + LDFLAGS="$(LDFLAGS) $(LDFLAGS_DBG)" +run: debug + - command $(BIN)/pw-test +test: clean run -.PHONY: test -test: clean all run - +# === UTILITY TARGETS === .PHONY: clean clean: - rm -rf $(BUILD) $(BIN) compile_commands.json + rm -rf $(BUILD) $(BIN) diff --git a/config.mk b/config.mk index 02810dd..ff83c13 100644 --- a/config.mk +++ b/config.mk @@ -1,23 +1,25 @@ -# === C Compiler COnfiguration === -COMPILER := gcc -CFLAGS := -LDFLAGS := +# === C Compiler Configuration === +CC := gcc +# CCOMPILER = $$([ -x "$$(command -v bear)" ] && echo 'bear -- ') $(CC) +CCOMPILER = $(CC) +CFLAGS := -Wall -Wextra -std=gnu23 -O +CFLAGS_DBG := -g -# === Nix Mutations === -ifdef NIX_PATH +# === C Linker Configuration === +CLINKER = $(CC) +LDFLAGS := -lpipewire-0.3 -lm -lc +LDFLAGS_DBG := -g -ifdef NIX_CC -# TODO: will using the Nix gcc-wrapper break Bear? -override COMPILER := $(NIX_CC)/bin/gcc -endif # NIX_CC +# # === Nix Mutations === +# ifdef NIX_PATH -# flake.nix adds NIX_CFLAGS_COMPILER/DORNE_LDFLAGS to env -CFLAGS += $(NIX_CFLAGS_COMPILE) -LDFLAGS += $(DORNE_LDFLAGS) +# ifdef NIX_CC +# # TODO: will using the Nix gcc-wrapper break Bear? +# override COMPILER := $(NIX_CC)/bin/gcc +# endif # NIX_CC -endif # NIX_PATH +# # flake.nix adds NIX_CFLAGS_COMPILER/DORNE_LDFLAGS to env +# CFLAGS += $(NIX_CFLAGS_COMPILE) +# LDFLAGS += $(DORNE_LDFLAGS) - -# C Compiler+Linker Commands -CC = $$([ -x "$$(command -v bear)" ] && echo 'bear -- ') $(COMPILER) -LD = $(COMPILER) +# endif # NIX_PATH