1CC = gcc 2ifeq ($(shell uname -s), Darwin) 3CC = clang 4endif 5ifeq ($(findstring clang, $(CC)), clang) 6E = -Weverything 7CFLAGS += $E -Wno-unknown-warning-option -Wno-missing-prototypes 8CFLAGS += -Wno-unused-macros -Wno-padded -Wno-missing-noreturn 9endif 10CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror 11#CFLAGS += -Wconversion #disabled because if falsely complains about the isinf and isnan macros 12CFLAGS += -Wno-switch-enum -Wno-double-promotion 13CFLAGS += -Wno-poison-system-directories 14CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstrict-overflow \ 15 -Wstrict-prototypes -Wswitch-default -Wundef 16#DEBUG = -O0 -g 17CFLAGS += $(DEBUG) 18UNITY_SUPPORT_64 = -D UNITY_SUPPORT_64 19UNITY_INCLUDE_DOUBLE = -D UNITY_INCLUDE_DOUBLE 20DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy 21DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\) 22DEFINES += -D UNITY_OUTPUT_FLUSH=flushSpy 23DEFINES += -D UNITY_OUTPUT_FLUSH_HEADER_DECLARATION=flushSpy\(void\) 24DEFINES += $(UNITY_SUPPORT_64) $(UNITY_INCLUDE_DOUBLE) 25SRC1 = ../src/unity.c tests/test_unity_arrays.c build/test_unity_arraysRunner.c 26SRC2 = ../src/unity.c tests/test_unity_core.c build/test_unity_coreRunner.c 27SRC3 = ../src/unity.c tests/test_unity_doubles.c build/test_unity_doublesRunner.c 28SRC4 = ../src/unity.c tests/test_unity_floats.c build/test_unity_floatsRunner.c 29SRC5 = ../src/unity.c tests/test_unity_integers.c build/test_unity_integersRunner.c 30SRC6 = ../src/unity.c tests/test_unity_integers_64.c build/test_unity_integers_64Runner.c 31SRC7 = ../src/unity.c tests/test_unity_memory.c build/test_unity_memoryRunner.c 32SRC8 = ../src/unity.c tests/test_unity_strings.c build/test_unity_stringsRunner.c 33INC_DIR = -I ../src 34COV_FLAGS = -fprofile-arcs -ftest-coverage -I ../../src 35BUILD_DIR = build 36TARGET = build/testunity-cov.exe 37 38# To generate coverage, call 'make -s', the default target runs. 39# For verbose output of all the tests, run 'make test'. 40default: coverage 41.PHONY: default coverage test clean 42coverage: $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6) $(SRC7) $(SRC8) 43 cd $(BUILD_DIR) && \ 44 $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC1), ../$i) $(COV_FLAGS) -o ../$(TARGET) 45 rm -f $(BUILD_DIR)/*.gcda 46 ./$(TARGET) | grep 'Tests\|]]]' -A1 47 cd $(BUILD_DIR) && \ 48 gcov unity.c | head -3 49 grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true 50 cd $(BUILD_DIR) && \ 51 $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC2), ../$i) $(COV_FLAGS) -o ../$(TARGET) 52 rm -f $(BUILD_DIR)/*.gcda 53 ./$(TARGET) | grep 'Tests\|]]]' -A1 54 cd $(BUILD_DIR) && \ 55 gcov unity.c | head -3 56 grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true 57 cd $(BUILD_DIR) && \ 58 $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC3), ../$i) $(COV_FLAGS) -o ../$(TARGET) 59 rm -f $(BUILD_DIR)/*.gcda 60 ./$(TARGET) | grep 'Tests\|]]]' -A1 61 cd $(BUILD_DIR) && \ 62 gcov unity.c | head -3 63 grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true 64 cd $(BUILD_DIR) && \ 65 $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC4), ../$i) $(COV_FLAGS) -o ../$(TARGET) 66 rm -f $(BUILD_DIR)/*.gcda 67 ./$(TARGET) | grep 'Tests\|]]]' -A1 68 cd $(BUILD_DIR) && \ 69 gcov unity.c | head -3 70 grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true 71 cd $(BUILD_DIR) && \ 72 $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC5), ../$i) $(COV_FLAGS) -o ../$(TARGET) 73 rm -f $(BUILD_DIR)/*.gcda 74 ./$(TARGET) | grep 'Tests\|]]]' -A1 75 cd $(BUILD_DIR) && \ 76 gcov unity.c | head -3 77 grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true 78 cd $(BUILD_DIR) && \ 79 $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC6), ../$i) $(COV_FLAGS) -o ../$(TARGET) 80 rm -f $(BUILD_DIR)/*.gcda 81 ./$(TARGET) | grep 'Tests\|]]]' -A1 82 cd $(BUILD_DIR) && \ 83 gcov unity.c | head -3 84 grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true 85 cd $(BUILD_DIR) && \ 86 $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC7), ../$i) $(COV_FLAGS) -o ../$(TARGET) 87 rm -f $(BUILD_DIR)/*.gcda 88 ./$(TARGET) | grep 'Tests\|]]]' -A1 89 cd $(BUILD_DIR) && \ 90 gcov unity.c | head -3 91 grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true 92 cd $(BUILD_DIR) && \ 93 $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC8), ../$i) $(COV_FLAGS) -o ../$(TARGET) 94 rm -f $(BUILD_DIR)/*.gcda 95 ./$(TARGET) | grep 'Tests\|]]]' -A1 96 cd $(BUILD_DIR) && \ 97 gcov unity.c | head -3 98 grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true 99 100test: $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6) $(SRC7) $(SRC8) 101 $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC1) -o $(TARGET) 102 ./$(TARGET) 103 $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC2) -o $(TARGET) 104 ./$(TARGET) 105 $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC3) -o $(TARGET) 106 ./$(TARGET) 107 $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC4) -o $(TARGET) 108 ./$(TARGET) 109 $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC5) -o $(TARGET) 110 ./$(TARGET) 111 $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC6) -o $(TARGET) 112 ./$(TARGET) 113 $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC7) -o $(TARGET) 114 ./$(TARGET) 115 $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC8) -o $(TARGET) 116 ./$(TARGET) 117 118# Compile only, for testing that preprocessor detection works 119UNITY_C_ONLY =-c ../src/unity.c -o $(BUILD_DIR)/unity.o 120intDetection: 121 $(CC) $(CFLAGS) $(INC_DIR) $(UNITY_C_ONLY) -D UNITY_EXCLUDE_STDINT_H 122 $(CC) $(CFLAGS) $(INC_DIR) $(UNITY_C_ONLY) -D UNITY_EXCLUDE_LIMITS_H 123 124$(BUILD_DIR)/test_unity_arraysRunner.c: tests/test_unity_arrays.c | $(BUILD_DIR) 125 awk $(AWK_SCRIPT) tests/test_unity_arrays.c > $@ 126 127$(BUILD_DIR)/test_unity_coreRunner.c: tests/test_unity_core.c | $(BUILD_DIR) 128 awk $(AWK_SCRIPT) tests/test_unity_core.c > $@ 129 130$(BUILD_DIR)/test_unity_doublesRunner.c: tests/test_unity_doubles.c | $(BUILD_DIR) 131 awk $(AWK_SCRIPT) tests/test_unity_doubles.c > $@ 132 133$(BUILD_DIR)/test_unity_floatsRunner.c: tests/test_unity_floats.c | $(BUILD_DIR) 134 awk $(AWK_SCRIPT) tests/test_unity_floats.c > $@ 135 136$(BUILD_DIR)/test_unity_integersRunner.c: tests/test_unity_integers.c | $(BUILD_DIR) 137 awk $(AWK_SCRIPT) tests/test_unity_integers.c > $@ 138 139$(BUILD_DIR)/test_unity_integers_64Runner.c: tests/test_unity_integers_64.c | $(BUILD_DIR) 140 awk $(AWK_SCRIPT) tests/test_unity_integers_64.c > $@ 141 142$(BUILD_DIR)/test_unity_memoryRunner.c: tests/test_unity_memory.c | $(BUILD_DIR) 143 awk $(AWK_SCRIPT) tests/test_unity_memory.c > $@ 144 145$(BUILD_DIR)/test_unity_stringsRunner.c: tests/test_unity_strings.c | $(BUILD_DIR) 146 awk $(AWK_SCRIPT) tests/test_unity_strings.c > $@ 147 148AWK_SCRIPT=\ 149 '/^void test/{ declarations[d++]=$$0; gsub(/\(?void\)? ?/,""); tests[t++]=$$0; line[u++]=NR } \ 150 END{ print "\#include \"unity.h\" /* Autogenerated by awk in Makefile */" ; \ 151 for (i=0; i<d; i++) { print declarations[i] ";" } \ 152 print "int main(void)\n{\n UnityBegin(\"" FILENAME "\");" ; \ 153 for (i=0; i<t; i++) { print " RUN_TEST(" tests[i] ", " line[i] ");" } \ 154 print " return UNITY_END();\n}" }' 155 156$(BUILD_DIR): 157 mkdir -p $(BUILD_DIR) 158 159clean: 160 rm -f $(TARGET) $(BUILD_DIR)/*.gc* $(BUILD_DIR)/test_unity_*Runner.c 161