Makefile 6.7 KB
Newer Older
1
CC = gcc
2
ifeq ($(shell uname -s), Darwin)
3
CC = clang
4
endif
5 6 7 8
ifeq ($(findstring clang, $(CC)), clang)
E = -Weverything
CFLAGS += $E -Wno-unknown-warning-option -Wno-missing-prototypes
CFLAGS += -Wno-unused-macros -Wno-padded -Wno-missing-noreturn
N
nah 已提交
9
endif
10 11
CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror
#CFLAGS += -Wconversion #disabled because if falsely complains about the isinf and isnan macros
12
CFLAGS += -Wno-switch-enum -Wno-double-promotion
13
CFLAGS += -Wno-poison-system-directories
14 15
CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstrict-overflow \
          -Wstrict-prototypes -Wswitch-default -Wundef
N
nah 已提交
16
#DEBUG = -O0 -g
17
CFLAGS += $(DEBUG)
18 19
UNITY_SUPPORT_64 = -D UNITY_SUPPORT_64
UNITY_INCLUDE_DOUBLE = -D UNITY_INCLUDE_DOUBLE
20
DEFINES =  -D UNITY_OUTPUT_CHAR=putcharSpy
21
DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\)
F
Fabian Zahn 已提交
22 23
DEFINES += -D UNITY_OUTPUT_FLUSH=flushSpy
DEFINES += -D UNITY_OUTPUT_FLUSH_HEADER_DECLARATION=flushSpy\(void\)
24
DEFINES += $(UNITY_SUPPORT_64) $(UNITY_INCLUDE_DOUBLE)
25 26 27 28 29 30 31 32
SRC1 = ../src/unity.c tests/test_unity_arrays.c build/test_unity_arraysRunner.c
SRC2 = ../src/unity.c tests/test_unity_core.c build/test_unity_coreRunner.c
SRC3 = ../src/unity.c tests/test_unity_doubles.c build/test_unity_doublesRunner.c
SRC4 = ../src/unity.c tests/test_unity_floats.c build/test_unity_floatsRunner.c
SRC5 = ../src/unity.c tests/test_unity_integers.c build/test_unity_integersRunner.c
SRC6 = ../src/unity.c tests/test_unity_integers_64.c build/test_unity_integers_64Runner.c
SRC7 = ../src/unity.c tests/test_unity_memory.c build/test_unity_memoryRunner.c
SRC8 = ../src/unity.c tests/test_unity_strings.c build/test_unity_stringsRunner.c
33 34 35 36 37 38 39 40
INC_DIR = -I ../src
COV_FLAGS = -fprofile-arcs -ftest-coverage -I ../../src
BUILD_DIR = build
TARGET = build/testunity-cov.exe

# To generate coverage, call 'make -s', the default target runs.
# For verbose output of all the tests, run 'make test'.
default: coverage
41
.PHONY: default coverage test clean
42
coverage: $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6) $(SRC7) $(SRC8)
43
	cd $(BUILD_DIR) && \
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
	$(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC1), ../$i) $(COV_FLAGS) -o ../$(TARGET)
	rm -f $(BUILD_DIR)/*.gcda
	./$(TARGET) | grep 'Tests\|]]]' -A1
	cd $(BUILD_DIR) && \
	gcov unity.c | head -3
	grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true
	cd $(BUILD_DIR) && \
	$(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC2), ../$i) $(COV_FLAGS) -o ../$(TARGET)
	rm -f $(BUILD_DIR)/*.gcda
	./$(TARGET) | grep 'Tests\|]]]' -A1
	cd $(BUILD_DIR) && \
	gcov unity.c | head -3
	grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true
	cd $(BUILD_DIR) && \
	$(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC3), ../$i) $(COV_FLAGS) -o ../$(TARGET)
	rm -f $(BUILD_DIR)/*.gcda
	./$(TARGET) | grep 'Tests\|]]]' -A1
	cd $(BUILD_DIR) && \
	gcov unity.c | head -3
	grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true
	cd $(BUILD_DIR) && \
	$(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC4), ../$i) $(COV_FLAGS) -o ../$(TARGET)
	rm -f $(BUILD_DIR)/*.gcda
	./$(TARGET) | grep 'Tests\|]]]' -A1
	cd $(BUILD_DIR) && \
	gcov unity.c | head -3
	grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true
	cd $(BUILD_DIR) && \
	$(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC5), ../$i) $(COV_FLAGS) -o ../$(TARGET)
	rm -f $(BUILD_DIR)/*.gcda
	./$(TARGET) | grep 'Tests\|]]]' -A1
	cd $(BUILD_DIR) && \
	gcov unity.c | head -3
	grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true
	cd $(BUILD_DIR) && \
	$(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC6), ../$i) $(COV_FLAGS) -o ../$(TARGET)
	rm -f $(BUILD_DIR)/*.gcda
	./$(TARGET) | grep 'Tests\|]]]' -A1
	cd $(BUILD_DIR) && \
	gcov unity.c | head -3
	grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true
	cd $(BUILD_DIR) && \
	$(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC7), ../$i) $(COV_FLAGS) -o ../$(TARGET)
	rm -f $(BUILD_DIR)/*.gcda
	./$(TARGET) | grep 'Tests\|]]]' -A1
	cd $(BUILD_DIR) && \
	gcov unity.c | head -3
	grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true
	cd $(BUILD_DIR) && \
	$(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC8), ../$i) $(COV_FLAGS) -o ../$(TARGET)
94
	rm -f $(BUILD_DIR)/*.gcda
95
	./$(TARGET) | grep 'Tests\|]]]' -A1
96 97 98 99
	cd $(BUILD_DIR) && \
	gcov unity.c | head -3
	grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
test: $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6) $(SRC7) $(SRC8)
	$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC1) -o $(TARGET)
	./$(TARGET)
	$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC2) -o $(TARGET)
	./$(TARGET)
	$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC3) -o $(TARGET)
	./$(TARGET)
	$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC4) -o $(TARGET)
	./$(TARGET)
	$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC5) -o $(TARGET)
	./$(TARGET)
	$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC6) -o $(TARGET)
	./$(TARGET)
	$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC7) -o $(TARGET)
	./$(TARGET)
	$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC8) -o $(TARGET)
116 117
	./$(TARGET)

J
jsalling 已提交
118 119 120 121 122 123
# Compile only, for testing that preprocessor detection works
UNITY_C_ONLY =-c ../src/unity.c -o $(BUILD_DIR)/unity.o
intDetection:
	$(CC) $(CFLAGS) $(INC_DIR) $(UNITY_C_ONLY) -D UNITY_EXCLUDE_STDINT_H
	$(CC) $(CFLAGS) $(INC_DIR) $(UNITY_C_ONLY) -D UNITY_EXCLUDE_LIMITS_H

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
$(BUILD_DIR)/test_unity_arraysRunner.c: tests/test_unity_arrays.c | $(BUILD_DIR)
	awk $(AWK_SCRIPT) tests/test_unity_arrays.c > $@

$(BUILD_DIR)/test_unity_coreRunner.c: tests/test_unity_core.c | $(BUILD_DIR)
	awk $(AWK_SCRIPT) tests/test_unity_core.c > $@

$(BUILD_DIR)/test_unity_doublesRunner.c: tests/test_unity_doubles.c | $(BUILD_DIR)
	awk $(AWK_SCRIPT) tests/test_unity_doubles.c > $@

$(BUILD_DIR)/test_unity_floatsRunner.c: tests/test_unity_floats.c | $(BUILD_DIR)
	awk $(AWK_SCRIPT) tests/test_unity_floats.c > $@

$(BUILD_DIR)/test_unity_integersRunner.c: tests/test_unity_integers.c | $(BUILD_DIR)
	awk $(AWK_SCRIPT) tests/test_unity_integers.c > $@

$(BUILD_DIR)/test_unity_integers_64Runner.c: tests/test_unity_integers_64.c | $(BUILD_DIR)
	awk $(AWK_SCRIPT) tests/test_unity_integers_64.c > $@

$(BUILD_DIR)/test_unity_memoryRunner.c: tests/test_unity_memory.c | $(BUILD_DIR)
	awk $(AWK_SCRIPT) tests/test_unity_memory.c > $@

$(BUILD_DIR)/test_unity_stringsRunner.c: tests/test_unity_strings.c | $(BUILD_DIR)
	awk $(AWK_SCRIPT) tests/test_unity_strings.c > $@
147

148 149
AWK_SCRIPT=\
  '/^void test/{ declarations[d++]=$$0; gsub(/\(?void\)? ?/,""); tests[t++]=$$0; line[u++]=NR } \
150 151 152 153 154
  END{ print "\#include \"unity.h\" /* Autogenerated by awk in Makefile */" ;                   \
       for (i=0; i<d; i++) { print declarations[i] ";" }                                        \
       print "int main(void)\n{\n    UnityBegin(\"" FILENAME "\");" ;                           \
       for (i=0; i<t; i++) { print "    RUN_TEST(" tests[i] ", " line[i] ");" }                 \
       print "    return UNITY_END();\n}" }'
155 156 157 158 159

$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)

clean:
160
	rm -f $(TARGET) $(BUILD_DIR)/*.gc* $(BUILD_DIR)/test_unity_*Runner.c