rpm-build/scripts/pkgconfiglib.req.in

115 lines
3.6 KiB
Plaintext
Raw Normal View History

2007-10-13 21:08:29 +04:00
#!/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
gcc= gcc_libdirs=
2007-10-13 21:08:29 +04:00
PkgconfigLibReq()
{
local f="$1"; shift
local srpm="${RPM_PACKAGE_NAME-}"
[ -n "$srpm" ] || srpm=$(rpmquery --qf='%{SOURCERPM}' -f "$f" 2>/dev/null) || srpm=foo
case "$srpm" in
# Below we use "gcc -print-search-dirs" to determine library
# search path. If we build gcc itself, then e.g. libgcj.pc
# (with -lgcj inside) cannot be processed reliably.
gcc | gcc-* | gcc[1-9]* | *-gcc | *-gcc-* | *-gcc[1-9]* )
Verbose "$f: $PROG disabled for gcc"
return 0 ;;
esac
local libs
libs=$(pkg-config --disable-recursion --print-errors --libs-only-l "$f") || Fatal "failed to process $f"
libs=$(echo '' $libs |sed -e 's/ -l/ /g' -e 's/^ //')
[ -n "$libs" ] || return 0
Debug "$f: libs=$libs"
local libdirs
libdirs=$(pkg-config --disable-recursion --print-errors --libs-only-L "$f") || Fatal "failed to process $f"
libdirs=$(echo '' $libdirs |sed -e 's/ -L/ /g' -e 's/^ //')
[ -z "$libdirs" ] || Debug "$f: libdirs=$libdirs"
if [ -z "$gcc" ]; then
gcc=/usr/bin/${RPM_ARCH:-noarch}-alt-linux-gcc
[ -x "$gcc" ] || gcc=/usr/bin/gcc
[ -z "${GCC_VERSION-}" ] || gcc=$gcc-$GCC_VERSION
Debug "gcc=$gcc"
gcc_libdirs=$("$gcc" -print-search-dirs |sed -n 's/^libraries: =//p')
[ -n "$gcc_libdirs" ] || Fatal "$gcc -print-search-dirs failed"
gcc_libdirs=$(IFS="$IFS:"
for dir in $gcc_libdirs; do
[ -d "$dir" ] || continue
readlink -ve "$dir"
done)
gcc_libdirs=$(printf '%s\n' "$gcc_libdirs" |cat -n |sort -u -k2 |sort -n |cut -f2-)
Debug "gcc_libdirs=$(echo $gcc_libdirs)"
fi
2007-10-13 21:08:29 +04:00
local lib libdir
for lib in $libs; do
local rep
2007-10-13 21:08:29 +04:00
if [ -n "${RPM_BUILD_ROOT-}" ]; then
for libdir in $libdirs $gcc_libdirs; do
rep=$libdir/lib$lib
# Allow absolute symbolic links.
if [ -f "$RPM_BUILD_ROOT$rep.so" -o -L "$RPM_BUILD_ROOT$rep.so" ]; then
rep=$rep.so
elif [ -f "$RPM_BUILD_ROOT$rep.a" -o -L "$RPM_BUILD_ROOT$rep.a" ]; then
rep=$rep.a
else
continue
fi
2007-10-13 21:08:29 +04:00
# The library is under RPM_BUILD_ROOT.
# Nothing is required. Do next lib.
Verbose "$f: -l$lib -> \$RPM_BUILD_ROOT$rep (skip)"
2007-10-13 21:08:29 +04:00
continue 2
done
fi
for libdir in $libdirs $gcc_libdirs; do
rep=$libdir/lib$lib
if [ -f "$rep.so" ]; then
rep=$rep.so
elif [ -f "$rep.a" ]; then
rep=$rep.a
else
continue
fi
2007-10-13 21:08:29 +04:00
# The library is found in the host system.
# Generate rpm dependency and do next lib.
rep=$(CanonPath "$rep")
2007-10-13 21:08:29 +04:00
local pkg n
pkg=$(rpmquery --whatprovides --queryformat='%{NAME}\n' "$rep" |sort -u)
2007-10-13 21:08:29 +04:00
n=$(set -- $pkg; echo $#)
if [ "$pkg" = glibc-devel ]; then
Verbose "$f: -l$lib -> $rep -> $pkg (skip)"
2007-10-13 21:08:29 +04:00
elif [ $n -eq 1 ]; then
Verbose "$f: -l$lib -> $rep -> $pkg"
2007-10-13 21:08:29 +04:00
printf '%s\n' "$pkg"
elif [ $n -gt 1 ]; then
Info "$f: $rep provided by:$(echo '' $pkg)"
Info "$f: -l$lib -> $rep (raw, ambiguous)"
printf '%s\n' "$rep"
2007-10-13 21:08:29 +04:00
else
2007-12-03 11:38:35 +03:00
Warning "$f: cannot map $rep to rpm dependency (skip)"
2007-10-13 21:08:29 +04:00
fi
continue 2
done
2007-12-03 11:38:35 +03:00
Warning "$f: cannot find -l$lib library path (skip)"
2007-10-13 21:08:29 +04:00
done
}
ArgvFileAction PkgconfigLibReq "$@"