File size: 2,221 Bytes
bad179a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# Build Server Monitor with Qt 5:  ./build.sh [run|clean]
# Uses system Qt 5 dev files (pkg-config Qt5Widgets) or a local SDK unpacked from
# the Ubuntu qtbase5-dev packages into ~/.local/share/qt5-sdk/root (no root needed).
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"; B="$HERE/build"
[[ "${1:-}" == clean ]] && { rm -rf "$B"; echo cleaned; exit 0; }

if pkg-config --exists Qt5Widgets 2>/dev/null; then
    read -r -a QTF <<<"$(pkg-config --cflags Qt5Widgets)"; read -r -a QTL <<<"$(pkg-config --libs Qt5Widgets)"
    MOC="$(pkg-config --variable=host_bins Qt5Core)/moc"
else
    SDK="${QT5_SDK:-$HOME/.local/share/qt5-sdk/root}"; I="$SDK/usr/include/x86_64-linux-gnu/qt5"
    [[ -d "$I/QtWidgets" ]] || { echo "Qt 5 headers missing. Install qtbase5-dev, or: mkdir -p ~/.local/share/qt5-sdk && cd ~/.local/share/qt5-sdk &&
  apt-get download qtbase5-dev qtbase5-dev-tools libgl-dev libglx-dev libopengl-dev libvulkan-dev && for f in *.deb; do dpkg -x \$f root; done" >&2; exit 1; }
    QTF=(-I"$I" -I"$I/QtCore" -I"$I/QtGui" -I"$I/QtWidgets" -I"$SDK/usr/include" -I"$SDK/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++")
    QTL=(-L/usr/lib/x86_64-linux-gnu -l:libQt5Widgets.so.5 -l:libQt5Gui.so.5 -l:libQt5Core.so.5)
    MOC="$SDK/usr/lib/qt5/bin/moc"
fi
FLAGS=(-std=c++17 -O2 -fPIC -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -DQT_NO_DEBUG "${QTF[@]}" -I"$HERE/src")
mkdir -p "$B/obj"
mapfile -t SRCS < <(find "$HERE/src" -name '*.cpp' | sort)
mapfile -t MOCH < <(grep -l Q_OBJECT -r "$HERE/src" --include='*.h')
for h in "${MOCH[@]}"; do # moc only what needs it
    m="$B/obj/moc_$(basename "${h%.h}").cpp"; [[ "$m" -nt "$h" ]] || "$MOC" "$h" -o "$m"; SRCS+=("$m")
done
NEWEST_H=$(find "$HERE/src" -name '*.h' -printf '%T@\n' | sort -n | tail -1)
OBJS=()
for s in "${SRCS[@]}"; do
    o="$B/obj/$(basename "${s%.cpp}").o"; OBJS+=("$o")
    if [[ ! -f "$o" || "$s" -nt "$o" || $(stat -c %Y "$o") < ${NEWEST_H%.*} ]]; then echo "  CXX ${s#$HERE/}"; g++ "${FLAGS[@]}" -c "$s" -o "$o" & fi
done
wait
g++ -o "$B/ServerMonitor" "${OBJS[@]}" "${QTL[@]}" -lpthread && echo "Done: $B/ServerMonitor"
[[ "${1:-}" == run ]] && exec "$B/ServerMonitor"; true