-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile
100 lines (83 loc) · 3.94 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Makefile for upkie targets
#
# SPDX-License-Identifier: Apache-2.0
# Copyright 2022 Stéphane Caron
# Copyright 2023-2024 Inria
# Hostname or IP address of the Raspberry Pi Uses the value from the UPKIE_NAME
# environment variable, if defined. Valid usage: ``make upload UPKIE_NAME=foo``
REMOTE = ${UPKIE_NAME}
# Project name needs to match the one in WORKSPACE
PROJECT_NAME = upkie
BAZEL = $(CURDIR)/tools/bazelisk
COVERAGE_DIR = $(CURDIR)/bazel-out/_coverage
CURDATE = $(shell date -Iseconds)
CURDIR_NAME = $(shell basename $(CURDIR))
RASPUNZEL = $(CURDIR)/tools/raspunzel
# Help snippet adapted from:
# http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help
help:
@echo "Host targets:\n"
@grep -P '^[a-zA-Z0-9_-]+:.*? ## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-24s\033[0m %s\n", $$1, $$2}'
@echo "\nRaspberry Pi targets:\n"
@grep -P '^[a-zA-Z0-9_-]+:.*?### .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?### "}; {printf " \033[36m%-24s\033[0m %s\n", $$1, $$2}'
@echo "" # manicure
.DEFAULT_GOAL := help
# HOST TARGETS
# ============
.PHONY: clean_broken_links
clean_broken_links:
find -L $(CURDIR) -type l ! -exec test -e {} \; -delete
.PHONY: clean
clean: clean_broken_links ## clean all local build and intermediate files
$(BAZEL) clean --expunge
.PHONY: build
build: clean_broken_links ## build Raspberry Pi targets
$(BAZEL) build --config=pi64 //pid_balancer
$(BAZEL) build --config=pi64 //spines:mock_spine
$(BAZEL) build --config=pi64 //spines:pi3hat_spine
.PHONY: coverage
coverage: ## check unit test coverage and open an HTML report in Firefox
$(BAZEL) coverage --combined_report=lcov --compilation_mode=fastbuild --instrument_test_targets //...
@if [ -z "$(shell which genhtml)" ]; then\
echo "Error: genhtml not found, is lcov installed?"; \
else \
genhtml $(COVERAGE_DIR)/_coverage_report.dat -o $(COVERAGE_DIR); \
firefox $(COVERAGE_DIR)/index.html; \
fi
.PHONY: check_upkie_name
check_upkie_name:
@if [ -z "${UPKIE_NAME}" ]; then \
echo "ERROR: Environment variable UPKIE_NAME is not set.\n"; \
echo "This variable should contain the robot's hostname or IP address for SSH. "; \
echo "You can define it inline for a one-time use:\n"; \
echo " make some_target UPKIE_NAME=your_robot_hostname\n"; \
echo "Or add the following line to your shell configuration:\n"; \
echo " export UPKIE_NAME=your_robot_hostname\n"; \
exit 1; \
fi
# Running ``raspunzel -s`` can create __pycache__ directories owned by root
# that rsync is not allowed to remove. We therefore give permissions first.
.PHONY: upload
upload: check_upkie_name build ## upload built targets to the Raspberry Pi
ssh $(REMOTE) sudo date -s "$(CURDATE)"
ssh $(REMOTE) mkdir -p $(PROJECT_NAME)
ssh $(REMOTE) sudo find $(PROJECT_NAME) -type d -name __pycache__ -user root -exec chmod go+wx {} "\;"
rsync -Lrtu --delete-after --delete-excluded --exclude bazel-out/ --exclude bazel-testlogs/ --exclude bazel-$(CURDIR_NAME) --exclude bazel-$(PROJECT_NAME)/ --exclude cache/ --exclude logs/ --exclude training/ --progress $(CURDIR)/ $(REMOTE):$(PROJECT_NAME)/
# REMOTE SPINE TARGETS
# ====================
run_mock_spine: ### run the mock spine on the Raspberry Pi
$(RASPUNZEL) run -s //spines:mock_spine
# NB: run_pi3hat_spine is used in build instructions
run_pi3hat_spine: ### run the pi3hat spine on the Raspberry Pi
$(RASPUNZEL) run -s //spines:pi3hat_spine
# REMOTE AGENT TARGETS
# ====================
# A specific gain config file can be loaded with the CONFIG variable
# Example: ``make run_pid_balancer CONFIG=michel-strogoff``
# where michel-strogoff.gin is a file in pid_balancer/config/
# By default we detect the config file to load by running `hostname`.
PID_BALANCER_CONFIG = $(or ${CONFIG}, hostname)
# NB: run_pid_balancer is used in build instructions
run_pid_balancer: ### run the test balancer on the Raspberry Pi
$(RASPUNZEL) run -s //pid_balancer:pid_balancer -- --config $(PID_BALANCER_CONFIG)