2 # OCaml-specific "find-requires" for RPM.
3 # By Richard W.M. Jones <rjones@redhat.com>
4 # $Id: ocaml-find-requires.sh,v 1.5 2009/10/04 22:34:51 rjones Exp $
9 # (1) If you don't want the module to depend on the exact compiler
10 # version then use ocaml-find-requires.sh -c, but this is not something
11 # you should do normally.
13 # (2) For any modules which you want to ignore, use '-i Modulename'.
15 OCAMLOBJINFO=ocamlobjinfo
16 TEMP=`getopt -o ci:f: -n ocaml-find-requires.sh -- "$@"`
17 if [ $? != 0 ]; then echo "ocaml-find-requires.sh: failed" >&2; exit 1; fi
20 emit_compiler_version=yes
21 ignore_modules=nOTREAL
25 -c) emit_compiler_version=; shift;;
26 -i) ignore_modules="$2 $ignore_modules"; shift 2;;
27 -f) OCAMLOBJINFO="$2"; shift 2;;
29 *) echo "ocaml-find-requires.sh: option error at $1"; exit 1;;
33 # Get the list of files.
34 files=`sed "s/['\"]/\\\&/g"`
36 # Use ordinary find-requires first.
37 # echo $files | tr '[:blank:]' '\n' | /usr/lib/rpm/find-requires
39 # Get list of .cmi, .cmo and .cma files.
40 files=`echo $files | tr '[:blank:]' '\n' | grep '\.cm[ioa]$'`
42 if [ -z "$files" ]; then exit 0; fi
44 # Get the list of modules exported by the file(s).
45 modules=`$OCAMLOBJINFO $files |
46 grep -E '(Unit|Module) name: ' |
49 # Turn list of modules into a regexp that matches the module names.
50 modules_re=`echo $modules | sed 's/ /|/g'`
51 ignore_modules_re=`echo $ignore_modules | sed 's/ /|/g'`
53 # Get a list of the modules these file(s) depend on.
54 $OCAMLOBJINFO $files |
55 grep -Eo '[0-9a-f]{32}[[:space:]]+[A-Za-z0-9_]+' |
56 grep -Ev '[0-9a-f]{32}[[:space:]]+'"($modules_re)\$" |
57 while read md5sum module; do
58 echo "ocaml($module) = $md5sum"
60 grep -Ev "$ignore_modules_re" |
61 grep -Ev "^ocaml\((Annot|Asttypes|Outcometree|Cmo_format|Parsetree)\) =" |
64 if [ -n "$emit_compiler_version" ]; then
65 # Every OCaml program depends on the version of the
66 # runtime which was used to compile it.
67 echo "ocaml(runtime) = `ocamlrun -version | awk '{print $NF}' | sed 's/\+.*//'`"