forked from Sopsy/joycon-turnoff
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild-deck.sh
More file actions
executable file
·56 lines (46 loc) · 1.5 KB
/
Copy pathbuild-deck.sh
File metadata and controls
executable file
·56 lines (46 loc) · 1.5 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
#!/bin/bash
# Exit on any error
set -e
# Function to restore backups if build fails
restore_backups() {
echo "Build failed, restoring original files..."
if [ -d "/tmp/jcoff_backup" ]; then
sudo cp -r /tmp/jcoff_backup/* /
sudo rm -rf /tmp/jcoff_backup
echo "Original files restored."
fi
# Clean up temp directory if it exists
[ -d "$TEMP_DIR" ] && rm -rf "$TEMP_DIR"
exit 1
}
# Set up trap to restore backups on script failure
trap restore_backups ERR
echo "Backing up existing files..."
sudo mkdir -p /tmp/jcoff_backup/usr/lib
sudo mkdir -p /tmp/jcoff_backup/usr/include
sudo mkdir -p /tmp/jcoff_backup/usr/lib/pkgconfig
# Only backup files if they exist
[ -f /usr/lib/libudev.a ] && sudo cp /usr/lib/libudev.a /tmp/jcoff_backup/usr/lib/
[ -f /usr/include/libudev.h ] && sudo cp /usr/include/libudev.h /tmp/jcoff_backup/usr/include/
[ -f /usr/lib/pkgconfig/libudev.pc ] && sudo cp /usr/lib/pkgconfig/libudev.pc /tmp/jcoff_backup/usr/lib/pkgconfig/
# Only remove our custom-built static libraries and headers
echo "Cleaning previous custom builds..."
sudo rm -f /usr/local/lib/libhidapi*.a
sudo rm -f /usr/local/include/hidapi/hidapi.h
rm -rf build/
echo "Installing static development libraries..."
sudo pacman -S --needed --noconfirm \
cmake \
hidapi \
libusb \
systemd-libs
# Build
rm -rf build
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
# Show info
ldd ./jcoff
file ./jcoff
echo "Build complete! Binary is at: $(pwd)/jcoff"