Makefile 2.5 KB
Newer Older
1
CC = gcc
2
ifeq ($(shell uname -s), Darwin)
3
CC = clang
N
nah 已提交
4 5
CFLAGS += -std=c99 -pedantic -Wall -Weverything -Werror
CFLAGS += -Wno-unknown-warning-option -Wno-switch-enum
N
nah 已提交
6 7
CFLAGS += -Wno-padded -Wno-double-promotion -Wno-missing-noreturn
CFLAGS += -Wno-missing-prototypes
8
endif
N
nah 已提交
9
ifeq ($(shell uname -s), Linux)
10
CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror
N
nah 已提交
11 12
endif
#DEBUG = -O0 -g
13
CFLAGS += $(DEBUG)
14 15
DEFINES =  -D UNITY_OUTPUT_CHAR=putcharSpy
DEFINES += -D UNITY_SUPPORT_64 -D UNITY_INCLUDE_DOUBLE -D UNITY_NO_WEAK
16 17 18 19 20 21 22 23 24
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
25
.PHONY: default coverage test clean
26 27 28 29 30 31 32 33 34
coverage: $(BUILD_DIR)/testunityRunner.c
	cd $(BUILD_DIR) && \
	$(CC) $(CFLAGS) $(DEFINES) $(foreach i,$(SRC), ../$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

35
test: CFLAGS += -Wbad-function-cast -Wcast-qual -Wconversion -Wformat=2 -Wold-style-definition \
36 37
-Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-overflow=5 -Wstrict-prototypes             \
-Wswitch-default -Wundef -Wunreachable-code -Wunused -fstrict-aliasing
38 39 40 41
test: $(BUILD_DIR)/testunityRunner.c
	$(CC) $(CFLAGS) $(DEFINES) $(INC_DIR) $(SRC) -o $(TARGET)
	./$(TARGET)

J
jsalling 已提交
42 43 44 45 46 47
# 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

48 49 50
$(BUILD_DIR)/testunityRunner.c: tests/testunity.c | $(BUILD_DIR)
	awk $(AWK_SCRIPT) tests/testunity.c > $@

51 52 53 54 55 56 57
AWK_SCRIPT=\
  '/^void test/{ declarations[d++]=$$0; gsub(/\(?void\)? ?/,""); tests[t++]=$$0; line[u++]=NR } \
  END{ print "\#include \"unity.h\" /* Autogenerated by awk in Makefile */" ;   \
       for (i=0; i<d; i++) { print declarations[i] ";" }                        \
       printf "int main(void)\n{\n    UNITY_BEGIN();\n" ;                       \
       for (i=0; i<t; i++) { print "    RUN_TEST(" tests[i] ", " line[i] ");" } \
       printf "    return UNITY_END();\n}\n" }'
58 59 60 61 62 63

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

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