2020-11-06 17:59:19 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2023-03-20 00:47:30 +00:00
|
|
|
usage() {
|
|
|
|
cat <<-EOF
|
2023-03-20 01:01:33 +00:00
|
|
|
Usage: $(basename $0) [OPTION…] REPO_URL COMMIT
|
2023-03-20 00:47:30 +00:00
|
|
|
|
|
|
|
Check out and install a meson project
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-Dkey=val Option to pass on to meson
|
2023-03-20 01:01:33 +00:00
|
|
|
--subdir Build subdirectory instead of whole project
|
|
|
|
--prepare Script to run before build
|
2023-03-20 00:47:30 +00:00
|
|
|
|
2023-03-20 00:55:59 +00:00
|
|
|
-h, --help Display this help
|
|
|
|
|
2023-03-20 00:47:30 +00:00
|
|
|
EOF
|
|
|
|
}
|
2020-11-06 17:59:19 +00:00
|
|
|
|
2023-03-20 00:41:15 +00:00
|
|
|
TEMP=$(getopt \
|
|
|
|
--name=$(basename $0) \
|
2023-03-20 00:55:59 +00:00
|
|
|
--options='D:h' \
|
2023-03-20 01:01:33 +00:00
|
|
|
--longoptions='subdir:' \
|
|
|
|
--longoptions='prepare:' \
|
2023-03-20 00:55:59 +00:00
|
|
|
--longoptions='help' \
|
2023-03-20 00:41:15 +00:00
|
|
|
-- "$@")
|
|
|
|
|
|
|
|
eval set -- "$TEMP"
|
|
|
|
unset TEMP
|
|
|
|
|
2020-11-06 17:59:19 +00:00
|
|
|
MESON_OPTIONS=()
|
2023-03-20 01:01:33 +00:00
|
|
|
SUBDIR=.
|
|
|
|
PREPARE=:
|
2020-11-06 17:59:19 +00:00
|
|
|
|
2023-03-20 00:41:15 +00:00
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
-D)
|
|
|
|
MESON_OPTIONS+=( -D$2 )
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
|
2023-03-20 01:01:33 +00:00
|
|
|
--subdir)
|
|
|
|
SUBDIR=$2
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
|
|
|
|
--prepare)
|
|
|
|
PREPARE=$2
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
|
2023-03-20 00:55:59 +00:00
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
|
2023-03-20 00:41:15 +00:00
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
2020-11-06 17:59:19 +00:00
|
|
|
done
|
|
|
|
|
2023-03-20 01:01:33 +00:00
|
|
|
if [[ $# -lt 2 ]]; then
|
2023-03-20 00:47:30 +00:00
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-11-06 17:59:19 +00:00
|
|
|
REPO_URL="$1"
|
|
|
|
COMMIT="$2"
|
|
|
|
|
2023-03-21 00:00:07 +00:00
|
|
|
CHECKOUT_DIR=$(mktemp --directory)
|
|
|
|
trap "rm -rf $CHECKOUT_DIR" EXIT
|
2020-11-06 17:59:19 +00:00
|
|
|
|
2023-03-21 00:00:07 +00:00
|
|
|
git clone --depth 1 "$REPO_URL" -b "$COMMIT" "$CHECKOUT_DIR"
|
|
|
|
|
|
|
|
pushd "$CHECKOUT_DIR/$SUBDIR"
|
2020-11-06 17:59:19 +00:00
|
|
|
sh -c "$PREPARE"
|
2023-03-20 00:40:43 +00:00
|
|
|
meson setup --prefix=/usr _build "${MESON_OPTIONS[@]}"
|
2021-08-05 01:46:53 +00:00
|
|
|
meson install -C _build
|
2020-11-06 17:59:19 +00:00
|
|
|
popd
|