Makefile 2.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 12 13
CFLAGS += -std=c99 -pedantic -Wall -Wextra -Wconversion -Werror
CFLAGS += -Wno-switch-enum -Wno-double-promotion
CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstrict-overflow \
          -Wstrict-prototypes -Wswitch-default -Wundef
N
nah 已提交
14
#DEBUG = -O0 -g
15
CFLAGS += $(DEBUG)
16 17
UNITY_SUPPORT_64 = -D UNITY_SUPPORT_64
UNITY_INCLUDE_DOUBLE = -D UNITY_INCLUDE_DOUBLE
18
DEFINES =  -D UNITY_OUTPUT_CHAR=putcharSpy
19
DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\)
F
Fabian Zahn 已提交
20 21
DEFINES += -D UNITY_OUTPUT_FLUSH=flushSpy
DEFINES += -D UNITY_OUTPUT_FLUSH_HEADER_DECLARATION=flushSpy\(void\)
22
DEFINES += $(UNITY_SUPPORT_64) $(UNITY_INCLUDE_DOUBLE)
23 24 25 26 27 28 29 30 31
SRC = ../src/unity.c tests/testunity.c build/testunityRunner.c
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
32
.PHONY: default coverage test clean
33 34 35 36
coverage: $(BUILD_DIR)/testunityRunner.c
	cd $(BUILD_DIR) && \
	$(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC), ../$i) $(COV_FLAGS) -o ../$(TARGET)
	rm -f $(BUILD_DIR)/*.gcda
37
	./$(TARGET) | grep 'Tests\|]]]' -A1
38 39 40 41 42 43 44 45
	cd $(BUILD_DIR) && \
	gcov unity.c | head -3
	grep '###' $(BUILD_DIR)/unity.c.gcov -C2 || true

test: $(BUILD_DIR)/testunityRunner.c
	$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC) -o $(TARGET)
	./$(TARGET)

J
jsalling 已提交
46 47 48 49 50 51
# 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

52 53 54
$(BUILD_DIR)/testunityRunner.c: tests/testunity.c | $(BUILD_DIR)
	awk $(AWK_SCRIPT) tests/testunity.c > $@

55 56
AWK_SCRIPT=\
  '/^void test/{ declarations[d++]=$$0; gsub(/\(?void\)? ?/,""); tests[t++]=$$0; line[u++]=NR } \
57 58 59 60 61
  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}" }'
62 63 64 65 66

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

clean:
67
	rm -f $(TARGET) $(BUILD_DIR)/*.gc* $(BUILD_DIR)/testunityRunner.c