BayesNet/Makefile

164 lines
5.9 KiB
Makefile
Raw Normal View History

2023-07-17 20:51:15 +00:00
SHELL := /bin/bash
.DEFAULT_GOAL := help
2024-04-19 12:33:00 +00:00
.PHONY: viewcoverage coverage setup help install uninstall diagrams buildr buildd test clean debug release sample updatebadge
2023-07-17 20:51:15 +00:00
2023-10-06 22:16:25 +00:00
f_release = build_release
f_debug = build_debug
2024-04-19 12:33:00 +00:00
f_diagrams = diagrams
2024-01-07 18:58:22 +00:00
app_targets = BayesNet
test_targets = TestBayesNet
clang-uml = clang-uml
plantuml = plantuml
lcov = lcov
genhtml = genhtml
dot = dot
2023-10-06 22:16:25 +00:00
n_procs = -j 16
define ClearTests
@for t in $(test_targets); do \
if [ -f $(f_debug)/tests/$$t ]; then \
echo ">>> Cleaning $$t..." ; \
rm -f $(f_debug)/tests/$$t ; \
fi ; \
done
2023-10-09 17:41:29 +00:00
@nfiles="$(find . -name "*.gcda" -print0)" ; \
if test "${nfiles}" != "" ; then \
2023-10-07 17:08:13 +00:00
find . -name "*.gcda" -print0 | xargs -0 rm 2>/dev/null ;\
fi ;
2023-10-06 22:16:25 +00:00
endef
2023-07-17 20:51:15 +00:00
setup: ## Install dependencies for tests and coverage
@if [ "$(shell uname)" = "Darwin" ]; then \
brew install gcovr; \
brew install lcov; \
fi
@if [ "$(shell uname)" = "Linux" ]; then \
pip install gcovr; \
2024-04-07 22:13:59 +00:00
sudo dnf install lcov;\
2023-07-17 20:51:15 +00:00
fi
2024-04-19 12:33:00 +00:00
@echo "* You should install plantuml & graphviz for the diagrams"
2023-07-17 20:51:15 +00:00
2024-04-19 12:33:00 +00:00
diagrams: ## Create an UML class diagram & depnendency of the project (diagrams/BayesNet.png)
@which $(plantuml) || (echo ">>> Please install plantuml"; exit 1)
@which $(dot) || (echo ">>> Please install graphviz"; exit 1)
@which $(clang-uml) || (echo ">>> Please install clang-uml"; exit 1)
2024-04-19 12:33:00 +00:00
@export PLANTUML_LIMIT_SIZE=16384
@echo ">>> Creating UML class diagram of the project...";
@$(clang-uml) -p
2024-04-19 12:33:00 +00:00
@cd $(f_diagrams); \
$(plantuml) -tsvg BayesNet.puml
2023-10-06 22:16:25 +00:00
@echo ">>> Creating dependency graph diagram of the project...";
$(MAKE) debug
2024-04-19 12:33:00 +00:00
cd $(f_debug) && cmake .. --graphviz=dependency.dot
@$(dot) -Tsvg $(f_debug)/dependency.dot.BayesNet -o $(f_diagrams)/dependency.svg
2023-07-17 20:51:15 +00:00
buildd: ## Build the debug targets
2024-01-07 18:58:22 +00:00
cmake --build $(f_debug) -t $(app_targets) $(n_procs)
buildr: ## Build the release targets
2024-01-07 18:58:22 +00:00
cmake --build $(f_release) -t $(app_targets) $(n_procs)
2023-08-05 12:40:42 +00:00
2023-10-06 22:16:25 +00:00
clean: ## Clean the tests info
@echo ">>> Cleaning Debug BayesNet tests...";
2023-10-05 09:45:00 +00:00
$(call ClearTests)
2023-08-06 09:31:44 +00:00
@echo ">>> Done";
2024-03-09 11:27:05 +00:00
uninstall: ## Uninstall library
@echo ">>> Uninstalling BayesNet...";
xargs rm < $(f_release)/install_manifest.txt
@echo ">>> Done";
prefix = "/usr/local"
2024-03-07 23:37:36 +00:00
install: ## Install library
@echo ">>> Installing BayesNet...";
@cmake --install $(f_release) --prefix $(prefix)
2024-03-07 23:37:36 +00:00
@echo ">>> Done";
2023-08-03 18:22:33 +00:00
debug: ## Build a debug version of the project
2023-10-05 09:45:00 +00:00
@echo ">>> Building Debug BayesNet...";
2023-10-06 22:16:25 +00:00
@if [ -d ./$(f_debug) ]; then rm -rf ./$(f_debug); fi
@mkdir $(f_debug);
2023-10-09 09:25:30 +00:00
@cmake -S . -B $(f_debug) -D CMAKE_BUILD_TYPE=Debug -D ENABLE_TESTING=ON -D CODE_COVERAGE=ON
2023-07-17 20:51:15 +00:00
@echo ">>> Done";
2023-08-03 18:22:33 +00:00
release: ## Build a Release version of the project
2023-10-05 09:45:00 +00:00
@echo ">>> Building Release BayesNet...";
2023-10-06 22:16:25 +00:00
@if [ -d ./$(f_release) ]; then rm -rf ./$(f_release); fi
@mkdir $(f_release);
2023-10-09 09:25:30 +00:00
@cmake -S . -B $(f_release) -D CMAKE_BUILD_TYPE=Release
@echo ">>> Done";
2024-02-27 16:16:26 +00:00
fname = "tests/data/iris.arff"
sample: ## Build sample
@echo ">>> Building Sample...";
2024-03-08 21:20:54 +00:00
@if [ -d ./sample/build ]; then rm -rf ./sample/build; fi
@cd sample && cmake -B build -S . && cmake --build build -t bayesnet_sample
sample/build/bayesnet_sample $(fname)
@echo ">>> Done";
2023-10-05 13:45:36 +00:00
opt = ""
test: ## Run tests (opt="-s") to verbose output the tests, (opt="-c='Test Maximum Spanning Tree'") to run only that section
2024-04-21 16:54:13 +00:00
@echo ">>> Running BayesNet tests...";
2023-10-06 22:16:25 +00:00
@$(MAKE) clean
2023-10-09 17:41:29 +00:00
@cmake --build $(f_debug) -t $(test_targets) $(n_procs)
2023-10-06 22:16:25 +00:00
@for t in $(test_targets); do \
echo ">>> Running $$t...";\
2023-10-06 22:16:25 +00:00
if [ -f $(f_debug)/tests/$$t ]; then \
cd $(f_debug)/tests ; \
./$$t $(opt) ; \
cd ../.. ; \
2023-10-06 22:16:25 +00:00
fi ; \
done
@echo ">>> Done";
2023-07-17 20:51:15 +00:00
coverage: ## Run tests and generate coverage report (build/index.html)
2024-01-07 18:58:22 +00:00
@echo ">>> Building tests with coverage..."
@which $(lcov) || (echo ">>> Please install lcov"; exit 1)
@if [ ! -f $(f_debug)/tests/coverage.info ] ; then $(MAKE) test ; fi
2024-04-07 22:13:59 +00:00
@echo ">>> Building report..."
@cd $(f_debug)/tests; \
$(lcov) --directory CMakeFiles --capture --demangle-cpp --ignore-errors source,source --output-file coverage.info >/dev/null 2>&1; \
$(lcov) --remove coverage.info '/usr/*' --output-file coverage.info >/dev/null 2>&1; \
$(lcov) --remove coverage.info 'lib/*' --output-file coverage.info >/dev/null 2>&1; \
$(lcov) --remove coverage.info 'libtorch/*' --output-file coverage.info >/dev/null 2>&1; \
$(lcov) --remove coverage.info 'tests/*' --output-file coverage.info >/dev/null 2>&1; \
$(lcov) --remove coverage.info 'bayesnet/utils/loguru.*' --ignore-errors unused --output-file coverage.info >/dev/null 2>&1; \
$(lcov) --remove coverage.info '/opt/miniconda/*' --ignore-errors unused --output-file coverage.info >/dev/null 2>&1; \
$(lcov) --summary coverage.info
2024-04-08 09:24:25 +00:00
@$(MAKE) updatebadge
2024-04-21 16:54:13 +00:00
@echo ">>> Done";
viewcoverage: ## View the html coverage report
@which $(genhtml) || (echo ">>> Please install lcov (genhtml not found)"; exit 1)
@$(genhtml) $(f_debug)/tests/coverage.info --demangle-cpp --output-directory html --title "BayesNet Coverage Report" -s -k -f --legend >/dev/null 2>&1;
@xdg-open html/index.html || open html/index.html 2>/dev/null
2024-04-07 22:13:59 +00:00
@echo ">>> Done";
2024-04-08 09:24:25 +00:00
updatebadge: ## Update the coverage badge in README.md
2024-04-21 16:54:13 +00:00
@which python || (echo ">>> Please install python"; exit 1)
@if [ ! -f $(f_debug)/tests/coverage.info ]; then \
echo ">>> No coverage.info file found. Run make coverage first!"; \
exit 1; \
fi
2024-04-08 09:24:25 +00:00
@echo ">>> Updating coverage badge..."
@env python update_coverage.py $(f_debug)/tests
@echo ">>> Done";
2023-07-17 20:51:15 +00:00
help: ## Show help message
@IFS=$$'\n' ; \
help_lines=(`fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##/:/'`); \
printf "%s\n\n" "Usage: make [task]"; \
printf "%-20s %s\n" "task" "help" ; \
printf "%-20s %s\n" "------" "----" ; \
for help_line in $${help_lines[@]}; do \
IFS=$$':' ; \
help_split=($$help_line) ; \
help_command=`echo $${help_split[0]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
help_info=`echo $${help_split[2]} | sed -e 's/^ *//' -e 's/ *$$//'` ; \
printf '\033[36m'; \
printf "%-20s %s" $$help_command ; \
printf '\033[0m'; \
printf "%s\n" $$help_info; \
done