Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cxx_rules #10

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions .yams/cpp_rules.min
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_@=@
Common_C_Flags = -DHAVE_CONFIG_H -g -O2

Module_C_Flags += $(Common_C_Flags) $(Module_Includes)
Expand Down Expand Up @@ -28,54 +29,66 @@ 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 $@
$(_@)$(CC) $(Module_C_Flags) -c $< -o $@
ifdef CPPCHECK
@$(CPPCHECK) $(Module_Includes) $<
$(_@)$(CPPCHECK) $(Module_Includes) $<
endif
@echo "CC <= $<"

%.o: %.cpp
@$(CXX) $(Module_C_Flags) -c $< -o $@
$(_@)$(CXX) $(Module_C_Flags) -c $< -o $@
ifdef CPPCHECK
@$(CPPCHECK) $(Module_Includes) $<
$(_@)$(CPPCHECK) $(Module_Includes) $<
endif
@echo "CXX <= $<"

$(Test_Dir)/%_q: $(Test_Dir)/%.c
ifdef CLANG_FORMAT
@$(CLANG_FORMAT) $<
$(_@)$(CLANG_FORMAT) $<
endif
@$(CC) $< -o $@ $(Module_Test_C_Flags) -L/usr/local/lib $($(*F)_FLAGS) -fprofile-arcs -ftest-coverage
$(_@)$(CC) $< -o $@ $(Module_Test_C_Flags) -L/usr/local/lib $($(*F)_FLAGS) $(GCOV_FLAGS)
ifdef CPPCHECK
@$(CPPCHECK) $(Module_Test_Includes) $($(*F)_Inc_FLAGS) $<
$(_@)$(CPPCHECK) $(Module_Test_Includes) $($(*F)_Inc_FLAGS) $<
endif
ifdef GCOV
$(_@)mv $(*F).gc* $(Test_Dir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend abstracting all shell commands into the variables (very much along the lines of $(CC), $(CLANG_FORMAT)) Makes for a slightly easier reading experience. I imagine we will be building out the build system into a richer system over time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still unclear what we are building out in terms of the build system. Are we creating a bespoke build system from scratch or iterating on something that starts with a large swath of the features we want?

It'd be good to get some alignment on this before getting too far down a particular path here.

/cc/ @turon

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, this makes GCOV a first class top-level visible aspect of code coverage. In nlbuild-autotools (a turnkey packaging of GNU autotools), there is support for the 'make coverage' target but the actual platform- and system-specific implementation decides how to carry that out, with slightly differing behavior, for example, on gcc versus clang.

Copy link
Contributor Author

@rwalker-apple rwalker-apple Mar 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree very much that we'll be iterating on (or abandoning) this. We're also evaluating cmake and we can't be sure that we won't need to leverage investments in automake.

This PR is intended to be a small, incremental improvement to aid debugging the current system.

endif
@echo "Building tests <= $<"

$(Test_Dir)/%_q: $(Test_Dir)/%.cpp
ifdef CLANG_FORMAT
@$(CLANG_FORMAT) $<
$(_@)$(CLANG_FORMAT) $<
endif
@$(CXX) $< -o $@ $(Module_Test_C_Flags) -L/usr/local/lib $($(*F)_FLAGS) -fprofile-arcs -ftest-coverage
$(_@)$(CXX) $< -o $@ $(Module_Test_C_Flags) -L/usr/local/lib $($(*F)_FLAGS) $(GCOV_FLAGS)
ifdef CPPCHECK
@$(CPPCHECK) $(Module_Test_Includes) $($(*F)_Inc_FLAGS) $<
$(_@)$(CPPCHECK) $(Module_Test_Includes) $($(*F)_Inc_FLAGS) $<
endif
ifdef GCOV
$(_@)mv $(*F).gc* $(Test_Dir)
endif
@echo "Building tests <= $<"

run_tests: $(Tests_C_Exe) $(Tests_CPP_Exe)
@echo "Running tests <= $<"
@$(foreach f,$^,$(VALGRIND) ./$(f);)
$(_@)$(foreach f,$^,$(VALGRIND) ./$(f);)
ifneq ($(and $(GCOV),$(Tests_C_Files)),)
@$(GCOV) $(notdir $(Tests_C_Files))
$(_@)$(GCOV) $(notdir $(Tests_C_Files))
endif
ifneq ($(and $(GCOV),$(Tests_CPP_Files)),)
@$(GCOV) $(notdir $(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
$(_@)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