From cc737e8225c97367fc82bcd9de445ec2cddbc80a Mon Sep 17 00:00:00 2001 From: tmeissner Date: Mon, 29 Jun 2015 23:09:28 +0200 Subject: [PATCH] seperated tests target into seperate targets for running tests and coverage --- tdd_for_embedded_c/chapter04/Makefile | 45 +++++++++++++++------------ 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/tdd_for_embedded_c/chapter04/Makefile b/tdd_for_embedded_c/chapter04/Makefile index e9c6c6b..1924789 100644 --- a/tdd_for_embedded_c/chapter04/Makefile +++ b/tdd_for_embedded_c/chapter04/Makefile @@ -6,22 +6,22 @@ #We try to detect the OS we are running on, and adjust commands as needed ifeq ($(OS),Windows_NT) - CLEANUP = del /F /Q - MKDIR = mkdir - TARGET_EXTENSION=.exe + CLEANUP := del /F /Q + MKDIR := mkdir + TARGET_EXTENSION := .exe else - CLEANUP = rm -rf - MKDIR = mkdir -p - TARGET_EXTENSION= + CLEANUP := rm -rf + MKDIR := mkdir -p + TARGET_EXTENSION := endif -UNITY_ROOT=../../../../Unity -C_COMPILER=gcc +UNITY_ROOT := ../../../../Unity +C_COMPILER := gcc CFLAGS = -std=c11 CFLAGS += -Wall -#CFLAGS += -Wextra +CFLAGS += -Wextra CFLAGS += -Werror CFLAGS += -Wpointer-arith CFLAGS += -Wcast-align @@ -40,9 +40,10 @@ CFLAGS += -g CFLAGS += -ftest-coverage CFLAGS += -fprofile-arcs -TARGET_BASE=test_leddriver -TARGET = $(TARGET_BASE)$(TARGET_EXTENSION) -SRC_FILES=\ +TARGET_BASE := test_leddriver +TARGET = $(TARGET_BASE)$(TARGET_EXTENSION) + +SRC_FILES = \ $(UNITY_ROOT)/extras/fixture/src/unity_fixture.c \ $(UNITY_ROOT)/src/unity.c \ ../test/LedDriverTest.c \ @@ -51,19 +52,24 @@ SRC_FILES=\ ../src/LedDriver.c \ ../mocks/RuntimeErrorStub.c -INC_DIRS=-I$(UNITY_ROOT)/src -I$(UNITY_ROOT)/extras/fixture/src -SYMBOLS= +INC_DIRS = -I$(UNITY_ROOT)/src -I$(UNITY_ROOT)/extras/fixture/src +SYMBOLS = -all: clean tests +all: clean tests cover -.PHONY: tests -tests: build/$(TARGET) - build/$(TARGET): test/*.c src/*.h src/*.c + @$(MKDIR) build + @$(MKDIR) build/cover @echo "Compiling"; cd build; $(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES) -o $(TARGET) + +.PHONY: tests +tests: build/$(TARGET) @echo "Running tests"; ./build/$(TARGET) + +.PHONY: cover +cover: tests @echo "Preparing coverage"; cp build/LedDriver.gc* src/ @echo "Running coverage"; cd src; gcovr -r . -b -p --html --html-details -o ../build/cover/test.html @echo "Clearing intermediate files"; rm src/*.gc* build/*.gc* @@ -71,5 +77,4 @@ build/$(TARGET): test/*.c src/*.h src/*.c .PHONY: clean clean: - @echo "Cleaning $<"; $(CLEANUP) build/$(TARGET) build/*.* build/cover/* - + @echo "Cleaning $<"; $(CLEANUP) build