2 # libnbd 'run' programs locally script
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #----------------------------------------------------------------------
23 # With this script you can run libnbd programs without needing to
24 # install libnbd first. You just have to do for example:
30 # ./run /path/to/my/libnbd/program
35 # >>> import nbd # locally-compiled nbd module
37 # This works for any C program and most non-C bindings.
39 # You can also compile other projects against this uninstalled libnbd
40 # tree if those projects are using pkgconf/pkg-config:
42 # ../libnbd/run ./configure
45 #----------------------------------------------------------------------
47 # Function to intelligently prepend a path to an environment variable.
48 # See http://stackoverflow.com/a/9631350
51 eval $1="$2\${$1:+:\$$1}"
54 # Source and build directories (absolute paths so this works from any
56 s
="$(cd @abs_srcdir@ && pwd)"
57 b
="$(cd @abs_builddir@ && pwd)"
59 # Set the PATH to contain all libnbd binaries.
60 prepend PATH
"$b/copy"
61 prepend PATH
"$b/dump"
62 prepend PATH
"$b/fuse"
63 prepend PATH
"$b/info"
65 prepend PATH
"$b/ublk"
68 # Set LD_LIBRARY_PATH and DYLD_LIBRARY_PATH to contain library.
69 # For use of _DYLD_LIBRARY_PATH see sh/nbdsh.
70 prepend LD_LIBRARY_PATH
"$b/lib/.libs"
71 prepend DYLD_LIBRARY_PATH
"$b/lib/.libs"
72 prepend _DYLD_LIBRARY_PATH
"$b/lib/.libs"
73 export LD_LIBRARY_PATH
74 export DYLD_LIBRARY_PATH
75 export _DYLD_LIBRARY_PATH
78 export PYTHON
="@PYTHON@"
79 prepend PYTHONPATH
"$b/python/.libs"
80 prepend PYTHONPATH
"$b/python"
81 prepend PYTHONPATH
"$s/python"
85 prepend CAML_LD_LIBRARY_PATH
"$b/ocaml"
86 export CAML_LD_LIBRARY_PATH
89 export GOLANG
="@GOLANG@"
90 if [ -z "$CGO_CFLAGS" ]; then
91 CGO_CFLAGS
="-I$s/include -I$b"
93 CGO_CFLAGS
="$CGO_CFLAGS -I$s/include -I$b"
96 if [ -z "$CGO_LDFLAGS" ]; then
97 CGO_LDFLAGS
="-L$b/lib/.libs"
99 CGO_LDFLAGS
="$CGO_LDFLAGS -L$b/lib/.libs"
102 # This implements complete pointer checking in cgo.
103 export GODEBUG
=cgocheck
=2,invalidptr
=1
104 # On failure, crash (giving us a useful core dump) instead of hiding that.
105 export GOTRACEBACK
=crash
107 # Allow dependent packages to be compiled against local libnbd.
108 prepend PKG_CONFIG_PATH
"$b/lib/local"
109 export PKG_CONFIG_PATH
110 prepend OCAMLPATH
"$b/ocaml"
113 # Do we have libtool? If we have it then we can use it to make
114 # running valgrind simpler. However don't depend on it.
115 if libtool
--help >/dev
/null
2>&1; then
116 libtool
="libtool --mode=execute"
121 # If we're running a binary then apply valgrind directly to it.
123 # If it's a shell script then we set $VG and the script must run any
124 # valgrinded programs by using $VG explicitly (note this variable is
125 # not set if not valgrinding).
127 # Unfortunately the obvious thing of running ‘file $1’ will not work
128 # because of libtool, so we have to base this off the file extension.
129 if [ "x$LIBNBD_VALGRIND" = "x1" ]; then
130 _VG
="valgrind --vgdb=no --leak-check=full --show-leak-kinds=all --error-exitcode=119 --suppressions=$b/valgrind/suppressions --trace-children=no --run-libc-freeres=no --num-callers=100"
133 VG
="$libtool $_VG"; export VG
;;
138 # Don't invoke malloc debugging when we are valgrinding because
139 # it duplicates work done by valgrind and might even hide issues.
141 # Originally this was a workaround for:
142 # https://sourceware.org/bugzilla/show_bug.cgi?id=28256
146 # Avoid GNOME keyring stupidity
147 export GNOME_KEYRING_CONTROL
=
148 export GNOME_KEYRING_PID
=
151 exec $libtool $valgrind "$@"