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