-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
159 lines (134 loc) · 4.87 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
VERSION_STRING := 0.6.0
ROOT_PACKAGE := znail
SYSTEST_PACKAGE := systest
.PHONY: help
help:
@echo
@echo "Usage make <target> <args> -jN"
@echo ""
@echo " Environment:"
@echo ""
@echo " venv Create virtualenv and install all dependencies"
@echo " Run 'source activate' to enable the environment"
@echo " Utilities:"
@echo ""
@echo " format Automatically format all Python source code"
@echo ""
@echo " Testing:"
@echo " check Run all tests in the local environment"
@echo " test Run all unit tests"
@echo " static Run static analysis"
@echo ""
@echo " Packaging:"
@echo ""
@echo " pypi Build PyPi packages"
@echo " image Build all image types"
@echo " raspbian_image Build a Raspbian image suitable for use with most Raspberry Pi models"
@echo " armbian_image Build a Armbian image suitable for use with the NanoPi R2S"
@echo ""
@echo " Clean:"
@echo ""
@echo " clean Cleans all temporary files and build output"
@echo " cleanup Cleans all temporary files and build output"
@echo " removes venvs and marks containers for rebuilding"
@echo " cleanvenv Removes all venvs"
@echo ""
@echo " If you find that a high level target is taking too long to build,"
@echo " try using the -j flag to run targets in parallel."
@echo ""
# The BASH_ENV variable tells bash where to find its rc file. If the rc file
# exists, it is sourced by bash on startup.
#
# Lets use this feature to automatically activate the virtual environment.
BASH_ENV := .venv/bin/activate
export BASH_ENV
SHELL := bash
# Targets related to verification and development environment:
.PHONY: test
test:
pytest $(ROOT_PACKAGE)
.PHONY: systest
systest:
pytest $(SYSTEST_PACKAGE)
.PHONY: static
static:
@flake8 $(ROOT_PACKAGE) $(SYSTEST_PACKAGE)
@black -l120 --check $(ROOT_PACKAGE) $(SYSTEST_PACKAGE)
.PHONY: check
check: venv static test
run: venv
run:
SHUTDOWN_COMMAND=echo IPTABLES_COMMAND=echo TC_COMMAND=echo HUB_CTRL_COMMAND=echo SYSTEMCTL_COMMAND=echo HOSTS_FILE=/dev/null DNSMASK_OVERRIDES_FILE=/dev/null znail -p 8080 -d
venv: .venv
.PHONY: format
format:
@black -l120 $(ROOT_PACKAGE) $(SYSTEST_PACKAGE)
.PHONY: clean
clean: cleanimage
rm -rf build/
rm -f $(ROOT_PACKAGE)/version.py
rm -f .benchmark
.PHONY: cleanup
cleanup: clean cleanvenv
rm -rf dist/
.venv: requirements.txt requirements-dev.txt setup.py
python3 -m venv .venv
.venv/bin/python3 -m pip install --upgrade setuptools pip wheel
.venv/bin/python3 -m pip install -r requirements-dev.txt -r requirements.txt
.venv/bin/python3 -m pip install -e .
cleanvenv:
-rm -rf .venv/*
-rmdir .venv
rm -rf *.egg-info/
$(ROOT_PACKAGE)/version.py: Makefile
@echo "# This file is automatically generated by Makefile" > $(ROOT_PACKAGE)/version.py
@echo "__version__ = '${VERSION_STRING}$(UPGRADE_VERSION)'" >> $(ROOT_PACKAGE)/version.py
# Packaging related targets:
pypi: bdist sdist
dist_pypi_directory:
mkdir -p dist/pypi
bdist: dist_pypi_directory znail/version.py
python3 setup.py bdist_wheel
mv dist/*.whl dist/pypi
sdist: dist_pypi_directory znail/version.py
python3 setup.py sdist
mv dist/*.tar.gz dist/pypi
package: pypi
# Targets related to image generation:
build/pi-gen:
mkdir -p build
cd build && git clone --branch 2020-02-13-raspbian-buster https://github.com/RPi-Distro/pi-gen.git
.PHONY: raspbian_image
raspbian_image: pypi | build/pi-gen
mkdir -p dist/image
rm -rf build/pi-gen/stage3 build/pi-gen/stage4 build/pi-gen/stage5
sed -e 's/wpasupplicant//' \
-e 's/wireless-tools//' \
-e 's/firmware-atheros//' \
-e 's/firmware-brcm80211//' \
-e 's/firmware-libertas//' \
-e 's/^\s*//' \
-i build/pi-gen/stage2/02-net-tweaks/00-packages
cp -r image/raspbian/* build/pi-gen/
cp -r requirements.txt dist/pypi/*.whl build/pi-gen/stage3/01-install-python-packages/files
cp -r image/common/files/* build/pi-gen/stage3/02-install-services/files
cd build/pi-gen && ./build-docker.sh
mv build/pi-gen/deploy/* dist/image/
build/armbian:
mkdir -p build
# It would be nice to be able to checkout specific branch or commit here to
# get builds that are reproducible, but this does not seem well supported by
# Armbian. For example, checking out branch v2021.05 yields a broken build
# due to upstream changes. As such, checkout the main branch.
cd build && git clone https://github.com/armbian/build.git armbian
.PHONY: armbian_image
armbian_image: pypi | build/armbian
mkdir -p dist/image build/armbian/userpatches/overlay
cp -r image/armbian/userpatches/* build/armbian/userpatches
cp -r requirements.txt dist/pypi/*.whl image/common/files/* image/armbian/files/* build/armbian/userpatches/overlay/
cd ./build/armbian && ./compile.sh docker znail-nanopi-r2s
mv build/armbian/output/images/* dist/image
.PHONY: image
image: raspbian_image armbian_image
cleanimage:
rm -rf build/image