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