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
2007-12-03 14:13:50 +03:00
. @RPMCONFIGDIR@/find-package
2007-10-13 21:08:29 +04: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
2007-10-13 22:16:16 +04:00
gcc= gcc_libdirs=
2007-10-13 21:08:29 +04:00
PkgconfigLibReq()
{
2007-10-16 13:17:39 +04:00
local f="$1"; shift
2007-10-13 22:16:16 +04:00
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.
2016-12-20 17:48:50 +03:00
gcc | gcc-[1-9]* | gcc[1-9]* )
2007-10-13 22:16:16 +04:00
Verbose "$f: $PROG disabled for gcc"
return 0 ;;
esac
2007-10-16 13:42:34 +04:00
local libs
2007-10-29 12:29:04 +03:00
libs=$(pkg-config --disable-recursion --print-errors --libs-only-l "$f") || Fatal "failed to process $f"
2007-10-16 13:42:34 +04:00
libs=$(echo '' $libs |sed -e 's/ -l/ /g' -e 's/^ //')
[ -n "$libs" ] || return 0
2007-10-29 14:50:18 +03:00
Debug "$f: libs=$libs"
2007-10-16 13:42:34 +04:00
local libdirs
2007-10-29 12:29:04 +03:00
libdirs=$(pkg-config --disable-recursion --print-errors --libs-only-L "$f") || Fatal "failed to process $f"
2007-10-16 13:42:34 +04:00
libdirs=$(echo '' $libdirs |sed -e 's/ -L/ /g' -e 's/^ //')
2007-10-29 14:50:18 +03:00
[ -z "$libdirs" ] || Debug "$f: libdirs=$libdirs"
2007-10-16 13:17:39 +04:00
2007-10-13 22:16:16 +04:00
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
2007-10-29 14:50:18 +03:00
Debug "gcc=$gcc"
2007-10-13 22:16:16 +04:00
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
2007-12-03 14:00:05 +03:00
readlink -ve "$dir"
2007-10-13 22:16:16 +04:00
done)
gcc_libdirs=$(printf '%s\n' "$gcc_libdirs" |cat -n |sort -u -k2 |sort -n |cut -f2-)
2007-12-03 14:00:05 +03:00
Debug "gcc_libdirs=$(echo $gcc_libdirs)"
2007-10-13 22:16:16 +04:00
fi
2008-03-17 22:23:33 +03:00
# FindPackage should use host-system package names.
local RPM_FINDPACKAGE_HOST_PKG_NAMES=1
2007-10-13 21:08:29 +04:00
local lib libdir
2007-10-16 13:17:39 +04:00
for lib in $libs; do
2007-10-16 14:47:34 +04:00
local rep
2007-10-13 21:08:29 +04:00
if [ -n "${RPM_BUILD_ROOT-}" ]; then
2007-10-16 13:17:39 +04:00
for libdir in $libdirs $gcc_libdirs; do
2007-10-16 14:47:34 +04:00
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.
2007-12-03 14:13:50 +03:00
# FindPackage will emit file-level dependency.
Verbose "$f: -l$lib -> \$RPM_BUILD_ROOT$rep"
FindPackage "$f" "$rep"
# Do next lib.
2007-10-13 21:08:29 +04:00
continue 2
done
fi
2007-10-16 13:17:39 +04:00
for libdir in $libdirs $gcc_libdirs; do
2007-10-16 14:47:34 +04:00
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.
2008-03-17 22:23:33 +03:00
Verbose "$f: -l$lib -> $rep ..."
FindPackage "$f" "$rep"
2007-10-13 21:08:29 +04:00
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 "$@"