-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
248 lines (210 loc) · 6.01 KB
/
Copy pathbuild.sh
File metadata and controls
248 lines (210 loc) · 6.01 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/bin/bash
# ImgLiex Build Script
# This script automates the build process for ImgLiex
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Default values
BUILD_TYPE="Release"
CLEAN_BUILD=false
INSTALL=false
THREADS=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)
VERBOSE=false
# Print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Help function
show_help() {
cat << EOF
ImgLiex Build Script
Usage: $0 [OPTIONS]
OPTIONS:
-t, --build-type TYPE Build type: Release, Debug, RelWithDebInfo (default: Release)
-j, --jobs N Number of parallel jobs (default: auto-detected)
-c, --clean Clean build directory before building
-i, --install Install after building
-v, --verbose Verbose output
-h, --help Show this help message
EXAMPLES:
$0 # Quick release build
$0 -t Debug -v # Debug build with verbose output
$0 -c -j 8 # Clean build with 8 parallel jobs
$0 -t Release -c -i # Clean release build and install
EOF
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-t|--build-type)
BUILD_TYPE="$2"
shift 2
;;
-j|--jobs)
THREADS="$2"
shift 2
;;
-c|--clean)
CLEAN_BUILD=true
shift
;;
-i|--install)
INSTALL=true
shift
;;
-v|--verbose)
VERBOSE=true
shift
;;
-h|--help)
show_help
exit 0
;;
*)
print_error "Unknown option: $1"
show_help
exit 1
;;
esac
done
# Validate build type
case $BUILD_TYPE in
Release|Debug|RelWithDebInfo|MinSizeRel)
;;
*)
print_error "Invalid build type: $BUILD_TYPE"
print_error "Valid types: Release, Debug, RelWithDebInfo, MinSizeRel"
exit 1
;;
esac
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="$SCRIPT_DIR/build"
print_status "ImgLiex Build Configuration:"
echo " Build Type: $BUILD_TYPE"
echo " Parallel Jobs: $THREADS"
echo " Clean Build: $CLEAN_BUILD"
echo " Install: $INSTALL"
echo " Verbose: $VERBOSE"
echo " Build Directory: $BUILD_DIR"
echo ""
# Check for required tools
check_dependency() {
if ! command -v $1 &> /dev/null; then
print_error "$1 is not installed or not in PATH"
return 1
fi
}
print_status "Checking dependencies..."
check_dependency cmake || exit 1
check_dependency git || exit 1
# Check for compiler
if command -v g++ &> /dev/null; then
COMPILER=$(g++ --version | head -n1)
print_status "Found compiler: $COMPILER"
elif command -v clang++ &> /dev/null; then
COMPILER=$(clang++ --version | head -n1)
print_status "Found compiler: $COMPILER"
else
print_error "No C++ compiler found (g++ or clang++)"
exit 1
fi
# Check for libcurl
if pkg-config --exists libcurl; then
CURL_VERSION=$(pkg-config --modversion libcurl)
print_status "Found libcurl: $CURL_VERSION"
else
print_warning "libcurl not found via pkg-config. Build may fail."
print_warning "Install libcurl development packages:"
print_warning " Ubuntu/Debian: sudo apt install libcurl4-openssl-dev"
print_warning " CentOS/RHEL: sudo yum install libcurl-devel"
print_warning " macOS: brew install curl"
fi
# Clean build directory if requested
if [[ $CLEAN_BUILD == true ]]; then
print_status "Cleaning build directory..."
rm -rf "$BUILD_DIR"
fi
# Create build directory
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
# Configure with CMake
print_status "Configuring with CMake..."
CMAKE_ARGS=(
"-DCMAKE_BUILD_TYPE=$BUILD_TYPE"
"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
)
if [[ $VERBOSE == true ]]; then
CMAKE_ARGS+=("-DCMAKE_VERBOSE_MAKEFILE=ON")
fi
cmake "${CMAKE_ARGS[@]}" .. || {
print_error "CMake configuration failed"
exit 1
}
print_success "Configuration completed"
# Build
print_status "Building ImgLiex..."
BUILD_ARGS=("-j$THREADS")
if [[ $VERBOSE == true ]]; then
BUILD_ARGS+=("VERBOSE=1")
fi
make "${BUILD_ARGS[@]}" || {
print_error "Build failed"
exit 1
}
print_success "Build completed successfully"
# Show binary info
BINARY_PATH="$BUILD_DIR/bin/imgliex"
if [[ -f "$BINARY_PATH" ]]; then
BINARY_SIZE=$(du -h "$BINARY_PATH" | cut -f1)
print_status "Binary created: $BINARY_PATH (size: $BINARY_SIZE)"
# Test the binary
if "$BINARY_PATH" --help &> /dev/null; then
print_success "Binary test passed"
else
print_warning "Binary test failed - may have missing dependencies"
fi
else
print_error "Binary not found at expected location: $BINARY_PATH"
exit 1
fi
# Install if requested
if [[ $INSTALL == true ]]; then
print_status "Installing ImgLiex..."
if [[ $EUID -eq 0 ]]; then
make install || {
print_error "Installation failed"
exit 1
}
else
print_status "Running installation with sudo..."
sudo make install || {
print_error "Installation failed"
exit 1
}
fi
print_success "Installation completed"
# Check if installed binary works
if command -v imgliex &> /dev/null; then
INSTALLED_VERSION=$(imgliex --help | head -n1 || echo "Unknown")
print_success "ImgLiex installed and available in PATH"
print_status "Installed version: $INSTALLED_VERSION"
else
print_warning "ImgLiex may not be in PATH. Check your installation prefix."
fi
fi
print_success "All tasks completed successfully!"
print_status "To run ImgLiex: $BINARY_PATH <filename> <start_chapter> <end_chapter>"