Makefile 2.6 KB

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