Makefile 2.5 KB

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