-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathhelper.mk
executable file
·239 lines (184 loc) · 6 KB
/
helper.mk
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/make -f
# -*- makefile -*-
# ex: set tabstop=4 noexpandtab:
# -*- coding: utf-8 -*
default: help all/default
@echo "$@: TODO: Support more than $^ by default"
@date -u
SELF?=${CURDIR}/helper.mk
project?=unifysdk
# Allow overloading from env if needed
# VERBOSE?=1
BUILD_DEV_GUI?=OFF
BUILD_IMAGE_PROVIDER?=ON
cmake_options?=-B ${build_dir}
CMAKE_GENERATOR?=Ninja
export CMAKE_GENERATOR
build_dir?=build
sudo?=sudo
debian_codename?=bookworm
packages?=cmake ninja-build build-essential python3-full ruby clang
packages+=git-lfs unp time file
packages+=nlohmann-json3-dev
# TODO: remove for offline build
packages+=curl wget python3-pip
packages+=time
# Extra for components, make it optional
packages+=python3-jinja2
packages+=yarnpkg
rust_url?=https://sh.rustup.rs
RUST_VERSION?=1.71.0
export PATH := ${HOME}/.cargo/bin:${PATH}
# Allow overloading from env if needed
ifdef VERBOSE
CMAKE_VERBOSE_MAKEFILE?=${VERBOSE}
cmake_options+=-DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE}
endif
ifdef BUILD_DEV_GUI
cmake_options+=-DBUILD_DEV_GUI=${BUILD_DEV_GUI}
ifeq (${BUILD_DEV_GUI}, ON)
packages+=nodejs
endif
endif
ifdef BUILD_IMAGE_PROVIDER
cmake_options+=-DBUILD_IMAGE_PROVIDER=${BUILD_IMAGE_PROVIDER}
endif
# Allow to bypass env detection, to support more build systems
ifdef CMAKE_SYSTEM_PROCESSOR
cmake_options+=-DCMAKE_SYSTEM_PROCESSOR="${CMAKE_SYSTEM_PROCESSOR}"
export CMAKE_SYSTEM_PROCESSOR
else
# CMAKE_SYSTEM_PROCESSOR?=$(shell uname -m)
endif
ifdef CARGO_TARGET_TRIPLE
cmake_options+=-DCARGO_TARGET_TRIPLE="${CARGO_TARGET_TRIPLE}"
export CMAKE_TARGET_TRIPLE
endif
help: README.md
@cat $<
@echo ""
@echo "# Available rules at your own risk:"
@grep -o '^[^ ]*:' ${SELF} | grep -v '\$$' | grep -v '^#' | grep -v '^\.'
@echo ""
@echo "# Environment:"
@echo "# PATH=${PATH}"
@echo ""
setup/debian: ${CURDIR}/docker/target_dependencies.apt ${CURDIR}/docker/host_dependencies.apt
cat /etc/debian_version
-${sudo} apt update
${sudo} apt install -y $(shell sort $^ | sed -e 's|//.*||g' )
${sudo} apt install -y ${packages}
@echo "$@: TODO: Support debian stable rustc=1.63 https://tracker.debian.org/pkg/rustc"
setup/rust:
@echo "$@: TODO: Support https://tracker.debian.org/pkg/rustup"
curl --insecure --proto '=https' --tlsv1.2 -sSf ${rust_url} | bash -s -- -y --default-toolchain ${RUST_VERSION}
cat $${HOME}/.cargo/env
@echo '$@: info: You might like to add ". $${HOME}/.cargo/env" to "$${HOME}/.bashrc"'
-which rustc
rustc --version
cargo --version
rustc --print target-list
@echo "$@: TODO: https://github.com/kornelski/cargo-deb/issues/159"
cargo install --version 1.44.0 --locked cargo-deb
@echo "$@: TODO: Support stable version from https://releases.rs/ or older"
setup/python:
python3 --version
@echo "$@: TODO: https://bugs.debian.org/1094297"
pip3 --version || echo "warning: Please install pip"
pip3 install "pybars3" \
|| pip3 install --break-system-packages "pybars3"
cmake_url?=https://github.com/Kitware/CMake/releases/download/v3.21.6/cmake-3.21.6-Linux-x86_64.sh
cmake_filename?=$(shell basename -- "${cmake_url}")
cmake_sha256?=d460a33c42f248388a8f2249659ad2f5eab6854bebaf4f57c1df49ded404e593
setup/cmake:
@echo "$@: TODO: remove for debian-12+"
curl -O -L ${cmake_url}
sha256sum ${cmake_filename} \
| grep "${cmake_sha256}"
${SHELL} "${cmake_filename}" \
--prefix=/usr/local \
--skip-license
rm -v "${cmake_filename}"
cmake --version
setup-cmake: setup/cmake
setup/debian/bullseye: setup/debian setup/rust setup/python setup/cmake
date -u
setup/debian/bookworm: setup/debian setup/rust setup/python
date -u
setup: setup/debian/${debian_codename}
date -u
git/lfs/prepare:
[ ! -r .git/lfs/objects ] \
|| { git lfs version || echo "$@: warning: Please install git-lfs" \
&& git lfs status --porcelain || git lfs install \
&& time git lfs pull \
&& git lfs update || git lfs update --force \
&& git lfs status --porcelain \
&& git lfs ls-files \
; }
git/modules/prepare:
[ ! -r .git/modules ] || git submodule update --init --recursive
git/prepare: git/modules/prepare git/lfs/prepare
configure: ${build_dir}/CMakeCache.txt
file -E $<
${build_dir}/CMakeCache.txt: CMakeLists.txt
cmake ${cmake_options}
build: ${build_dir}/CMakeCache.txt
cmake --build ${<D} \
|| cat ${build_dir}/CMakeFiles/CMakeOutput.log
cmake --build ${<D}
.PHONY: build
${build_dir}/%: build
file -E "$@"
test: ${build_dir}
ctest --test-dir ${<}
check: test
dist: ${build_dir}
cmake --build $< --target package
install -d $</$@
cp -av ${<}/*.deb $</$@
distclean:
rm -rf ${build_dir}
prepare: git/prepare
all/default: configure prepare build test dist
@date -u
### @rootfs is faster than docker for env check
rootfs_dir?=/var/tmp/var/lib/machines/${project}
rootfs_shell?=${sudo} systemd-nspawn \
--machine="${project}" \
--directory="${rootfs_dir}"
${rootfs_dir}:
@mkdir -pv ${@D}
time ${sudo} debootstrap --include="systemd,dbus" "${debian_codename}" "${rootfs_dir}"
@${sudo} chmod -v u+rX "${rootfs_dir}"
clean/rootfs:
-${sudo} mv -fv -- "${rootfs_dir}" "${rootfs_dir}._$(shell date -u +%s).bak"
rootfs/%: ${rootfs_dir}
${sudo} file -E -- "${rootfs_dir}" \
|| ${SELF} "${rootfs_dir}"
${rootfs_shell} apt-get update
${rootfs_shell} apt-get install -- make sudo
${rootfs_shell} \
--bind="${CURDIR}:${CURDIR}" \
${MAKE} \
--directory="${CURDIR}" \
--file="${CURDIR}/helper.mk" \
HOME="${HOME}" \
USER="${USER}" \
-- "${@F}"
check/rootfs: prepare rootfs/check
echo "# TODO only touched files"
@echo "# ${project}: log: $@: done: $^"
test/rootfs: clean/rootfs rootfs/setup rootfs/distclean check/rootfs
@echo "# ${project}: log: $@: done: $^"
### @Docker: is only for validation no need to rely on it
prepare/docker: Dockerfile prepare
time docker build \
--tag="${project}" \
--file="$<" .
@echo "# ${project}: log: $@: done: $^"
docker_workdir?=/usr/local/opt/${project}
docker/%: Dockerfile
time docker run "${project}:latest" -C "${docker_workdir}" "${@F}"
test/docker: distclean prepare/docker docker/help docker/test
@echo "# ${project}: log: $@: done: $^"