aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/ootb103
1 files changed, 103 insertions, 0 deletions
diff --git a/bin/ootb b/bin/ootb
new file mode 100755
index 0000000..3aa58db
--- /dev/null
+++ b/bin/ootb
@@ -0,0 +1,103 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ ootb BUILD_DIRECTORY < FILE...
+ ootb -h
+ EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+
+ Options:
+ -h, --help show this message
+
+ BUILD_DIRECTORY the path of the build directory
+ FILE the files to be linked
+
+
+ Create a directory out of symlinks of the given files.
+
+ The goal is to enable parallel build directories to coexist,
+ so that one do *O*ut *O*f *T*ree *B*uilds without requiring the
+ build system or the project to explicitly support it.
+
+ If a repository contains the files:
+
+ .git/
+ Makefile
+ README.md
+ src/
+ file1.ext
+ file2.ext
+
+ Running `git ls-files | ootb build-1/` would create the
+ 'build-1/' directory with:
+
+ build-1/
+ Makefile -> /absolute/path/to/Makefile
+ README.md -> /absolute/path/to/README.md
+ src/
+ file1.ext -> /absolute/path/to/file1.ext
+ file2.ext -> /absolute/path/to/file2.ext
+
+ With that one can `cd build-1/` and run builds there, without
+ the build artifacts littering the source tree. Also, one could
+ create a build-2/ directory, where different compiler flags or
+ build options are given, such as debug/release, while sharing the
+ underlying source code.
+
+
+ Examples:
+
+ Create a 'build/' directory with the files from the Git repository:
+
+ $ git ls-files | ootb build/
+ EOF
+}
+
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+
+BUILD_DIRECTORY="${1:-}"
+eval "$(assert-arg "$BUILD_DIRECTORY" 'BUILD_DIRECTORY')"
+mkdir -p "$BUILD_DIRECTORY"
+
+
+while read -r f; do
+ mkdir -p "$BUILD_DIRECTORY"/"$(dirname "$f")"
+ ln -fs "$PWD"/"$f" "$BUILD_DIRECTORY"/"$f"
+done