-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdeploy.sh
executable file
·134 lines (113 loc) · 3 KB
/
deploy.sh
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
#!/usr/bin/env bash
MAIN_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
case $(uname) in
Linux)
OS=linux
CMAKE="cmake" # sudo apt install cmake
export CC=g++-12
export CXX=g++-12
;;
Darwin)
OS=mac
CMAKE="cmake" # brew install cmake
;;
CYGWIN*|MINGW*|MSYS*)
OS=win
OS_EXT=Win
EXT=".exe"
CMAKE="$USERPROFILE/scoop/apps/cmake/current/bin/cmake" # scoop install cmake
;;
*)
echo "Error: Unknown OS."
exit 1
;;
esac
TMP_DIR="$MAIN_DIR/tmp/deploy"
CMAKE_DIR="$MAIN_DIR/cmake"
BUILD_DIR="$CMAKE_DIR/build"
GIT_TAG=$(git describe --abbrev=0)
ZIP_FILE="fsrc-$OS-$GIT_TAG.zip"
FSRC_BIN="$MAIN_DIR/fsrc$EXT"
HELPER="$BUILD_DIR/compile.bat"
function createHelper {
local VERSIONS=("2022")
local EDITIONS=("BuildTools" "Community" "Professional" "Enterprise")
echo -ne '@echo off\r\n\r\n' > "$HELPER"
for VERSION in "${VERSIONS[@]}"; do
for EDITION in "${EDITIONS[@]}"; do
local VCVARS_DIR="C:/Program Files/Microsoft Visual Studio/$VERSION/$EDITION/VC/Auxiliary/Build"
if [ -d "$VCVARS_DIR" ]; then
export VSNEWCOMNTOOLS="${VCVARS_DIR////\\}"
break 2
fi
done
done
# VS 2019 Professional/BuildTools/Community
if [ -n "$VSNEWCOMNTOOLS" ]; then
echo -ne "call \"$VSNEWCOMNTOOLS\\\\vcvars64.bat\"" >> "$HELPER"
else
echo "Could not find Visual Studio 2022"
exit 1
fi
echo -ne ' > nul\r\n\r\n' >> "$HELPER"
echo -ne 'echo %*\r\n' >> "$HELPER"
echo -ne '%*\r\n' >> "$HELPER"
chmod +x "$HELPER"
}
function please_remove {
if [ -f "$1" ]; then rm "$1"; fi
if [ -d "$1" ]; then rm -r "$1"; fi
}
function prepare {
please_remove "$FSRC_BIN"
please_remove "$ZIP_FILE"
please_remove "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
mkdir -p "$TMP_DIR"
}
function buildBoost {
if [ ! -d "$MAIN_DIR/libs/boost" ]; then
echo "Building boost"
./scripts/build_boost.sh
fi
}
function buildFsrc {
(
cd "$BUILD_DIR" || exit 1
# configure
"$CMAKE" -S .. -DCMAKE_BUILD_TYPE:STRING=Release &> "$TMP_DIR/cmake.log"
# build
"$CMAKE" --build . --parallel >> "$TMP_DIR/cmake.log" 2>&1
)
}
function buildFsrcWin {
createHelper
(
cd "$BUILD_DIR" || exit 1
# configure
"$HELPER" \
"$CMAKE" -S .. -DCMAKE_BUILD_TYPE:STRING=Release &> "$TMP_DIR/cmake.log"
# build
"$HELPER" \
"$CMAKE" --build . --parallel --config Release >> "$TMP_DIR/cmake.log" 2>&1
)
}
function check {
if [ ! -f "$FSRC_BIN" ]; then
echo "Failed to build fsrc"
exit 1
fi
}
function package {
zip -j "$ZIP_FILE" "$FSRC_BIN" > "$TMP_DIR/zip.log"
}
function please {
echo "$1"
"$1"
}
echo "Deploying fsrc $GIT_TAG to $ZIP_FILE"
please prepare
please buildBoost
please "buildFsrc$OS_EXT"
please check
please package