-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
98 lines (83 loc) · 1.98 KB
/
build.sh
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
#!/bin/bash
is_clean=0
while getopts "rf" opt_sg; do
case $opt_sg in
f) is_clean=2 ;;
r) is_clean=1 ;;
?) echo "unknown option: $opt_sg" ;;
esac
done
pwd=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
bdir="_build"
# todo, add into meson.build
# only for test, need sudo
# cp $pwd/data/asciibox.gschema.xml /usr/share/glib-2.0/schemas/
# glib-compile-schemas /usr/share/glib-2.0/schemas/
function sudo_run() {
sudo -u root -H sh -c "$1"
}
function sync_version() {
local ver_o="" ver_n=""
ver_o=$(sed -n '2p' meson.build | grep -Eo "[0-9]+\.[0-9]+\.+[0-9]")
ver_n=$(sed -n '3p' Cargo.toml | grep -Eo "[0-9]+\.[0-9]+\.+[0-9]")
if [ "$ver_o" != "$ver_n" ]; then
echo "change Cargo: $ver_n --> $ver_o"
sed -i "3s/${ver_n}/${ver_o}/g" Cargo.toml
fi
}
function build_resource() {
cd "${pwd}/data" || exit
glib-compile-resources asciibox.gresource.xml
cd - || exit
}
function rm_target() {
local target="$pwd/$bdir/src/asciibox"
if [ -f "$target" ]; then
rm -f "$target"
fi
}
function build_target() {
cd "$pwd" || exit
if [ $is_clean -eq 1 ]; then
meson setup $bdir --reconfigure
elif [ $is_clean -eq 2 ]; then
rm -rf $bdir
meson setup $bdir
else
meson setup $bdir
fi
cd "${pwd}/${bdir}" || exit
meson compile
cd - || exit
cd - || exit
}
function link_target_resource() {
local sdir="$pwd/$bdir/data" ddir="" src="" dst=""
src="$sdir/asciibox.gresource"
ddir=$(grep "PKGDATA_DIR" "${pwd}/src/config.rs" | awk '{print $6}' | sed 's/;//g' | sed 's/"//g')
dst="$ddir/asciibox.gresource"
if [ ! -d "$ddir" ]; then
sudo_run "mkdir -p $ddir"
fi
if [ ! -h "$dst" ]; then
sudo_run "ln -s $src $dst"
fi
}
function run_target() {
local target="$pwd/$bdir/src/asciibox"
if [ -f "$target" ]; then
cd "$pwd/$bdir/src" || exit
./asciibox
cd - || exit
else
echo "[error]: build failed."
fi
}
function main() {
sync_version
build_resource
build_target
# link_target_resource
run_target
}
main "$@"