summaryrefslogtreecommitdiff
path: root/tools/find-build-dir.sh
blob: e449b6e8650aa66e051748b87b6b39160bcc2f33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh
# SPDX-License-Identifier: LGPL-2.1-or-later
set -e

# Try to guess the build directory:
# we look for subdirectories of the parent directory that look like ninja build dirs.

if [ -n "$BUILD_DIR" ]; then
    echo "$(realpath "$BUILD_DIR")"
    exit 0
fi

root="$(dirname "$(realpath "$0")")"

found=
for i in "$root"/../*/build.ninja; do
    c="$(dirname $i)"
    [ -d "$c" ] || continue
    [ "$(basename "$c")" != mkosi.builddir ] || continue

    if [ -n "$found" ]; then
        echo 'Found multiple candidates, specify build directory with $BUILD_DIR' >&2
        exit 2
    fi
    found="$c"
done

if [ -z "$found" ]; then
    echo 'Specify build directory with $BUILD_DIR' >&2
    exit 1
fi

echo "$(realpath $found)"