Remove dependency on xml-light, replace with libxml2
[virt-top.git] / ocaml-dep.sh.in
1 #!/bin/bash -
2 # (C) Copyright 2009-2020 Red Hat Inc.
3 # @configure_input@
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 # This is a smarter wrapper around ocamldep(1) which is used to create
20 # the .depend files which are present in each subdirectory that builds
21 # OCaml code.
22 #
23 # Usage:
24 #   .depend: *.mli *.ml
25 #       $(top_builddir)/ocaml-dep.sh $^
26 #   -include .depend
27
28 set -e
29
30 # List of directories that contain common OCaml libraries.  If it
31 # contains OCaml code that can be included from another directory,
32 # then it should go here.  Note that OCaml modules in these
33 # directories must have unique names (eg. not ‘Utils’) else
34 # dependencies don't get built right.
35 include_dirs="
36 "
37
38 # Output file is always created in the current directory.
39 output=.depend
40
41 subdir=$(realpath --relative-to=@abs_top_builddir@ .)
42 srcdir=$(realpath --relative-to=. @abs_top_srcdir@/${subdir})
43 srcdir_re=$(realpath --relative-to=. @abs_top_srcdir@/${subdir} | sed 's/\./[.]/g')
44 top_builddir=$(realpath --relative-to=. @abs_top_builddir@)
45
46 includes="-I @abs_top_srcdir@/$subdir -I @abs_top_builddir@/$subdir"
47 for i in $include_dirs; do
48     includes="$includes -I @abs_top_srcdir@/$i -I @abs_top_builddir@/$i"
49 done
50
51 rm -f $output $output-t
52
53 echo "# OCaml dependencies generated by $0" > $output-t
54 echo >> $output-t
55
56 # Rewrite paths
57 # 1. Normalize absolute srcdir to relative path
58 # 2. Object files (*.cm*, *.o), in srcdir: Rewrite to builddir
59 # 3. Generated _config.ml in srcdir: Rewrite to builddir
60 # 4. Other object files below abs_top_srcdir: rewrite to corresponding builddir
61 # 5. Eliminate "./" prefix
62 @OCAMLFIND@ ocamldep @OCAMLDEP_ALL@ @OCAMLDEP_ONE_LINE@ $includes "$@" \
63     | sed \
64           -e "s,@abs_top_srcdir@/${subdir},.,g" \
65           -e "s,\B${srcdir_re}/\\([^ ]*[.]\\)\\(cm[^ ]*\\|o\\),\\1\\2,g" \
66           -e "s,\B${srcdir_re}/\\([^ /]*_config[.]ml\\),\\1,g" \
67           -e "s,@abs_top_srcdir@/\\([^ ]*[.]\\)\\(cm[^ ]*\\|o\\),${top_builddir}/\\1\\2,g" \
68           -e 's,\(^\| \)./,\1,g' \
69     >> $output-t
70
71 chmod -w $output-t
72
73 mv $output-t $output