Advertisement
Guest User

Untitled

a guest
Jul 17th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 19.48 KB | None | 0 0
  1. #---------
  2. #
  3. # MakefileWorker.mk
  4. #
  5. # Include this helper file in your makefile
  6. # It makes
  7. #    A static library
  8. #    A test executable
  9. #
  10. # See this example for parameter settings
  11. #    examples/Makefile
  12. #
  13. #----------
  14. # Inputs - these variables describe what to build
  15. #
  16. #   INCLUDE_DIRS - Directories used to search for include files.
  17. #                   This generates a -I for each directory
  18. #   SRC_DIRS - Directories containing source files to build into the library
  19. #   SRC_FILES - Specific source files to build into library. Helpful when not all code
  20. #               in a directory can be built for test (hopefully a temporary situation)
  21. #   TEST_SRC_DIRS - Directories containing unit test code build into the unit test runner
  22. #               These do not go in a library. They are explicitly included in the test runner
  23. #   TEST_SRC_FILES - Specific source files to build into the unit test runner
  24. #               These do not go in a library. They are explicitly included in the test runner
  25. #   MOCKS_SRC_DIRS - Directories containing mock source files to build into the test runner
  26. #               These do not go in a library. They are explicitly included in the test runner
  27. #----------
  28. # You can adjust these variables to influence how to build the test target
  29. # and where to put and name outputs
  30. # See below to determine defaults
  31. #   COMPONENT_NAME - the name of the thing being built
  32. #   TEST_TARGET - name of the test executable. By default it is
  33. #           $(COMPONENT_NAME)_tests
  34. #       Helpful if you want 1 > make files in the same directory with different
  35. #       executables as output.
  36. #   CPPUTEST_HOME - where CppUTest home dir found
  37. #   TARGET_PLATFORM - Influences how the outputs are generated by modifying the
  38. #       CPPUTEST_OBJS_DIR and CPPUTEST_LIB_DIR to use a sub-directory under the
  39. #       normal objs and lib directories.  Also modifies where to search for the
  40. #       CPPUTEST_LIB to link against.
  41. #   CPPUTEST_OBJS_DIR - a directory where o and d files go
  42. #   CPPUTEST_LIB_DIR - a directory where libs go
  43. #   CPPUTEST_ENABLE_DEBUG - build for debug
  44. #   CPPUTEST_USE_MEM_LEAK_DETECTION - Links with overridden new and delete
  45. #   CPPUTEST_USE_STD_CPP_LIB - Set to N to keep the standard C++ library out
  46. #       of the test harness
  47. #   CPPUTEST_USE_GCOV - Turn on coverage analysis
  48. #       Clean then build with this flag set to Y, then 'make gcov'
  49. #   CPPUTEST_MAPFILE - generate a map file
  50. #   CPPUTEST_WARNINGFLAGS - overly picky by default
  51. #   OTHER_MAKEFILE_TO_INCLUDE - a hook to use this makefile to make
  52. #       other targets. Like CSlim, which is part of fitnesse
  53. #   CPPUTEST_USE_VPATH - Use Make's VPATH functionality to support user
  54. #       specification of source files and directories that aren't below
  55. #       the user's Makefile in the directory tree, like:
  56. #           SRC_DIRS += ../../lib/foo
  57. #       It defaults to N, and shouldn't be necessary except in the above case.
  58. #----------
  59. #
  60. #  Other flags users can initialize to sneak in their settings
  61. #   CPPUTEST_CXXFLAGS - flags for the C++ compiler
  62. #   CPPUTEST_CPPFLAGS - flags for the C++ AND C preprocessor
  63. #   CPPUTEST_CFLAGS - flags for the C complier
  64. #   CPPUTEST_LDFLAGS - Linker flags
  65. #----------
  66.  
  67. # Some behavior is weird on some platforms. Need to discover the platform.
  68.  
  69. # Platforms
  70. UNAME_OUTPUT = "$(shell uname -a)"
  71. MACOSX_STR = Darwin
  72. MINGW_STR = MINGW
  73. CYGWIN_STR = CYGWIN
  74. LINUX_STR = Linux
  75. SUNOS_STR = SunOS
  76. UNKNWOWN_OS_STR = Unknown
  77.  
  78. # Compilers
  79. CC_VERSION_OUTPUT ="$(shell $(CXX) -v 2>&1)"
  80. CLANG_STR = clang
  81. SUNSTUDIO_CXX_STR = SunStudio
  82.  
  83. UNAME_OS = $(UNKNWOWN_OS_STR)
  84.  
  85. ifeq ($(findstring $(MINGW_STR),$(UNAME_OUTPUT)),$(MINGW_STR))
  86.     UNAME_OS = $(MINGW_STR)
  87. endif
  88.  
  89. ifeq ($(findstring $(CYGWIN_STR),$(UNAME_OUTPUT)),$(CYGWIN_STR))
  90.     UNAME_OS = $(CYGWIN_STR)
  91. endif
  92.  
  93. ifeq ($(findstring $(LINUX_STR),$(UNAME_OUTPUT)),$(LINUX_STR))
  94.     UNAME_OS = $(LINUX_STR)
  95. endif
  96.  
  97. ifeq ($(findstring $(MACOSX_STR),$(UNAME_OUTPUT)),$(MACOSX_STR))
  98.     UNAME_OS = $(MACOSX_STR)
  99. #lion has a problem with the 'v' part of -a
  100.     UNAME_OUTPUT = "$(shell uname -pmnrs)"
  101. endif
  102.  
  103. ifeq ($(findstring $(SUNOS_STR),$(UNAME_OUTPUT)),$(SUNOS_STR))
  104.     UNAME_OS = $(SUNOS_STR)
  105.  
  106.     SUNSTUDIO_CXX_ERR_STR = CC -flags
  107. ifeq ($(findstring $(SUNSTUDIO_CXX_ERR_STR),$(CC_VERSION_OUTPUT)),$(SUNSTUDIO_CXX_ERR_STR))
  108.     CC_VERSION_OUTPUT ="$(shell $(CXX) -V 2>&1)"
  109.     COMPILER_NAME = $(SUNSTUDIO_CXX_STR)
  110. endif
  111. endif
  112.  
  113. ifeq ($(findstring $(CLANG_STR),$(CC_VERSION_OUTPUT)),$(CLANG_STR))
  114.     COMPILER_NAME = $(CLANG_STR)
  115. endif
  116.  
  117. #Kludge for mingw, it does not have cc.exe, but gcc.exe will do
  118. ifeq ($(UNAME_OS),$(MINGW_STR))
  119.     CC := gcc
  120. endif
  121.  
  122. #And another kludge. Exception handling in gcc 4.6.2 is broken when linking the
  123. # Standard C++ library as a shared library. Unbelievable.
  124. ifeq ($(UNAME_OS),$(MINGW_STR))
  125.   CPPUTEST_LDFLAGS += -static
  126. endif
  127. ifeq ($(UNAME_OS),$(CYGWIN_STR))
  128.   CPPUTEST_LDFLAGS += -static
  129. endif
  130.  
  131.  
  132. #Kludge for MacOsX gcc compiler on Darwin9 who can't handle pendantic
  133. ifeq ($(UNAME_OS),$(MACOSX_STR))
  134. ifeq ($(findstring Version 9,$(UNAME_OUTPUT)),Version 9)
  135.     CPPUTEST_PEDANTIC_ERRORS = N
  136. endif
  137. endif
  138.  
  139. ifndef COMPONENT_NAME
  140.     COMPONENT_NAME = name_this_in_the_makefile
  141. endif
  142.  
  143. # Debug on by default
  144. ifndef CPPUTEST_ENABLE_DEBUG
  145.     CPPUTEST_ENABLE_DEBUG = Y
  146. endif
  147.  
  148. # new and delete for memory leak detection on by default
  149. ifndef CPPUTEST_USE_MEM_LEAK_DETECTION
  150.     CPPUTEST_USE_MEM_LEAK_DETECTION = Y
  151. endif
  152.  
  153. # Use the standard C library
  154. ifndef CPPUTEST_USE_STD_C_LIB
  155.     CPPUTEST_USE_STD_C_LIB = Y
  156. endif
  157.  
  158. # Use the standard C++ library
  159. ifndef CPPUTEST_USE_STD_CPP_LIB
  160.     CPPUTEST_USE_STD_CPP_LIB = Y
  161. endif
  162.  
  163. # Use long long, off by default
  164. ifndef CPPUTEST_USE_LONG_LONG
  165.     CPPUTEST_USE_LONG_LONG = N
  166. endif
  167.  
  168. # Use gcov, off by default
  169. ifndef CPPUTEST_USE_GCOV
  170.     CPPUTEST_USE_GCOV = N
  171. endif
  172.  
  173. ifndef CPPUTEST_PEDANTIC_ERRORS
  174.     CPPUTEST_PEDANTIC_ERRORS = Y
  175. endif
  176.  
  177. # Default warnings
  178. ifndef CPPUTEST_WARNINGFLAGS
  179.     CPPUTEST_WARNINGFLAGS =  -Wall -Wextra -Werror -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -Wno-long-long
  180. ifeq ($(CPPUTEST_PEDANTIC_ERRORS), Y)
  181.     CPPUTEST_WARNINGFLAGS += -pedantic-errors
  182. endif
  183. ifeq ($(UNAME_OS),$(LINUX_STR))
  184.     CPPUTEST_WARNINGFLAGS += -Wsign-conversion
  185. endif
  186.     CPPUTEST_CXX_WARNINGFLAGS = -Woverloaded-virtual
  187.     CPPUTEST_C_WARNINGFLAGS = -Wstrict-prototypes
  188. endif
  189.  
  190. #Wonderful extra compiler warnings with clang
  191. ifeq ($(COMPILER_NAME),$(CLANG_STR))
  192. # -Wno-disabled-macro-expansion -> Have to disable the macro expansion warning as the operator new overload warns on that.
  193. # -Wno-padded -> I sort-of like this warning but if there is a bool at the end of the class, it seems impossible to remove it! (except by making padding explicit)
  194. # -Wno-global-constructors Wno-exit-time-destructors -> Great warnings, but in CppUTest it is impossible to avoid as the automatic test registration depends on the global ctor and dtor
  195. # -Wno-weak-vtables -> The TEST_GROUP macro declares a class and will automatically inline its methods. Thats ok as they are only in one translation unit. Unfortunately, the warning can't detect that, so it must be disabled.
  196. # -Wno-old-style-casts -> We only use old style casts by decision
  197. # -Wno-c++11-long-long -> When it detects long long, then we can use it and no need for a warning about that
  198. # -Wno-c++98-compat-pedantic -> Incompatibilities with C++98, these are happening through #define.
  199. # -Wno-reserved-id-macro -> Macro uses __ in MINGW... can't change that.
  200. # -Wno-keyword-macro -> new overload
  201.     CPPUTEST_CXX_WARNINGFLAGS += -Weverything -Wno-disabled-macro-expansion -Wno-padded -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables -Wno-old-style-cast -Wno-c++11-long-long -Wno-c++98-compat-pedantic -Wno-reserved-id-macro -Wno-keyword-macro
  202.     CPPUTEST_C_WARNINGFLAGS += -Weverything -Wno-padded
  203.  
  204. # Clang "7" or newer (Xcode 7 or newer command-line tools) introduced new warnings by default that don't exist on previous versions of clang and cause errors when present.
  205. CLANG_VERSION := $(shell echo $(CC_VERSION_OUTPUT) | grep -o 'clang-[0-9][0-9][0-9]*.')
  206. CLANG_VERSION_NUM := $(subst .,,$(subst clang-,,$(CLANG_VERSION)))
  207. CLANG_VERSION_NUM_GT_700 := $(shell [[ $(CLANG_VERSION_NUM) -ge 700 ]] && echo Y)
  208.  
  209. ifeq ($(CLANG_VERSION_NUM_GT_700), Y)
  210. # -Wno-reserved-id-macro -> Many CppUTest macros start with __, which is a reserved namespace
  211. # -Wno-keyword-macro -> CppUTest redefines the 'new' keyword for memory leak tracking
  212.     CPPUTEST_CXX_WARNINGFLAGS += -Wno-reserved-id-macro -Wno-keyword-macro
  213.     CPPUTEST_C_WARNINGFLAGS += -Wno-reserved-id-macro -Wno-keyword-macro
  214. endif
  215. endif
  216.  
  217. # Uhm. Maybe put some warning flags for SunStudio here?
  218. ifeq ($(COMPILER_NAME),$(SUNSTUDIO_CXX_STR))
  219.     CPPUTEST_CXX_WARNINGFLAGS =
  220.     CPPUTEST_C_WARNINGFLAGS =
  221. endif
  222.  
  223. # Default dir for temporary files (d, o)
  224. ifndef CPPUTEST_OBJS_DIR
  225. ifndef TARGET_PLATFORM
  226.     CPPUTEST_OBJS_DIR = objs
  227. else
  228.     CPPUTEST_OBJS_DIR = objs/$(TARGET_PLATFORM)
  229. endif
  230. endif
  231.  
  232. # Default dir for the outout library
  233. ifndef CPPUTEST_LIB_DIR
  234. ifndef TARGET_PLATFORM
  235.     CPPUTEST_LIB_DIR = lib
  236. else
  237.     CPPUTEST_LIB_DIR = lib/$(TARGET_PLATFORM)
  238. endif
  239. endif
  240.  
  241. # No map by default
  242. ifndef CPPUTEST_MAP_FILE
  243.     CPPUTEST_MAP_FILE = N
  244. endif
  245.  
  246. # No extentions is default
  247. ifndef CPPUTEST_USE_EXTENSIONS
  248.     CPPUTEST_USE_EXTENSIONS = N
  249. endif
  250.  
  251. # No VPATH is default
  252. ifndef CPPUTEST_USE_VPATH
  253.     CPPUTEST_USE_VPATH := N
  254. endif
  255. # Make empty, instead of 'N', for usage in $(if ) conditionals
  256. ifneq ($(CPPUTEST_USE_VPATH), Y)
  257.     CPPUTEST_USE_VPATH :=
  258. endif
  259.  
  260. ifndef TARGET_PLATFORM
  261. CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib
  262. else
  263. CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib/$(TARGET_PLATFORM)
  264. endif
  265.  
  266. # --------------------------------------
  267. # derived flags in the following area
  268. # --------------------------------------
  269.  
  270. # Without the C library, we'll need to disable the C++ library and ...
  271. ifeq ($(CPPUTEST_USE_STD_C_LIB), N)
  272.     CPPUTEST_USE_STD_CPP_LIB = N
  273.     CPPUTEST_USE_MEM_LEAK_DETECTION = N
  274.     CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_C_LIB_DISABLED
  275.     CPPUTEST_CPPFLAGS += -nostdinc
  276. endif
  277.  
  278. ifeq ($(CPPUTEST_USE_MEM_LEAK_DETECTION), N)
  279.     CPPUTEST_CPPFLAGS += -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED
  280. else
  281.     ifndef CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE
  282.             CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h
  283.     endif
  284.     ifndef CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE
  285.         CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorMallocMacros.h
  286.     endif
  287. endif
  288.  
  289. ifeq ($(CPPUTEST_USE_LONG_LONG), Y)
  290.     CPPUTEST_CPPFLAGS += -DCPPUTEST_USE_LONG_LONG
  291. endif
  292.  
  293. ifeq ($(CPPUTEST_ENABLE_DEBUG), Y)
  294.     CPPUTEST_CXXFLAGS += -g
  295.     CPPUTEST_CFLAGS += -g
  296.     CPPUTEST_LDFLAGS += -g
  297. endif
  298.  
  299. ifeq ($(CPPUTEST_USE_STD_CPP_LIB), N)
  300.     CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_CPP_LIB_DISABLED
  301. ifeq ($(CPPUTEST_USE_STD_C_LIB), Y)
  302.     CPPUTEST_CXXFLAGS += -nostdinc++
  303. endif
  304. endif
  305.  
  306. ifdef $(GMOCK_HOME)
  307.     GTEST_HOME = $(GMOCK_HOME)/gtest
  308.     CPPUTEST_CPPFLAGS += -I$(GMOCK_HOME)/include
  309.     GMOCK_LIBRARY = $(GMOCK_HOME)/lib/.libs/libgmock.a
  310.     LD_LIBRARIES += $(GMOCK_LIBRARY)
  311.     CPPUTEST_CPPFLAGS += -DCPPUTEST_INCLUDE_GTEST_TESTS
  312.     CPPUTEST_WARNINGFLAGS =
  313.     CPPUTEST_CPPFLAGS += -I$(GTEST_HOME)/include -I$(GTEST_HOME)
  314.     GTEST_LIBRARY = $(GTEST_HOME)/lib/.libs/libgtest.a
  315.     LD_LIBRARIES += $(GTEST_LIBRARY)
  316. endif
  317.  
  318.  
  319. ifeq ($(CPPUTEST_USE_GCOV), Y)
  320.     CPPUTEST_CXXFLAGS += -fprofile-arcs -ftest-coverage
  321.     CPPUTEST_CFLAGS += -fprofile-arcs -ftest-coverage
  322. endif
  323.  
  324. CPPUTEST_CXXFLAGS += $(CPPUTEST_WARNINGFLAGS) $(CPPUTEST_CXX_WARNINGFLAGS)
  325. CPPUTEST_CPPFLAGS += $(CPPUTEST_WARNINGFLAGS)
  326. CPPUTEST_CXXFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE)
  327. CPPUTEST_CPPFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE)
  328. CPPUTEST_CFLAGS += $(CPPUTEST_C_WARNINGFLAGS)
  329.  
  330. TARGET_MAP = $(COMPONENT_NAME).map.txt
  331. ifeq ($(CPPUTEST_MAP_FILE), Y)
  332.     CPPUTEST_LDFLAGS += -Wl,-map,$(TARGET_MAP)
  333. endif
  334.  
  335. # Link with CppUTest lib
  336. CPPUTEST_LIB = $(CPPUTEST_LIB_LINK_DIR)/libCppUTest.a
  337.  
  338. ifeq ($(CPPUTEST_USE_EXTENSIONS), Y)
  339. CPPUTEST_LIB += $(CPPUTEST_LIB_LINK_DIR)/libCppUTestExt.a
  340. endif
  341.  
  342. ifdef CPPUTEST_STATIC_REALTIME
  343.     LD_LIBRARIES += -lrt
  344. endif
  345.  
  346. TARGET_LIB = \
  347.     $(CPPUTEST_LIB_DIR)/lib$(COMPONENT_NAME).a
  348.  
  349. ifndef TEST_TARGET
  350.     ifndef TARGET_PLATFORM
  351.         TEST_TARGET = $(COMPONENT_NAME)_tests
  352.     else
  353.         TEST_TARGET = $(COMPONENT_NAME)_$(TARGET_PLATFORM)_tests
  354.     endif
  355. endif
  356.  
  357. #Helper Functions
  358. get_src_from_dir  = $(wildcard $1/*.cpp) $(wildcard $1/*.cc) $(wildcard $1/*.c)
  359. get_dirs_from_dirspec  = $(wildcard $1)
  360. get_src_from_dir_list = $(foreach dir, $1, $(call get_src_from_dir,$(dir)))
  361. __src_to = $(subst .c,$1, $(subst .cc,$1, $(subst .cpp,$1,$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2))))
  362. src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2))
  363. src_to_o = $(call src_to,.o,$1)
  364. src_to_d = $(call src_to,.d,$1)
  365. src_to_gcda = $(call src_to,.gcda,$1)
  366. src_to_gcno = $(call src_to,.gcno,$1)
  367. time = $(shell date +%s)
  368. delta_t = $(eval minus, $1, $2)
  369. debug_print_list = $(foreach word,$1,echo "  $(word)";) echo;
  370.  
  371. #Derived
  372. STUFF_TO_CLEAN += $(TEST_TARGET) $(TEST_TARGET).exe $(TARGET_LIB) $(TARGET_MAP)
  373.  
  374. SRC += $(call get_src_from_dir_list, $(SRC_DIRS)) $(SRC_FILES)
  375. OBJ = $(call src_to_o,$(SRC))
  376.  
  377. STUFF_TO_CLEAN += $(OBJ)
  378.  
  379. TEST_SRC += $(call get_src_from_dir_list, $(TEST_SRC_DIRS)) $(TEST_SRC_FILES)
  380. TEST_OBJS = $(call src_to_o,$(TEST_SRC))
  381. STUFF_TO_CLEAN += $(TEST_OBJS)
  382.  
  383.  
  384. MOCKS_SRC += $(call get_src_from_dir_list, $(MOCKS_SRC_DIRS))
  385. MOCKS_OBJS = $(call src_to_o,$(MOCKS_SRC))
  386. STUFF_TO_CLEAN += $(MOCKS_OBJS)
  387.  
  388. ALL_SRC = $(SRC) $(TEST_SRC) $(MOCKS_SRC)
  389.  
  390. # If we're using VPATH
  391. ifeq ($(CPPUTEST_USE_VPATH), Y)
  392. # gather all the source directories and add them
  393.     VPATH += $(sort $(dir $(ALL_SRC)))
  394. # Add the component name to the objs dir path, to differentiate between same-name objects
  395.     CPPUTEST_OBJS_DIR := $(addsuffix /$(COMPONENT_NAME),$(CPPUTEST_OBJS_DIR))
  396. endif
  397.  
  398. #Test coverage with gcov
  399. GCOV_OUTPUT = gcov_output.txt
  400. GCOV_REPORT = gcov_report.txt
  401. GCOV_ERROR = gcov_error.txt
  402. GCOV_GCDA_FILES = $(call src_to_gcda, $(ALL_SRC))
  403. GCOV_GCNO_FILES = $(call src_to_gcno, $(ALL_SRC))
  404. TEST_OUTPUT = $(TEST_TARGET).txt
  405. STUFF_TO_CLEAN += \
  406.     $(GCOV_OUTPUT)\
  407.     $(GCOV_REPORT)\
  408.     $(GCOV_REPORT).html\
  409.     $(GCOV_ERROR)\
  410.     $(GCOV_GCDA_FILES)\
  411.     $(GCOV_GCNO_FILES)\
  412.     $(TEST_OUTPUT)
  413.  
  414. #The gcda files for gcov need to be deleted before each run
  415. #To avoid annoying messages.
  416. GCOV_CLEAN = $(SILENCE)rm -f $(GCOV_GCDA_FILES) $(GCOV_OUTPUT) $(GCOV_REPORT) $(GCOV_ERROR)
  417. RUN_TEST_TARGET = $(SILENCE)  $(GCOV_CLEAN) ; echo "Running $(TEST_TARGET)"; ./$(TEST_TARGET) $(CPPUTEST_EXE_FLAGS)
  418.  
  419. ifeq ($(CPPUTEST_USE_GCOV), Y)
  420.  
  421.     ifeq ($(COMPILER_NAME),$(CLANG_STR))
  422.         LD_LIBRARIES += --coverage
  423.     else
  424.         LD_LIBRARIES += -lgcov
  425.     endif
  426. endif
  427.  
  428.  
  429. INCLUDES_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(INCLUDE_DIRS))
  430. INCLUDES += $(foreach dir, $(INCLUDES_DIRS_EXPANDED), -I$(dir))
  431. MOCK_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(MOCKS_SRC_DIRS))
  432. INCLUDES += $(foreach dir, $(MOCK_DIRS_EXPANDED), -I$(dir))
  433.  
  434. CPPUTEST_CPPFLAGS +=  $(INCLUDES)
  435.  
  436. DEP_FILES = $(call src_to_d, $(ALL_SRC))
  437. STUFF_TO_CLEAN += $(DEP_FILES) $(PRODUCTION_CODE_START) $(PRODUCTION_CODE_END)
  438. STUFF_TO_CLEAN += $(STDLIB_CODE_START) $(MAP_FILE) cpputest_*.xml junit_run_output
  439.  
  440. # We'll use the CPPUTEST_CFLAGS etc so that you can override AND add to the CppUTest flags
  441. CFLAGS = $(CPPUTEST_CFLAGS) $(CPPUTEST_ADDITIONAL_CFLAGS)
  442. CPPFLAGS = $(CPPUTEST_CPPFLAGS) $(CPPUTEST_ADDITIONAL_CPPFLAGS)
  443. CXXFLAGS = $(CPPUTEST_CXXFLAGS) $(CPPUTEST_ADDITIONAL_CXXFLAGS)
  444. LDFLAGS = $(CPPUTEST_LDFLAGS) $(CPPUTEST_ADDITIONAL_LDFLAGS)
  445.  
  446. # Don't consider creating the archive a warning condition that does STDERR output
  447. ARFLAGS := $(ARFLAGS)c
  448.  
  449. DEP_FLAGS=-MMD -MP
  450.  
  451. # Some macros for programs to be overridden. For some reason, these are not in Make defaults
  452. RANLIB = ranlib
  453.  
  454. # Targets
  455.  
  456. .PHONY: all
  457. all: start $(TEST_TARGET)
  458.     $(RUN_TEST_TARGET)
  459.  
  460. .PHONY: start
  461. start: $(TEST_TARGET)
  462.     $(SILENCE)START_TIME=$(call time)
  463.  
  464. .PHONY: all_no_tests
  465. all_no_tests: $(TEST_TARGET)
  466.  
  467. .PHONY: flags
  468. flags:
  469.     @echo
  470.     @echo "OS ${UNAME_OS}"
  471.     @echo "Compile C and C++ source with CPPFLAGS:"
  472.     @$(call debug_print_list,$(CPPFLAGS))
  473.     @echo "Compile C++ source with CXXFLAGS:"
  474.     @$(call debug_print_list,$(CXXFLAGS))
  475.     @echo "Compile C source with CFLAGS:"
  476.     @$(call debug_print_list,$(CFLAGS))
  477.     @echo "Link with LDFLAGS:"
  478.     @$(call debug_print_list,$(LDFLAGS))
  479.     @echo "Link with LD_LIBRARIES:"
  480.     @$(call debug_print_list,$(LD_LIBRARIES))
  481.     @echo "Create libraries with ARFLAGS:"
  482.     @$(call debug_print_list,$(ARFLAGS))
  483.  
  484. TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) $(PRODUCTION_CODE_START) $(TARGET_LIB) $(USER_LIBS) $(PRODUCTION_CODE_END) $(CPPUTEST_LIB) $(STDLIB_CODE_START)
  485. test-deps: $(TEST_DEPS)
  486.  
  487. $(TEST_TARGET): $(TEST_DEPS)
  488.     @echo Linking $@
  489.     $(SILENCE)$(CXX) -o $@ $^ $(LD_LIBRARIES) $(LDFLAGS)
  490.  
  491. $(TARGET_LIB): $(OBJ)
  492.     @echo Building archive $@
  493.     $(SILENCE)mkdir -p $(dir $@)
  494.     $(SILENCE)$(AR) $(ARFLAGS) $@ $^
  495.     $(SILENCE)$(RANLIB) $@
  496.  
  497. test: $(TEST_TARGET)
  498.     $(RUN_TEST_TARGET) | tee $(TEST_OUTPUT)
  499.  
  500. vtest: $(TEST_TARGET)
  501.     $(RUN_TEST_TARGET) -v  | tee $(TEST_OUTPUT)
  502.  
  503. $(CPPUTEST_OBJS_DIR)/%.o: %.cc
  504.     @echo compiling $(notdir $<)
  505.     $(SILENCE)mkdir -p $(dir $@)
  506.     $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $<
  507.  
  508. $(CPPUTEST_OBJS_DIR)/%.o: %.cpp
  509.     @echo compiling $(notdir $<)
  510.     $(SILENCE)mkdir -p $(dir $@)
  511.     $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $<
  512.  
  513. $(CPPUTEST_OBJS_DIR)/%.o: %.c
  514.     @echo compiling $(notdir $<)
  515.     $(SILENCE)mkdir -p $(dir $@)
  516.     $(SILENCE)$(COMPILE.c) $(DEP_FLAGS) $(OUTPUT_OPTION) $<
  517.  
  518. ifneq "$(MAKECMDGOALS)" "clean"
  519. -include $(DEP_FILES)
  520. endif
  521.  
  522. .PHONY: clean
  523. clean:
  524.     @echo Making clean
  525.     $(SILENCE)$(RM) $(STUFF_TO_CLEAN)
  526.     $(SILENCE)rm -rf gcov $(CPPUTEST_OBJS_DIR) $(CPPUTEST_LIB_DIR)
  527.     $(SILENCE)find . -name "*.gcno" | xargs rm -f
  528.     $(SILENCE)find . -name "*.gcda" | xargs rm -f
  529.  
  530. #realclean gets rid of all gcov, o and d files in the directory tree
  531. #not just the ones made by this makefile
  532. .PHONY: realclean
  533. realclean: clean
  534.     $(SILENCE)rm -rf gcov
  535.     $(SILENCE)find . -name "*.gdcno" | xargs rm -f
  536.     $(SILENCE)find . -name "*.[do]" | xargs rm -f
  537.  
  538. gcov: test
  539. ifeq ($(CPPUTEST_USE_VPATH), Y)
  540.     $(SILENCE)gcov $(GCOV_ARGS) --object-directory $(CPPUTEST_OBJS_DIR) $(SRC) >> $(GCOV_OUTPUT) 2>> $(GCOV_ERROR)
  541. else
  542.     $(SILENCE)for d in $(SRC_DIRS) ; do \
  543.         FILES=`ls $$d/*.c $$d/*.cc $$d/*.cpp 2> /dev/null` ; \
  544.         gcov $(GCOV_ARGS) --object-directory $(CPPUTEST_OBJS_DIR)/$$d $$FILES >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \
  545.     done
  546.     $(SILENCE)for f in $(SRC_FILES) ; do \
  547.         gcov $(GCOV_ARGS) --object-directory $(CPPUTEST_OBJS_DIR)/$$f $$f >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \
  548.     done
  549. endif
  550.     $(CPPUTEST_HOME)/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT)
  551.     $(SILENCE)cat $(GCOV_REPORT)
  552.     $(SILENCE)mkdir -p gcov
  553.     $(SILENCE)mv *.gcov gcov
  554.     $(SILENCE)mv gcov_* gcov
  555.     @echo "See gcov directory for details"
  556.  
  557. .PHONY: format
  558. format:
  559.     $(CPPUTEST_HOME)/scripts/reformat.sh $(PROJECT_HOME_DIR)
  560.  
  561. .PHONY: debug
  562. debug:
  563.     @echo
  564.     @echo "Target Source files:"
  565.     @$(call debug_print_list,$(SRC))
  566.     @echo "Target Object files:"
  567.     @$(call debug_print_list,$(OBJ))
  568.     @echo "Test Source files:"
  569.     @$(call debug_print_list,$(TEST_SRC))
  570.     @echo "Test Object files:"
  571.     @$(call debug_print_list,$(TEST_OBJS))
  572.     @echo "Mock Source files:"
  573.     @$(call debug_print_list,$(MOCKS_SRC))
  574.     @echo "Mock Object files:"
  575.     @$(call debug_print_list,$(MOCKS_OBJS))
  576.     @echo "All Input Dependency files:"
  577.     @$(call debug_print_list,$(DEP_FILES))
  578.     @echo Stuff to clean:
  579.     @$(call debug_print_list,$(STUFF_TO_CLEAN))
  580.     @echo Includes:
  581.     @$(call debug_print_list,$(INCLUDES))
  582.  
  583. -include $(OTHER_MAKEFILE_TO_INCLUDE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement