23ad026
#!/bin/sh -
23ad026
# OCaml-specific "find-provides" for RPM.
23ad026
# By Richard W.M. Jones <rjones@redhat.com>
23ad026
# $Id: ocaml-find-provides.sh,v 1.7 2007/06/11 15:03:17 rjones Exp $
23ad026
23ad026
#set -x
23ad026
23ad026
# Usage:
23ad026
#   (1) Add the following to the spec file:
23ad026
#   %define _use_internal_dependency_generator 0
23ad026
#   %define __find_requires /usr/lib/rpm/ocaml-find-requires.sh
23ad026
#   %define __find_provides /usr/lib/rpm/ocaml-find-provides.sh
23ad026
#
23ad026
#   (2) If you don't want the module to depend on the exact compiler
23ad026
#   version then use ocaml-find-requires.sh -c, but this is not something
23ad026
#   you should do normally.
23ad026
#
23ad026
#   (3) For any modules which you want to ignore, use '-i Modulename'.
23ad026
23ad026
OCAMLOBJINFO=ocamlobjinfo
23ad026
TEMP=`getopt -o i:f: -n ocaml-find-provides.sh -- "$@"`
23ad026
if [ $? != 0 ]; then echo "ocaml-find-provides.sh: failed" >&2; exit 1; fi
23ad026
eval set -- "$TEMP"
23ad026
23ad026
ignore_modules=nOTREAL
23ad026
23ad026
while true; do
23ad026
    case "$1" in
23ad026
	-i) ignore_modules="$2 $ignore_modules"; shift 2;;
23ad026
	-f) OCAMLOBJINFO="$2"; shift 2;;
23ad026
	--) shift; break;;
23ad026
	*) echo "ocaml-find-provides.sh: option error at $1"; exit 1;;
23ad026
    esac
23ad026
done
23ad026
23ad026
# Get the list of files.
23ad026
files=`sed "s/['\"]/\\\&/g"`
23ad026
23ad026
# Use ordinary find-provides first.
23ad026
echo $files | tr [:blank:] '\n' | /usr/lib/rpm/find-provides
23ad026
23ad026
# Get list of .cmi, .cmo and .cma files.
23ad026
files=`echo $files | tr [:blank:] '\n' | grep '\.cm[ioa]$'`
23ad026
23ad026
if [ -z "$files" ]; then exit 0; fi
23ad026
23ad026
# Get the list of modules exported by the files.
23ad026
modules=`$OCAMLOBJINFO $files |
23ad026
          grep -E '(Unit|Module) name: ' |
23ad026
          awk '{print $3}'`
23ad026
23ad026
# Turn list of modules into a regexp that matches the module names.
23ad026
modules_re=`echo $modules | sed 's/ /|/g'`
23ad026
ignore_modules_re=`echo $ignore_modules | sed 's/ /|/g'`
23ad026
23ad026
# Get a list of the modules these file(s) provide.
23ad026
$OCAMLOBJINFO $files |
23ad026
grep -Eo '[0-9a-f]{32}[[:space:]]+[A-Za-z0-9_]+' |
23ad026
grep -E "$modules_re" |
23ad026
while read md5sum module; do
23ad026
    echo "ocaml($module) = $md5sum"
23ad026
done |
23ad026
grep -Ev "$ignore_modules_re" |
23ad026
sort -u