xo-reader2/xo-cmake/bin/xo-build.in

336 lines
7.4 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<EOF
$0 [-u|--usage|-h|--help]
[--list] [-n|--dry-run] [--xoname=NAME]
[--repo|--clone|--configure|--build|--install]
[--with-examples] [--with-utests] [--with-asm] [--debug-build]
[--with-opengl=GLFLAG] [--with-vulkan=VKFLAG]
[-S=SOURCEDIR] [-B=BUILDDIR]
EOF
}
help() {
usage
cat <<EOF
fetch and/or build xo component libraries
Options:
-u | --usage brief help message
-h | --help this help message
--list list known xo libraries
-n | --dry-run dry-run: don't actually invoke state-changing commands
--xoname=NAME operate on xo subsystem NAME
--repo report github repo for NAME
--clone git clone xo library NAME in current directory
--configure run cmake for xo library NAME in immediate subdir
Will use NAME/.build as build directory
--build run cmake build for xo library NAME in immediate subdir
--build-docs build documentation for xo library NAME in immediate subdir
--install run cmake install for xo library NAME in immediate subdir
--realclean nuke build directory
-S=SOURCEDIR override path/to/source
-B=BUILDDIR override path/to/build
--with-examples in configure step, set -DXO_ENABLE_EXAMPLES=1
--with-utests in configure step, set -DENABLE_TESTING=1
--with-asm in configure step, set -DXO_ENABLE_ASM=1
--debug-build in configure step, set -DCMAKE_BUILD_TYPE=Debug
--with-opengl=GLFLAG in configure step, set -DXO_ENABLE_OPENGL=GLFLAG [ON]
--with-vulkan=VKFLAG in configure step, set -DXO_ENABLE_VULKAN=VKFLAG [OFF]
EOF
}
cmd=
noop_flag=0
xoname=
repo_flag=0
clone_flag=0
configure_flag=0
build_flag=0
build_docs_flag=0
install_flag=0
realclean_flag=0
pathtosource=
pathtobuild=
with_examples=0
with_utests=0
with_asm=0
debug_build=0
with_opengl=
with_vulkan=
while [[ $# > 0 ]]; do
case "$1" in
-u | --usage)
cmd='usage'
;;
-h | --help)
cmd='help'
;;
-n | --dry-run)
noop_flag=1
;;
-S)
shift
pathtosource=$1
;;
-S=*)
pathtosource="${1#*=}"
;;
-B)
shift
pathtobuild=$1
;;
-B=*)
pathtobuild="${1#*=}"
;;
--list)
cmd='list'
;;
--xoname=*)
xoname="${1#*=}"
;;
--repo)
repo_flag=1
;;
--clone)
clone_flag=1
;;
--configure|--config)
configure_flag=1
;;
--build)
build_flag=1
;;
--build-docs)
build_docs_flag=1
;;
--install)
install_flag=1
;;
--realclean)
realclean_flag=1
;;
--with-examples)
with_examples=1
;;
--with-utests)
with_utests=1
;;
--with-asm)
with_asm=1
;;
--debug-build)
debug_build=1
;;
--with-opengl=*)
with_opengl="${1#*=}"
;;
--with-vulkan=*)
with_vulkan="${1#*=}"
;;
xo-*)
xoname="$1"
;;
*)
usage
exit 1
;;
esac
shift
done
#echo xoname=$xoname pathtosource=$pathtosource pathtobuild=$pathtobuild
if [[ -z "$pathtosource" ]]; then
pathtosource=$xoname
fi
if [[ -z "$pathtobuild" ]]; then
if [[ -n $xoname ]]; then
pathtobuild=$xoname/.build
else
pathtobuild=.build
fi
fi
SUBSYSTEMLIST_FILE=@CMAKE_INSTALL_FULL_DATADIR@/etc/xo/subsystem-list
subsystem_list() {
cat ${SUBSYSTEMLIST_FILE}
}
XO_REPO_STEM="https://github.com/Rconybea"
printrepo() {
xoname=$1
case "$xoname" in
# carve-outs for 4 snowflake xo repo names
xo-indentlog)
echo "${XO_REPO_STEM}/indentlog.git"
;;
xo-refcnt)
echo "${XO_REPO_STEM}/refcnt.git"
;;
xo-subsys)
echo "${XO_REPO_STEM}/subsys.git"
;;
xo-reflect)
echo "${XO_REPO_STEM}/reflect.git"
;;
*)
if grep -q $1 ${SUBSYSTEMLIST_FILE}; then
echo "${XO_REPO_STEM}/${1}.git"
else
>&2 echo "$0: unknown xo component [${xoname}]"
return 1
fi
esac
return 0
}
if [[ $cmd == 'usage' ]]; then
echo -n "usage: "
usage
exit 0
elif [[ $cmd == 'help' ]]; then
echo -n "help; "
help
exit 0
fi
set -e
if [[ $cmd == 'list' ]]; then
subsystem_list
fi
if [[ $repo_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
printrepo $xoname
fi
fi
if [[ $clone_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
url=$(printrepo $xoname)
cmd="git clone $url"
if [[ $noop_flag -eq 1 ]]; then
echo $cmd
else
$cmd
fi
fi
fi
if [[ $configure_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
testingarg=
if [[ $with_utests -eq 1 ]]; then
testingarg="-DENABLE_TESTING=1"
fi
if [[ $with_asm -eq 1 ]]; then
asmarg="-DENABLE_ASM=1"
fi
examplearg=
if [[ $with_examples -eq 1 ]]; then
examplearg="-DXO_ENABLE_EXAMPLES=1"
fi
cmakebuildtype=
if [[ $debug_build -eq 1 ]]; then
cmakebuildtype="-DCMAKE_BUILD_TYPE=Debug"
fi
openglarg=
if [[ -n ${with_opengl} ]]; then
openglarg="-DXO_ENABLE_OPENGL=${with_opengl}"
fi
vulkanarg=
if [[ -n ${with_vulkan} ]]; then
vulkanarg="-DXO_ENABLE_VULKAN=${with_vulkan}"
fi
cmd="cmake -DCMAKE_INSTALL_PREFIX=@CMAKE_INSTALL_PREFIX@ -DCMAKE_MODULE_PATH=@CMAKE_INSTALL_PREFIX@/share/cmake -S $pathtosource -B $pathtobuild ${testingarg} ${examplearg} ${asmarg} ${openglarg} ${vulkanarg} ${cmakebuildtype}"
if [[ $noop_flag -eq 1 ]]; then
echo $cmd
else
cwd=$(pwd)
# write script to re-run cmake later
rebootcmake=$pathtobuild/rebootcmake
mkdir -p $(dirname ${rebootcmake})
cat > ${rebootcmake} <<EOF
#!/usr/bin/env bash
cd ${cwd} && ${cmd}
EOF
chmod +rx ${rebootcmake}
$cmd
fi
fi
fi
if [[ $build_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
cmd="cmake --build $pathtobuild -j"
if [[ $noop_flag -eq 1 ]]; then
echo $cmd
else
$cmd
fi
fi
fi
if [[ $build_docs_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
cmd="cmake --build $pathtobuild -- docs"
if [[ $noop_flag -eq 1 ]]; then
echo $cmd
else
$cmd
fi
fi
fi
if [[ $install_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
cmd="cmake --install $pathtobuild"
if [[ $noop_flag -eq 1 ]]; then
echo $cmd
else
$cmd
fi
fi
fi
if [[ $realclean_flag -eq 1 ]]; then
if [[ $noop_flag -eq 1 ]]; then
echo "rm -rf $pathtobuild"
else
rm -rf "${pathtobuild}"
fi
fi