-
Notifications
You must be signed in to change notification settings - Fork 3
/
install-capi.sh
executable file
·130 lines (114 loc) · 3.53 KB
/
install-capi.sh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/sh
# WARNING: do not commit changes to this file unless you've checked it against
# `shellcheck` (https://www.shellcheck.net/); run `shellcheck install-capi.sh`
# to make sure this script is POSIX shell compatible; we cannot rely on bash
# being present
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)'"
exit 1;;
esac
fi
# if no prefix is given, prompt for one
if [ -z "${prefix}" ]; then
# read from stdin (`<&1`), even if piped into a shell
printf "Enter installation path: "
read -r <&1 prefix
echo
fi
# we need the absolute path; use `eval` to expand possible tilde `~`
eval mkdir -p "${prefix}"
eval cd "${prefix}"
prefix=$(pwd)
cd - >/dev/null
# 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
url="https://github.com/NNPDF/pineappl/releases/download/v${version}/pineappl_capi-${target}.tar.gz"
echo "prefix: '${prefix}'"
echo "target: '${target}'"
echo "version: '${version}'"
echo "URL: '${url}'"
curl -s -LJ "${url}" | 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
pcbin=
if command -v pkg-config >/dev/null; then
pcbin=$(command -v pkg-config)
elif command -v pkgconf >/dev/null; then
pcbin=$(command -v pkgconf)
else
echo
echo "Error: neither \`pkg-config\` nor \`pkgconf\` not found. At least one is needed for the CAPI to be found"
exit 1
fi
# check whether the library can be found
if "${pcbin}" --exists pineappl_capi; then
found_prefix=$(cd "$("${pcbin}" --variable=prefix pineappl_capi)" && pwd)
if [ "${prefix}" != "${found_prefix}" ]; then
echo
echo "Warning: Your PKG_CONFIG_PATH environment variable isn't properly set."
echo "It appears a different installation of PineAPPL is found:"
echo
echo " ${found_prefix}"
echo
echo "Remove this installation or reorder your PKG_CONFIG_PATH"
fi
else
echo
echo "Warning: Your PKG_CONFIG_PATH environment variable isn't properly set."
echo "Try adding"
echo
echo " export PKG_CONFIG_PATH=${prefix}/lib/pkgconfig:\"\${PKG_CONFIG_PATH\}\""
echo
echo "to your shell configuration file"
fi