-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbxdecay0-config.in
192 lines (163 loc) · 5.7 KB
/
bxdecay0-config.in
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env bash
#
# Utility script used to locate resources and files installed within
# the BxDecay0 library. This implementation does not support a
# relocatable binary distribution of BxDecay0.
#
# Copyright 2017-2020 François Mauger <mauger@lpccaen.in2p3.fr>
#
# This file is part of BxDecay0.
#
# BxDecay0 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BxDecay0 is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BxDecay0. If not, see <http://www.gnu.org/licenses/>.
#
# Description: an utility script to fetch informations about the
# current BxDecay0 installation. This should be very useful when
# used from some client scripts (i.e. build system scripts or
# wrapper/launcher scripts for a batch system on a computing farm).
APPNAME="bxdecay0-config"
# Self-locate ourselves, allowing for symlinks
#-----------------------------------------------------------------------
# Determine location of this script.
# NB, we don't always use the result of this calculation, but it does not
# hurt to do it. Only possible error is if too long a chain of symbolic
# links are used to point to the physical script.
#
# Resolve symbolic links to script - we should end up with a physical file
script="$0"
calldir=`pwd`
loopcount=""
while [ "x`readlink $script`" != "x" ] ; do
preloc=`dirname $script`
script=`readlink $script`
if [ ${script##/} = ${script##~} ] ; then
# The symbolic link was relative...
script="$preloc/$script"
fi
loopcount="l$loopcount"
if [ ${#loopcount} -gt 10 ] ; then
echo "error: more than 10 symbolic links to ${APPNAME} traversed."
exit 1
fi
done
# If we still have a relative path, then it must be relative to the
# calling dir. NB we don't attempt to resolve directory symbolic
# links or remove '.' or '..'
if [ ${script##/} = ${script##~} ] ; then
script="$calldir/$script"
fi
#-----------------------------------------------------------------------
# Finally, grab the directory in which the script is located,
# using a helper function to resolve any intermediate ".."
get_abs_filename() {
# $1 : relative filename
filename=$1
parentdir=$(dirname "${filename}")
if [ -d "${filename}" ]; then
echo "$(cd "${filename}" && pwd)"
elif [ -d "${parentdir}" ]; then
echo "$(cd "${parentdir}" && pwd)/$(basename "${filename}")"
fi
}
bin_dir="$(dirname $(get_abs_filename $script))"
prefix_dir="$(get_abs_filename "${bin_dir}/@BxDecay0_BINDIR_TO_PREFIX@")"
version_str="@BxDecay0_VERSION@"
orig_version_str="@BxDecay0_DECAY0_VERSION@"
lib_dir="${prefix_dir}/@CMAKE_INSTALL_LIBDIR@"
cmake_dir="${prefix_dir}/@CMAKE_INSTALL_CMAKEDIR@/BxDecay0"
inc_dir="${prefix_dir}/@CMAKE_INSTALL_INCLUDEDIR@"
data_dir="${prefix_dir}/@CMAKE_INSTALL_DATADIR@/@BxDecay0_TAG@"
example_dir="${data_dir}/examples"
resource_dir="${data_dir}/resources"
# plugin_dir="${lib_dir}/BxDecay0/plugins"
if [ -n "${BXDECAY0_RESOURCE_DIR}" ]; then
echo >&2 "[log] Overriding BxDecay0 resource dir from env 'BXDECAY0_RESOURCE_DIR'..."
if [ ! -d "${BXDECAY0_RESOURCE_DIR}" ]; then
echo >&2 "[error] Overriden BxDecay0 resource dir '${BXDECAY0_RESOURCE_DIR}' does not exist!"
exit 0
fi
resource_dir="${BXDECAY0_RESOURCE_DIR}"
fi
function print_usage()
{
cat<<EOF
bxdecay0-config - Utility script to fetch informations about the BxDecay0 library installation.
Options:
-h [ --help ] Print help.
--version Print version.
--original-version Print version of the original FORTRAN Decay0 code
--prefix Print installation prefix directory.
--libdir Print library directory.
--bindir Print binary directory.
--incdir Print include base directory.
--datadir Print data base directory.
--cmakedir Print CMake config directory.
--resourcedir Print resource directory.
--exampledir Print examples directory.
EOF
return
}
while [ -n "$?" ]; do
token="$1"
if [ "${token:0:1}" = "-" ]; then
option="${token}"
if [ "${option}" = "--help" -o "${option}" = "-h" ]; then
print_usage
exit 0
elif [ "${option}" = "--version" ]; then
echo ${version_str}
exit 0
elif [ "${option}" = "--original-version" ]; then
echo ${orig_version_str}
exit 0
elif [ "${option}" = "--prefix" ]; then
echo ${prefix_dir}
exit 0
elif [ "${option}" = "--libdir" ]; then
echo ${lib_dir}
exit 0
elif [ "${option}" = "--bindir" ]; then
echo ${bin_dir}
exit 0
# elif [ "${option}" = "--plugindir" ]; then
# echo ${plugin_dir}
# exit 0
elif [ "${option}" = "--incdir" ]; then
echo ${inc_dir}
exit 0
elif [ "${option}" = "--datadir" ]; then
echo ${data_dir}
exit 0
elif [ "${option}" = "--exampledir" ]; then
echo ${example_dir}
exit 0
elif [ "${option}" = "--resourcedir" ]; then
echo ${resource_dir}
exit 0
elif [ "${option}" = "--cmakedir" ]; then
echo ${cmake_dir}
exit 0
else
echo "error: ${APPNAME}: Invalid option '${option}' !" >&2
print_usage
exit 1
fi
else
echo "error: ${APPNAME}: Invalid argument '${token}' !" >&2
print_usage
exit 1
fi
shift 1
done
exit 0
# end