-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·186 lines (172 loc) · 5.63 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·186 lines (172 loc) · 5.63 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
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
#!/usr/bin/env bash
#
# build.sh — krkr2 unified build entry point
#
# Usage:
# ./build.sh <platform> [options]
# ./build.sh # Interactive platform selection
#
# Platforms:
# android, ios, macos
#
# Options:
# debug|release Build type (default: debug)
# --abi=<abis> Android only: target ABIs (default: arm64-v8a)
# --jobs=<N> Parallel build jobs (default: 8)
# --clean Clean build artifacts before building
# --help, -h Show this help message
#
# Examples:
# ./build.sh android debug --abi=arm64-v8a
# ./build.sh ios release
# ./build.sh macos debug --jobs=16
# ./build.sh --clean android release
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_SCRIPTS_DIR="$SCRIPT_DIR/build"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
NC='\033[0m'
# ============================================================
# Help
# ============================================================
show_help() {
echo ""
echo -e "${CYAN}krkr2 Unified Build Script${NC}"
echo ""
echo "Usage:"
echo " ./build.sh <platform> [options]"
echo " ./build.sh # Interactive platform selection"
echo ""
echo "Platforms:"
echo " android Build Android APK (Flutter + native engine)"
echo " ios Build iOS app (C++ static lib + Flutter)"
echo " macos Build macOS app (C++ dylib + Flutter)"
echo ""
echo "Options:"
echo " debug|release Build type (default: debug)"
echo " --abi=<abis> Android only: comma-separated ABIs"
echo " (arm64-v8a, armeabi-v7a, x86_64, x86)"
echo " --jobs=<N> Parallel build jobs (default: 8)"
echo " --clean Clean build artifacts before building"
echo " --help, -h Show this help message"
echo ""
echo "Examples:"
echo " ./build.sh android debug --abi=arm64-v8a"
echo " ./build.sh ios release"
echo " ./build.sh macos debug --jobs=16"
echo " ./build.sh --clean android release"
echo ""
}
# ============================================================
# Parse arguments
# ============================================================
PLATFORM=""
BUILD_TYPE=""
CLEAN=false
EXTRA_ARGS=()
for arg in "$@"; do
case "$arg" in
--help|-h)
show_help
exit 0
;;
--clean)
CLEAN=true
;;
--jobs=*)
export JOBS="${arg#*=}"
;;
android|ios|macos)
PLATFORM="$arg"
;;
debug|release|Debug|Release)
BUILD_TYPE="$(echo "$arg" | tr '[:upper:]' '[:lower:]')"
;;
--abi=*)
EXTRA_ARGS+=("$arg")
;;
*)
echo -e "${YELLOW}[WARN]${NC} Unknown argument: $arg (passing through)"
EXTRA_ARGS+=("$arg")
;;
esac
done
# ============================================================
# Interactive platform selection (if not specified)
# ============================================================
if [[ -z "$PLATFORM" ]]; then
echo ""
echo -e "${CYAN}==============================${NC}"
echo -e "${CYAN} krkr2 Build System${NC}"
echo -e "${CYAN}==============================${NC}"
echo ""
echo "Select target platform:"
echo ""
echo " 1) android"
echo " 2) ios"
echo " 3) macos"
echo ""
read -rp "Enter choice [1-3]: " choice
case "$choice" in
1|android) PLATFORM="android" ;;
2|ios) PLATFORM="ios" ;;
3|macos) PLATFORM="macos" ;;
*)
echo -e "${RED}[ERROR]${NC} Invalid choice: $choice"
exit 1
;;
esac
echo ""
fi
# Default build type
if [[ -z "$BUILD_TYPE" ]]; then
BUILD_TYPE="debug"
fi
# ============================================================
# Validate platform script exists
# ============================================================
PLATFORM_SCRIPT="$BUILD_SCRIPTS_DIR/build_${PLATFORM}.sh"
if [[ ! -f "$PLATFORM_SCRIPT" ]]; then
echo -e "${RED}[ERROR]${NC} Build script not found: $PLATFORM_SCRIPT"
exit 1
fi
# ============================================================
# Clean (optional)
# ============================================================
if [[ "$CLEAN" == true ]]; then
echo -e "${CYAN}Cleaning build artifacts for $PLATFORM...${NC}"
case "$PLATFORM" in
android)
rm -rf "$SCRIPT_DIR/apps/flutter_app/build/app"
rm -rf "$SCRIPT_DIR/apps/flutter_app/build/.cxx"
echo -e "${GREEN}[INFO]${NC} Android build artifacts cleaned."
;;
ios)
rm -rf "$SCRIPT_DIR/out/ios/$BUILD_TYPE"
rm -rf "$SCRIPT_DIR/apps/flutter_app/build/ios"
echo -e "${GREEN}[INFO]${NC} iOS build artifacts cleaned."
;;
macos)
rm -rf "$SCRIPT_DIR/out/macos/$BUILD_TYPE"
rm -rf "$SCRIPT_DIR/apps/flutter_app/build/macos"
echo -e "${GREEN}[INFO]${NC} macOS build artifacts cleaned."
;;
esac
echo ""
fi
# ============================================================
# Run platform build script
# ============================================================
echo -e "${CYAN}==============================${NC}"
echo -e "${CYAN} Building: $PLATFORM ($BUILD_TYPE)${NC}"
echo -e "${CYAN}==============================${NC}"
echo ""
# Ensure the script is executable
chmod +x "$PLATFORM_SCRIPT"
# Execute the platform-specific build script with arguments
exec bash "$PLATFORM_SCRIPT" "$BUILD_TYPE" ${EXTRA_ARGS[@]+"${EXTRA_ARGS[@]}"}