rpm-build/scripts/pkgconfiglib.req.in
2007-10-13 21:08:29 +04:00

66 lines
2.2 KiB
Bash
Executable File

#!/bin/sh -efu
#
# Copyright (C) 2007 Alexey Tourbin <at@altlinux.org>
#
# This program 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 2 of the License, or
# (at your option) any later version.
. @RPMCONFIGDIR@/functions
[ -n "${RPM_LIBDIR-}" ] || RPM_LIBDIR=`rpm --eval %_libdir`
PKG_CONFIG_PATH=$RPM_LIBDIR/pkgconfig:/usr/share/pkgconfig
[ -z "${RPM_BUILD_ROOT-}" ] ||
PKG_CONFIG_PATH=$RPM_BUILD_ROOT$RPM_LIBDIR/pkgconfig:$RPM_BUILD_ROOT/usr/share/pkgconfig:$PKG_CONFIG_PATH
export PKG_CONFIG_PATH
PkgconfigLibReq()
{
local f="$1" l L; shift
l=$(pkg-config --print-errors --libs-only-l "$f") || Fatal "failed to process $f"
L=$(pkg-config --print-errors --libs-only-L "$f") || Fatal "failed to process $f"
l=$(echo '' $l |sed -e 's/ -l/ /g')
L=$(echo '' $L |sed -e 's/ -L/ /g')
local lib libdir
for lib in $l; do
lib=lib$lib.so
if [ -n "${RPM_BUILD_ROOT-}" ]; then
for libdir in $L "$RPM_LIBDIR"; do
[ -f "$RPM_BUILD_ROOT$libdir/$lib" ] ||
# ... allow absolute symbolic links:
[ -L "$RPM_BUILD_ROOT$libdir/$lib" ] || continue
# The library is under RPM_BUILD_ROOT.
# Nothing is required. Do next lib.
Verbose "$f: $lib -> \$RPM_BUILD_ROOT$libdir/$lib (skip)"
continue 2
done
fi
for libdir in $L "$RPM_LIBDIR"; do
[ -f "$libdir/$lib" ] || continue
# The library is found in the host system.
# Generate rpm dependency and do next lib.
libdir=$(CanonPath "$libdir")
local pkg n
pkg=$(rpmquery --whatprovides --queryformat='%{NAME}\n' "$libdir/$lib" |sort -u)
n=$(set -- $pkg; echo $#)
if [ "$pkg" = glibc-devel ]; then
Verbose "$f: $lib -> $pkg (skip)"
elif [ $n -eq 1 ]; then
Verbose "$f: $lib -> $pkg"
printf '%s\n' "$pkg"
elif [ $n -gt 1 ]; then
Info "$f: $libdir/$lib provided by:$(echo '' $pkg)"
Info "$f: $lib -> $libdir/$lib (raw, ambiguous)"
printf '%s\n' "$libdir/$lib"
else
Info "$f: cannot map $libdir/$lib to rpm dependency (skip)"
fi
continue 2
done
Info "$f: cannot find $lib library path (skip)"
done
}
ArgvFileAction PkgconfigLibReq "$@"