khanat-code-old/dist/docker/builder/debian-8-i686/build.sh

200 lines
4.2 KiB
Bash
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#
# Script to build under docker
#
# Copyright : GNU/AGPLv3
#
# Created : 1 AUG 2017
# Created by : AleaJactaEst
declare -i REMOVE=0
declare -i IMAGE=1
declare -i BUILD=1
declare -i DEBUG=0
declare JOBS=""
declare CMAKEOPTS=""
declare DIRBUILD=""
declare CLEANDOCKER=0
declare IMAGEDOCKER="builder_debian_8_i686"
declare LOCALBUILDDIR="build_linux32"
declare LOCALSRC="debian-8-i686"
usage()
{
cat << EOF
usage:$0 [options]
script to build under docker
Step:
1) clean old build directory
2) create image builder
3) launch build under docker (launch script build-under-docker.sh)
4) remove docker container with state exited
options:
-h, --help : Show this help
-d, --debug : Show debug message
-r, --remove : Remove old build repository
-i, --image-only : Just create image (no build)
-b, --build-only : Just build (no create new image)
-j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg.
-a OPTS, --add-opts-cmake=OPTS : Adding options on cmake command (before build)
-c, --clean-container : remove all container in state Exited
Example :
cd [root Khanat directory]
dist/docker/builder/${LOCALSRC}/build.sh -c -r
dist/docker/builder/${LOCALSRC}/build.sh -c -r -j 4 -a '-DWITH_SYMBOLS=ON' -a '-DWITH_RYZOM_TOOLS=OFF' -a '-DWITH_NEL_TOOLS=OFF'
EOF
}
while test $# -gt 0
do
case "$1" in
-h|--help)
usage
exit 1
;;
-d|--debug)
DEBUG=1
shift
;;
-c|--clean-container)
CLEANDOCKER=1
shift
;;
-r|--remove)
REMOVE=1
shift
;;
-i|--image-only)
BUILD=0
IMAGE=1
shift
;;
-b|--build-only)
BUILD=1
IMAGE=0
shift
;;
-j)
shift
# search next argument is value or new argument
if [[ ${1:0:1} == "-" ]]
then
JOBS="-j"
else
JOBS="-j $1"
shift
fi
;;
--jobs*)
if [[ ${1#*=} == "" ]]
then
JOBS="-j"
else
JOBS="-j ${1#*=}"
fi
shift
;;
-a)
shift
CMAKEOPTS="$CMAKEOPTS $1"
shift
;;
--add-opts-cmake=*)
CMAKEOPTS="$CMAKEOPTS ${1#*=}"
shift
;;
*)
echo "*** ERROR : options '$1' not recoginze"
usage
exit 1
;;
esac
done
function chrashed()
{
echo "$(date "+%Y/%m/%d %H:%M:%S") BUILD FAILED (code:$?)"
exit 2
}
trap chrashed EXIT
if [[ $DEBUG -ne 0 ]]
then
echo "prg: $0"
fi
calldir="$(dirname $0)"
if [[ ${calldir:0:1} == "/" ]]
then
basedir="${calldir}"
else
basedir="$(pwd)/${calldir}"
fi
rootdir="$(dirname $(dirname $(dirname $(dirname ${basedir}))))"
docker -v 1>/dev/null
if [[ $? -ne 0 ]]
then
echo "*** ERROR docker not installed"
exit 2
fi
DIRBUILD="${rootdir}/code/${LOCALBUILDDIR}"
if [[ $DEBUG -ne 0 ]]
then
echo "calldir: $calldir"
echo "basedir: $basedir"
echo "rootdir: $rootdir"
echo "JOBS: '$JOBS'"
echo "CMAKEOPTS: '$CMAKEOPTS'"
fi
mkdir -p "${DIRBUILD}"
if [[ $REMOVE -ne 0 ]]
then
echo "$(date "+%Y/%m/%d %H:%M:%S") REMOVE OLD BUILD"
rm -rf ${DIRBUILD}/* || exit 2
fi
touch ${DIRBUILD}/build.log
cat << EOF > ${DIRBUILD}/envi.sh
#!/bin/bash
export MAKEOPTS="$JOBS"
export CMAKEOPTS="$CMAKEOPTS"
EOF
if [[ $IMAGE -ne 0 ]]
then
echo "$(date "+%Y/%m/%d %H:%M:%S") GENERATE DOCKER IMAGE"
cd $rootdir; docker build . -t ${IMAGEDOCKER} \
--file "${basedir}/Dockerfile" || exit 2
fi
if [[ $BUILD -ne 0 ]]
then
echo "$(date "+%Y/%m/%d %H:%M:%S") BUILD"
cd $rootdir; docker run -it \
--hostname=builder \
-u "$(id -u $USERNAME):$(id -g $USERNAME)" \
-v $rootdir/dist:/opt/dist \
-v $rootdir/code:/opt/code \
${IMAGEDOCKER} \
/opt/dist/docker/builder/${LOCALSRC}/build-under-docker.sh "/opt/code/${LOCALBUILDDIR}/" || exit 2
fi
if [[ $CLEANDOCKER -ne 0 ]]
then
docker rm --force `docker ps -qf 'status=exited' -f "ancestor=${IMAGEDOCKER}"` || exit 2
fi
trap '' EXIT
echo "$(date "+%Y/%m/%d %H:%M:%S") END"