-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (100 loc) · 2.95 KB
/
Makefile
File metadata and controls
117 lines (100 loc) · 2.95 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
.PHONY: all sync-submodules dev build test final refresh clean
.DEFAULT_GOAL := all
# TODO Configure these
ROS_DISTRO ?= kilted
REPO_NAME ?= ros-template
CONTAINERFILE := Containerfile
CONTAINER_ENGINE := docker
# Tag names
# These are dependent on the distro, meaning changing distro will cause a rebuild
BASE_TAG := $(ROS_DISTRO)-base
DEV_TAG := $(ROS_DISTRO)-dev
FINAL_TAG := $(ROS_DISTRO)-final
# Image names
BASE_IMAGE := $(REPO_NAME):$(BASE_TAG)
DEV_IMAGE := $(REPO_NAME):$(DEV_TAG)
FINAL_IMAGE := $(REPO_NAME):$(FINAL_TAG)
# Marker files
# These are used by `build`, `test`, `dev`, and `final` commands
# to ensure rebuilds only happen when necessary
MARKER_DIR := .make-markers
BASE_BUILT := $(MARKER_DIR)/base.built
DEV_BUILT := $(MARKER_DIR)/dev.built
FINAL_BUILT := $(MARKER_DIR)/final.built
all: final
sync-submodules:
@echo "==> Syncing submodules to .gitmodules..."
@git submodule sync
@git submodule update --init --recursive
dev: $(DEV_BUILT) sync-submodules
@echo "==> Entering workspace..."
@$(CONTAINER_ENGINE) run \
--rm \
--tty \
--interactive \
--volume=./:/workspace/:rw \
--workdir=/workspace \
--name=$(REPO_NAME)-dev \
--userns=host \
--network=host \
--pid=host \
--ipc=host \
-e QT_X11_NO_MITSHM=1 \
-e NVIDIA_DRIVER_CAPABILITIES=all \
-e DISPLAY=$(DISPLAY) \
--volume=/tmp/.X11-unix:/tmp/.X11-unix:rw \
$(DEV_IMAGE) \
bash
build: $(BASE_BUILT) sync-submodules
@echo "==> Building colcon workspace..."
@$(CONTAINER_ENGINE) run \
--rm \
--volume=./:/workspace/:rw \
--workdir=/workspace \
--name=$(REPO_NAME)-build \
$(BASE_IMAGE) \
colcon build --symlink-install
test: $(BASE_BUILT) sync-submodules
@echo "==> Testing colcon workspace..."
@$(CONTAINER_ENGINE) run \
--rm \
--volume=./:/workspace/:rw \
--workdir=/workspace \
--name=$(REPO_NAME)-test \
$(BASE_IMAGE) \
colcon test --event-handlers console_cohesion+
final: $(FINAL_BUILT) sync-submodules
$(BASE_BUILT): $(CONTAINERFILE)
@echo "==> Building base image..."
@$(CONTAINER_ENGINE) build \
-t $(BASE_IMAGE) \
-f $(CONTAINERFILE) \
--target=base \
--build-arg ROS_DISTRO=$(ROS_DISTRO) .
@mkdir -p $(MARKER_DIR)
@touch $@
$(DEV_BUILT): $(BASE_BUILT) $(CONTAINERFILE)
@echo "==> Building dev image..."
@$(CONTAINER_ENGINE) build \
-t $(DEV_IMAGE) \
-f $(CONTAINERFILE) \
--target=dev \
--build-arg ROS_DISTRO=$(ROS_DISTRO) .
@mkdir -p $(MARKER_DIR)
@touch $@
$(FINAL_BUILT): $(BASE_BUILT) $(CONTAINERFILE)
@echo "==> Building final image..."
@$(CONTAINER_ENGINE) build \
-t $(BASE_IMAGE) \
-f $(CONTAINERFILE) \
--target=final \
--build-arg ROS_DISTRO=$(ROS_DISTRO) .
@mkdir -p $(MARKER_DIR)
@touch $@
refresh:
@rm -rf $(MARKER_DIR)
@echo "==> Removed build markers, which will trigger rebuilds on next runs."
clean:
@rm -rf $(MARKER_DIR)
-@$(CONTAINER_ENGINE) rmi $(BASE_IMAGE) $(DEV_IMAGE) $(FINAL_IMAGE) 2>/dev/null
@echo "==> Removed build markers and deleted images..."