2 # (C) Copyright 2009-2020 Red Hat Inc.
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.
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.
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.
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
25 # $(top_builddir)/ocaml-dep.sh $^
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.
38 # Output file is always created in the current directory.
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@)
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"
51 rm -f $output $output-t
53 echo "# OCaml dependencies generated by $0" > $output-t
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 "$@" \
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' \