Browse code

Recursively include dependencies via LDADD/LIBADD

Now, also module provided via automake _LDADD/_LIBADD statements are
considered and added as dependencies, if used by the target.

Lorenz Hüdepohl authored on01/06/2015 12:01:22
Showing2 changed files
... ...
@@ -4,10 +4,14 @@
4 4
 # see the file LICENSE for more information
5 5
 #
6 6
 
7
+define translate_name
8
+$(subst -,_,$(subst .,_,$1))
9
+endef
10
+
7 11
 _f90_verbose = $(_f90_verbose_$(V))
8 12
 _f90_verbose_ = $(_f90_verbose_$(AM_DEFAULT_VERBOSITY))
9 13
 _f90_verbose_0 = @echo "  $1";
10
-_f90_targets = $(subst -,_,$(subst .,_,$(PROGRAMS) $(LTLIBRARIES)))
14
+_f90_targets = $(call translate_name,$(PROGRAMS) $(LTLIBRARIES))
11 15
 
12 16
 FORTRAN_CPP ?= cpp -P -traditional -Wall -Werror
13 17
 
... ...
@@ -53,7 +57,7 @@ $(dir $1)$(2)$(call strip_fortran_ext,$(notdir $1)).use_mods.$(call object_exten
53 57
 
54 58
 $(eval _$(3)_def_mods += $(dir $1)$(2)$(call strip_fortran_ext,$(notdir $1)).def_mods.$(call object_extension,$3))
55 59
 $(dir $1)$(2)$(call strip_fortran_ext,$(notdir $1)).def_mods.$(call object_extension,$3): $1 $(dir $1)$(am__dirstamp)
56
-	$(call _f90_verbose,F90 MOD  [$3] $$<)$(FORTRAN_CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $($p_CPPFLAGS) $(CPPFLAGS) -o /dev/stdout $$< | grep -i -o '^ *module [^!]*' | tr '[:upper:]' '[:lower:]' | grep -v "\<procedure\>" > $$@ || true
60
+	$(call _f90_verbose,F90 MOD  [$3] $$<)$(FORTRAN_CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $($p_CPPFLAGS) $(CPPFLAGS) -o /dev/stdout $$< | grep -i -o '^ *module [^!]*' | tr '[:upper:]' '[:lower:]' | grep -v "\<procedure\>\|\<intrinsic\>" > $$@ || true
57 61
 
58 62
 endef
59 63
 $(foreach p,$(_f90_targets),$(if $(call is_per_target,$p),$(foreach s,$(call fortran_sources,$p),$(eval $(call module_targets,$s,$p-,$p))),$(foreach s,$(call fortran_sources,$p),$(eval $(call module_targets,$s,,$p)))))
... ...
@@ -61,6 +65,11 @@ $(foreach p,$(_f90_targets),$(if $(call is_per_target,$p),$(foreach s,$(call for
61 65
 _f90_depdir=$(abs_builddir)/.fortran_dependencies
62 66
 _f90_depfile = $(_f90_depdir)/dependencies.mk
63 67
 
68
+# $1 target-name
69
+define recursive_lib_deps
70
+$(foreach l,$(call translate_name,$($1_LDADD) $($1_LIBADD)),$l $(call recursive_lib_deps,$l))
71
+endef
72
+
64 73
 define is_clean
65 74
 $(if $(filter-out mostlyclean clean distclean maintainer-clean,$(MAKECMDGOALS)),0,1)
66 75
 endef
... ...
@@ -69,7 +78,7 @@ ifneq ($(call is_clean),1)
69 78
 include $(_f90_depfile)
70 79
 endif
71 80
 $(_f90_depfile): $(top_srcdir)/fdep/fortran_dependencies.pl $(foreach p,$(_f90_targets),$(_$p_use_mods) $(_$p_def_mods)) | $(foreach p,$(_f90_targets),$(_f90_depdir)/$p)
72
-	$(call _f90_verbose,F90 DEPS $@)echo > $@; $(foreach p,$(_f90_targets),$(top_srcdir)/fdep/fortran_dependencies.pl $p $(_$p_use_mods) $(_$p_def_mods) >> $@; )
81
+	$(call _f90_verbose,F90 DEPS $@)echo > $@; $(foreach p,$(_f90_targets),$(top_srcdir)/fdep/fortran_dependencies.pl $p $(_$p_use_mods) $(_$p_def_mods) $(foreach l,$(call recursive_lib_deps,$p),$(_$l_use_mods) $(_$l_def_mods)) >> $@; )
73 82
 
74 83
 $(_f90_depdir):
75 84
 	@mkdir $@
... ...
@@ -10,6 +10,7 @@ use strict;
10 10
 
11 11
 my %defs = ();
12 12
 my %uses = ();
13
+my %files = ();
13 14
 
14 15
 my $use_re = qr/^\s*use\s+(\S+)\s*$/;
15 16
 my $def_re = qr/^\s*module\s+(\S+)\s*$/;
... ...
@@ -42,6 +43,11 @@ sub add_def {
42 43
 my $target = shift;
43 44
 
44 45
 foreach my $file (@ARGV) {
46
+	if (exists $files{$file}) {
47
+		next;
48
+	} else {
49
+		$files{$file} = 1;
50
+	}
45 51
 	my $re;
46 52
 	my $add;
47 53
 	my $object;