2016-10-02 08:18:37 +00:00
|
|
|
# Simply sets up a few useful variables.
|
|
|
|
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
|
|
|
function relative() {
|
|
|
|
local full_path="${SCRIPT_DIR}/../${1}"
|
2016-10-02 08:23:28 +00:00
|
|
|
|
2016-10-04 00:25:55 +00:00
|
|
|
if [ -d "${full_path}" ]; then
|
2016-12-26 04:23:54 +00:00
|
|
|
# Try to use readlink as a fallback to readpath for cross-platform compat.
|
|
|
|
if command -v realpath >/dev/null 2>&1; then
|
2018-01-24 02:53:02 +00:00
|
|
|
realpath "${full_path}"
|
2016-12-26 04:23:54 +00:00
|
|
|
elif ! (readlink -f 2>&1 | grep illegal > /dev/null); then
|
2018-01-24 02:53:02 +00:00
|
|
|
readlink -f "${full_path}"
|
2016-10-04 00:25:55 +00:00
|
|
|
else
|
2016-12-26 04:23:54 +00:00
|
|
|
echo "Rocket's scripts require 'realpath' or 'readlink -f' support." >&2
|
|
|
|
echo "Install realpath or GNU readlink via your package manager." >&2
|
|
|
|
echo "Aborting." >&2
|
|
|
|
exit 1
|
2016-10-04 00:25:55 +00:00
|
|
|
fi
|
2016-10-02 08:23:28 +00:00
|
|
|
else
|
2016-10-04 00:25:55 +00:00
|
|
|
# when the directory doesn't exist, fallback to this.
|
|
|
|
echo "${full_path}"
|
2016-10-02 08:23:28 +00:00
|
|
|
fi
|
2016-10-02 08:18:37 +00:00
|
|
|
}
|
|
|
|
|
2016-12-29 04:33:56 +00:00
|
|
|
ROOT_DIR=$(relative "") || exit $?
|
2016-12-26 04:23:54 +00:00
|
|
|
EXAMPLES_DIR=$(relative "examples") || exit $?
|
|
|
|
LIB_DIR=$(relative "lib") || exit $?
|
|
|
|
CODEGEN_DIR=$(relative "codegen") || exit $?
|
|
|
|
CONTRIB_DIR=$(relative "contrib") || exit $?
|
|
|
|
DOC_DIR=$(relative "target/doc") || exit $?
|
2016-10-02 08:18:37 +00:00
|
|
|
|
|
|
|
if [ "${1}" = "-p" ]; then
|
2018-01-24 02:53:02 +00:00
|
|
|
echo "${ROOT_DIR}"
|
|
|
|
echo "${SCRIPT_DIR}"
|
|
|
|
echo "${EXAMPLES_DIR}"
|
|
|
|
echo "${LIB_DIR}"
|
|
|
|
echo "${CODEGEN_DIR}"
|
|
|
|
echo "${CONTRIB_DIR}"
|
|
|
|
echo "${DOC_DIR}"
|
2016-10-02 08:18:37 +00:00
|
|
|
fi
|