Merge "allow rpm to custom systemd installation" into tizen
[platform/upstream/rpm.git] / scripts / ocaml-find-provides.sh
1 #!/bin/sh -
2 # OCaml-specific "find-provides" for RPM.
3 # By Richard W.M. Jones <rjones@redhat.com>
4 # $Id: ocaml-find-provides.sh,v 1.2 2007/09/06 11:49:59 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 i:f: -n ocaml-find-provides.sh -- "$@"`
17 if [ $? != 0 ]; then echo "ocaml-find-provides.sh: failed" >&2; exit 1; fi
18 eval set -- "$TEMP"
19
20 ignore_modules=nOTREAL
21
22 while true; do
23     case "$1" in
24         -i) ignore_modules="$2 $ignore_modules"; shift 2;;
25         -f) OCAMLOBJINFO="$2"; shift 2;;
26         --) shift; break;;
27         *) echo "ocaml-find-provides.sh: option error at $1"; exit 1;;
28     esac
29 done
30
31 # Get the list of files.
32 files=`sed "s/['\"]/\\\&/g"`
33
34 # Get list of .cmi, .cmo and .cma files.
35 files=`echo $files | tr '[:blank:]' '\n' | grep '\.cm[ioa]$'`
36
37 if [ -z "$files" ]; then exit 0; fi
38
39 # Get the list of modules exported by the files.
40 modules=`$OCAMLOBJINFO $files |
41           grep -E '(Unit|Module) name: ' |
42           awk '{print $3}'`
43
44 # Turn list of modules into a regexp that matches the module names.
45 modules_re=`echo $modules | sed 's/ /|/g'`
46 ignore_modules_re=`echo $ignore_modules | sed 's/ /|/g'`
47
48 # Get a list of the modules these file(s) provide.
49 $OCAMLOBJINFO $files |
50 grep -Eo '[0-9a-f]{32}[[:space:]]+[A-Za-z0-9_]+' |
51 grep -E '[0-9a-f]{32}[[:space:]]+'"($modules_re)\$" |
52 while read md5sum module; do
53     echo "ocaml($module) = $md5sum"
54 done |
55 grep -Ev "$ignore_modules_re" |
56 sort -u