khanat-server-docker-NeL/builder/debian/stretch/x86_64/build-under-docker.sh

170 lines
4.5 KiB
Bash
Raw Normal View History

#!/bin/bash
# Script to build Khaganat binary (executed in docker)
#
# Copyright (C) 2017 AleaJactaEst
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
declare DIRBUILD="/opt/build/"
declare DIRCODE="/opt/ref/opennel-code"
declare CXXFLAGS=""
function usage()
{
cat << EOF
usage:$0 [options] <workdir>
internal script to build under docker
workdir: directory use to buid
options:
-h, --help : Show this help
-d, --debug : Show debug message
--add-opts-cmake="string" : add option use on command cmake (generate Makefile)
--add-opts-make="string" : add option use on command make
--cxxflags=[String] : adding cxx flags when generate Makefile (and build)
EOF
}
function chrashed()
{
echo "$(date "+%Y/%m/%d %H:%M:%S") ERROR - BUILD FAILED (code:$?)"
if [ -n "$LOGFILE" ]
then
echo "$(date "+%Y/%m/%d %H:%M:%S") ERROR - BUILD FAILED (code:$?)" >> $LOGFILE
fi
exit 2
}
function msg_error()
{
echo "$(date "+%Y/%m/%d %H:%M:%S") ERROR - $1"
if [ -n "$LOGFILE" ]
then
echo "$(date "+%Y/%m/%d %H:%M:%S") ERROR - $1" >> $LOGFILE
fi
}
function msg_info()
{
echo "$(date "+%Y/%m/%d %H:%M:%S") INFO - $1"
if [ -n "$LOGFILE" ]
then
echo "$(date "+%Y/%m/%d %H:%M:%S") INFO - $1" >> $LOGFILE
fi
}
function msg_debug()
{
if [[ $DEBUG -ne 0 ]]
then
echo "$(date "+%Y/%m/%d %H:%M:%S") DEBUG - $1"
if [ -n "$LOGFILE" ]
then
echo "$(date "+%Y/%m/%d %H:%M:%S") DEBUG - $1" >> $LOGFILE
fi
fi
}
#
# MAIN
#
trap chrashed EXIT
while test $# -gt 0
do
case "$1" in
-h|--help)
usage
exit 1
;;
-d|--debug)
DEBUG=1
shift
;;
--add-opts-cmake=*)
CMAKEOPTS="$CMAKEOPTS ${1#*=}"
shift
;;
--add-opts-make=*)
MAKEOPTS="$MAKEOPTS ${1#*=}"
shift
;;
--build-dir=*)
DIRBUILD="${1#*=}"
shift
;;
--code-dir=*)
DIRCODE="${1#*=}"
shift
;;
--cxxflags=*)
CXXFLAGS="$CXXFLAGS ${1#*=}"
shift
;;
*)
msg_error "options '$1' not recognize"
usage
exit 2
;;
esac
done
declare LOGFILE="${DIRBUILD}/build.log"
msg_debug "DIRBUILD:$DIRBUILD"
msg_debug "DIRCODE:$DIRCODE"
msg_debug "CMAKEOPTS:$CMAKEOPTS"
msg_debug "MAKEOPTS:$MAKEOPTS"
msg_debug "LOGFILE:$LOGFILE"
msg_debug "CXXFLAGS:$CXXFLAGS"
msg_info "CREATE BUILD DIRECTORY"
mkdir -p ${DIRBUILD}/ || exit 2
msg_info "COPY CODE"
mkdir -p ${DIRBUILD}/opennel-code
cp -pr $DIRCODE/* ${DIRBUILD}/opennel-code
msg_info "PATCH CODE"
cd ${DIRBUILD}/opennel-code/code
patch -Z -t -i ${DIRBUILD}/opennel-code/patch/libcrypto.patch || exit 2
patch -Z -t -i ${DIRBUILD}/opennel-code/patch/libicuuc.patch || exit 2
patch -Z -t -i ${DIRBUILD}/opennel-code/patch/01_ryzom_debug_callNativeCallBack.patch -p 1 || exit 2
msg_info "PREPARE BUILD"
msg_debug "cmake option : -DWITH_NEL=ON -DWITH_STATIC=ON -DWITH_STATIC_DRIVERS=ON -DWITH_STATIC_EXTERNAL=ON -DWITH_SYMBOLS=ON -DWITH_LUA52=ON -DWITH_RYZOM_PATCH=ON -DWITH_RYZOM_CUSTOM_PATCH_SERVER=ON ${CMAKEOPTS}"
cd ${DIRBUILD}; CXXFLAGS="$CXXFLAGS" cmake -DWITH_NEL=ON \
-DWITH_STATIC=ON \
-DWITH_STATIC_DRIVERS=ON \
-DWITH_STATIC_EXTERNAL=ON \
-DWITH_SYMBOLS=ON \
-DWITH_LUA52=ON \
-DWITH_RYZOM_PATCH=ON \
-DWITH_RYZOM_CUSTOM_PATCH_SERVER=ON \
${CMAKEOPTS} \
${DIRBUILD}/opennel-code/code 1>>$LOGFILE 2>&1 || exit 2
msg_info "BUILD START"
msg_debug "make option : $MAKEOPTS"
cd ${DIRBUILD}; VERBOSE=1 make $MAKEOPTS 1>>$LOGFILE 2>&1 || exit 2
msg_info "GENERATE PACKAGE"
cd ${DIRBUILD}; make package 1>>$LOGFILE 2>&1 || exit 2
trap '' EXIT
msg_info "BUILD END"