xo-umbrella2/xo-cmake/bin/xo-build.in
Roland Conybeare 7038ddad2a xo-build: explicit local clone name
e.g. so xo-build --clone xo-refcnt uses xo-refcnt/, not refcnt/
2026-05-26 08:01:17 -04:00

440 lines
10 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<EOF
$0 [-u|--usage|-h|--help]
[--list] [-n|--dry-run] [--xoname=NAME]
[--repo
|--add-umbrella-remote
|--split-umbrella-remote
|--pull-umbrella-remote
|--push-umbrella-remote]
[--clone|--configure|--build|--install]
[--with-examples] [--with-utests] [--with-asm] [--debug-build]
[--with-opengl=GLFLAG] [--with-vulkan=VKFLAG]
[-S=SOURCEDIR] [-B=BUILDDIR]
NAME
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
--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]
--repo report github repo for NAME
--add-umbrella-remote (in umbrella sandbox) add remote for xo library NAME
--split-umbrella-remote (in umbrella sandbox) generate split branch for xo library NAME
--pull-umbrella-remote (in umbrella sandbox) pull satellite remote for xo library NAME
--push-umbrella-remote (in umbrella sandbox) push satellite remote for xo library NAME
EOF
}
cmd=
noop_flag=0
xoname=
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=
repo_flag=0
add_umbrella_remote_flag=0
split_umbrella_remote_flag=0
pull_umbrella_remote_flag=0
push_umbrella_remote_flag=0
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#*=}"
;;
--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#*=}"
;;
--repo)
repo_flag=1
;;
--add-umbrella-remote)
add_umbrella_remote_flag=1
;;
--split-umbrella-remote)
split_umbrella_remote_flag=1
;;
--pull-umbrella-remote)
pull_umbrella_remote_flag=1
;;
--push-umbrella-remote)
push_umbrella_remote_flag=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=
if [[ $(whoami) == "roland" ]]; then
XO_REPO_STEM="git@github.com:Rconybea"
else
XO_REPO_STEM="https://github.com/Rconybea"
fi
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-randomgen)
echo "${XO_REPO_STEM}/randomgen.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 [[ $add_umbrella_remote_flag -eq 1 ]]; then
if [[ $clone_flag -eq 1 || $configure_flag -eq 1 || $build_flag -eq 1 || $build_docs_flag -eq 1 || $install_flag -eq 1 || $realclean_flag -eq 1 ]]; then
2>&1 echo "error: xo-build: repo operation --add-umbrella-remote conflicts with"
2>&1 echo " build operation --clone|--configure|--build|--build-docs|--install|--realclean"
exit 1
fi
if [[ -n "$xoname" ]]; then
url=$(printrepo $xoname)
cmd="git remote add $xoname $url"
if [[ $noop_flag -eq 1 ]]; then
echo $cmd
else
$cmd
fi
fi
fi
if [[ $split_umbrella_remote_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
#branch=$(git branch --show-current)
demux_branch=_demux/$xoname
cmd="git subtree split --rejoin --prefix=$xoname -b ${demux_branch}"
if [[ $noop_flag -eq 1 ]]; then
echo $cmd
else
$cmd
fi
fi
fi
if [[ $pull_umbrella_remote_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
branch=$(git branch --show-current)
cmd="git subtree pull --rejoin --prefix=$xoname $xoname ${branch}"
if [[ $noop_flag -eq 1 ]]; then
echo $cmd
else
$cmd
fi
fi
fi
if [[ $push_umbrella_remote_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
branch=$(git branch --show-current)
demux_branch=_demux/$xoname
cmd1="git subtree split --rejoin --prefix=$xoname -b ${demux_branch}"
remote=${xoname}
remote_branch=${branch}
cmd2="git push ${remote} ${demux_branch}:${remote_branch}"
#cmd="git subtree push --rejoin --prefix=$xoname $xoname ${branch}"
if [[ $noop_flag -eq 1 ]]; then
echo $cmd1
echo $cmd2
else
$cmd1
$cmd2
fi
fi
fi
if [[ $clone_flag -eq 1 ]]; then
if [[ -n "$xoname" ]]; then
url=$(printrepo $xoname)
cmd="git clone $url $xoname"
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
asmarg=
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