-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·223 lines (181 loc) · 5.15 KB
/
make.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
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
#!/usr/bin/env bash
set -e
cd "$(dirname "$0")"
#############
# Functions #
#############
cred="\e[31m"
cclear="\e[0m"
cgreen="\e[32m"
echo_err() {
printf "${cred}$1${cclear}\n"
}
echo_ok() {
printf "${cgreen}$1${cclear}\n"
}
ensure_command() {
command -v $1 >/dev/null 2>&1 || { echo_err "Command $1 is not installed; please install it. $2"; exit 1; }
echo_ok "Command $1 found:$cclear $(command -v $1)"
}
check_command() {
command -v $1 >/dev/null 2>&1
}
# Look for library with pkg-config
ensure_package() {
pkg-config --exists $1 || { echo_err "Library $1 is not installed; please install it. $2"; exit 1; }
echo_ok "Library $1 found"
}
defdir() {
if ! [ -d $1 ]
then
mkdir -p $1
fi
}
##########
# Checks #
##########
#= Init cache =#
defdir .build
if [ ! -f .build/make_data.json ]; then
echo "{}" > .build/make_data.json
fi
#= Required libraries =#
# Find libdrm
if [ ! -f /usr/lib/aarch64-linux-gnu/libdrm.so ]; then
if [ -f /usr/lib/aarch64-linux-gnu/libdrm.so.2 ]; then
# Problem on Pi's
sudo ln -s /usr/lib/aarch64-linux-gnu/libdrm.so.2 /usr/lib/aarch64-linux-gnu/libdrm.so
else
echo_err "Couldn't find libdrm!"
exit 1
fi
fi
# install rpicam-apps
#= Find commands =#
echo "Checking required commands..."
ensure_command "swift" "https://www.swift.org/install/"
# ensure_command "cmake" "sudo apt-get install cmake"
# ensure_command "make"
# check_command "g++" || ensure_command "clang++" "sudo apt-get install clang"
# ensure_command "wget" "sudo apt-get install wget"
# ensure_command "unzip" "sudo apt-get install unzip"
ensure_command "pushd"
ensure_command "popd"
# ensure_command "cargo" "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
# ensure_command "xinit" "sudo apt-get install --no-install-recommends xserver-xorg x11-xserver-utils xinit openbox"
# ensure_command "jq" "sudo apt-get install jq"
# ensure_command "compgen"
ensure_command "libcamera-still" "sudo apt-get install libcamera-apps"
ensure_package "cairo" "sudo apt-get install libcairo2-dev"
# ensure_package "libcamera" "sudo apt-get install libcamera-dev"
##############
# Parameters #
##############
echo "Checking parameters..."
if check_command "nproc"
then
jobs=${JOBS:-$(nproc)}
elif check_command "sysctl"
then
jobs=${JOBS:-$(sysctl -n hw.ncpu)}
else
jobs=${JOBS:-4}
fi
echo_ok "JOBS: $jobs"
# "debug" or "release"
CONFIGURATION=${CONFIGURATION:-debug}
echo_ok "CONFIGURATION: $CONFIGURATION"
############
# Building #
############
OPENCV_VERSION="4.x"
libs=(
"drm"
# "opencv_video" "opencv_core" "opencv_videoio"
)
lib_dirs=(
"/usr/lib/aarch64-linux-gnu" "/usr/local/lib"
)
include_dirs=(
"deps/libdrm/include/drm"
"deps/libdrm"
# "deps/olive.c"
# "deps/opencv-$OPENCV_VERSION/include"
# ".build/opencv"
)
linker_flags=()
cflags=()
cflags+=($(pkg-config --cflags cairo))
linker_flags+=($(pkg-config --libs libjpeg))
cflags+=($(pkg-config --cflags libjpeg))
# libs+=$(pkg-config --libs-only-l cairo)
# lib_dirs+=$(pkg-config --libs-only-L cairo)
case "$1" in
"run" | "build")
#= Build OpenCV =#
# if [ ! -d deps/opencv-$OPENCV_VERSION ]; then
# pushd deps
# wget -O opencv.zip https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip
# unzip opencv.zip
# rm opencv.zip
# popd
# fi
# if [ "$((cat .build/make_data.json || echo '{}') | jq '.opencv_built')" != "true" ]; then
# defdir .build/opencv
# pushd .build/opencv
# set -x
# cmake ../../deps/opencv-$OPENCV_VERSION -DBUILD_PERF_TESTS=NO -DBUILD_TESTS=NO -DINSTALL_TESTS=NO
# cmake --build . -j$jobs
# set +x
#
# echo "OpenCV built successfully"
# echo "Installing OpenCV libraries"
# sudo make install
# popd
# echo "$((cat .build/make_data.json || echo '{}') | jq '. + {opencv_built: true}')" > .build/make_data.json
# fi
#
# opencv_include_dirs=$(compgen -G "deps/opencv-$OPENCV_VERSION/modules/*/include")
# while read -r path; do
# include_dirs+=($path)
# done < <(compgen -G "deps/opencv-$OPENCV_VERSION/modules/*/include" || true)
#= Camera =#
# pushd Sources/Camera/LibCameraRs
# if [ "$CONFIGURATION" == "release" ]; then
# cargo build --release
# else
# cargo build
# fi
# popd
#= Generate swift file =#
echo "// This file is generated by make.sh on $(date)
let LIBCAMERA_STILL_LOCATION: String = \"$(command -v libcamera-still)\"
" > Sources/Photobooth/generated.swift
#= Photobooth =#
swift_flags=""
for include_dir in "${include_dirs[@]}"; do
swift_flags+=" -Xcc -I$include_dir"
done
for lib_dir in "${lib_dirs[@]}"; do
swift_flags+=" -Xlinker -L$lib_dir"
done
for lib in "${libs[@]}"; do
swift_flags+=" -Xlinker -l$lib"
done
for cflag in "${cflags[@]}"; do
swift_flags+=" -Xcc $cflag"
done
for linker_flag in "${linker_flags[@]}"; do
swift_flags+=" -Xlinker $linker_flag"
done
set -x
swift $1 -c $CONFIGURATION $swift_flags
;;
"clean")
swift package clean
;;
*)
echo "No command given. Use \`build\`, \`run\`, \`clean\`"
exit 1
;;
esac