restructure Make

This commit is contained in:
Emile Clark-Boman 2025-09-09 11:12:09 +10:00
parent 2711027dcf
commit c1d82b5046
2 changed files with 35 additions and 30 deletions

View file

@ -7,8 +7,6 @@ BIN := bin
BUILD := build BUILD := build
LIB := lib LIB := lib
LDLIBS := -lm -lc -lpipewire-0.3
# Macro definitions # Macro definitions
define mkbin define mkbin
$(addprefix $(BIN)/,$1) $(addprefix $(BIN)/,$1)
@ -20,21 +18,26 @@ define mklib
$(addprefix $(LIB)/,$1) $(addprefix $(LIB)/,$1)
endef 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) $(BIN)/pw-test: $(call mklib, main.c)
$(CC) $(CFLAGS) -o $(BUILD)/pw-test.o -c $^ $(CCOMPILER) $(CFLAGS) -o $(BUILD)/pw-test.o -c $^
$(LD) $(LDFLAGS) $(LDLIBS) -o $@ $(BUILD)/pw-test.o $(CLINKER) $(LDFLAGS) -o $@ $(BUILD)/pw-test.o
$(BUILD) $(BIN): $(BUILD) $(BIN):
mkdir -p $@ mkdir -p $@
.PHONY: run # === DEVELOPMENT TARGETS ===
run: .PHONY: debug run test
command $(BIN)/pw-test debug:
$(MAKE) all \
.PHONY: test CFLAGS="$(CFLAGS) $(CFLAGS_DBG)" \
test: clean all run LDFLAGS="$(LDFLAGS) $(LDFLAGS_DBG)"
run: debug
- command $(BIN)/pw-test
test: clean run
# === UTILITY TARGETS ===
.PHONY: clean .PHONY: clean
clean: clean:
rm -rf $(BUILD) $(BIN) compile_commands.json rm -rf $(BUILD) $(BIN)

View file

@ -1,23 +1,25 @@
# === C Compiler COnfiguration === # === C Compiler Configuration ===
COMPILER := gcc CC := gcc
CFLAGS := # CCOMPILER = $$([ -x "$$(command -v bear)" ] && echo 'bear -- ') $(CC)
LDFLAGS := CCOMPILER = $(CC)
CFLAGS := -Wall -Wextra -std=gnu23 -O
CFLAGS_DBG := -g
# === Nix Mutations === # === C Linker Configuration ===
ifdef NIX_PATH CLINKER = $(CC)
LDFLAGS := -lpipewire-0.3 -lm -lc
LDFLAGS_DBG := -g
ifdef NIX_CC # # === Nix Mutations ===
# TODO: will using the Nix gcc-wrapper break Bear? # ifdef NIX_PATH
override COMPILER := $(NIX_CC)/bin/gcc
endif # NIX_CC
# flake.nix adds NIX_CFLAGS_COMPILER/DORNE_LDFLAGS to env # ifdef NIX_CC
CFLAGS += $(NIX_CFLAGS_COMPILE) # # TODO: will using the Nix gcc-wrapper break Bear?
LDFLAGS += $(DORNE_LDFLAGS) # 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)
# endif # NIX_PATH
# C Compiler+Linker Commands
CC = $$([ -x "$$(command -v bear)" ] && echo 'bear -- ') $(COMPILER)
LD = $(COMPILER)