#!/usr/bin/env bash set -euo pipefail usage() { cat < 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-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" 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} <