Modify eu-strip option to perform strip in post script of rpm package & add option...
[platform/upstream/rpm.git] / scripts / ocaml-find-requires.sh
1 #!/bin/sh -
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 $
5
6 #set -x
7
8 # Usage:
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.
12 #
13 #   (2) For any modules which you want to ignore, use '-i Modulename'.
14
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
18 eval set -- "$TEMP"
19
20 emit_compiler_version=yes
21 ignore_modules=nOTREAL
22
23 while true; do
24     case "$1" in
25         -c) emit_compiler_version=; shift;;
26         -i) ignore_modules="$2 $ignore_modules"; shift 2;;
27         -f) OCAMLOBJINFO="$2"; shift 2;;
28         --) shift; break;;
29         *) echo "ocaml-find-requires.sh: option error at $1"; exit 1;;
30     esac
31 done
32
33 # Get the list of files.
34 files=`sed "s/['\"]/\\\&/g"`
35
36 # Use ordinary find-requires first.
37 # echo $files | tr '[:blank:]' '\n' | /usr/lib/rpm/find-requires
38
39 # Get list of .cmi, .cmo and .cma files.
40 files=`echo $files | tr '[:blank:]' '\n' | grep '\.cm[ioa]$'`
41
42 if [ -z "$files" ]; then exit 0; fi
43
44 # Get the list of modules exported by the file(s).
45 modules=`$OCAMLOBJINFO $files |
46           grep -E '(Unit|Module) name: ' |
47           awk '{print $3}'`
48
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'`
52
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"
59 done |
60 grep -Ev "$ignore_modules_re" |
61 grep -Ev "^ocaml\((Annot|Asttypes|Outcometree|Cmo_format|Parsetree)\) =" |
62 sort -u
63
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/\+.*//'`"
68 fi