forked from TylerBoni/FlipMouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-mouse
More file actions
executable file
·148 lines (121 loc) · 3.57 KB
/
Copy pathmake-mouse
File metadata and controls
executable file
·148 lines (121 loc) · 3.57 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
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
#!/bin/bash
# make-mouse (macOS + Android NDK)
set -euo pipefail
# Parse args
DEBUG_MODE=0
for arg in "$@"; do
case $arg in
--debug) DEBUG_MODE=1 ;;
esac
done
CWD="$(pwd)"
# Small helpers
nproc_compat() {
if command -v nproc >/dev/null 2>&1; then nproc
else sysctl -n hw.ncpu
fi
}
require_cmd() {
command -v "$1" >/dev/null 2>&1 || {
echo "Missing required command: $1"
exit 1
}
}
if [ "$DEBUG_MODE" -eq 1 ]; then
echo "=== Running in DEBUG mode for macOS (host build) ==="
echo "Note: libevdev is Linux-specific; macOS debug build is not supported by this script."
echo "Run without --debug to build the Android binary."
exit 1
fi
# ---- Android build on macOS ----
# SDK/NDK locations (default Android Studio path on macOS)
ANDROID_SDK_ROOT="${ANDROID_SDK_ROOT:-$HOME/Library/Android/sdk}"
NDK_VERSION="${NDK_VERSION:-26.1.10909125}"
NDK="$ANDROID_SDK_ROOT/ndk/$NDK_VERSION"
API="${API:-30}"
TARGET="${TARGET:-armv7a-linux-androideabi}"
# macOS host tag for Apple Silicon; fall back to x86_64 if needed
HOST_TAG=""
if [ -d "$NDK/toolchains/llvm/prebuilt/darwin-arm64" ]; then
HOST_TAG="darwin-arm64"
elif [ -d "$NDK/toolchains/llvm/prebuilt/darwin-x86_64" ]; then
HOST_TAG="darwin-x86_64"
else
echo "Could not find NDK toolchain prebuilts under:"
echo " $NDK/toolchains/llvm/prebuilt"
echo
echo "Make sure NDK $NDK_VERSION is installed under:"
echo " $ANDROID_SDK_ROOT/ndk/$NDK_VERSION"
exit 1
fi
TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/$HOST_TAG"
# NDK wrapper compilers (recommended for Autoconf)
CC="$TOOLCHAIN/bin/${TARGET}${API}-clang"
CXX="$TOOLCHAIN/bin/${TARGET}${API}-clang++"
AR="$TOOLCHAIN/bin/llvm-ar"
RANLIB="$TOOLCHAIN/bin/llvm-ranlib"
STRIP="$TOOLCHAIN/bin/llvm-strip"
require_cmd curl
require_cmd tar
require_cmd make
require_cmd zip
# Sanity check the compiler exists
[ -x "$CC" ] || { echo "Missing compiler: $CC"; exit 1; }
BUILD_DIR="$CWD/build"
mkdir -p "$BUILD_DIR"
echo "=== Building for Android API $API ($TARGET) on macOS ($HOST_TAG) ==="
echo "SDK: $ANDROID_SDK_ROOT"
echo "NDK: $NDK"
# Download/extract libevdev
cd "$BUILD_DIR"
if [[ ! -f "install/include/libevdev-1.0/libevdev/libevdev.h" || \
! -f "install/include/libevdev-1.0/libevdev/libevdev-uinput.h" ]]; then
if [ ! -f "libevdev-1.13.2.tar.xz" ]; then
echo "Downloading libevdev..."
curl -L -o libevdev-1.13.2.tar.xz \
https://www.freedesktop.org/software/libevdev/libevdev-1.13.2.tar.xz
fi
if [ ! -d "libevdev-1.13.2" ]; then
echo "Extracting libevdev..."
tar xf libevdev-1.13.2.tar.xz
fi
cd "$BUILD_DIR/libevdev-1.13.2"
# Clean prior configure cache if you rerun with different toolchain/flags
rm -f config.cache
echo "Configuring libevdev..."
# Important: use wrapper CC/CXX (not `clang --target=...`) and pass host
CC="$CC" \
CXX="$CXX" \
AR="$AR" \
RANLIB="$RANLIB" \
STRIP="$STRIP" \
./configure \
--host="$TARGET" \
--prefix="$BUILD_DIR/install" \
--disable-shared \
--enable-static
echo "Building libevdev..."
make -j"$(nproc_compat)"
make install
fi
echo "Building mouse application..."
cd "$CWD"
"$CC" \
-I"$BUILD_DIR/install/include" \
-I"$BUILD_DIR/install/include/libevdev-1.0" \
-L"$BUILD_DIR/install/lib" \
-o "$BUILD_DIR/mouse" \
*.c \
-levdev
# Strip binary
"$STRIP" "$BUILD_DIR/mouse"
echo "=== Build completed ==="
echo "Binary is at: $BUILD_DIR/mouse"
# Bundle zip
rm -rf "$CWD/build/bundle"
mkdir -p "$CWD/build/bundle"
cd "$CWD/build/bundle"
cp -r "$CWD/properties/"* .
cp "$CWD/build/mouse" .
zip -r -FS FlipMouse.zip .
echo "Bundle is at: $CWD/build/bundle/FlipMouse.zip"