Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience script for (re-)building #127

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env bash

(
theCalcaholic marked this conversation as resolved.
Show resolved Hide resolved

if [[ " $* " =~ " "("-h"|"--help")" " ]]
then
echo "Update and (re-)build backscrub"
echo "USAGE:"
echo " ./build.sh [OPTIONS]"
echo ""
echo " Options:"
echo " --h, --help Show this help message and exit"
echo " --no-update Skip fetching updates from github"
exit 0
fi

# Get the root directory of the repository
wd="$(cd "$(dirname $0)" || exit 1; pwd)"
theCalcaholic marked this conversation as resolved.
Show resolved Hide resolved

echo "working directory: $wd"
cd "$wd"

# Make sure we have the latest version of backscrub
echo "Fetching latest version..."
[[ " $* " =~ " --no-update" ]] || git pull --recurse-submodules
echo "..done"
echo ""


# Backup the current build directory (if present)
if [[ -d "./build" ]]
then
echo "Backing up build directory..."
[[ ! -d "./build_bk" ]] || rm -rf "./build_bk"
mv ./build ./build_bk
echo "..done"
echo ""
fi

# Restore the backup on error
trap 'rm -rf ./build && mv ./build_bk ./build' SIGHUP SIGINT SIGTERM
theCalcaholic marked this conversation as resolved.
Show resolved Hide resolved

# Abort on errors
set -e
theCalcaholic marked this conversation as resolved.
Show resolved Hide resolved

echo "Building backscrub..."

#mkdir build
theCalcaholic marked this conversation as resolved.
Show resolved Hide resolved
cd build
theCalcaholic marked this conversation as resolved.
Show resolved Hide resolved

# Build backscrub
cmake ..
make -j "$(nproc || echo 4)"
ln -s ../models models

echo "..done"
echo ""

echo "Cleaning up..."
# Delete the backup on success
[[ ! -d "./build_bk" ]] || rm -rf "./build_bk"
theCalcaholic marked this conversation as resolved.
Show resolved Hide resolved
echo "..done"
echo ""

echo "All done. You can run backscrub like this:"
echo " cd \"$wd/build\" && ./backscrub -h"
echo ""
echo "Or you can add the following line to your ~/.bashrc, to get a backscrub command:"
echo "backscrub() { pushd \"$wd/build\" > /dev/null && { ./backscrub \"\$@\"; popd > /dev/null; }; }"
theCalcaholic marked this conversation as resolved.
Show resolved Hide resolved


)