Makefile 2.5 KB

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