rpm-build/scripts/pkgconfig.req.in
2007-08-29 02:19:10 +04:00

112 lines
3.5 KiB
Bash
Executable File

#!/bin/sh -efu
#
# Copyright (C) 2006 Dmitry V. Levin <ldv@altlinux.org>
# 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.
#
# 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.
#
. @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
PkgconfigReq()
{
local f="$1" out=; shift
out=$(pkg-config --print-errors --print-requires "$f") ||
Fatal "failed to process $f"
[ -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
}
PkgconfigProv()
{
local f="$1" out=; shift
out=$(pkg-config --print-errors --print-provides "$f") ||
Fatal "failed to process $f"
[ -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
}
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.
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
}
case "${0##*/}" in
pkgconfig.req*) ArgvFileAction PkgconfigReq "$@" ;;
pkgconfig.prov*) ArgvFileAction PkgconfigProv "$@" ;;
pkgconfiglib.req*) ArgvFileAction PkgconfigLibReq "$@" ;;
*) Fatal "req/prov method not recognized" ;;
esac