Miguel Young de la Sota | 6379357 | 2019-11-13 14:18:51 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright lowRISC contributors. |
| 3 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | |
| 6 | # This file provides common definitions for build output locations in the |
| 7 | # OpenTitan repository; scripts that wish to use it should |source| it at their |
| 8 | # start. |
| 9 | # |
| 10 | # OpenTitan has two build directories: |
| 11 | # - $OBJ_DIR, which contains all outputs and intermediates of the build |
| 12 | # process, with an unstable directory structure. |
| 13 | # - $BIN_DIR, which contains "executable" outputs of the build process, such as |
| 14 | # binaries, tests, and bitstreams. It has a stable directory structure. |
| 15 | # |
| 16 | # $OBJ_DIR and $BIN_DIR are the subdirectories build-out and build-bin of |
| 17 | # $BUILD_ROOT, which can be configured to any desired directory. Build artifacts |
| 18 | # can be cleaned out by running |rm -rf $BUILD_ROOT/build-*|. |
Miguel Young de la Sota | b2ef483 | 2019-11-22 12:55:46 -0600 | [diff] [blame] | 19 | # |
| 20 | # This file also provides $OT_VERSION, which can be embedded in artifacts as a |
| 21 | # timestamp. If a git repo is present, it will be computed from that, or else |
| 22 | # will be an arbitrary string. |
Miguel Young de la Sota | 6379357 | 2019-11-13 14:18:51 -0600 | [diff] [blame] | 23 | |
Miguel Young de la Sota | 7e011c7 | 2019-11-22 10:14:17 -0600 | [diff] [blame] | 24 | # Since this file is intended to be sourced, we can't use |$0| to get our |
| 25 | # bearings. However, the bash-specific $BASH_SOURCE works perfectly fine. |
Miles Dai | 762b9ae | 2022-07-07 15:29:11 -0400 | [diff] [blame] | 26 | if [[ -n "${BASH_SOURCE[0]}" ]]; then |
| 27 | REPO_TOP="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 28 | readonly REPO_TOP |
Philipp Wagner | bb0b276 | 2020-09-09 22:44:30 +0100 | [diff] [blame] | 29 | export REPO_TOP |
Miguel Young de la Sota | 7e011c7 | 2019-11-22 10:14:17 -0600 | [diff] [blame] | 30 | else |
| 31 | echo "Non-bash shells are currently not supported." >&2 |
| 32 | exit 1 |
| 33 | fi |
Miguel Young de la Sota | 6379357 | 2019-11-13 14:18:51 -0600 | [diff] [blame] | 34 | |
Miles Dai | 762b9ae | 2022-07-07 15:29:11 -0400 | [diff] [blame] | 35 | OT_GIT_VERSION="$(git describe --always 2>/dev/null)" |
| 36 | export OT_GIT_VERSION |
Miguel Young de la Sota | b2ef483 | 2019-11-22 12:55:46 -0600 | [diff] [blame] | 37 | if [[ -n "$OT_GIT_VERSION" ]]; then |
| 38 | readonly OT_VERSION="opentitan-$OT_GIT_VERSION" |
| 39 | else |
| 40 | readonly OT_VERSION="opentitan-<unknown>" |
| 41 | fi |
Philipp Wagner | bb0b276 | 2020-09-09 22:44:30 +0100 | [diff] [blame] | 42 | export OT_VERSION |
Miguel Young de la Sota | b2ef483 | 2019-11-22 12:55:46 -0600 | [diff] [blame] | 43 | |
Philipp Wagner | bb0b276 | 2020-09-09 22:44:30 +0100 | [diff] [blame] | 44 | export BUILD_ROOT="${BUILD_ROOT:-"$REPO_TOP"}" |
Miguel Young de la Sota | 6379357 | 2019-11-13 14:18:51 -0600 | [diff] [blame] | 45 | readonly OBJ_DIR="$BUILD_ROOT/build-out" |
Philipp Wagner | bb0b276 | 2020-09-09 22:44:30 +0100 | [diff] [blame] | 46 | export OBJ_DIR |
Miguel Young de la Sota | 6379357 | 2019-11-13 14:18:51 -0600 | [diff] [blame] | 47 | readonly BIN_DIR="$BUILD_ROOT/build-bin" |
Philipp Wagner | bb0b276 | 2020-09-09 22:44:30 +0100 | [diff] [blame] | 48 | export BIN_DIR |
Chris Frantz | 58fa34d | 2022-04-22 10:14:19 -0700 | [diff] [blame] | 49 | export PYTHONPATH="${REPO_TOP}" |