forked from weareaudiofile/bluez-dbus-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·119 lines (100 loc) · 3.21 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·119 lines (100 loc) · 3.21 KB
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
#!/bin/bash
clear
echo "[INFO] Setting up bluez-dbus-cpp build environment..."
set -e
trap 'echo "[ERROR] Script interrupted or failed"; exit 1' ERR
TARGET_USER="root"
TARGET_DIR="/usr/local"
APP_NAME="example"
OUT_BINARY="../build/bin/$APP_NAME"
# Detect build type
if [[ "$1" == "R" || "$1" == "r" ]]; then
BUILD_TYPE="Release"
else
BUILD_TYPE="Debug"
fi
# Rebuild flag
REBUILD_FLAG=false
if [[ "$2" == "rebuild" ]]; then
echo "[INFO] Rebuild flag detected. Cleaning build directory..."
REBUILD_FLAG=true
fi
# Check previous target
PREV_TARGET=""
if [[ -f "build/CMakeCache.txt" ]]; then
if grep -q "TARGET_STM32:BOOL=ON" "build/CMakeCache.txt"; then
PREV_TARGET="STM32"
else
PREV_TARGET="Linux"
fi
fi
# Detect target IP over USB
get_target_ip() {
echo "[INFO] Detecting STM32MP1 IP (USB)..."
IP_CANDIDATES=$(ip a | grep -A 2 "enx" | grep inet | awk '{print $2}' | cut -d/ -f1)
TARGET_IPv4=$(echo "$IP_CANDIDATES" | grep -oP '^\d+\.\d+\.\d+\.\d+')
if [[ -z "$TARGET_IPv4" ]]; then
echo "[ERROR] No IP found on USB interface. Is STM32MP1 connected?"
exit 1
fi
TARGET_IP=$(echo "$TARGET_IPv4" | sed 's/\.[0-9]*$/.1/')
echo "[INFO] Found target IP: $TARGET_IP"
}
# Select build target
echo "Choose build target:"
echo "1) STM32MP1 (cross-compilation)"
echo "2) Native Linux (host build)"
read -rp "Enter choice [1 for STM32MP1 or any other key for native]: " choice
if [[ "$choice" == "1" ]]; then
CURRENT_TARGET="STM32"
else
CURRENT_TARGET="Linux"
fi
# Clean build if needed
if [[ "$REBUILD_FLAG" == "true" || "$PREV_TARGET" != "$CURRENT_TARGET" && -n "$PREV_TARGET" ]]; then
echo "[INFO] Cleaning build directory due to rebuild or target change..."
rm -rf build
fi
mkdir -p build
cd build
sudo chown -R $USER:$USER .
# Optional protocol regeneration flag
if [[ "$REBUILD_FLAG" == "true" ]]; then
CMAKE_FLAGS="-DFORCE_PROTOCOL_REGENERATION=ON"
else
CMAKE_FLAGS=""
fi
# Configure & build
if [[ "$CURRENT_TARGET" == "STM32" ]]; then
echo "[INFO] Building for STM32MP1..."
SDK_ENV="/home/aiospace/STM32MPU_workspace/STM32MPU-Ecosystem-v6.0.0/Developer-Package/SDK/environment-setup-cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi"
if [[ ! -f "$SDK_ENV" ]]; then
echo "[ERROR] SDK environment file not found!"
exit 1
fi
source "$SDK_ENV"
echo "[DEBUG] CC=$CC"
cmake .. -DTARGET_STM32=ON -DBUILD_EXAMPLE=1 -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE_FLAGS
else
echo "[INFO] Building for native Linux..."
cmake .. -DTARGET_STM32=OFF -DBUILD_EXAMPLE=1 -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE_FLAGS
fi
cmake --build .
# Validate binary
if [[ ! -f "$OUT_BINARY" ]]; then
echo "[ERROR] Build failed: $OUT_BINARY not found."
exit 1
fi
# Run/deploy
if [[ "$CURRENT_TARGET" == "STM32" ]]; then
get_target_ip
echo "[INFO] Copying binary to target..."
scp "$OUT_BINARY" "$TARGET_USER@$TARGET_IP:$TARGET_DIR"
echo "[INFO] Setting execute permission..."
ssh "$TARGET_USER@$TARGET_IP" "chmod +x $TARGET_DIR/$APP_NAME"
echo "[INFO] Running app on target..."
# ssh "$TARGET_USER@$TARGET_IP" "cd $TARGET_DIR && ./$APP_NAME"
else
echo "[INFO] Running $APP_NAME locally..."
./"$OUT_BINARY"
fi