From 36a9cbb2e2cb4e1e0a90cd410e4f31bcfea5fa47 Mon Sep 17 00:00:00 2001 From: leonmavr <0xleo.git@gmail.com> Date: Fri, 27 Sep 2024 03:35:24 +0200 Subject: [PATCH] Simplify makefile --- Makefile | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 47743b6..9411830 100644 --- a/Makefile +++ b/Makefile @@ -7,36 +7,30 @@ TEST_DIR = test CFLAGS = -g -I$(INC_DIR) -Wall LDFLAGS = -lm TEST_SRC = $(wildcard $(TEST_DIR)/*.c) -TARGET_SRC = $(wildcard $(TARGET_DIR)/*.c) -# If `test` is passed as a cmd argument, extend flags to handle unit tests ifeq ($(MAKECMDGOALS), test) - SRC = $(wildcard $(SRC_DIR)/*.c) - TARGETS = $(patsubst $(TEST_DIR)/%.c,%,$(TEST_SRC)) - TARGET_DIR = test - OBJECTS = $(SRC:%.c=%.o) $(TEST_SRC) + # If `test` is passed as a cmd argument, extend flags to handle unit tests + TARGET_SRC = $(wildcard $(TEST_DIR)/*.c) + TARGETS = $(patsubst $(TEST_DIR)/%.c,%,$(TEST_SRC)) + TARGET_DIR = test else - # Strip file path so each demo source gets a target, - # e.g. examples/01_demo.c -> 01_demo - TARGETS = $(patsubst $(TARGET_DIR)/%.c, %, $(TARGET_SRC)) - SRC = $(wildcard $(SRC_DIR)/*.c) - OBJECTS = $(SRC:%.c=%.o) + # Strip file path so each demo source gets a target, + # e.g. examples/01_demo.c -> 01_demo + TARGET_SRC = $(wildcard $(TARGET_DIR)/*.c) + TARGETS = $(patsubst $(TARGET_DIR)/%.c, %, $(TARGET_SRC)) + TARGET_DIR = examples endif - # What to do by default (no arguments) all: $(TARGETS) +test: all $(TARGETS): %: $(TARGET_DIR)/%.c $(wildcard $(SRC_DIR)/*.c) $(CC) $(CFLAGS) $(SRC_DIR)/*.c $< -o $@ $(LDFLAGS) -%.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ - -test: all .PHONY: clean RM = rm -rf clean: - $(RM) $(TARGETS) $(SRC_DIR)/*.o test/*.o tests + $(RM) $(TARGETS) $(SRC_DIR)/*.o $(TARGET_DIR)/*.o tests