Commit b91e3ac1 authored by Lorenz Hüdepohl's avatar Lorenz Hüdepohl
Browse files

Initial version

parents
.fortran_modules
Makefile
Makefile.in
aclocal.m4
autom4te.cache
compile
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
install-sh
libtool
ltmain.sh
m4/libtool.m4
m4/ltoptions.m4
m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4
missing
.deps
.dirstamp
*.def_mods
*.use_mods
*.o
*~
stamp-h1
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4
AM_CFLAGS = @AM_CFLAGS@
AM_LDFLAGS = @AM_LDFLAGS@
# programs
bin_PROGRAMS = foo test_bar test_baz
foo_SOURCES = src/foo.F90 src2/baz.F90 src/bar.F90
foo_CPPFLAGS = -DPROGRAM_foo
foo_FCFLAGS = $(FC_MODOUT)$(_f90_moddir)/foo $(FC_MODINC)$(_f90_moddir)/foo
test_bar_SOURCES = src/bar.F90
test_bar_CPPFLAGS = -DPROGRAM_test_bar
test_bar_FCFLAGS = $(FC_MODOUT)$(_f90_moddir)/test_bar $(FC_MODINC)$(_f90_moddir)/test_bar
test_baz_SOURCES = src2/baz.F90 src/bar.F90
test_baz_CPPFLAGS = -DPROGRAM_test_baz
test_baz_FCFLAGS = $(FC_MODOUT)$(_f90_moddir)/test_baz $(FC_MODINC)$(_f90_moddir)/test_baz
CLEANFILES=
@FORTRAN_MAKEFILE@
#!/bin/sh -e
mkdir -p m4/
test -n "$srcdir" || srcdir=`dirname "$0"`
test -n "$srcdir" || srcdir=.
autoreconf --force --install --verbose "$srcdir"
AC_INIT([fdep_test], [0.1])
AC_PREREQ([2.59])
AM_INIT_AUTOMAKE([foreign -Wall subdir-objects])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
AM_SILENT_RULES([yes])
# gnu-make fortran module dependencies
m4_include([fdep/fortran_dependencies.m4])
FDEP_F90_GNU_MAKE_DEPS
# necessary tools
AC_PROG_FC
AC_PROG_INSTALL
AM_PROG_CC_C_O
# fortran stuff
AC_FC_MODULE_FLAG
AC_FC_MODULE_OUTPUT_FLAG
AC_FC_FREEFORM
# libtool
LT_INIT
AC_SUBST([AM_CFLAGS])
AC_SUBST([AM_LDFLAGS])
AC_SUBST([FC_MODINC])
AC_SUBST([FC_MODOUT])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
AC_DEFUN([FDEP_F90_GNU_MAKE_DEPS],[
AC_MSG_CHECKING([for GNU make])
for a in "$MAKE" make gmake gnumake ; do
if test -z "$a" ; then continue ; fi ;
if ( sh -c "$a --version" 2> /dev/null | grep GNU 2>&1 > /dev/null ) ; then
_fdep_gnu_make_command=$a ;
break;
fi
done ;
AC_MSG_RESULT([$_fdep_gnu_make_command])
if test x$_fdep_gnu_make_command = x ; then
AC_MSG_ERROR([Need GNU Make])
fi
AC_SUBST([FORTRAN_MAKEFILE], ["include ${srcdir}/fdep/fortran_dependencies.mk"])
AM_SUBST_NOTMAKE([FORTRAN_MAKEFILE])
])
_f90_verbose = $(_f90_verbose_$(V))
_f90_verbose_ = $(_f90_verbose_$(AM_DEFAULT_VERBOSITY))
_f90_verbose_0 = @echo " $1";
# $1 program
define is_per_target
$(if $(filter $(patsubst %.F90,%.o,$(firstword $($1_SOURCES))),$($1_OBJECTS)),,1)
endef
# $1 source_file
# $2 stem
# $3 program
define module_targets
$(eval _$(3)_use_mods += $(dir $1)$(2)$(patsubst %.F90,%,$(notdir $1)).use_mods)
$(dir $1)$(2)$(patsubst %.F90,%,$(notdir $1)).use_mods: $1 $(dir $1)$(am__dirstamp)
$(call _f90_verbose,F90 USE [$3] $$<)$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $($p_CPPFLAGS) $(CPPFLAGS) -o /dev/stdout $$< | grep -i -o '^ *use [^ ,!:]*' | sort -u > $$@
$(eval _$(3)_def_mods += $(dir $1)$(2)$(patsubst %.F90,%,$(notdir $1)).def_mods)
$(dir $1)$(2)$(patsubst %.F90,%,$(notdir $1)).def_mods: $1 $(dir $1)$(am__dirstamp)
$(call _f90_verbose,F90 MOD [$3] $$<)$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $($p_CPPFLAGS) $(CPPFLAGS) -o /dev/stdout $$< | grep -i -o '^ *module [^!]*' > $$@ || true
endef
$(foreach p,$(bin_PROGRAMS),$(if $(call is_per_target,$p),$(foreach s,$($p_SOURCES),$(eval $(call module_targets,$s,$p-,$p))),$(foreach s,$($p_SOURCES),$(eval $(call module_targets,$s,,$p)))))
_f90_moddir=$(abs_builddir)/.fortran_modules
_f90_depfile = $(_f90_moddir)/dependencies.mk
define is_clean
$(if $(filter-out mostlyclean clean distclean maintainer-clean,$(MAKECMDGOALS)),0,1)
endef
ifneq ($(call is_clean),1)
include $(_f90_depfile)
endif
$(_f90_depfile): $(top_srcdir)/fdep/fortran_dependencies.pl $(foreach p,$(bin_PROGRAMS),$(_$p_use_mods) $(_$p_def_mods)) | $(foreach p,$(bin_PROGRAMS),$(_f90_moddir)/$p)
$(call _f90_verbose,F90 DEPS $@)echo > $@; $(foreach p,$(bin_PROGRAMS),$(top_srcdir)/fdep/fortran_dependencies.pl $(_$p_use_mods) $(_$p_def_mods) >> $@; )
$(_f90_moddir):
@mkdir $@
$(foreach p,$(bin_PROGRAMS),$(_f90_moddir)/$p): | $(_f90_moddir)
@mkdir $@
CLEANFILES += $(foreach p,$(bin_PROGRAMS),$(_$p_def_mods) $(_$p_use_mods))
CLEANFILES += $(foreach p,$(bin_PROGRAMS),$(_f90_moddir)/$p/*)
CLEANFILES += $(_f90_depfile)
#!/usr/bin/perl -w
use strict;
my %defs = ();
my %uses = ();
my $use_re = qr/^\s*use\s+(\S+)\s*$/;
my $def_re = qr/^\s*module\s+(\S+)\s*$/;
sub add_use {
my ($file, $module) = @_;
if (defined($defs{$module}) && $defs{$module} eq $file) {
# do not add self-dependencies
return;
}
if (!defined($uses{$file})) {
$uses{$file} = { $module => 1 };
} else {
$uses{$file}{$module} = 1;
}
}
sub add_def {
my ($file, $module) = @_;
if (!defined($defs{$module})) {
$defs{$module} = $file;
if (defined($uses{$file}) && defined($uses{$file}{$module})) {
delete $uses{$file}{$module};
}
} else {
die "Module $module both defined in $file, $defs{$module}";
}
}
foreach my $file (@ARGV) {
my $re;
my $add;
my $object;
if ($file =~ /(.*).def_mods$/) {
$re = $def_re;
$add = \&add_def;
$object = $1 . ".o";
} elsif ($file =~ /^(.*).use_mods$/) {
$re = $use_re;
$add = \&add_use;
$object = $1 . ".o";
} else {
die "Unrecognized file extension for '$file'";
}
open(FILE,"<",$file) || die "\nCan't open $file: $!\n\n";
while(<FILE>) {
chomp;
$_ = lc($_);
if ($_ =~ $re) {
&$add($object, $1);
} else {
die "Cannot parse module statement '$_', was expecting $re";
}
}
close(FILE)
}
foreach my $object (sort keys %uses) {
print "$object: ", join(" ", sort (map {$defs{$_}} keys $uses{$object})), "\n";
}
module bar
implicit none
contains
function two() result(t)
integer :: t
t = 2
end function
end module
#ifdef PROGRAM_test_bar
program test_bar
use bar, only : two
if (two() /= 2) then
stop 1
endif
end program
#endif
program foo
use bar
use baz
write(*,*) "Nop"
end program
module baz
use bar
implicit none
contains
function two_times_two() result(t)
integer :: t
t = 2 * two()
end function
end module
#ifdef PROGRAM_test_baz
program test_bar
use baz
if (two_times_two() /= 4) then
stop 1
endif
end program
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment