#!/bin/sh -
# OCaml-specific "find-provides" for RPM.
# By Richard W.M. Jones <rjones@redhat.com>

#set -x

while read file; do
    # Get the list of modules exported by the file.
    modules=`ocamlobjinfo $file |
    grep 'Unit name: ' |
    awk '{print $3}'`

    # Turn list of modules into a regexp that matches the module names.
    modules_re=`echo $modules | sed 's/ /|/g'`

    # Get a list of the modules this file provides.
    ocamlobjinfo $file |
    grep -Eo '[0-9a-f]{32}[[:space:]]+[A-Za-z0-9_]+' |
    grep -E $modules_re |
    while read md5sum module; do
	echo ocaml-$module-$md5sum
    done
done |
sort -u