File pkg-buildrequires-analyze of Package pkg-buildrequires

#! /bin/bash

# Check requires defined by pkgconfig .pc files.
#
# Copyright (C) 2005, 2007 Stanislav Brabec <sbrabec@suse.cz>, SuSE Linux
#
# 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.
#
# See http://www.gnu.org/copyleft/lesser.html
#
# 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.


# Set default PKG_CONFIG_PATH.
# Guess default path from existing directories.
# FIXME: This guess does not work in live system.
if test -d "$BUILD_ROOT/usr/lib64" ; then
    COMPLETE_PKG_CONFIG_PATH=/usr/lib64/pkgconfig
else
    COMPLETE_PKG_CONFIG_PATH=/usr/lib/pkgconfig
fi
if test -d "$BUILD_ROOT/usr/share/pkgconfig" ; then
    COMPLETE_PKG_CONFIG_PATH=$COMPLETE_PKG_CONFIG_PATH:/usr/share/pkgconfig
fi

# locate package file.
# locate_pc name_without_pc
function locate_pc {
    local DIR
    for DIR in $COMPLETE_PKG_CONFIG_PATH ; do
	if test -f $BUILD_ROOT$DIR/$1.pc ; then
	    LOCATED_PC=$DIR/$1.pc
	    return
	fi
    done
    return 1
}

# Check requirements of RPM package.
# check_rpm_requires rpm

declare -a RPMS
declare -a UNKNOWNS

IFS=$IFS":,"
PKGS=$(sed <pkg-buildrequires-wrap.log '/^--atleast-pkgconfig-version/d;s/--atleast-version [^ ][^ ]*//;s/--[^ ][^ ]*//g;s/ *[<>=][<>=]* [^ ]*//g' | tr ' ' '\n' | sort -u)
for REQ in $PKGS ; do
    if test "$REQ" ; then
	if locate_pc $REQ ; then
	    RPM=$(rpm --queryformat '%{NAME}\n' -qf $LOCATED_PC)
	    # NOTE: Here is a place for plugins or version dependent corrections.
	    RPMS[${#RPMS[@]}]=$RPM
	else
	    UNKNOWNS[${#UNKNOWNS[@]}]=$REQ.pc
	fi
    fi
done

RPMLIST=$( (IFS=$'\n' ; echo "${RPMS[*]}" ) | LC_ALL=C sort -u | tr '\n' ' ' | sed 's/ $//')
SUM=$(echo "$RPMLIST" | md5sum | sed 's/ .*$//')
if test ${#UNKNOWNS[@]} -gt 0 ; then
    UNKNOWNSUM=$(echo "${UNKNOWNS[*]}" | md5sum | sed 's/ .*$//')
    if test -n "$RPMLIST" ; then
	echo "#BEGIN pkg-buildrequires
# Created by pkg-buildrequires. Do not edit by hand.
BuildRequires:  $RPMLIST
%define pkg_buildrequires_checksum $SUM
%define pkg_buildrequires_unknown_checksum $UNKNOWNSUM
#END pkg-buildrequires" | tee pkg-buildrequires.log
    else
	echo "#BEGIN pkg-buildrequires
# Created by pkg-buildrequires. Do not edit by hand.
%define pkg_buildrequires_checksum $SUM
%define pkg_buildrequires_unknown_checksum $UNKNOWNSUM
#END pkg-buildrequires" | tee pkg-buildrequires.log
    fi
else
    if test -n "$RPMLIST" ; then
    echo "#BEGIN pkg-buildrequires
# Created by pkg-buildrequires. Do not edit by hand.
BuildRequires:  $RPMLIST
%define pkg_buildrequires_checksum $SUM
#END pkg-buildrequires" | tee pkg-buildrequires.log
    else
    echo "#BEGIN pkg-buildrequires
# Created by pkg-buildrequires. Do not edit by hand.
%define pkg_buildrequires_checksum $SUM
#END pkg-buildrequires" | tee pkg-buildrequires.log
    fi
fi

if test ${#UNKNOWNS[@]} -gt 0 ; then
    echo >&2 "WARNING: These pkg-config files were not located: ${UNKNOWNS[*]}"
fi

if test "$SUM" != "$PKG_BUILDREQUIRES_CHECKSUM" ; then
    echo >&2 "ERROR_PKG_BUILDREQUIRES_UPDATE_NEEDED
Your BuildRequires are outdated. Please call:
pkg-buildrequires-update [ $PWD or build_log_file ] [ spec_file ]
If you are using build root, you may have to install pkg-buildrequires-wrap
and prepend root path it to the path."
    exit 1
fi
if test "$SUM" != "$PKG_BUILDREQUIRES_CHECKSUM" ; then
    echo >&2 "ERROR_PKG_BUILDREQUIRES_UPDATE_NEEDED
Your BuildRequires may be outdated. Please call pkg-buildrequires-update $PWD [ spec_file ]
or update requirements manually.
Please see above and fix or confirm its correctness by calling:
pkg-buildrequires-update $PWD [ spec_file ]
If you are using build root, you may have to install pkg-buildrequires-wrap
and prepend root path it to the path."
    exit 1
fi
openSUSE Build Service is sponsored by