forked from ScanTailor-Advanced/scantailor-advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-windows.sh
More file actions
executable file
·91 lines (79 loc) · 2.98 KB
/
Copy pathbuild-windows.sh
File metadata and controls
executable file
·91 lines (79 loc) · 2.98 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
#!/usr/bin/env bash
# Cross-compile ScanTailor Advanced to Windows .exe from Linux using MXE.
#
# Prerequisites:
# 1. Install MXE (M Cross Environment): https://mxe.cc/
# 2. Build the required packages (one-time, can take 1–2 hours):
# cd /path/to/mxe
# make MXE_TARGETS=x86_64-w64-mingw32.static \
# qt5 jpeg libpng tiff zlib boost
#
# Usage:
# MXE_DIR=/path/to/mxe ./build-windows.sh
# ./build-windows.sh # uses MXE_DIR or ~/mxe or /opt/mxe
# ./build-windows.sh shared # use .shared target (exe + DLLs)
#
# Output: build-win-static/scantailor-advanced.exe (default), or build-win-shared/ for shared (exe + DLLs)
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Target: static (single exe) or shared (exe + DLLs)
SUFFIX="${1:-static}"
if [[ "$SUFFIX" != "static" && "$SUFFIX" != "shared" ]]; then
echo "Usage: $0 [static|shared]" >&2
echo " static = one .exe (default); shared = exe + DLLs" >&2
exit 1
fi
MXE_TARGET="x86_64-w64-mingw32.${SUFFIX}"
BUILD_DIR="build-win-${SUFFIX}"
# Find MXE root
if [[ -n "$MXE_DIR" && -d "$MXE_DIR" ]]; then
MXE_ROOT="$MXE_DIR"
elif [[ -d "$HOME/mxe" ]]; then
MXE_ROOT="$HOME/mxe"
elif [[ -d "/opt/mxe" ]]; then
MXE_ROOT="/opt/mxe"
else
echo "Error: MXE not found. Set MXE_DIR or install MXE in ~/mxe or /opt/mxe." >&2
echo "" >&2
echo "One-time setup:" >&2
echo " git clone https://github.com/mxe/mxe.git ~/mxe" >&2
echo " cd ~/mxe && make MXE_TARGETS=${MXE_TARGET} qt5 jpeg libpng tiff zlib boost" >&2
echo " (This can take 1–2 hours.)" >&2
exit 1
fi
TOOLCHAIN_FILE="${MXE_ROOT}/usr/${MXE_TARGET}/share/cmake/mxe-conf.cmake"
if [[ ! -f "$TOOLCHAIN_FILE" ]]; then
echo "Error: MXE toolchain not found: $TOOLCHAIN_FILE" >&2
echo "Build the MXE target first:" >&2
echo " cd $MXE_ROOT && make MXE_TARGETS=${MXE_TARGET} qt5 jpeg libpng tiff zlib boost" >&2
exit 1
fi
# Use a dedicated build dir so CMake does not pick up ../libs (native Windows deps).
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
echo "Cross-compiling for Windows (${MXE_TARGET})..."
cmake -DCMAKE_TOOLCHAIN_FILE="${TOOLCHAIN_FILE}" \
-DCMAKE_BUILD_TYPE=Release \
..
make -j"$(nproc)"
if [[ -f scantailor-advanced.exe ]]; then
EXE_PATH="scantailor-advanced.exe"
elif [[ -f release/scantailor-advanced.exe ]]; then
EXE_PATH="release/scantailor-advanced.exe"
elif [[ -f scantailor.exe ]]; then
EXE_PATH="scantailor.exe"
elif [[ -f release/scantailor.exe ]]; then
EXE_PATH="release/scantailor.exe"
else
EXE_PATH=$(find . -name "scantailor-advanced.exe" -o -name "scantailor.exe" -type f 2>/dev/null | head -1)
fi
if [[ -z "$EXE_PATH" || ! -f "$EXE_PATH" ]]; then
echo "Error: scantailor-advanced.exe not found in $BUILD_DIR" >&2
exit 1
fi
echo ""
echo "Done. Windows executable: $(cd "$SCRIPT_DIR" && realpath "$BUILD_DIR/$EXE_PATH")"
if [[ "$SUFFIX" == "shared" ]]; then
echo "For .shared build, copy the required DLLs from ${MXE_ROOT}/usr/${MXE_TARGET}/bin/ next to the .exe when deploying."
fi