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.
48 # Output file is always created in the current directory.
51 subdir=$(realpath --relative-to=@abs_top_builddir@ .)
52 srcdir=$(realpath --relative-to=. @abs_top_srcdir@/${subdir})
53 srcdir_re=$(realpath --relative-to=. @abs_top_srcdir@/${subdir} | sed 's/\./[.]/g')
54 top_builddir=$(realpath --relative-to=. @abs_top_builddir@)
56 includes="-I @abs_top_srcdir@/$subdir -I @abs_top_builddir@/$subdir"
57 for i in $include_dirs; do
58 includes="$includes -I @abs_top_srcdir@/$i -I @abs_top_builddir@/$i"
61 rm -f $output $output-t
63 echo "# OCaml dependencies generated by $0" > $output-t
67 # 1. Normalize absolute srcdir to relative path
68 # 2. Object files (*.cm*, *.o), in srcdir: Rewrite to builddir
69 # 3. Generated _config.ml in srcdir: Rewrite to builddir
70 # 4. Other object files below abs_top_srcdir: rewrite to corresponding builddir
71 # 5. Eliminate "./" prefix
72 @OCAMLFIND@ ocamldep @OCAMLDEP_ALL@ @OCAMLDEP_ONE_LINE@ $includes "$@" \
74 -e "s,@abs_top_srcdir@/${subdir},.,g" \
75 -e "s,\B${srcdir_re}/\\([^ ]*[.]\\)\\(cm[^ ]*\\|o\\),\\1\\2,g" \
76 -e "s,\B${srcdir_re}/\\([^ /]*_config[.]ml\\),\\1,g" \
77 -e "s,@abs_top_srcdir@/\\([^ ]*[.]\\)\\(cm[^ ]*\\|o\\),${top_builddir}/\\1\\2,g" \
78 -e 's,\(^\| \)./,\1,g' \