2020-11-20 18:13:46 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2023-05-19 15:52:52 +00:00
|
|
|
usage() {
|
|
|
|
cat <<-EOF
|
|
|
|
Usage: $(basename $0) [OPTION…] REPO_URL COMMIT
|
|
|
|
|
|
|
|
Check out and install a meson project
|
|
|
|
|
|
|
|
Options:
|
2024-10-04 15:12:23 +00:00
|
|
|
-Dkey=val Option to pass on to meson
|
|
|
|
--subdir=DIR Build subdirectory instead of whole project
|
|
|
|
--prepare=SCRIPT Script to run before build
|
|
|
|
--libdir=DIR Setup the project with a different libdir
|
|
|
|
--destdir=DIR Install the project to an additional destdir
|
2023-05-19 15:52:52 +00:00
|
|
|
|
2024-10-04 15:12:23 +00:00
|
|
|
-h, --help Display this help
|
2023-05-19 15:52:52 +00:00
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
TEMP=$(getopt \
|
|
|
|
--name=$(basename $0) \
|
|
|
|
--options='D:h' \
|
|
|
|
--longoptions='subdir:' \
|
|
|
|
--longoptions='prepare:' \
|
2024-07-11 15:44:43 +00:00
|
|
|
--longoptions='libdir:' \
|
2024-07-12 14:13:26 +00:00
|
|
|
--longoptions='destdir:' \
|
2023-05-19 15:52:52 +00:00
|
|
|
--longoptions='help' \
|
|
|
|
-- "$@")
|
|
|
|
|
|
|
|
eval set -- "$TEMP"
|
|
|
|
unset TEMP
|
2020-11-20 18:13:46 +00:00
|
|
|
|
|
|
|
MESON_OPTIONS=()
|
2023-05-19 15:52:52 +00:00
|
|
|
SUBDIR=.
|
|
|
|
PREPARE=:
|
2024-07-12 14:13:26 +00:00
|
|
|
DESTDIR=""
|
2020-11-20 18:13:46 +00:00
|
|
|
|
2023-05-19 15:52:52 +00:00
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
-D)
|
|
|
|
MESON_OPTIONS+=( -D$2 )
|
|
|
|
shift 2
|
|
|
|
;;
|
2020-11-20 18:13:46 +00:00
|
|
|
|
2023-05-19 15:52:52 +00:00
|
|
|
--subdir)
|
|
|
|
SUBDIR=$2
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
|
|
|
|
--prepare)
|
|
|
|
PREPARE=$2
|
|
|
|
shift 2
|
|
|
|
;;
|
2020-11-20 18:13:46 +00:00
|
|
|
|
2024-07-11 15:44:43 +00:00
|
|
|
--libdir)
|
|
|
|
MESON_OPTIONS+=( --libdir=$2 )
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
|
2024-07-12 14:13:26 +00:00
|
|
|
--destdir)
|
|
|
|
DESTDIR=$2
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
|
2023-05-19 15:52:52 +00:00
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
2020-11-20 18:13:46 +00:00
|
|
|
|
2023-05-19 15:52:52 +00:00
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2021-01-21 18:14:23 +00:00
|
|
|
|
2023-05-19 15:52:52 +00:00
|
|
|
if [[ $# -lt 2 ]]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
2021-01-21 18:14:23 +00:00
|
|
|
fi
|
|
|
|
|
2023-05-19 15:52:52 +00:00
|
|
|
REPO_URL="$1"
|
|
|
|
COMMIT="$2"
|
|
|
|
|
|
|
|
CHECKOUT_DIR=$(mktemp --directory)
|
|
|
|
trap "rm -rf $CHECKOUT_DIR" EXIT
|
|
|
|
|
|
|
|
git clone --depth 1 "$REPO_URL" -b "$COMMIT" "$CHECKOUT_DIR"
|
|
|
|
|
|
|
|
pushd "$CHECKOUT_DIR/$SUBDIR"
|
|
|
|
sh -c "$PREPARE"
|
|
|
|
meson setup --prefix=/usr _build "${MESON_OPTIONS[@]}"
|
2024-07-12 14:13:26 +00:00
|
|
|
|
|
|
|
# Install it to an additional directory e.g., system extension directory
|
|
|
|
if [ -n "${DESTDIR}" ]; then
|
2024-07-13 16:48:14 +00:00
|
|
|
sudo meson install -C _build --destdir=$DESTDIR
|
2024-07-12 14:13:26 +00:00
|
|
|
fi
|
|
|
|
|
2024-07-13 16:48:14 +00:00
|
|
|
sudo meson install -C _build
|
2020-11-20 18:13:46 +00:00
|
|
|
popd
|