blob: dd59c3de1245598ff6673cf9899bc7376694efee [file] [log] [blame]
Miguel Young de la Sota63793572019-11-13 14:18:51 -06001#!/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 Sotab2ef4832019-11-22 12:55:46 -060019#
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 Sota63793572019-11-13 14:18:51 -060023
Miguel Young de la Sota7e011c72019-11-22 10:14:17 -060024# 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 Dai762b9ae2022-07-07 15:29:11 -040026if [[ -n "${BASH_SOURCE[0]}" ]]; then
27 REPO_TOP="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
28 readonly REPO_TOP
Philipp Wagnerbb0b2762020-09-09 22:44:30 +010029 export REPO_TOP
Miguel Young de la Sota7e011c72019-11-22 10:14:17 -060030else
31 echo "Non-bash shells are currently not supported." >&2
32 exit 1
33fi
Miguel Young de la Sota63793572019-11-13 14:18:51 -060034
Miles Dai762b9ae2022-07-07 15:29:11 -040035OT_GIT_VERSION="$(git describe --always 2>/dev/null)"
36export OT_GIT_VERSION
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060037if [[ -n "$OT_GIT_VERSION" ]]; then
38 readonly OT_VERSION="opentitan-$OT_GIT_VERSION"
39else
40 readonly OT_VERSION="opentitan-<unknown>"
41fi
Philipp Wagnerbb0b2762020-09-09 22:44:30 +010042export OT_VERSION
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060043
Philipp Wagnerbb0b2762020-09-09 22:44:30 +010044export BUILD_ROOT="${BUILD_ROOT:-"$REPO_TOP"}"
Miguel Young de la Sota63793572019-11-13 14:18:51 -060045readonly OBJ_DIR="$BUILD_ROOT/build-out"
Philipp Wagnerbb0b2762020-09-09 22:44:30 +010046export OBJ_DIR
Miguel Young de la Sota63793572019-11-13 14:18:51 -060047readonly BIN_DIR="$BUILD_ROOT/build-bin"
Philipp Wagnerbb0b2762020-09-09 22:44:30 +010048export BIN_DIR
Chris Frantz58fa34d2022-04-22 10:14:19 -070049export PYTHONPATH="${REPO_TOP}"