| _@=@ |
| Common_C_Flags = -DHAVE_CONFIG_H -g -O2 |
| |
| Module_C_Flags += $(Common_C_Flags) $(Module_Includes) |
| Module_Test_C_Flags += $(Common_C_Flags) $(Module_Test_Includes) |
| |
| C_Objects = $(C_Files:.c=.o) |
| CPP_Objects = $(CPP_Files:.cpp=.o) |
| |
| Tests_C_Files = $(wildcard $(Test_Dir)/*.c) |
| Tests_C_Exe = $(Tests_C_Files:.c=_q) |
| |
| Tests_CPP_Files = $(wildcard $(Test_Dir)/*.cpp) |
| Tests_CPP_Exe = $(Tests_CPP_Files:.cpp=_q) |
| |
| VALGRIND := $(shell command -v valgrind 2> /dev/null) |
| |
| ifdef VALGRIND |
| VALGRIND += --leak-check=yes -q |
| endif |
| |
| CPPCHECK := $(shell command -v cppcheck 2> /dev/null) |
| ifdef CPPCHECK |
| CPPCHECK += -q --error-exitcode=1 |
| endif |
| |
| CLANG_FORMAT := $(shell command -v clang-format 2> /dev/null) |
| ifdef CLANG_FORMAT |
| CLANG_FORMAT += -style=Chromium -i |
| endif |
| |
| |
| GCOV := $(shell command -v gcov 2> /dev/null) |
| |
| ifdef GCOV |
| GCOV_FLAGS=-fprofile-arcs -ftest-coverage |
| endif |
| |
| %.o: %.c |
| $(_@)$(CC) $(Module_C_Flags) -c $< -o $@ |
| ifdef CPPCHECK |
| $(_@)$(CPPCHECK) $(Module_Includes) $< |
| endif |
| @echo "CC <= $<" |
| |
| %.o: %.cpp |
| $(_@)$(CXX) $(Module_C_Flags) -c $< -o $@ |
| ifdef CPPCHECK |
| $(_@)$(CPPCHECK) $(Module_Includes) $< |
| endif |
| @echo "CXX <= $<" |
| |
| $(Test_Dir)/%_q: $(Test_Dir)/%.c |
| ifdef CLANG_FORMAT |
| $(_@)$(CLANG_FORMAT) $< |
| endif |
| $(_@)$(CC) $< -o $@ $(Module_Test_C_Flags) -L/usr/local/lib $($(*F)_FLAGS) $(GCOV_FLAGS) |
| ifdef CPPCHECK |
| $(_@)$(CPPCHECK) $(Module_Test_Includes) $($(*F)_Inc_FLAGS) $< |
| endif |
| @echo "Building tests <= $<" |
| |
| $(Test_Dir)/%_q: $(Test_Dir)/%.cpp |
| ifdef CLANG_FORMAT |
| $(_@)$(CLANG_FORMAT) $< |
| endif |
| $(_@)$(CXX) $< -o $@ $(Module_Test_C_Flags) -L/usr/local/lib $($(*F)_FLAGS) $(GCOV_FLAGS) |
| ifdef CPPCHECK |
| $(_@)$(CPPCHECK) $(Module_Test_Includes) $($(*F)_Inc_FLAGS) $< |
| endif |
| @echo "Building tests <= $<" |
| |
| run_tests: $(Tests_C_Exe) $(Tests_CPP_Exe) |
| @echo "Running tests <= $<" |
| $(_@)$(foreach f,$^,$(VALGRIND) ./$(f);) |
| ifneq ($(and $(GCOV),$(Tests_C_Files)),) |
| $(_@)$(GCOV) $(notdir $(Tests_C_Files)) |
| endif |
| ifneq ($(and $(GCOV),$(Tests_CPP_Files)),) |
| $(_@)$(GCOV) $(notdir $(Tests_CPP_Files)) |
| endif |
| |
| my_clean: |
| $(_@)rm -f $(C_Objects) $(CPP_Objects) |
| $(_@)rm -f *.gcda *.gcno *.gcov |
| $(_@)rm -f $(Tests_C_Exe) $(Tests_CPP_Exe) $(Test_Dir)/*.gcda $(Test_Dir)/*.gcno $(Test_Dir)/*.gcov |
| $(_@)rm -rf $(Test_Dir)/*.dSYM |
| |