This patch complements a new set of macros that I recently submitted to autoconf-patches. At this point, I'm mainly submitting it to give a clearer understanding of the autoconf patch's intention (but I think it doesn't break anything in automake). It gives autoconf the control whether .F files are to be compiled directly into object files with a sufficiently smart compiler, or whether independent preprocessing is used to produce "pure" fortran (.f files) first (if the compiler understands no or only rudimentary cpp). Regards, Martin -- Martin Wilck <[EMAIL PROTECTED]> Institute for Tropospheric Research, Permoserstr. 15, D-04318 Leipzig, Germany Tel. +49-341-2352151 / Fax +49-341-2352361 Index: ChangeLog =================================================================== RCS file: /cvs/automake/ChangeLog,v retrieving revision 1.874 diff -u -r1.874 ChangeLog --- ChangeLog 2000/07/02 21:55:44 1.874 +++ ChangeLog 2000/07/13 17:11:00 @@ -1,3 +1,15 @@ +2000-07-13 Martin Wilck <[EMAIL PROTECTED]> + + * automake.in: Improve support for ppf77 through new autoconf + macros. + (main): change call for ®ister_language ('ppf77'). + (scan_one_configure_file): look for AC_PROG_FPP. + (lang_ppf77_rewrite): remember ppf77 filenames. + (lang_f77_finish): work around the FIXME (routine called more than + once). + (lang_ppf77_finish): override a lot of stuff from + finish_languages, because direct .F.o compilation may be impossible. + 2000-07-02 Jim Meyering <[EMAIL PROTECTED]> * automake.in (scan_one_configure_file): Recognize AC_LIBOBJ. Index: automake.in =================================================================== RCS file: /cvs/automake/automake.in,v retrieving revision 1.787 diff -u -r1.787 automake.in --- automake.in 2000/07/02 21:55:20 1.787 +++ automake.in 2000/07/13 17:03:11 @@ -355,10 +355,9 @@ 'compiler-name=F77COMPILE', 'output-arg=-c -o $@', 'f', 'for', 'f90'); +# For ppf77, we must override automakes's default behaviour +# (see comments for lang_ppf77_finish) ®ister_language ('ppf77', 'linker=F77LINK', 'flags=FFLAGS', - 'compile=$(F77) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)', - 'compiler-name=PPF77COMPILE', - 'output-arg=-c -o $@', 'F'); ®ister_language ('ratfor', 'linker=F77LINK', 'flags=RFLAGS', # FIXME also FFLAGS. @@ -4568,7 +4567,7 @@ &am_conf_line_warning ($filename, $., "automake requires \`AM_PROG_LEX', not \`AC_PROG_LEX'"); } - if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/) + if (/AC_PROG_(F77|FPP|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/) { $configure_vars{$1} = $filename . ':' . $.; } @@ -4910,7 +4909,17 @@ # Rewrite a single preprocessed Fortran 77 file. sub lang_ppf77_rewrite { - return $LANG_PROCESS; + local ($directory, $base, $ext) = @_; + + local ($r) = &lang_f77_rewrite ($directory, $base, $ext); + local ($pfx) = ''; + if ($r == $LANG_SUBDIR) + { + $pfx = $directory . '/'; + } + $ppf77_sources{$pfx . $base . '.' . $ext} = 1; + &saw_extension ('f'); + return $r; } # Rewrite a single ratfor file. @@ -5143,42 +5152,100 @@ sub lang_f77_finish { - # FIXME: this function can be called more than once. We should - # arrange for it to only do anything the first time through. - local ($ltcompile, $ltlink) = &libtool_compiler; - &define_variable ('F77LD', '$(F77)'); - &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@'); + if (!$content_seen{'F77LD'}) + { + &define_variable ('F77LD', '$(F77)'); + &define_variable ('F77LINK', $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) +$(AM_LDFLAGS) $(LDFLAGS) -o $@'); + + if (! defined $configure_vars{'F77'}) + { + &am_error ("Fortran 77 source seen but \`F77' not defined in +\`configure.in'"); + } + }; - if (! defined $configure_vars{'F77'}) - { - &am_error ("Fortran 77 source seen but \`F77' not defined in \`configure.in'"); - } } # Preprocessed Fortran 77 -# -# The current support for preprocessing Fortran 77 just involves passing -# `$(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)' as additional flags -# to the Fortran 77 compiler, since this is how GNU Make does it; see -# the `GNU Make Manual, Edition 0.51 for `make' Version 3.76 Beta' -# (specifically, from info file `(make)Catalogue of Rules'). # -# A better approach would be to write an Autoconf test -# (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all -# Fortran 77 compilers know how to do preprocessing. The Autoconf macro -# AC_PROG_FPP should test the Fortran 77 compiler first for +# The autoconf macro AC_PROG_FPP tests the Fortran 77 compiler first for # preprocessing capabilities, and then fall back on cpp (if cpp were # available). +# +# If Fortran 77 doesn't handle cpp, but cpp (or equivalent) is available +# as an external program, we must override make's "direct" .F.o rule in +# order to do "indirect" compilation (.F.f, .f.o). To do that in a +# portable manner, we write an explicit rule for each .F file. +# +# It's up to autoconf to decide whether indirect or direct compilation works +# better; this is achieved through the @FPP_SOURCE_EXT@ and @FPP_MAKE_FLAGS@ +# configure-time variables. sub lang_ppf77_finish { + local $file, @files; + local $ofile, $objfile, $lofile, $base; + local $ppf77_compile="\$(F77) \$(FPP_MAKE_FLAGS) \$(AM_FFLAGS) \$(FFLAGS)"; + local $output_arg="-c -o"; + local ($ltcompile, $ltlink) = &libtool_compiler; + &lang_f77_finish; + + if (! defined $configure_vars{'FPP'}) + { + &am_error ("Preprocessed Fortran 77 source seen but \`FPP' not defined in +\`configure.in'"); + } + +# FPP_OUTPUT is needed because some preprocessers print output to +# stdout, others to (base).f + +# this is a hack - autoconf strictly refuses to handle variable AM_CPPFLAGS + define_variable('ALL_CPPFLAGS','$(CPPFLAGS) $(AM_CPPFLAGS)'); + define_configure_variable('FPPFLAGS'); + define_configure_variable('FPP_MAKE_FLAGS'); + define_configure_variable('FPP_SOURCE_EXT'); - # We also handle the case of preprocessing `.F' files into `.f' - # files. - $output_rules .= (".F.f:\n" - . "\t\$(F77COMPILE) -F \$<\n"); + &define_compiler_variable ('PPF77COMPILE', + $ltcompile, $ppf77_compile); + + local ($full) = ("\t\$(PPF77COMPILE) $output_arg \$@"); + +# To override make's builtin .F.o rule and stay compatible, +# we need to print explicit rules for each source file + foreach $file (sort keys %ppf77_sources) + { + ($base=$file) =~ s/\.F$//; + $ofile= $base . ".o"; + $lofile= $base . ".lo"; + $objfile= $base . ".obj"; + + $output_rules .= ("$ofile:\t$base.\@FPP_SOURCE_EXT\@\n" + . $full + . " \$<\n"); + $output_rules .= ("\@objfile:\t$base.\@FPP_SOURCE_EXT\@\n" + . $full + . " \$<\n") + if $seen_objext; + + $output_rules .= ("$lofile:\t$base.\@FPP_SOURCE_EXT\@\n" + . "\t\$(LTPPF77COMPILE) $output_arg" + . " \$<\n") + if $seen_libtool; + } + + $output_rules .= (".F.f:\t\n" + . "\t\$(FPP) \$(DEFS) \$(INCLUDES) \$(FPPFLAGS) \$(AM_CPPFLAGS) +\$(CPPFLAGS)\$< \@FPP_OUTPUT\@\n\n"); + + @files = sort keys %ppf77_sources; + map ($_=~s/.F$/.f/, @files); + $output_rules .= "mostlyclean-PPF77:\n"; + pretty_print_rule ("\t-rm -f","\t ", @files); + $output_rules .= "\n"; + + push (@clean, 'PPF77'); + &push_phony_cleaners ('PPF77'); + + } sub lang_ratfor_finish