Skip to content

Commit

Permalink
Use make primitives for enumerating source files
Browse files Browse the repository at this point in the history
  • Loading branch information
rhargreaves committed Sep 8, 2024
1 parent 36607c8 commit 97bf161
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,16 @@ LDFLAGS+=$(foreach MOCK,$(MD_MOCKS),-Wl,--wrap=$(MOCK))
SYSTEM_TEST_LDFLAGS=$(LDFLAGS)
UNIT_TEST_LDFLAGS=$(LDFLAGS) $(foreach MOCK,$(MOCKS),-Wl,--wrap=$(MOCK))

SRC=$(shell find ../src/* -maxdepth 0 -type f -name '*.c' ! -name '*main.c*' -printf '%f\n')
SRC+=$(shell find ../src/comm/* -maxdepth 0 -type f -name '*.c' ! -name '*main.c*' -printf 'comm/%f\n')
COMMON_TEST_SRC=$(shell find * -maxdepth 0 -type f -name '*.c' -print)
UNIT_TEST_SRC=$(shell find ./unit/* -maxdepth 0 -type f -name '*.c' -print)
SYSTEM_TEST_SRC=$(shell find ./system/* -maxdepth 0 -type f -name '*.c' -print)
SRC=$(wildcard ../src/*.c)
SRC+=$(wildcard ../src/*/*.c)
SRC:=$(filter-out ../src/boot/rom_head.c,$(SRC))
SRC:=$(filter-out ../src/main.c,$(SRC))

SRC_OBJ=$(patsubst %.c,obj/%.o,$(SRC))
COMMON_TEST_SRC=$(wildcard *.c)
UNIT_TEST_SRC+=$(wildcard unit/*.c)
SYSTEM_TEST_SRC+=$(wildcard system/*.c)

SRC_OBJ=$(patsubst ../src/%.c,obj/%.o,$(SRC))
COMMON_TEST_OBJ=$(patsubst %.c,obj/%.o,$(COMMON_TEST_SRC))
UNIT_TEST_OBJ=$(patsubst %.c,obj/%.o,$(UNIT_TEST_SRC))
SYSTEM_TEST_OBJ=$(patsubst %.c,obj/%.o,$(SYSTEM_TEST_SRC))
Expand All @@ -237,20 +240,18 @@ system: $(SYSTEM_TESTS_TARGET)
$(SRC_OBJ): | $(OBJ_DIR) $(CMOCKA_DIR)

$(OBJ_DIR):
mkdir -p $@
mkdir -p $@/comm
mkdir -p $@/unit
mkdir -p $@/system
mkdir -p $(dir $@)

$(OBJ_DIR)/%.o: %.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@

$(UNIT_TESTS_TARGET): $(SRC_OBJ) $(UNIT_TEST_OBJ) $(COMMON_TEST_OBJ)
mkdir -p $(BIN_DIR)
mkdir -p $(dir $@)
$(CC) -o $@ $^ $(UNIT_TEST_LDFLAGS)

$(SYSTEM_TESTS_TARGET): $(SRC_OBJ) $(SYSTEM_TEST_OBJ) $(COMMON_TEST_OBJ)
mkdir -p $(BIN_DIR)
mkdir -p $(dir $@)
$(CC) -o $@ $^ $(SYSTEM_TEST_LDFLAGS)

$(CMOCKA_DIR):
Expand Down

0 comments on commit 97bf161

Please sign in to comment.