Hello Steven, everyone, Steven suggested (quite) a while ago[1] to exploit AC_FC_SRCEXT in Automake in two ways: - add the computed flag to the compilation rule, - infer from the macro argument that files with this extensions should be compiled with $(FC) rather than $(F77).
I'm not yet sure about the desired semantics: 1) Should $(FCFLAGS_foo) be added to the compile command for Fortran sources ending with extension .foo - only if AC_FC_SRCEXT(foo) was given, or - in any case? (`foo' being a placeholder for some suitable extension) 2) Should `AC_FC_SRCEXT(f)' globally override Automake to use $(FC) for all files with extension .f, or should we have a thin wrapper AM_FC_SRCEXT that calls AC_FC_SRCEXT($@) _and_ overrides extension mapping (would be a bit more backwards-compatible probably)? Or even none of this overriding stuff? The incomplete patch below chooses the first answer for both questions. Based on feedback I can supply documentation and finish my tests. Notes/questions: - We add %SOURCEFLAG% to all compile commands in depend2, although strictly for FC it would suffice for a subset of rules. I think it is better to be consistent here. - The expansion of %SOURCEFLAG% contains a space, in order to not affect unrelated compile commands' spacing. - AC_FC_SRCEXT tracing is enabled in autoconf-2.60/lib/autom4te.in, needed for the change to scan_autoconf_traces. :-) - The depend2.am patch conflicts (trivially) with the pending patch in PR 501. - The patch contains only incomplete changes to automake.texi that need rewriting based on consensus for above. - I'd like to not claim full Fortran 9x support: even after this and following stuff, modules handling (install/clean) and dependency tracking will not be automatic yet. - Is it too dirty to use a global such as %sourceflags for Automake style? [1] http://lists.gnu.org/archive/html/automake/2005-06/msg00012.html Cheers, Ralf * lib/am/depend2.am (%SOURCEFLAG%): New substitution, goes right before the expanded source file name. * automake.in (%sourceflags): New global: per-extension flag to denote that the next compiler argument is the source file. (scan_autoconf_traces): Trace AC_FC_SRCEXT; initialize %sourceflags accordingly; override extension map to use FC. (handle_languages): pass flag in SOURCEFLAG. * doc/automake.texi (): ... Suggested by Steven G. Johnson <[EMAIL PROTECTED]>. Index: automake.in =================================================================== RCS file: /cvs/automake/automake/automake.in,v retrieving revision 1.1630 diff -u -r1.1630 automake.in --- automake.in 30 Aug 2006 18:50:38 -0000 1.1630 +++ automake.in 30 Aug 2006 19:28:29 -0000 @@ -415,6 +415,9 @@ # Maps each linker variable onto a language object. my %link_languages = (); +# maps extensions to needed source flags. +my %sourceflags = (); + # List of targets we must always output. # FIXME: Complete, and remove falsely required targets. my %required_targets = @@ -1223,6 +1228,7 @@ 'AMDEP' => $AMDEP, 'FASTDEP' => $FASTDEP, '-c' => $lang->compile_flag || '', + SOURCEFLAG => $sourceflags{$ext} || '', # These are not used, but they need to be defined # so &transform do not complain. SUBDIROBJ => 0, @@ -4775,6 +4783,7 @@ AC_CONFIG_HEADERS => 1, AC_CONFIG_LIBOBJ_DIR => 1, AC_CONFIG_LINKS => 1, + AC_FC_SRCEXT => 1, AC_INIT => 0, AC_LIBSOURCE => 1, AC_REQUIRE_AUX_FILE => 1, @@ -4886,6 +4898,18 @@ push @config_links, $spec; } } + elsif ($macro eq 'AC_FC_SRCEXT') + { + my $lang = $languages{'fc'}; + my $suffix = $args[1]; + my $ext = '.' . $suffix; + $extension_map{$ext} = 'fc'; + ($sourceflags{$ext} = '$(FCFLAGS_' . $ext . ') ') =~ s/\.//; + foreach my $dest (&{$lang->output_extensions} ($suffix)) + { + register_suffix_rule (INTERNAL, $suffix, $dest); + } + } elsif ($macro eq 'AC_INIT') { if (defined $args[2]) Index: doc/automake.texi =================================================================== RCS file: /cvs/automake/automake/doc/automake.texi,v retrieving revision 1.150 diff -u -r1.150 automake.texi --- doc/automake.texi 28 Aug 2006 16:04:24 -0000 1.150 +++ doc/automake.texi 30 Aug 2006 19:28:36 -0000 @@ -2887,6 +2887,11 @@ languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and C++}). @xref{Macros, , Autoconf macros supplied with Automake}. [EMAIL PROTECTED] AC_FC_SRCEXT +Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation +of files with the respective source extension (@pxref{Fortran Compiler, , +Fortran Compiler Characteristics, autoconf, The Autoconf Manual}). + @item AC_PROG_FC This is required if any Fortran 90/95 source is included. This macro is distributed with Autoconf version 2.58 and later. @xref{Particular @@ -6405,7 +6426,7 @@ @cindex Fortran 9x support @cindex Support for Fortran 9x -Automake includes full support for Fortran 9x. +Automake includes support for Fortran 9x. Any package including Fortran 9x code must define the output variable @code{FC} in @file{configure.ac}; the simplest way to do this is to use @@ -6445,13 +6466,22 @@ @subsection Compiling Fortran 9x Files @file{N.o} is made automatically from @file{N.f90} or @file{N.f95} -by running the Fortran 9x compiler. The precise command used -is as follows: +by running the Fortran 9x compiler. + +If you use the Autoconf macro @code{AC_FC_SRCEXT(f90)} which computes +the value of @samp{FCFLAGS_f90}, Automake will add this to the compile +command (@pxref{Fortran Compiler, , Fortran Compiler Characteristics, +autoconf, The Autoconf Manual}), and likewise with @code{f95}. + +The precise command used is then as follows: @table @file [EMAIL PROTECTED] .f9x [EMAIL PROTECTED](FC) -c $(AM_FCFLAGS) $(FCFLAGS)} [EMAIL PROTECTED] .f90 [EMAIL PROTECTED](FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<} + [EMAIL PROTECTED] .f95 [EMAIL PROTECTED](FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<} @end table Index: lib/am/depend2.am =================================================================== RCS file: /cvs/automake/automake/lib/am/depend2.am,v retrieving revision 1.60 diff -u -r1.60 depend2.am --- lib/am/depend2.am 23 Mar 2006 06:35:15 -0000 1.60 +++ lib/am/depend2.am 30 Aug 2006 19:28:37 -0000 @@ -65,9 +65,9 @@ if %FASTDEP% ## In fast-dep mode, we can always use -o. ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%. -?!GENERIC? if %COMPILE% -MT %OBJ% -MD -MP -MF "%DEPBASE%.Tpo" %-c% -o %OBJ% `test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE%; \ +?!GENERIC? if %COMPILE% -MT %OBJ% -MD -MP -MF "%DEPBASE%.Tpo" %-c% -o %OBJ% %SOURCEFLAG%`test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE%; \ ?SUBDIROBJ??GENERIC? depbase=`echo %OBJ% | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`; \ -?GENERIC? if %COMPILE% -MT %OBJ% -MD -MP -MF "%DEPBASE%.Tpo" %-c% -o %OBJ% %SOURCE%; \ +?GENERIC? if %COMPILE% -MT %OBJ% -MD -MP -MF "%DEPBASE%.Tpo" %-c% -o %OBJ% %SOURCEFLAG%%SOURCE%; \ then mv -f "%DEPBASE%.Tpo" "%DEPBASE%.Po"; else rm -f "%DEPBASE%.Tpo"; exit 1; fi else !%FASTDEP% if %AMDEP% @@ -75,12 +75,12 @@ DEPDIR=$(DEPDIR) $(%FPFX%DEPMODE) $(depcomp) @AMDEPBACKSLASH@ endif %AMDEP% if %?GENERIC% -?-o? %COMPILE% %-c% %-o% %OBJ% %SOURCE% -?!-o? %COMPILE% %-c% %SOURCE% +?-o? %COMPILE% %-c% %-o% %OBJ% %SOURCEFLAG%%SOURCE% +?!-o? %COMPILE% %-c% %SOURCEFLAG%%SOURCE% else !%?GENERIC% ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%. -?-o? %COMPILE% %-c% %-o% %OBJ% `test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% -?!-o? %COMPILE% %-c% `test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% +?-o? %COMPILE% %-c% %-o% %OBJ% %SOURCEFLAG%`test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% +?!-o? %COMPILE% %-c% %SOURCEFLAG%`test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% endif !%?GENERIC% endif !%FASTDEP% @@ -89,9 +89,9 @@ if %FASTDEP% ## In fast-dep mode, we can always use -o. ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%. -?!GENERIC? if %COMPILE% -MT %OBJOBJ% -MD -MP -MF "%DEPBASE%.Tpo" %-c% -o %OBJOBJ% `if test -f '%SOURCE%'; then $(CYGPATH_W) '%SOURCE%'; else $(CYGPATH_W) '$(srcdir)/%SOURCE%'; fi`; \ +?!GENERIC? if %COMPILE% -MT %OBJOBJ% -MD -MP -MF "%DEPBASE%.Tpo" %-c% -o %OBJOBJ% %SOURCEFLAG%`if test -f '%SOURCE%'; then $(CYGPATH_W) '%SOURCE%'; else $(CYGPATH_W) '$(srcdir)/%SOURCE%'; fi`; \ ?SUBDIROBJ??GENERIC? depbase=`echo %OBJ% | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`; \ -?GENERIC? if %COMPILE% -MT %OBJOBJ% -MD -MP -MF "%DEPBASE%.Tpo" %-c% -o %OBJOBJ% `$(CYGPATH_W) '%SOURCE%'`; \ +?GENERIC? if %COMPILE% -MT %OBJOBJ% -MD -MP -MF "%DEPBASE%.Tpo" %-c% -o %OBJOBJ% %SOURCEFLAG%`$(CYGPATH_W) '%SOURCE%'`; \ then mv -f "%DEPBASE%.Tpo" "%DEPBASE%.Po"; else rm -f "%DEPBASE%.Tpo"; exit 1; fi else !%FASTDEP% if %AMDEP% @@ -99,12 +99,12 @@ DEPDIR=$(DEPDIR) $(%FPFX%DEPMODE) $(depcomp) @AMDEPBACKSLASH@ endif %AMDEP% if %?GENERIC% -?-o? %COMPILE% %-c% %-o% %OBJOBJ% `$(CYGPATH_W) '%SOURCE%'` -?!-o? %COMPILE% %-c% `$(CYGPATH_W) '%SOURCE%'` +?-o? %COMPILE% %-c% %-o% %OBJOBJ% %SOURCEFLAG%`$(CYGPATH_W) '%SOURCE%'` +?!-o? %COMPILE% %-c% %SOURCEFLAG%`$(CYGPATH_W) '%SOURCE%'` else !%?GENERIC% ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%. -?-o? %COMPILE% %-c% %-o% %OBJOBJ% `if test -f '%SOURCE%'; then $(CYGPATH_W) '%SOURCE%'; else $(CYGPATH_W) '$(srcdir)/%SOURCE%'; fi` -?!-o? %COMPILE% %-c% `if test -f '%SOURCE%'; then $(CYGPATH_W) '%SOURCE%'; else $(CYGPATH_W) '$(srcdir)/%SOURCE%'; fi` +?-o? %COMPILE% %-c% %-o% %OBJOBJ% %SOURCEFLAG%`if test -f '%SOURCE%'; then $(CYGPATH_W) '%SOURCE%'; else $(CYGPATH_W) '$(srcdir)/%SOURCE%'; fi` +?!-o? %COMPILE% %-c% %SOURCEFLAG%`if test -f '%SOURCE%'; then $(CYGPATH_W) '%SOURCE%'; else $(CYGPATH_W) '$(srcdir)/%SOURCE%'; fi` endif !%?GENERIC% endif !%FASTDEP% endif %?NONLIBTOOL% @@ -115,9 +115,9 @@ if %FASTDEP% ## In fast-dep mode, we can always use -o. ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%. -?!GENERIC? if %LTCOMPILE% -MT %LTOBJ% -MD -MP -MF "%DEPBASE%.Tpo" %-c% -o %LTOBJ% `test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE%; \ +?!GENERIC? if %LTCOMPILE% -MT %LTOBJ% -MD -MP -MF "%DEPBASE%.Tpo" %-c% -o %LTOBJ% %SOURCEFLAG%`test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE%; \ ?SUBDIROBJ??GENERIC? depbase=`echo %OBJ% | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`; \ -?GENERIC? if %LTCOMPILE% -MT %LTOBJ% -MD -MP -MF "%DEPBASE%.Tpo" %-c% -o %LTOBJ% %SOURCE%; \ +?GENERIC? if %LTCOMPILE% -MT %LTOBJ% -MD -MP -MF "%DEPBASE%.Tpo" %-c% -o %LTOBJ% %SOURCEFLAG%%SOURCE%; \ then mv -f "%DEPBASE%.Tpo" "%DEPBASE%.Plo"; else rm -f "%DEPBASE%.Tpo"; exit 1; fi else !%FASTDEP% if %AMDEP% @@ -125,8 +125,8 @@ DEPDIR=$(DEPDIR) $(%FPFX%DEPMODE) $(depcomp) @AMDEPBACKSLASH@ endif %AMDEP% ## We can always use `-o' with Libtool. -?GENERIC? %LTCOMPILE% %-c% -o %LTOBJ% %SOURCE% +?GENERIC? %LTCOMPILE% %-c% -o %LTOBJ% %SOURCEFLAG%%SOURCE% ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%. -?!GENERIC? %LTCOMPILE% %-c% -o %LTOBJ% `test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% +?!GENERIC? %LTCOMPILE% %-c% -o %LTOBJ% %SOURCEFLAG%`test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% endif !%FASTDEP% endif %?LIBTOOL%