csomh / source-git / rpm

Forked from source-git/rpm 4 years ago
Clone
2ff057
#!/bin/sh -
2ff057
# OCaml-specific "find-requires" for RPM.
2ff057
# By Richard W.M. Jones <rjones@redhat.com>
2ff057
# $Id: ocaml-find-requires.sh,v 1.5 2009/10/04 22:34:51 rjones Exp $
2ff057
2ff057
#set -x
2ff057
2ff057
# Usage:
2ff057
#   (1) If you don't want the module to depend on the exact compiler
2ff057
#   version then use ocaml-find-requires.sh -c, but this is not something
2ff057
#   you should do normally.
2ff057
#
2ff057
#   (2) For any modules which you want to ignore, use '-i Modulename'.
2ff057
2ff057
OCAMLOBJINFO=ocamlobjinfo
2ff057
TEMP=`getopt -o ci:f: -n ocaml-find-requires.sh -- "$@"`
2ff057
if [ $? != 0 ]; then echo "ocaml-find-requires.sh: failed" >&2; exit 1; fi
2ff057
eval set -- "$TEMP"
2ff057
2ff057
emit_compiler_version=yes
2ff057
ignore_modules=nOTREAL
2ff057
2ff057
while true; do
2ff057
    case "$1" in
2ff057
	-c) emit_compiler_version=; shift;;
2ff057
	-i) ignore_modules="$2 $ignore_modules"; shift 2;;
2ff057
	-f) OCAMLOBJINFO="$2"; shift 2;;
2ff057
	--) shift; break;;
2ff057
	*) echo "ocaml-find-requires.sh: option error at $1"; exit 1;;
2ff057
    esac
2ff057
done
2ff057
2ff057
# Get the list of files.
2ff057
files=`sed "s/['\"]/\\\&/g"`
2ff057
2ff057
# Use ordinary find-requires first.
2ff057
# echo $files | tr '[:blank:]' '\n' | /usr/lib/rpm/find-requires
2ff057
2ff057
# Get list of .cmi, .cmo and .cma files.
2ff057
files=`echo $files | tr '[:blank:]' '\n' | grep '\.cm[ioa]$'`
2ff057
2ff057
if [ -z "$files" ]; then exit 0; fi
2ff057
2ff057
# Get the list of modules exported by the file(s).
2ff057
modules=`$OCAMLOBJINFO $files |
2ff057
          grep -E '(Unit|Module) name: ' |
2ff057
          awk '{print $3}'`
2ff057
2ff057
# Turn list of modules into a regexp that matches the module names.
2ff057
modules_re=`echo $modules | sed 's/ /|/g'`
2ff057
ignore_modules_re=`echo $ignore_modules | sed 's/ /|/g'`
2ff057
2ff057
# Get a list of the modules these file(s) depend on.
2ff057
$OCAMLOBJINFO $files |
2ff057
grep -Eo '[0-9a-f]{32}[[:space:]]+[A-Za-z0-9_]+' |
2ff057
grep -Ev '[0-9a-f]{32}[[:space:]]+'"($modules_re)\$" |
2ff057
while read md5sum module; do
2ff057
    echo "ocaml($module) = $md5sum"
2ff057
done |
2ff057
grep -Ev "$ignore_modules_re" |
2ff057
grep -Ev "^ocaml\((Annot|Asttypes|Outcometree|Cmo_format|Parsetree)\) =" |
2ff057
sort -u
2ff057
2ff057
if [ -n "$emit_compiler_version" ]; then
2ff057
    # Every OCaml program depends on the version of the
2ff057
    # runtime which was used to compile it.
2ff057
    echo "ocaml(runtime) = `ocamlrun -version | awk '{print $NF}' | sed 's/\+.*//'`"
2ff057
fi