-
Notifications
You must be signed in to change notification settings - Fork 6
/
compile.sh
executable file
·64 lines (62 loc) · 2.67 KB
/
compile.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
#!/usr/bin/env bash
export REVISION=`git rev-list HEAD --count`
PROJECT="$(tput bold ; tput setaf 3)SuckerServ-v6 $(tput setaf 2)r$REVISION$(tput sgr0)"
if [ -z $THREADS ]; then
THREADS=1
case "$(uname -s)" in
*Darwin*|*BSD*)
THREADS=`sysctl -n hw.ncpu`
;;
*)
if [ -r "/proc/cpuinfo" ]; then
THREADS=`cat /proc/cpuinfo | grep processor | wc -l`
fi
;;
esac
fi
ARG_LENGTH=$#
if [ $ARG_LENGTH -gt 2 -o "$1" == "--help" ]; then
echo "Usage: $(tput bold ; tput setaf 4)$0$(tput sgr0) [--$(tput bold ; tput setaf 5)recompile$(tput sgr0)] [--$(tput bold ; tput setaf 1)debug$(tput sgr0)] — Build $PROJECT"
echo " --$(tput bold ; tput setaf 5)recompile$(tput sgr0) — Delete $(tput bold ; tput setaf 6)\$COMPILEDIR$(tput sgr0) (release_build or debug_build with --$(tput bold ; tput setaf 1)debug$(tput sgr0)) before compiling $PROJECT again"
echo " --$(tput bold ; tput setaf 1)debug$(tput sgr0) — Make a $(tput bold ; tput setaf 1)debug$(tput sgr0) build"
exit
fi
STRCOMPILE="$(tput bold ; tput setaf 2)Compiling$(tput sgr0)"
COMPILEDIR="release_build"
COMPILEFLAGS=""
BUILDTYPE="$(tput bold ; tput setaf 6)release$(tput sgr0)"
if [ "$ARG_LENGTH" -gt 0 -a "$1" == "--debug" -o "$2" == "--debug" ]; then
COMPILEDIR="debug-build"
COMPILEFLAGS="-D CMAKE_BUILD_TYPE=DEBUG"
BUILDTYPE="$(tput bold ; tput setaf 1)debug$(tput sgr0)"
fi
if [ "$ARG_LENGTH" -gt 0 -a "$1" == "--recompile" -o "$2" == "--recompile" ]; then
STRCOMPILE="$(tput bold ; tput setaf 5)Recompiling$(tput sgr0)"
rm -rf $COMPILEDIR
fi
if [ $THREADS -lt 1 ]; then
echo "$(tput bold ; tput setaf 1)Unable to detect number of threads, using 1 thread.$(tput sgr0)"
THREADS=1
fi
if [ ! -d $COMPILEDIR ]; then
mkdir $COMPILEDIR
fi
cd $COMPILEDIR
STRTHREADS="threads"
if [ $THREADS -eq 1 ]; then
STRTHREADS="thread"
fi
# Now compile the source code and install it in server's directory
echo "$STRCOMPILE $PROJECT using $(tput bold ; tput setaf 4)$THREADS$(tput sgr0) $STRTHREADS ($BUILDTYPE build)"
cmake $COMPILEFLAGS ..
[[ "$?" != "0" ]] && echo "$(tput bold ; tput setaf 1)CMAKE FAILED$(tput sgr0)" && exit 1
if `echo "$COMPILEFLAGS" | grep -q "DEBUG"`; then
make -j$THREADS install
[[ "$?" != "0" ]] && echo "$(tput bold ; tput setaf 1)MAKE INSTALL FAILED$(tput sgr0)" && exit 1
else
make -j$THREADS install/strip
[[ "$?" != "0" ]] && echo "$(tput bold ; tput setaf 1)MAKE INSTALL/STRIP FAILED$(tput sgr0)" && exit 1
fi
# Give right execution permissions to executables
cd ../bin
for i in sauer_server server monitor env.sh utils/newserver.sh utils/convert utils/luapp utils/keygen utils/shell.rb utils/shell.pl; do chmod +x $i; done