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 -Wconversion -Werror 11CFLAGS += -Wno-switch-enum -Wno-double-promotion 12CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstrict-overflow \ 13 -Wstrict-prototypes -Wswitch-default -Wundef 14#DEBUG = -O0 -g 15CFLAGS += $(DEBUG) 16UNITY_SUPPORT_64 = -D UNITY_SUPPORT_64 17UNITY_INCLUDE_DOUBLE = -D UNITY_INCLUDE_DOUBLE 18DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy 19DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\) 20DEFINES += -D UNITY_OUTPUT_FLUSH=flushSpy 21DEFINES += -D UNITY_OUTPUT_FLUSH_HEADER_DECLARATION=flushSpy\(void\) 22DEFINES += $(UNITY_SUPPORT_64) $(UNITY_INCLUDE_DOUBLE) 23SRC = ../src/unity.c tests/testunity.c build/testunityRunner.c 24INC_DIR = -I ../src 25COV_FLAGS = -fprofile-arcs -ftest-coverage -I ../../src 26BUILD_DIR = build 27TARGET = build/testunity-cov.exe 28 29# To generate coverage, call 'make -s', the default target runs. 30# For verbose output of all the tests, run 'make test'. 31default: coverage 32.PHONY: default coverage test clean 33coverage: $(BUILD_DIR)/testunityRunner.c 34 cd $(BUILD_DIR) && \ 35 $(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC), ../$i) $(COV_FLAGS) -o ../$(TARGET) 36 rm -f $(BUILD_DIR)/*.gcda 37 ./$(TARGET) | grep 'Tests\|]]]' -A1 38 cd $(BUILD_DIR) && \ 39 gcov unity.c | head -3 40 grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true 41 42test: $(BUILD_DIR)/testunityRunner.c 43 $(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC) -o $(TARGET) 44 ./$(TARGET) 45 46# Compile only, for testing that preprocessor detection works 47UNITY_C_ONLY =-c ../src/unity.c -o $(BUILD_DIR)/unity.o 48intDetection: 49 $(CC) $(CFLAGS) $(INC_DIR) $(UNITY_C_ONLY) -D UNITY_EXCLUDE_STDINT_H 50 $(CC) $(CFLAGS) $(INC_DIR) $(UNITY_C_ONLY) -D UNITY_EXCLUDE_LIMITS_H 51 52$(BUILD_DIR)/testunityRunner.c: tests/testunity.c | $(BUILD_DIR) 53 awk $(AWK_SCRIPT) tests/testunity.c > $@ 54 55AWK_SCRIPT=\ 56 '/^void test/{ declarations[d++]=$$0; gsub(/\(?void\)? ?/,""); tests[t++]=$$0; line[u++]=NR } \ 57 END{ print "\#include \"unity.h\" /* Autogenerated by awk in Makefile */" ; \ 58 for (i=0; i<d; i++) { print declarations[i] ";" } \ 59 print "int main(void)\n{\n UnityBegin(\"" FILENAME "\");" ; \ 60 for (i=0; i<t; i++) { print " RUN_TEST(" tests[i] ", " line[i] ");" } \ 61 print " return UNITY_END();\n}" }' 62 63$(BUILD_DIR): 64 mkdir -p $(BUILD_DIR) 65 66clean: 67 rm -f $(TARGET) $(BUILD_DIR)/*.gc* $(BUILD_DIR)/testunityRunner.c 68