1#!/usr/bin/env bash
2
3set -e
4
5# This is unset by meson
6# shellcheck disable=SC2157
7if [ -z "@MESON@" ]; then
8	SOURCEDIR="@MESON_SOURCE_ROOT@"
9	BUILDDIR="@MESON_BUILD_ROOT@"
10else
11	SOURCEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
12	BUILDDIR=$(find "${SOURCEDIR}" -maxdepth 2 -name build.ninja -printf "%h\n" -quit 2>/dev/null || echo "${SOURCEDIR}/builddir")
13fi
14
15while getopts ":b:v:" opt; do
16	case ${opt} in
17		b)
18			BUILDDIR=${OPTARG}
19			;;
20		v)
21			VERSION=${OPTARG}
22			echo "Version: ${VERSION}"
23			;;
24		\?)
25			echo "Invalid option: -${OPTARG}"
26			exit 1
27			;;
28		:)
29			echo "Option -${OPTARG} requires an argument"
30			exit 1
31			;;
32	esac
33done
34
35shift $((OPTIND-1))
36
37if [ ! -d "${BUILDDIR}" ]; then
38	echo "Invalid build directory: ${BUILDDIR}"
39	exit 1
40fi
41
42# the config file read by the daemon
43export MEDIA_SESSION_CONFIG_DIR="${BUILDDIR}/media-session.d"
44export PATH="${BUILDDIR}/src:${PATH}"
45
46export PW_UNINSTALLED=1
47export PKG_CONFIG_PATH="${BUILDDIR}/meson-uninstalled/:${PKG_CONFIG_PATH}"
48
49if [ -z "$1" ]; then
50	# FIXME: find a nice, shell-neutral way to specify a prompt
51	${SHELL}
52else
53	exec "$@"
54fi
55