build: Don't assume that libc.so is always in /usr/lib or /usr/lib64

The location for public shared libraries can change from one operating
system distribution to another. eg., while Fedora uses /usr/lib and
/usr/lib64, depending on the hardware architecture, Debian uses paths
like /usr/lib/x86_64-linux-gnu. Therefore, it's best not to assume
anything and ask the toolchain.

https://github.com/containers/toolbox/pull/923
This commit is contained in:
Debarshi Ray 2021-11-13 03:17:39 +01:00
parent b80ffecd3d
commit c8aaed52c5
3 changed files with 22 additions and 3 deletions

View file

@ -1,10 +1,13 @@
project( project(
'toolbox', 'toolbox',
'c',
version: '0.0.99.2', version: '0.0.99.2',
license: 'ASL 2.0', license: 'ASL 2.0',
meson_version: '>= 0.53.0', meson_version: '>= 0.53.0',
) )
cc = meson.get_compiler('c')
go = find_program('go') go = find_program('go')
go_md2man = find_program('go-md2man') go_md2man = find_program('go-md2man')
patchelf = find_program('patchelf') patchelf = find_program('patchelf')

View file

@ -16,9 +16,9 @@
# #
if [ "$#" -ne 3 ]; then if [ "$#" -ne 4 ]; then
echo "go-build-wrapper: wrong arguments" >&2 echo "go-build-wrapper: wrong arguments" >&2
echo "Usage: go-build-wrapper [SOURCE DIR] [OUTPUT DIR] [VERSION]" >&2 echo "Usage: go-build-wrapper [SOURCE DIR] [OUTPUT DIR] [VERSION] [C COMPILER]" >&2
exit 1 exit 1
fi fi
@ -27,7 +27,22 @@ if ! cd "$1"; then
exit 1 exit 1
fi fi
go build -trimpath -ldflags "-extldflags '-Wl,-rpath,/run/host/usr/lib -Wl,-rpath,/run/host/usr/lib64' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2/toolbox" if ! libc_dir=$("$4" --print-file-name=libc.so); then
echo "go-build-wrapper: failed to read the path to libc.so" >&2
exit 1
fi
if ! libc_dir_canonical=$(readlink --canonicalize "$libc_dir"); then
echo "go-build-wrapper: failed to canonicalize the path to libc.so" >&2
exit 1
fi
if ! libc_dir_canonical_dirname=$(dirname "$libc_dir_canonical"); then
echo "go-build-wrapper: failed to read the dirname of the canonicalized path to libc.so" >&2
exit 1
fi
go build -trimpath -ldflags "-extldflags '-Wl,-rpath,/run/host$libc_dir_canonical_dirname' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2/toolbox"
if ! interpreter=$(patchelf --print-interpreter "$2/toolbox"); then if ! interpreter=$(patchelf --print-interpreter "$2/toolbox"); then
echo "go-build-wrapper: failed to read PT_INTERP from $2/toolbox" >&2 echo "go-build-wrapper: failed to read PT_INTERP from $2/toolbox" >&2

View file

@ -27,6 +27,7 @@ custom_target(
meson.current_source_dir(), meson.current_source_dir(),
meson.current_build_dir(), meson.current_build_dir(),
meson.project_version(), meson.project_version(),
cc.cmd_array().get(-1),
], ],
input: sources, input: sources,
install: true, install: true,