Skip to content

Commit efb2ff9

Browse files
committed
Support cmake antibob
See ChillerDragon/antibob#29
1 parent 273bd58 commit efb2ff9

2 files changed

Lines changed: 83 additions & 15 deletions

File tree

lib/include/update/antibot.sh

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#
88
# supported antibot repo formats:
99
#
10-
# - standalone built from source (recommended)
11-
# the repository is expected to contain a Makefile
10+
# - standalone make/cmake built from source (recommended)
11+
# the repository is expected to contain a Makefile or CMakeLists.txt
1212
# and be able to compile on its own
1313
# the resulting libantibot.so is then copied to the runtime path
1414
# have a look at antibob for an example of such a repository
@@ -36,10 +36,14 @@ function update_antibot() {
3636
git_save_pull
3737
) || exit 1
3838

39-
if [ -f "$CFG_GITPATH_ANTIBOT/Makefile" ]
39+
if [ -f "$CFG_GITPATH_ANTIBOT/CMakeLists.txt" ]
4040
then
41-
log "detected antibot format: standalone"
42-
_antibot_format_standalone
41+
log "detected antibot format: standalone cmake"
42+
_antibot_format_standalone_cmake
43+
elif [ -f "$CFG_GITPATH_ANTIBOT/Makefile" ]
44+
then
45+
log "detected antibot format: standalone make"
46+
_antibot_format_standalone_make
4347
elif compgen -G "$CFG_GITPATH_ANTIBOT/*.{h,cpp}" > /dev/null
4448
then
4549
log "detected antibot format: source patches"
@@ -50,7 +54,55 @@ function update_antibot() {
5054
fi
5155
}
5256

53-
function _antibot_format_standalone() {
57+
function _antibot_format_standalone_cmake() {
58+
(
59+
cd "$CFG_GITPATH_ANTIBOT" || exit 1
60+
log -n "compiling standalone antibot with cmake "
61+
62+
build_log="/tmp/${USER}_ddpp_antibot_build_$$.log"
63+
:>"$build_log"
64+
65+
function __run_build_cmd() {
66+
local cmd="$1"
67+
printf '$ %s\n' "$cmd" >> "$build_log"
68+
if ! $cmd &>> "$build_log"
69+
then
70+
log_status_error
71+
cat "$build_log"
72+
rm "$build_log"
73+
err "Error: building antibot with make failed, failed command: $cmd"
74+
exit 1
75+
fi
76+
printf '.'
77+
}
78+
79+
__run_build_cmd 'mkdir -p build'
80+
__run_build_cmd 'cd build'
81+
__run_build_cmd 'cmake ..'
82+
__run_build_cmd 'make'
83+
84+
rm "$build_log"
85+
printf ' '
86+
log_status_ok
87+
88+
if [ ! -f "$CFG_GITPATH_ANTIBOT"/build/libantibot.so ]
89+
then
90+
err "Error: antibot cmake passed but did not produce a libantibot.so file"
91+
exit 1
92+
fi
93+
94+
# TODO: remove this backcompat layer once cmake antibob rolled out everywhere
95+
if [ -f "$CFG_GITPATH_ANTIBOT"/libantibot.so ]
96+
then
97+
# this avoids having libantibot.so and build/libantibot.so
98+
# in the antibot git repo when transitioning from antibob Makefile to cmake
99+
log "cleaning up legacy Makefile antibot at $CFG_GITPATH_ANTIBOT/libantibot.so"
100+
rm "$CFG_GITPATH_ANTIBOT"/libantibot.so
101+
fi
102+
) || exit 1
103+
}
104+
105+
function _antibot_format_standalone_make() {
54106
(
55107
cd "$CFG_GITPATH_ANTIBOT" || exit 1
56108
log -n "compiling standalone antibot with make .. "

lib/include/update/cmake.sh

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,39 @@ function cmake_refresh_teeworlds_binary() {
1919
if [ "$CFG_GITPATH_ANTIBOT" != "" ]
2020
then
2121
log "refreshing antibot binary ..."
22-
local libantibot_path="$CFG_GITPATH_ANTIBOT"/libantibot.so
23-
if [ -f "$libantibot_path" ]
22+
23+
if [ -f "$CFG_GITPATH_ANTIBOT"/libantibot.so ] && \
24+
[ -f "$CFG_GITPATH_ANTIBOT"/build/libantibot.so ]
2425
then
25-
log "found $libantibot_path"
26-
else
27-
libantibot_path="$CFG_GIT_PATH_MOD/build/$CFG_COMPILED_BIN"
28-
if [ -f "$libantibot_path" ]
26+
err "Error: found libantibot.so in root and build dir of $CFG_GITPATH_ANTIBOT"
27+
err " this is ambiguous. Please delete one of the files"
28+
err ""
29+
err " $CFG_GITPATH_ANTIBOT/libantibot.so"
30+
err " $CFG_GITPATH_ANTIBOT/build/libantibot.so"
31+
err ""
32+
exit 1
33+
fi
34+
35+
local libantibot_path=''
36+
for libantibot_path_candidate in \
37+
"$CFG_GITPATH_ANTIBOT"/libantibot.so \
38+
"$CFG_GITPATH_ANTIBOT"/build/libantibot.so \
39+
"$CFG_GIT_PATH_MOD"/build/libantibot.so
40+
do
41+
if [ -f "$libantibot_path_candidate" ]
2942
then
43+
libantibot_path="$libantibot_path_candidate"
3044
log "found $libantibot_path"
45+
break
3146
fi
32-
fi
33-
if [ -f "$libantibot_path" ]
47+
done
48+
49+
if [ "$libantibot_path" != "" ]
3450
then
3551
log "move libantibot.so ..."
3652
cp "$libantibot_path" "$libantibot_runtime_path"
3753
else
38-
err "Error: libantibot.so not found $libantibot_path"
54+
err "Error: libantibot.so not found"
3955
fi
4056
fi
4157
}

0 commit comments

Comments
 (0)