2017-11-21 21:10:28 +00:00
|
|
|
#!/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/"
|
2018-06-28 08:45:45 +00:00
|
|
|
declare DIRCODEUSE="/opt/build/opennel-code"
|
2018-04-19 13:55:43 +00:00
|
|
|
declare DIRCODE="/opt/ref/opennel-code"
|
2018-08-05 11:36:12 +00:00
|
|
|
declare DIRPYMANAGER="/opt/ref/opennel-pymanager"
|
2018-04-30 18:34:08 +00:00
|
|
|
declare CXXFLAGS=""
|
2018-06-28 08:45:45 +00:00
|
|
|
declare -i DONTCOPYSOURCE=0
|
2018-08-05 11:36:12 +00:00
|
|
|
declare -i BUILD_OPENNEL_CODE=1
|
|
|
|
declare -i PACKAGE_OPENNEL_PYMANAGER=1
|
2018-04-19 13:55:43 +00:00
|
|
|
|
|
|
|
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
|
2018-04-30 18:34:08 +00:00
|
|
|
--cxxflags=[String] : adding cxx flags when generate Makefile (and build)
|
2018-06-28 08:45:45 +00:00
|
|
|
--dont-copy-source : disable copy source, work directly on source (apply patch)
|
2018-04-19 13:55:43 +00:00
|
|
|
EOF
|
|
|
|
}
|
2017-11-21 21:10:28 +00:00
|
|
|
|
|
|
|
function chrashed()
|
|
|
|
{
|
2018-06-28 08:45:45 +00:00
|
|
|
local code=$?
|
|
|
|
echo "$(date "+%Y/%m/%d %H:%M:%S") ERROR - BUILD (under docker) FAILED (code:$code)"
|
2018-04-30 18:34:08 +00:00
|
|
|
if [ -n "$LOGFILE" ]
|
|
|
|
then
|
2018-06-28 08:45:45 +00:00
|
|
|
echo "$(date "+%Y/%m/%d %H:%M:%S") ERROR - BUILD (under docker) FAILED (code:$code)" >> $LOGFILE
|
2018-04-30 18:34:08 +00:00
|
|
|
fi
|
2017-11-21 21:10:28 +00:00
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
2018-04-30 18:34:08 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-11-21 21:10:28 +00:00
|
|
|
function msg_info()
|
|
|
|
{
|
|
|
|
echo "$(date "+%Y/%m/%d %H:%M:%S") INFO - $1"
|
2018-04-30 18:34:08 +00:00
|
|
|
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
|
2017-11-21 21:10:28 +00:00
|
|
|
}
|
|
|
|
|
2018-06-28 08:45:45 +00:00
|
|
|
function patch_onlyifnotapply()
|
|
|
|
{
|
|
|
|
# Check path is apply or not (if not apply patch)
|
|
|
|
msg_debug "check patch $1"
|
|
|
|
if ! patch -Z -t -R -s -f --dry-run -p 1 -i $1 1>/dev/null
|
|
|
|
then
|
|
|
|
msg_debug "patch $1"
|
|
|
|
patch -f -Z -t -p 1 -i $1 || exit 2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-04-19 13:55:43 +00:00
|
|
|
#
|
|
|
|
# MAIN
|
|
|
|
#
|
|
|
|
|
2017-11-21 21:10:28 +00:00
|
|
|
trap chrashed EXIT
|
|
|
|
|
2018-04-19 13:55:43 +00:00
|
|
|
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
|
|
|
|
;;
|
2018-08-05 11:36:12 +00:00
|
|
|
--opennel-pymanager-dir=*)
|
|
|
|
DIRPYMANAGER="${1#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
2018-04-30 18:34:08 +00:00
|
|
|
--cxxflags=*)
|
|
|
|
CXXFLAGS="$CXXFLAGS ${1#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
2018-06-28 08:45:45 +00:00
|
|
|
--dont-copy-source)
|
|
|
|
DONTCOPYSOURCE=1
|
|
|
|
DIRCODEUSE="$DIRCODE"
|
|
|
|
shift
|
|
|
|
;;
|
2018-08-05 11:36:12 +00:00
|
|
|
--disable-build-opennel-code)
|
|
|
|
BUILD_OPENNEL_CODE=0
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--disable-package-opennel-pymanager)
|
|
|
|
PACKAGE_OPENNEL_PYMANAGER=0
|
|
|
|
shift
|
|
|
|
;;
|
2018-04-19 13:55:43 +00:00
|
|
|
*)
|
|
|
|
msg_error "options '$1' not recognize"
|
|
|
|
usage
|
2018-04-30 18:34:08 +00:00
|
|
|
exit 2
|
2018-04-19 13:55:43 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
declare LOGFILE="${DIRBUILD}/build.log"
|
|
|
|
|
2018-04-30 18:34:08 +00:00
|
|
|
msg_debug "DIRBUILD:$DIRBUILD"
|
|
|
|
msg_debug "DIRCODE:$DIRCODE"
|
2018-08-05 11:36:12 +00:00
|
|
|
msg_debug "DIRPYMANAGER:$DIRPYMANAGER"
|
2018-04-30 18:34:08 +00:00
|
|
|
msg_debug "CMAKEOPTS:$CMAKEOPTS"
|
|
|
|
msg_debug "MAKEOPTS:$MAKEOPTS"
|
|
|
|
msg_debug "LOGFILE:$LOGFILE"
|
|
|
|
msg_debug "CXXFLAGS:$CXXFLAGS"
|
2018-06-28 08:45:45 +00:00
|
|
|
msg_debug "DONTCOPYSOURCE:$DONTCOPYSOURCE"
|
2018-04-19 13:55:43 +00:00
|
|
|
|
2017-11-21 21:10:28 +00:00
|
|
|
msg_info "CREATE BUILD DIRECTORY"
|
|
|
|
mkdir -p ${DIRBUILD}/ || exit 2
|
|
|
|
|
2018-08-05 11:36:12 +00:00
|
|
|
if [[ $PACKAGE_OPENNEL_PYMANAGER -ne 0 ]]
|
2018-06-28 08:45:45 +00:00
|
|
|
then
|
2018-08-05 11:36:12 +00:00
|
|
|
msg_info "PACKAGE OPENNEL-PYMANAGER"
|
|
|
|
mkdir -p /tmp/pymanager/tmp || exit 2
|
|
|
|
cp -pr $DIRPYMANAGER/* /tmp/pymanager || exit 2
|
|
|
|
msg_debug "cd /tmp/pymanager; `which python3` setup.py bdist_wheel -d ${DIRBUILD} -b /tmp"
|
2018-10-10 22:48:24 +00:00
|
|
|
rm -f ${DIRBUILD}/*.whl || exit 2
|
2018-08-05 11:36:12 +00:00
|
|
|
cd /tmp/pymanager; `which python3` setup.py bdist_wheel -d ${DIRBUILD} -b /tmp/pymanager/tmp || exit 2
|
2018-06-28 08:45:45 +00:00
|
|
|
fi
|
2018-04-19 13:55:43 +00:00
|
|
|
|
2018-08-05 11:36:12 +00:00
|
|
|
if [[ $BUILD_OPENNEL_CODE -ne 0 ]]
|
|
|
|
then
|
|
|
|
if [[ $DONTCOPYSOURCE -eq 0 ]]
|
|
|
|
then
|
|
|
|
msg_info "COPY CODE"
|
|
|
|
DIRCODEUSE="$DIRBUILD/opennel-code"
|
|
|
|
mkdir -p ${DIRBUILD}/opennel-code || exit 2
|
|
|
|
cp -pr $DIRCODE/* ${DIRBUILD}/opennel-code || exit 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
msg_info "PATCH CODE"
|
|
|
|
for patchfile in $(cat ${DIRCODE}/patch/series)
|
|
|
|
do
|
|
|
|
cd ${DIRCODEUSE}
|
|
|
|
patch_onlyifnotapply ${DIRCODE}/patch/$patchfile || exit 2
|
|
|
|
done
|
2017-11-21 21:10:28 +00:00
|
|
|
|
2018-08-05 11:36:12 +00:00
|
|
|
msg_info "PREPARE BUILD"
|
|
|
|
msg_debug "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} ${DIRCODEUSE}/code 1>>$LOGFILE 2>&1 "
|
|
|
|
cd ${DIRBUILD}; CXXFLAGS="$CXXFLAGS" cmake -DWITH_NEL=ON \
|
2017-11-21 21:10:28 +00:00
|
|
|
-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} \
|
2018-06-28 08:45:45 +00:00
|
|
|
${DIRCODEUSE}/code 1>>$LOGFILE 2>&1 || exit 2
|
2017-11-21 21:10:28 +00:00
|
|
|
|
2018-08-05 11:36:12 +00:00
|
|
|
msg_info "BUILD START"
|
|
|
|
msg_debug "make option : $MAKEOPTS"
|
|
|
|
cd ${DIRBUILD}; VERBOSE=1 make $MAKEOPTS 1>>$LOGFILE 2>&1 || exit 2
|
|
|
|
fi
|
2017-11-21 21:10:28 +00:00
|
|
|
|
|
|
|
trap '' EXIT
|
|
|
|
msg_info "BUILD END"
|