Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·159 lines (136 loc) · 3.53 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·159 lines (136 loc) · 3.53 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
#!/usr/bin/env bash
set -e
BASE_DIR="$(readlink -f "$(dirname "${0}")")"
. "${BASE_DIR}/scripts/utils.sh"
CMAKE=${CMAKE:-cmake}
BUILD_DIR="${BASE_DIR}/build"
INSTALL_DIR=""
TOOLCHAIN=""
COMMAND=""
ARCH=""
function print_help()
{
echo "usage: $(basename "${0}") [options]... command"
echo ""
echo "options:"
echo " -d, --dbg"
echo " print every executed shell command"
echo " -i, --install-dir INSTALL_DIR"
echo " set install dir to INSTALL_DIR"
echo " -b, --build-type BUILD_TYPE"
echo " select type of build; possible values: Debug, Release, RelWithDebInfo, MinSizeRel"
echo " -t, --toolchain TOOLCHAIN"
echo " select toolchain; possible values: i686-w64-mingw32, linux-i686, x86_64-w64-mingw32"
echo " -h, --help"
echo " print help"
echo ""
echo "commands:"
echo " assets-update"
echo " update openjo.pk3"
echo " build"
echo " build OpenJO"
echo " install"
echo " update openjo.pk3, build, install OpenJO"
echo " run"
echo " update openjo.pk3, build, install and run OpenJO"
exit 0
}
while [[ $# -gt 0 ]]; do
case "${1}" in
-d|--dbg)
set -x
;;
-i|--install-dir)
shift
INSTALL_DIR="${1}"
;;
-b|--build-type)
shift
BUILD_TYPE="${1}"
;;
-t|--toolchain)
shift
TOOLCHAIN="${1}"
;;
-h|--help)
print_help
;;
build|install|run|update-assets)
COMMAND="${1}"
;;
*)
die "Unsupported flag/command: ${1}"
;;
esac
shift
done
if [ ! -d "${BUILD_DIR}" ] || [ ! -f "${BUILD_DIR}/Makefile" ] || [ ! -f "${BUILD_DIR}/CMakeCache.txt" ]
then
mkdir -p "${BUILD_DIR}"
pushd_silent "${BUILD_DIR}"
[ -z "${INSTALL_DIR}" ] && die "No install dir given"
declare -a cmake_args
cmake_args+=( "-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}" )
cmake_args+=( "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" )
[ -n "${BUILD_TYPE}" ] && cmake_args+=( "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" )
[ -n "${TOOLCHAIN}" ] && cmake_args+=( "-DCMAKE_TOOLCHAIN_FILE=cmake/Toolchains/${TOOLCHAIN}.cmake" )
${CMAKE} "${cmake_args[@]}" "${BASE_DIR}"
popd_silent
else
INSTALL_DIR=$(sed -n -e "s/^CMAKE_INSTALL_PREFIX:PATH=//p" "${BUILD_DIR}/CMakeCache.txt")
echo "Deduced install dir: ${INSTALL_DIR}"
fi
ARCH=$(sed -n -e "s/^ARCHITECTURE:STRING=//p" "${BUILD_DIR}/CMakeCache.txt")
[ -z "${ARCH}" ] && die "Unknown architecture"
function assets_update()
{
declare -a assets_to_update
pushd_silent assets
for file in $(find . -type f)
do
if [ "${file}" -nt "${INSTALL_DIR}/base/openjo.pk3" ]
then
assets_to_update+=( "${file#./}" )
fi
done
if [ ${#assets_to_update[@]} -ne 0 ]
then
zip -r "${INSTALL_DIR}/base/openjo.pk3" "${assets_to_update[@]}"
fi
popd_silent
}
function build()
{
assets_update
pushd_silent build
make -j"$(nproc)"
popd_silent
}
function install()
{
build
pushd_silent build
make install -j"$(nproc)"
popd_silent
}
function run()
{
install
"${INSTALL_DIR}/openjo_sp.${ARCH}"
}
case "${COMMAND}" in
build)
build
;;
install)
install
;;
run)
run
;;
assets-update)
assets_update
;;
*)
echo "No command to run"
esac