Browse code

Handle case where modules are different per target

Previously, the list of modules used or defined by a source file was
assumed to be the same regardless for which target the file was used
(except for library/non-library compilation). Now, every target has its
own list of defined and required modules per source file

Lorenz Hüdepohl authored on16/12/2015 15:23:32
Showing2 changed files
... ...
@@ -47,17 +47,27 @@ define object_extension
47 47
 $(if $(filter $1,$(PROGRAMS)),o,lo)
48 48
 endef
49 49
 
50
+# $1 source file
51
+# $2 stem
52
+# $3 program
53
+# $4 kind of file ('use' or 'def')
54
+define modinfo_name
55
+$(dir $1)$(2)$(call strip_fortran_ext,$(notdir $1)).$4_mods_$(patsubst .,_,$3).$(call object_extension,$3)
56
+endef
57
+
50 58
 # $1 source_file
51 59
 # $2 stem
52 60
 # $3 program
53 61
 define module_targets
54
-$(eval _$(3)_use_mods += $(dir $1)$(2)$(call strip_fortran_ext,$(notdir $1)).use_mods.$(call object_extension,$3))
55
-$(dir $1)$(2)$(call strip_fortran_ext,$(notdir $1)).use_mods.$(call object_extension,$3): $1 $(dir $1)$(am__dirstamp)
56
-	$(call _f90_verbose,F90 USE  [$3] $$<)$(FORTRAN_CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $($p_CPPFLAGS) $(CPPFLAGS) -o /dev/stdout $$< | grep -i -o '^ *use [^ ,!:]*' | tr '[:upper:]' '[:lower:]' | sort -u > $$@
57
-
58
-$(eval _$(3)_def_mods += $(dir $1)$(2)$(call strip_fortran_ext,$(notdir $1)).def_mods.$(call object_extension,$3))
59
-$(dir $1)$(2)$(call strip_fortran_ext,$(notdir $1)).def_mods.$(call object_extension,$3): $1 $(dir $1)$(am__dirstamp)
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
62
+$(eval _$(3)_use_mods += $(call modinfo_name,$1,$2,$3,use))
63
+$(call modinfo_name,$1,$2,$3,use): $1 $(dir $1)$(am__dirstamp)
64
+	$(call _f90_verbose,F90 USE  [$3] $$<)$(FORTRAN_CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $($p_CPPFLAGS) $(CPPFLAGS) -o /dev/stdout $$< | \
65
+		grep -i -o '^ *use [^ ,!:]*' | sed 's/^[[:space:]]*//;' | tr '[:upper:]' '[:lower:]' | sort -u > $$@
66
+
67
+$(eval _$(3)_def_mods += $(call modinfo_name,$1,$2,$3,def))
68
+$(call modinfo_name,$1,$2,$3,def): $1 $(dir $1)$(am__dirstamp)
69
+	$(call _f90_verbose,F90 MOD  [$3] $$<)$(FORTRAN_CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $($p_CPPFLAGS) $(CPPFLAGS) -o /dev/stdout $$< | \
70
+		grep -i -o '^ *module [^!]*' | sed 's/^[[:space:]]*//;' | tr '[:upper:]' '[:lower:]' | grep -v "\<procedure\>\|\<intrinsic\>" > $$@ || true
61 71
 
62 72
 endef
63 73
 $(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)))))
... ...
@@ -54,11 +54,11 @@ foreach my $file (@ARGV) {
54 54
 	if (defined($ENV{V}) && $ENV{V} ge "2") {
55 55
 		print STDERR "fdep: Considering file $file for target $target\n";
56 56
 	}
57
-	if ($file =~ /^(.*)\.def_mods(\..*)$/) {
57
+	if ($file =~ /^(.*)\.def_mods_[^.]*(\..*)$/) {
58 58
 		$re = $def_re;
59 59
 		$add = \&add_def;
60 60
 		$object = $1 . $2;
61
-	} elsif ($file =~ /^(.*)\.use_mods(\..*)$/) {
61
+	} elsif ($file =~ /^(.*)\.use_mods_[^.]*(\..*)$/) {
62 62
 		$re = $use_re;
63 63
 		$add = \&add_use;
64 64
 		$object = $1 . $2;