-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
136 lines (101 loc) · 3.42 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# ----------------------------------------------------------------------------#
# --------------- MAKEFILE FOR H2 COMPILATION --------------------------------#
# ----------------------------------------------------------------------------#
# For reference see
# https://gist.github.com/mpneuried/0594963ad38e68917ef189b4e6a269db
# --------------- DECLARATIONS -----------------------------------------------#
.DEFAULT_GOAL := help
.PHONY: help
help: ## List of main goals
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / \
{printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
ifeq ($(OS),Windows_NT)
# Windows is not supported!
else
# Some commands are different in Linux and Mac
UNAME_S := $(shell uname -s)
# User's credential will be passed to the image and container
USERNAME=$(shell whoami)
USER_UID=$(shell id -u)
USER_GID=$(shell id -g)
endif
PWD=$(shell pwd)
IMAGENAME=h2-compilation
CONTAINERNAME=h2-compilation
DBUILD=docker build . \
--file ./environment/Dockerfile \
--tag ${IMAGENAME} \
--build-arg USERNAME=${USERNAME} \
--build-arg USER_UID=${USER_UID} \
--build-arg USER_GID=${USER_GID}
DRUN=docker run \
--interactive \
--privileged \
--rm \
--volume ${PWD}:/workdir \
--workdir /workdir \
--name=${CONTAINERNAME}
DEXEC=docker exec \
--interactive \
$(shell cat container)
PYLINT=pylint \
--exit-zero \
--rcfile=.pylintrc \
src/ >> pylint.log
# --------------- DOCKER STUFF -----------------------------------------------#
.PHONY: build
build: ./environment/Dockerfile ## Build the image
${DBUILD}
.PHONY: build-nc
build-nc: ./environment/Dockerfile ## Build the image from scratch
${DBUILD} --no-cache
# --privileged: needed for DGB, but also needed for leaksan,
# so causes a heisenbug: lsan throws a warning, enabling --priv fixes it
container: ## Spin out the container
# if `build` is put in dependencies then it will cause rerun of `container`,
# we want it to be blocked by `container` file though
make build
${DRUN} \
--detach \
--cidfile=container \
${IMAGENAME} \
/bin/bash
.PHONY: rshell
rshell: container
docker exec --privileged -it $(shell cat container) /bin/bash
.PHONY: shell
shell: container
docker exec -it $(shell cat container) /bin/bash
# --------------- CLEANING ---------------------------------------------------#
.PHONY: clean
clean: dev-clean clean-container ## Clean everything
.PHONY: clean-cache
clean-cache: ## Clean python cache
ifeq ($(UNAME_S),Linux)
find . -name "__pycache__" -type d -print0 | xargs -r0 -- rm -r
find . -name "*.pyc" -type f -print0 | xargs -r0 -- rm -r
else
find . -name "*.pyc" -type f -exec rm -rf {} \;
find . -name "__pycache__" -type d -exec rm -rf {} \;
endif
.PHONY: clean-container
clean-container: ## Stop and remove the container
docker ps -q --filter "name=${CONTAINERNAME}" | grep -q . && \
docker stop ${CONTAINERNAME} || true
rm -f container
.PHONY: clean-data
clean-data: ## Clean any data
ifeq ($(UNAME_S),Linux)
find . -name "printed_graph.df" -type f -print0 | xargs -r0 -- rm -r
else
find . -name "printed_graph.df" -exec rm -rf {} \;
endif
rm -f *.vcd *.png *.txt
.PHONY: clean-logs
clean-logs: ## Clean logs
rm -f pylint.log pycodestyle.log
# --------------- DEVELOPMENT ------------------------------------------------#
# Commands from this section are meant to be used ONLY inside of
# the development container via VSCode
.PHONY: dev-clean
dev-clean: clean-cache clean-data clean-logs ## See non-dev version