https://github.com/N3PDF/pineappl
Raw File
Tip revision: e0a45f6107befb63e25164c91244eb669b1bcfe1 authored by Christopher Schwan on 13 March 2024, 12:46:35 UTC
Simplify detection of target triplet
Tip revision: e0a45f6
install-capi.sh
#!/bin/sh

set -eu

prefix=
version=

while [ $# -gt 0 ]; do
    case $1 in
        --version)
            version=$2
            shift
            shift
            ;;
        --version=*)
            version=${1#--version=}
            shift
            ;;
        --prefix)
            prefix=$2
            shift
            shift
            ;;
        --prefix=*)
            prefix=${1#--prefix=}
            shift
            ;;
        --target)
            target=$2
            shift
            shift
            ;;
        --target=*)
            target=${1#--target=}
            shift
            ;;
        *)
            echo "Error: argument '$1' unknown"
            exit 1
            ;;
    esac
done

if [ -z ${target+x} ]; then
    case $(uname -m):$(uname -s) in
        arm64:Darwin)
            target=aarch64-apple-darwin;;
        x86_64:Darwin)
            target=x86_64-apple-darwin;;
        x86_64:Linux)
            target=x86_64-unknown-linux-gnu;;
        *)
            echo "Error: unknown target, uname = '$(uname -a)'"
    esac
fi

# if no prefix is given, prompt for one
if [ -z ${prefix} ]; then
    # read from stdin (`<&1`), even if piped into a shell
    read -p "Enter installation path: " <&1 prefix
fi

if [ ! -d "${prefix}" ]; then
    mkdir -p "${prefix}"
fi

# if no version is given, use the latest version
if [ -z ${version} ]; then
    version=$(curl -s https://api.github.com/repos/NNPDF/pineappl/releases/latest | \
        sed -n 's/[ ]*"tag_name"[ ]*:[ ]*"v\([^"]*\)"[ ]*,[ ]*$/\1/p')
fi

base_url=https://github.com/NNPDF/pineappl/releases/download

echo "prefix:  ${prefix}"
echo "target:  ${target}"
echo "version: ${version}"

# we need the absolute path
cd "${prefix}"
prefix=$(pwd)
cd - >/dev/null

curl -s -LJ "${base_url}"/v${version}/pineappl_capi-${target}.tar.gz \
    | tar xzf - -C "${prefix}"

# instead of `sed` and `mv` we could use `sed -i`, but on Mac it doesn't work as expected from GNU sed
sed s:prefix=/:prefix=${prefix}: "${prefix}"/lib/pkgconfig/pineappl_capi.pc > \
    "${prefix}"/lib/pkgconfig/pineappl_capi.pc.new
mv "${prefix}"/lib/pkgconfig/pineappl_capi.pc.new "${prefix}"/lib/pkgconfig/pineappl_capi.pc

if command -v pkg-config >/dev/null; then
    if ! pkg-config --libs pineappl_capi >/dev/null; then
        echo
        echo "Warning: Your PKG_CONFIG_PATH environment variable isn't properly set. Try adding"
        echo "  export PKG_CONFIG_PATH=${prefix}/lib/pkgconfig"
        echo "to your shell configuration file"
    fi
else
    echo
    echo "Warning: \`pkg-config\` binary not found. Without it the CAPI may not be found."
fi
back to top