forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-build.sh
More file actions
executable file
·286 lines (244 loc) · 7.67 KB
/
docker-build.sh
File metadata and controls
executable file
·286 lines (244 loc) · 7.67 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/usr/bin/env bash
#
# Build script for compiling Generals/Zero Hour on Linux using Docker
#
# This script builds Windows executables using a Docker container with Wine and VC6.
# The resulting binaries can be run on Linux using Wine or on Windows natively.
#
# Usage:
# ./scripts/docker-build.sh # Full build (both games)
# ./scripts/docker-build.sh --game zh # Build Zero Hour only
# ./scripts/docker-build.sh --game generals # Build Generals only
# ./scripts/docker-build.sh --target z_generals # Build specific target
# ./scripts/docker-build.sh --clean # Clean build directory
# ./scripts/docker-build.sh --interactive # Enter container shell
#
set -euo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
BUILD_DIR="$PROJECT_DIR/build/docker"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
print_header() {
echo -e "${BLUE}======================================${NC}"
echo -e "${BLUE} Generals Game Code - Linux Builder${NC}"
echo -e "${BLUE}======================================${NC}"
echo ""
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
usage() {
cat <<EOF
Usage: $(basename "$0") [OPTIONS] [TARGET...]
Build Generals/Zero Hour on Linux using Docker (produces Windows executables).
Options:
-h, --help Show this help message
-g, --game GAME Build specific game: 'zh' (Zero Hour), 'generals', or 'all' (default: all)
-t, --target TARGET Build specific CMake target (e.g., z_generals, z_worldbuilder)
-c, --clean Clean build directory before building
-i, --interactive Enter container shell for debugging
--cmake Force CMake reconfiguration
-j, --jobs N Number of parallel jobs (passed to ninja)
Examples:
$(basename "$0") # Build everything
$(basename "$0") --game zh # Build Zero Hour only
$(basename "$0") --target z_generals # Build Zero Hour executable only
$(basename "$0") --clean --game all # Clean and rebuild everything
$(basename "$0") --interactive # Enter container for debugging
Output:
Build artifacts are placed in: $BUILD_DIR/
Zero Hour executables:
- generalszh.exe (Main game)
- WorldBuilderZH.exe (Map editor)
- W3DViewZH.exe (3D model viewer)
Generals executables:
- generalsv.exe (Main game)
- WorldBuilderV.exe (Map editor)
- W3DViewV.exe (3D model viewer)
Running the game:
After building, you can run the game with Wine:
wine $BUILD_DIR/GeneralsMD/generalszh.exe
Note: You need the original game data files installed.
EOF
}
check_dependencies() {
print_info "Checking dependencies..."
if ! command -v docker &>/dev/null; then
print_error "Docker is not installed. Please install Docker first."
echo " See: https://docs.docker.com/engine/install/"
exit 1
fi
if ! docker info &>/dev/null; then
print_error "Docker daemon is not running or you don't have permission."
echo " Try: sudo systemctl start docker"
echo " Or add your user to the docker group: sudo usermod -aG docker \$USER"
exit 1
fi
print_success "All dependencies satisfied"
}
build_docker_image() {
print_info "Building Docker image (this may take a while on first run)..."
docker build \
--build-arg UID="$(id -u)" \
--build-arg GID="$(id -g)" \
"$PROJECT_DIR/resources/dockerbuild" \
-t zerohour-build \
|| {
print_error "Failed to build Docker image"
exit 1
}
print_success "Docker image ready"
}
fix_compile_commands() {
local fix_script="$SCRIPT_DIR/fix_compile_commands.py"
if [[ -f "$fix_script" ]] && command -v python3 &>/dev/null; then
# Only run if compile_commands.json exists in the build dir
if [[ -f "$BUILD_DIR/compile_commands.json" ]]; then
print_info "Fixing compile_commands.json for host environment..."
python3 "$fix_script" || print_warning "Failed to fix compile_commands.json"
fi
fi
}
run_build() {
local force_cmake="$1"
local target="$2"
local interactive="$3"
local docker_flags=""
if [[ "$interactive" == "true" ]]; then
docker_flags="-it --entrypoint bash"
fi
print_info "Starting build..."
if [[ -n "$target" ]]; then
print_info "Target: $target"
fi
# shellcheck disable=SC2086
docker run \
-u "$(id -u):$(id -g)" \
-e MAKE_TARGET="$target" \
-e FORCE_CMAKE="$force_cmake" \
-v "$PROJECT_DIR:/build/cnc" \
--rm \
$docker_flags \
zerohour-build \
|| {
print_error "Build failed"
exit 1
}
if [[ "$interactive" != "true" ]]; then
print_success "Build completed"
fi
}
clean_build() {
print_info "Cleaning build directory..."
rm -rf "$BUILD_DIR"
print_success "Build directory cleaned"
}
list_outputs() {
echo ""
print_info "Build outputs:"
echo ""
if [[ -d "$BUILD_DIR/GeneralsMD" ]]; then
echo "Zero Hour (GeneralsMD):"
find "$BUILD_DIR/GeneralsMD" -maxdepth 1 -name "*.exe" -printf " %f (%s bytes)\n" 2>/dev/null || true
fi
if [[ -d "$BUILD_DIR/Generals" ]]; then
echo ""
echo "Generals:"
find "$BUILD_DIR/Generals" -maxdepth 1 -name "*.exe" -printf " %f (%s bytes)\n" 2>/dev/null || true
fi
}
# Parse arguments
GAME="all"
TARGET=""
CLEAN=false
INTERACTIVE=false
FORCE_CMAKE=false
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-g|--game)
GAME="$2"
shift 2
;;
-t|--target)
TARGET="$2"
shift 2
;;
-c|--clean)
CLEAN=true
shift
;;
-i|--interactive)
INTERACTIVE=true
shift
;;
--cmake)
FORCE_CMAKE=true
shift
;;
-j|--jobs)
# Jobs are handled by ninja in the container
shift 2
;;
-*)
print_error "Unknown option: $1"
usage
exit 1
;;
*)
# Positional argument treated as target
TARGET="$TARGET $1"
shift
;;
esac
done
# Set target based on game selection
if [[ -z "$TARGET" ]]; then
case "$GAME" in
zh|zerohour)
TARGET="z_generals z_worldbuilder core_particleeditor core_debugwindow z_guiedit z_imagepacker z_mapcachebuilder z_w3dview z_wdump"
;;
generals)
TARGET="g_generals g_worldbuilder core_particleeditor core_debugwindow g_guiedit g_imagepacker g_mapcachebuilder g_w3dview"
;;
all)
TARGET="" # Build all
;;
*)
print_error "Unknown game: $GAME (use 'zh', 'generals', or 'all')"
exit 1
;;
esac
fi
# Main execution
print_header
check_dependencies
if [[ "$CLEAN" == "true" ]]; then
clean_build
fi
build_docker_image
run_build "$FORCE_CMAKE" "$TARGET" "$INTERACTIVE"
if [[ "$INTERACTIVE" != "true" ]]; then
fix_compile_commands
list_outputs
echo ""
print_info "To run the game with Wine:"
echo " wine $BUILD_DIR/GeneralsMD/generalszh.exe"
fi