Skip to content

Commit 703a326

Browse files
rzragarwal57
authored andcommitted
GH-14: build: Add helper.mk to setup system
It has been tested on debian but might work elsewhere (ie: WSL2 users) Testing on cloud should be enabled in separate commit Bug-SiliconLabs: UIC-3082 Bug-GitHub: rzr#3 Forwarded: #14 Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
1 parent 861d661 commit 703a326

File tree

1 file changed

+212
-0
lines changed

1 file changed

+212
-0
lines changed

helper.mk

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
#!/usr/bin/make -f
2+
# -*- makefile -*-
3+
# ex: set tabstop=4 noexpandtab:
4+
# -*- coding: utf-8 -*
5+
6+
default: help zpc/default
7+
@echo "$@: TODO: Support more than $^ by default"
8+
@date -u
9+
10+
SELF?=${CURDIR}/helper.mk
11+
12+
project?=unifysdk
13+
14+
CMAKE_GENERATOR?=Ninja
15+
export CMAKE_GENERATOR
16+
17+
build_dir?=build
18+
sudo?=sudo
19+
20+
debian_codename?=bullseye
21+
22+
packages?=cmake ninja-build build-essential python3-full ruby clang
23+
packages+=git-lfs unp time file
24+
packages+=nlohmann-json3-dev
25+
# TODO: remove for offline build
26+
packages+=curl wget python3-pip
27+
packages+=time
28+
29+
RUST_VERSION?=1.65.0
30+
export PATH := ${HOME}/.cargo/bin:${PATH}
31+
32+
zpc_exe?=${build_dir}/applications/zpc/zpc
33+
exes+=${zpc_exe}
34+
35+
zpc_cmake_options?=\
36+
-DBUILD_AOXPC=OFF \
37+
-DBUILD_CPCD=OFF \
38+
-DBUILD_DEV_GUI=OFF \
39+
-DBUILD_EMD=OFF \
40+
-DBUILD_EPC=OFF \
41+
-DBUILD_GMS=OFF \
42+
-DBUILD_IMAGE_PROVIDER=OFF \
43+
-DBUILD_NAL=OFF \
44+
-DBUILD_OTBR=OFF \
45+
-DBUILD_POSITIONING=OFF \
46+
-DBUILD_TESTING=ON \
47+
-DBUILD_UPTI_CAP=OFF \
48+
-DBUILD_UPTI_WRITER=OFF \
49+
-DBUILD_UPVL=OFF \
50+
-DBUILD_ZIGBEED=OFF \
51+
-DBUILD_ZIGPC=OFF
52+
53+
help: README.md
54+
@cat $<
55+
@echo ""
56+
@echo "# Available rules at your own risk:"
57+
@grep -o '^[^ ]*:' ${SELF} | grep -v '\$$' | grep -v '^#' | grep -v '^\.'
58+
@echo ""
59+
@echo "# Environment:"
60+
@echo "# PATH=${PATH}"
61+
@echo ""
62+
63+
setup/debian: ${CURDIR}/docker/target_dependencies.apt
64+
cat /etc/debian_version
65+
-${sudo} apt update
66+
${sudo} apt install -y $(shell cat $<)
67+
${sudo} apt install -y ${packages}
68+
@echo "$@: TODO: Support debian stable rustc=1.63 https://tracker.debian.org/pkg/rustc"
69+
70+
setup/rust:
71+
@echo "$@: TODO: Support https://tracker.debian.org/pkg/rustup"
72+
curl https://sh.rustup.rs -sSf | bash -s -- -y --default-toolchain ${RUST_VERSION}
73+
cat $${HOME}/.cargo/env
74+
@echo '$@: info: You might like to add ". $${HOME}/.cargo/env" to "$${HOME}/.bashrc"'
75+
-which rustc
76+
rustc --version
77+
cargo --version
78+
@echo "$@: TODO: Support stable version from https://releases.rs/ or older"
79+
80+
setup/python:
81+
@echo "$@: TODO: https://github.com/wbond/pybars3/issues/82"
82+
pip3 --version || echo "warning: Please install pip"
83+
pip3 install pybars3
84+
85+
cmake_url?=https://github.com/Kitware/CMake/releases/download/v3.21.6/cmake-3.21.6-Linux-x86_64.sh
86+
cmake_filename?=$(shell basename -- "${cmake_url}")
87+
cmake_sha256?=d460a33c42f248388a8f2249659ad2f5eab6854bebaf4f57c1df49ded404e593
88+
89+
setup/cmake:
90+
@echo "$@: TODO: remove for debian-12+"
91+
curl -O -L ${cmake_url}
92+
sha256sum ${cmake_filename} \
93+
| grep "${cmake_sha256}"
94+
${SHELL} "${cmake_filename}" \
95+
--prefix=/usr/local \
96+
--skip-license
97+
rm -v "${cmake_filename}"
98+
cmake --version
99+
100+
setup-cmake: setup/cmake
101+
102+
setup/debian/bullseye: setup/debian setup/rust setup/python setup/cmake
103+
date -u
104+
105+
setup/debian/bookworm: setup/debian setup/rust setup/python
106+
date -u
107+
108+
setup: setup/debian/${debian_codename}
109+
date -u
110+
111+
git: .git/lfs
112+
git lfs version || echo "$@: warning: Please install git-lfs"
113+
git lfs status --porcelain || git lfs install
114+
time git lfs pull
115+
git lfs update || git lfs update --force
116+
git lfs status --porcelain
117+
118+
configure: ${build_dir}/CMakeCache.txt
119+
file -E $<
120+
121+
${build_dir}/CMakeCache.txt: CMakeLists.txt ${build_pre_list}
122+
cmake -B ${build_dir}
123+
124+
build: ${build_dir}/CMakeCache.txt
125+
cmake --build ${<D} \
126+
|| cat ${build_dir}/CMakeFiles/CMakeOutput.log
127+
cmake --build ${<D}
128+
.PHONY: build
129+
130+
${build_dir}/%: build
131+
file -E "$<"
132+
133+
${exe}: build
134+
file -E $<
135+
136+
all: ${exes}
137+
file -E $<
138+
139+
test: ${build_dir}
140+
ctest --test-dir ${<}
141+
142+
distclean:
143+
rm -rf ${build_dir}
144+
145+
prepare: git
146+
147+
all/default: configure build test
148+
@date -u
149+
150+
zpc/configure: CMakeLists.txt
151+
cmake -B ${build_dir} ${zpc_cmake_options}
152+
153+
zpc/build: zpc/configure build
154+
@date -u
155+
156+
zpc/test: ${build_dir}/applications/zpc/components/zwave_command_classes/test/
157+
ctest --test-dir ${<}
158+
159+
zpc/default: zpc/configure zpc/build
160+
@date -u
161+
162+
### @rootfs is faster than docker for env check
163+
164+
rootfs_dir?=/var/tmp/var/lib/machines/${project}
165+
166+
rootfs_shell?=${sudo} systemd-nspawn \
167+
--machine="${project}" \
168+
--directory="${rootfs_dir}"
169+
${rootfs_dir}:
170+
@mkdir -pv ${@D}
171+
time ${sudo} debootstrap --include="systemd,dbus" "${debian_codename}" "${rootfs_dir}"
172+
@${sudo} chmod -v u+rX "${rootfs_dir}"
173+
174+
clean/rootfs:
175+
-${sudo} mv -fv -- "${rootfs_dir}" "${rootfs_dir}._$(shell date -u +%s).bak"
176+
177+
rootfs/%: ${rootfs_dir}
178+
${sudo} file -E -- "${rootfs_dir}" \
179+
|| ${SELF} "${rootfs_dir}"
180+
${rootfs_shell} apt-get update
181+
${rootfs_shell} apt-get install -- make sudo
182+
${rootfs_shell} \
183+
--bind="${CURDIR}:${CURDIR}" \
184+
${MAKE} \
185+
--directory="${CURDIR}" \
186+
--file="${CURDIR}/helper.mk" \
187+
HOME="${HOME}" \
188+
USER="${USER}" \
189+
-- "${@F}"
190+
191+
check/rootfs: prepare rootfs/check
192+
echo "# TODO only touched files"
193+
@echo "# ${project}: log: $@: done: $^"
194+
195+
test/rootfs: clean/rootfs rootfs/setup rootfs/distclean check/rootfs
196+
@echo "# ${project}: log: $@: done: $^"
197+
198+
### @Docker: is only for validation no need to rely on it
199+
200+
prepare/docker: Dockerfile prepare
201+
time docker build \
202+
--tag="${project}" \
203+
--file="$<" .
204+
@echo "# ${project}: log: $@: done: $^"
205+
206+
docker_workdir?=/usr/local/opt/${project}
207+
208+
docker/%: Dockerfile
209+
time docker run "${project}:latest" -C "${docker_workdir}" "${@F}"
210+
211+
test/docker: distclean prepare/docker docker/help docker/test
212+
@echo "# ${project}: log: $@: done: $^"

0 commit comments

Comments
 (0)