From 8314d58c4c08d6f51cfdd3324829af1f24618684 Mon Sep 17 00:00:00 2001 From: leonmavr <0xleo.git@gmail.com> Date: Thu, 26 Sep 2024 21:31:41 +0200 Subject: [PATCH] WIP: try to fix Makefile to compile both examples and tests --- Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index a8587f0..b97bc4e 100644 --- a/Makefile +++ b/Makefile @@ -14,14 +14,17 @@ EXAMPLES = $(patsubst $(EXAMPLES_DIR)/%.c,%,$(EXAMPLES_SRC)) # If `test` is passed as a cmd argument, extend flags to handle unit tests ifeq ($(MAKECMDGOALS), test) CFLAGS += -DRUN_UNIT_TESTS - TARGET = test/test - SRC = $(wildcard $(SRC_DIR)/*.c) $(TEST_SRC) + SRC = $(wildcard $(SRC_DIR)/*.c) + EXAMPLES = $(patsubst $(TEST_DIR)/%.c,%,$(TEST_SRC)) + EXAMPLES_DIR = test + TARGET = $(EXAMPLES) + OBJECTS = $(SRC:%.c=%.o) $(TEST_SRC) else TARGET = $(EXAMPLES) SRC = $(wildcard $(SRC_DIR)/*.c) + OBJECTS = $(SRC:%.c=%.o) endif -OBJECTS = $(SRC:%.c=%.o) # What to do by default (no arguments) all: $(EXAMPLES) @@ -32,11 +35,8 @@ $(EXAMPLES): %: $(EXAMPLES_DIR)/%.c $(wildcard $(SRC_DIR)/*.c) %.o: %.c $(CC) $(CFLAGS) -c $< -o $@ -# Phony to always rerun it - -test: $(TARGET) - ./$(TARGET) +test: all .PHONY: clean RM = rm -rf