-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·264 lines (228 loc) · 7.33 KB
/
build.sh
File metadata and controls
executable file
·264 lines (228 loc) · 7.33 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/bash
# filepath: /home/rishi/graph_c/build.sh
set -e # Exit on any error
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="$PROJECT_ROOT/build"
SRC_DIR="$PROJECT_ROOT/src/cpp"
EXAMPLES_DIR="$PROJECT_ROOT/examples/cpp"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Default values
PLATFORM=""
TARGET=""
BUILD_TYPE="Release"
CLEAN=false
VERBOSE=false
show_help() {
echo "Fern Graphics Library Build System"
echo ""
echo "Usage: $0 [OPTIONS] <platform> [target]"
echo ""
echo "Platforms:"
echo " linux - Build for Linux (X11)"
echo " web - Build for Web (Emscripten)"
echo " all - Build for all platforms"
echo ""
echo "Targets (optional):"
echo " platform_test - Build platform test example"
echo " expanded_example - Build expanded widget example"
echo " [filename.cpp] - Build specific example file"
echo ""
echo "Options:"
echo " -d, --debug Build in debug mode"
echo " -c, --clean Clean build directory first"
echo " -v, --verbose Verbose output"
echo " -h, --help Show this help"
echo ""
echo "Examples:"
echo " $0 linux platform_test"
echo " $0 web"
echo " $0 all expanded_example"
echo " $0 --clean --debug linux platform_test"
}
log() {
echo -e "${BLUE}[BUILD]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1" >&2
exit 1
}
success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-d|--debug)
BUILD_TYPE="Debug"
shift
;;
-c|--clean)
CLEAN=true
shift
;;
-v|--verbose)
VERBOSE=true
shift
;;
-h|--help)
show_help
exit 0
;;
linux|web|all)
PLATFORM="$1"
shift
;;
*.cpp)
TARGET="$1"
shift
;;
*)
if [[ -z "$TARGET" ]]; then
TARGET="$1"
else
error "Unknown argument: $1"
fi
shift
;;
esac
done
if [[ -z "$PLATFORM" ]]; then
error "Platform not specified. Use 'linux', 'web', or 'all'"
fi
# Clean if requested
if [[ "$CLEAN" == true ]]; then
log "Cleaning build directory..."
rm -rf "$BUILD_DIR"
fi
# Create build directories
mkdir -p "$BUILD_DIR/linux"
mkdir -p "$BUILD_DIR/web"
# Find source files
CORE_SOURCES=$(find "$SRC_DIR/src" -name "*.cpp" | grep -v platform | tr '\n' ' ')
PLATFORM_FACTORY="$SRC_DIR/src/platform/platform_factory.cpp"
LINUX_RENDERER="$SRC_DIR/src/platform/linux_renderer.cpp"
WEB_RENDERER="$SRC_DIR/src/platform/web_renderer.cpp"
build_linux() {
log "Building for Linux (X11)..."
# Check for X11 development libraries
if ! pkg-config --exists x11; then
warning "X11 development libraries not found. Install with:"
warning " Ubuntu/Debian: sudo apt-get install libx11-dev"
warning " Fedora/RHEL: sudo dnf install libX11-devel"
warning " Arch: sudo pacman -S libx11"
fi
local LINUX_FLAGS="-std=c++17 -D__linux__ -I$SRC_DIR/include"
local LINUX_LIBS="-lX11"
if [[ "$BUILD_TYPE" == "Debug" ]]; then
LINUX_FLAGS="$LINUX_FLAGS -g -O0 -DDEBUG"
else
LINUX_FLAGS="$LINUX_FLAGS -O3 -DNDEBUG"
fi
if [[ "$VERBOSE" == true ]]; then
LINUX_FLAGS="$LINUX_FLAGS -v"
fi
# Build library components first
local LINUX_SOURCES="$CORE_SOURCES $PLATFORM_FACTORY $LINUX_RENDERER"
if [[ -n "$TARGET" ]]; then
# Build specific target
local TARGET_FILE=""
if [[ "$TARGET" == *.cpp ]]; then
TARGET_FILE="$EXAMPLES_DIR/$TARGET"
else
TARGET_FILE="$EXAMPLES_DIR/${TARGET}.cpp"
fi
if [[ ! -f "$TARGET_FILE" ]]; then
error "Target file not found: $TARGET_FILE"
fi
local OUTPUT_NAME=$(basename "$TARGET_FILE" .cpp)
log "Building Linux target: $OUTPUT_NAME"
g++ $LINUX_FLAGS $LINUX_SOURCES "$TARGET_FILE" $LINUX_LIBS -o "$BUILD_DIR/linux/$OUTPUT_NAME"
success "Linux build complete: $BUILD_DIR/linux/$OUTPUT_NAME"
else
# Build all examples
log "Building all Linux examples..."
for example in "$EXAMPLES_DIR"/*.cpp; do
if [[ -f "$example" ]]; then
local example_name=$(basename "$example" .cpp)
log " Building $example_name..."
g++ $LINUX_FLAGS $LINUX_SOURCES "$example" $LINUX_LIBS -o "$BUILD_DIR/linux/$example_name"
fi
done
success "All Linux examples built"
fi
}
build_web() {
log "Building for Web (Emscripten)..."
# Check for Emscripten
if ! command -v emcc &> /dev/null; then
error "Emscripten not found. Install from: https://emscripten.org/docs/getting_started/downloads.html"
fi
local WEB_FLAGS="-std=c++17 -D__EMSCRIPTEN__ -I$SRC_DIR/include"
local WEB_SETTINGS="-s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s USE_WEBGL2=1"
WEB_SETTINGS="$WEB_SETTINGS -s EXPORTED_FUNCTIONS='[_main]'"
WEB_SETTINGS="$WEB_SETTINGS -s EXPORTED_RUNTIME_METHODS='[ccall,cwrap]'"
if [[ "$BUILD_TYPE" == "Debug" ]]; then
WEB_FLAGS="$WEB_FLAGS -g -O0 -DDEBUG"
WEB_SETTINGS="$WEB_SETTINGS -s ASSERTIONS=1"
else
WEB_FLAGS="$WEB_FLAGS -O3 -DNDEBUG"
fi
# Build library components
local WEB_SOURCES="$CORE_SOURCES $PLATFORM_FACTORY $WEB_RENDERER"
if [[ -n "$TARGET" ]]; then
# Build specific target
local TARGET_FILE=""
if [[ "$TARGET" == *.cpp ]]; then
TARGET_FILE="$EXAMPLES_DIR/$TARGET"
else
TARGET_FILE="$EXAMPLES_DIR/${TARGET}.cpp"
fi
if [[ ! -f "$TARGET_FILE" ]]; then
error "Target file not found: $TARGET_FILE"
fi
local OUTPUT_NAME=$(basename "$TARGET_FILE" .cpp)
log "Building Web target: $OUTPUT_NAME"
emcc $WEB_FLAGS $WEB_SOURCES "$TARGET_FILE" $WEB_SETTINGS -o "$BUILD_DIR/web/$OUTPUT_NAME.html"
success "Web build complete: $BUILD_DIR/web/$OUTPUT_NAME.html"
log "To run: cd $BUILD_DIR/web && python3 -m http.server 8000"
log "Then open: http://localhost:8000/$OUTPUT_NAME.html"
else
# Build all examples
log "Building all Web examples..."
for example in "$EXAMPLES_DIR"/*.cpp; do
if [[ -f "$example" ]]; then
local example_name=$(basename "$example" .cpp)
log " Building $example_name..."
emcc $WEB_FLAGS $WEB_SOURCES "$example" $WEB_SETTINGS -o "$BUILD_DIR/web/$example_name.html"
fi
done
success "All Web examples built"
log "To run examples: cd $BUILD_DIR/web && python3 -m http.server 8000"
fi
}
# Main build logic
case "$PLATFORM" in
linux)
build_linux
;;
web)
build_web
;;
all)
build_linux
echo ""
build_web
;;
*)
error "Unknown platform: $PLATFORM"
;;
esac
success "Build process completed!"