#!/bin/sh
#---------------------------------------------------------------
# Project         : Linux-Mandrake
# Module          : rpm-rebuilder
# File            : compute-build-requires
# Version         : $Id: compute-build-requires,v 1.3 2000/10/01 19:47:24 flepied Exp $
# Author          : Frederic Lepied
# Created On      : Sat Sep 30 14:44:03 2000
#---------------------------------------------------------------

set -e

if [ -z "$*" ]; then
    echo "usage: `basename $0` <rpm build command>"
    exit 1
fi

# load global config file
RB_GLOBAL_CONFIG=${RB_GLOBAL_CONFIG=/etc/rpm-rebuilder.conf}
if [ -r "$RB_GLOBAL_CONFIG" ]; then
    . $RB_GLOBAL_CONFIG
fi

# load user config file
RB_USER_CONFIG=${RB_USER_CONFIG=$HOME/.rpm-rebuilder}
if [ -r "$RB_USER_CONFIG" ]; then
    . $RB_USER_CONFIG
fi

## Variables
RPM_REBUILDER_LIB=${RPM_REBUILDER_LIB=/usr/share/rpm-rebuilder}

TMPDIR=.$$

mkdir -p $TMPDIR

strace -f -q -o $TMPDIR/strace.out -e trace=file $@

echo "Processing strace output" 1>&2

sed -n 's/^.*("\(\/[^"]*\)".*$/\1/gp' < $TMPDIR/strace.out | sort | uniq > $TMPDIR/files.sorted

echo "BuildRequires:" 1>&2

$RPM_REBUILDER_LIB/files-to-requires.py < $TMPDIR/files.sorted

rm -rf $TMPDIR

# compute-build-requires ends here
