#!/bin/sh
#---------------------------------------------------------------
# Project         : Linux-Mandrake
# Module          : rpm-rebuilder
# File            : compute-build-requires
# Version         : $Id: compute-build-requires,v 1.4 2001/07/06 05:00:46 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}

TMP=$PWD/.$$

mkdir -p $TMP

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

echo "Processing strace output" 1>&2

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

echo "BuildRequires:" 1>&2

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

rm -rf $TMP

# compute-build-requires ends here
