2007-03-06 22:47:27 +03:00
#!/bin/sh -efu
2006-02-02 04:51:38 +03:00
#
# Copyright (C) 2006 Dmitry V. Levin <ldv@altlinux.org>
2007-03-06 22:47:27 +03:00
# Copyright (C) 2007 Alexey Tourbin <at@altlinux.org>
2006-02-02 04:51:38 +03:00
#
# 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.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
2007-03-06 22:47:27 +03:00
. @RPMCONFIGDIR@/functions
2006-02-02 04:51:38 +03:00
2007-03-06 22:47:27 +03:00
[ -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
PkgconfigReq()
{
local f="$1" out=; shift
2007-08-28 18:52:13 +04:00
out=$(pkg-config --print-errors --print-requires "$f") ||
Fatal "failed to process $f"
2007-03-06 22:47:27 +03:00
[ -n "$out" ] || return 0
echo "$out" |while read -r line; do
set -- $line
case $# in
1) echo "pkgconfig($1)" ;;
3) echo "pkgconfig($1) $2 $3" ;;
*) Fatal "$f: invalid pkg-config output: $line"
esac
done
}
2007-08-28 18:05:30 +04:00
PkgconfigProv()
{
local f="$1" out=; shift
2007-08-28 18:52:13 +04:00
out=$(pkg-config --print-errors --print-provides "$f") ||
Fatal "failed to process $f"
2007-08-28 18:05:30 +04:00
[ -n "$out" ] || return 0
echo "$out" |while read -r line; do
set -- $line
case $# in
1) echo "pkgconfig($1)" ;;
3) echo "pkgconfig($1) $2 $3" ;;
*) Fatal "$f: invalid pkg-config output: $line"
esac
done
}
2007-08-28 20:10:35 +04:00
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" ] || 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.
2007-08-29 01:59:16 +04:00
libdir=$(CanonPath "$libdir")
2007-08-28 20:10:35 +04:00
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
2007-08-29 02:19:10 +04:00
Info "$f: cannot map $libdir/$lib to rpm dependency (skip)"
2007-08-28 20:10:35 +04:00
fi
continue 2
done
Info "$f: cannot find $lib library path (skip)"
done
}
2007-08-28 18:05:30 +04:00
case "${0##*/}" in
pkgconfig.req*) ArgvFileAction PkgconfigReq "$@" ;;
pkgconfig.prov*) ArgvFileAction PkgconfigProv "$@" ;;
2007-08-28 20:10:35 +04:00
pkgconfiglib.req*) ArgvFileAction PkgconfigLibReq "$@" ;;
2007-08-28 18:05:30 +04:00
*) Fatal "req/prov method not recognized" ;;
esac