Bug 18428 - No preprocessing option -cpp for gfortran
Summary: No preprocessing option -cpp for gfortran
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.0.0
: P2 enhancement
Target Milestone: ---
Assignee: Daniel Franke
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-11 13:29 UTC by Carsten Lemmen
Modified: 2008-05-29 19:12 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-02-10 14:35:46


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carsten Lemmen 2004-11-11 13:29:31 UTC
Whoops, where has the preprocessing option gone, used to be -cpp ??  Neither
does the -traditional-cpp option work for the fortran front end.

>gfortran -cpp
gfortran unrecognized option »-cpp«
>  gfortran -v testcase_preprocess.f90
.Warning: testcase_preprocess.f90:16: Illegal preprocessor directive
 In file testcase_preprocess.f90:15

  real :: value=0.0E0
              1
Error: Symbol 'value' at (1) already has basic type of REAL
!------------------------------------------------------------------

program test

#ifdef DOUBLE
  double precision :: value=0.0D0
#else
  real :: value=0.0E0
#endif

end program test
Comment 1 Andrew Pinski 2004-11-11 15:05:42 UTC
"gfortran -x f95-cpp-input" works
So does "gfortran -x f77-cpp-input"

maybe this should be documented.
Comment 2 Carsten Lemmen 2005-06-12 11:36:59 UTC
> "gfortran -x f95-cpp-input" works
> maybe this should be documented.

This is not the same.  

1) The -x <language> option states that ALL following input files should be
treated as being of type <language">

2) The former -cpp option stated that all following SOURCE files should be
preprocessed

In many legacy Makefiles, subroutines are compiled into object files, and in a
last step the main code ist compiled and linked to all dependencies in ONE step,
like

gfortran main.f90 -o main sub1.o sub2.o sub3.o

Now, for code with preprocessor directives, with other compilers you can specify
 to precompile the sources, like

f90 -cpp main.f90 -o main sub1.o sub2.o sub3.o

With gfortran and the -cpp option gone, someone who replaces the -cpp with -x
f95-cpp-input (easy to do with FLAGS), a la

gfortran -x f95-cpp-input main.f90 -o main sub1.o sub2.o sub3.o  
doesn't compile properly, since the binary object files are read as source (to
be preprocessed)
You would need to specify another -x object-input (or similar) before the object
files, that makes it significantly harder to adjust or write Makefiles. 
Alternatively, all source must be compiled first and linked in a separate step.
As stated above, this rather clean version is not considered in lots of existing
Makefiles.



Comment 3 Carsten Lemmen 2005-08-12 12:29:22 UTC
Rather than fiddling with -x f95-cpp-input I found that the best option is to
use the gcc specs option to redeclare suffix rules.  To enforce preprocessing
for files with suffix .f90 create a file override-specs.h with the content

> cat override-specs.h
.f90:
@f95-cpp-input
>gfortran -specs override-specs.h testcase.f90

Now, testcase.f90 will be preprocessed.  This should be reflected in the
documentation (rather than having to dig around the 400 page gcc manual) 
Comment 4 Andrew Pinski 2005-08-12 12:32:22 UTC
(In reply to comment #3)
> Now, testcase.f90 will be preprocessed.  This should be reflected in the
> documentation (rather than having to dig around the 400 page gcc manual) 

Why, specs files are not for the light hearted.  Really they are designed for GCC developers can quickly 
test some spec changed without recompiling the whole compiler.
Comment 5 Carsten Lemmen 2005-08-12 13:22:25 UTC
Subject: Re:  No preprocessing option -cpp for gfortran

pinskia at gcc dot gnu dot org wrote:
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-12 12:32 -------
> (In reply to comment #3)
> 
>>Now, testcase.f90 will be preprocessed.  This should be reflected in the
>>documentation (rather than having to dig around the 400 page gcc manual) 
> 
> 
> Why, specs files are not for the light hearted.  Really they are designed for GCC developers can quickly 
> test some spec changed without recompiling the whole compiler.
> 

1) I agree in principle, a user should not have to revert to using spec
files.
2) However, a user *should* be able to tell the compiler that he/she
wishes files with a certain extension to be preprocessed.

Lots of other compilers (free and non-free) give the user this choice,
below just four examples
 * pgf90 -Mpreprocess
 * nagf90 -fpp
 * g95 -cpp
 * xlf90 -qsuffix=cpp=f90

The -x option in gfortran is not really a good replacement as described
in my comment #2.

CL
Comment 6 Francois-Xavier Coudert 2005-11-24 22:11:22 UTC
(In reply to comment #5)
> The -x option in gfortran is not really a good replacement as described
> in my comment #2.

While I completely agree with you, I don't see a way to do that with the current framework. On the other hand, when (or if) we switch to cpplib, it will be fairly easy.
Comment 7 Tom Browder 2006-03-07 20:37:32 UTC
(In reply to comment #6)
> While I completely agree with you, I don't see a way to do that with the
> current framework. On the other hand, when (or if) we switch to cpplib, it 

How does the current framework now handle the difference between source files t.f (not preprocessed) and t.F (preprocessed).  Couldn't command line arg '-cpp' set a flag to change the handling of any source file to the same as t.F?

(I know it's probably not that easy in reality.)
Comment 8 Daniel Franke 2008-02-10 14:35:46 UTC
Ancient, but still valid.
Comment 9 Daniel Franke 2008-05-25 22:38:27 UTC
Subject: Bug 18428

Author: dfranke
Date: Sun May 25 22:37:41 2008
New Revision: 135882

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=135882
Log:
gcc:
2008-05-26  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/18428
	* c.opt: Removed undocumented option '-lang-fortran'.
	* c-common.h: Removed global variable 'lang_fortran'.
	* c-opts.c (c_common_handle_option): Removed code to handle
	option '-lang-fortran'. Updated includes.
	* c-cppbuiltin.c (c_cpp_builtins): Removed conditional
	definition of '__GFORTRAN__'.
	(define__GNUC__): Reimplemented to use BASEVER and
	cpp_define_formatted.
	(builtin_define_with_value_n): Removed.
	* c-incpath.h: Renamed to ...
	* incpath.h: ... this.
	* c-incpath.c: Renamed to ...
	* incpath.c: ... this. Updated includes.
	* fix-header.c: Updated includes.
	* Makefile.in: Replaced c-incpath.[ch] by incpath.[ch].
	(c-cppbuiltin.o): Added dependency on and definition of BASEVER.
	(OBJ-archive): Added cppdefault.o, incpath.o and prefix.o.


gcc/cp:
2008-05-26  Daniel Franke  <franke.daniel@gmail.com>

	* Makefile.in: Adjusted dependencies on c-incpath.o.


gcc/fortran:
2008-05-26  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/18428
	* lang.opt (A, C, CC, D, E, H, P, U, cpp, d, fworking-directory,
	imultilib, iprefix, iquote, isysroot, isystem, nocpp, nostdinc,
	o, undef, v): New options.
	* options.c (gfc_init_options): Also initialize preprocessor
	options.
	(gfc_post_options): Also handle post-initialization of preprocessor
	options.
	(gfc_handle_option): Check if option is a preprocessor option.
	If yes, let gfc_cpp_handle_option() handle the option.
	* lang-specs.h: Reorganized to handle new options.
	* scanner.c (gfc_new_file): Read temporary file instead of
	input source if preprocessing is enabled.
	* f95-lang.c (gfc_init): Initialize preprocessor.
	(gfc_finish): Clean up preprocessor.
	* cpp.c: New.
	* cpp.h: New.
	* Make-lang.in: Added new objects and dependencies.
	* gfortran.texi: Updated section "Preprocessing and
	conditional compilation".
	* invoke.texi: Added new section "Preprocessing Options",
	listed and documented the preprocessing options handled by gfortran.


Added:
    trunk/gcc/fortran/cpp.c
    trunk/gcc/fortran/cpp.h
    trunk/gcc/incpath.c
      - copied, changed from r135880, trunk/gcc/c-incpath.c
    trunk/gcc/incpath.h
      - copied unchanged from r135880, trunk/gcc/c-incpath.h
Removed:
    trunk/gcc/c-incpath.c
    trunk/gcc/c-incpath.h
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/Makefile.in
    trunk/gcc/c-common.h
    trunk/gcc/c-cppbuiltin.c
    trunk/gcc/c-opts.c
    trunk/gcc/c.opt
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/Make-lang.in
    trunk/gcc/fix-header.c
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/Make-lang.in
    trunk/gcc/fortran/f95-lang.c
    trunk/gcc/fortran/gfortran.texi
    trunk/gcc/fortran/invoke.texi
    trunk/gcc/fortran/lang-specs.h
    trunk/gcc/fortran/lang.opt
    trunk/gcc/fortran/options.c
    trunk/gcc/fortran/scanner.c

Comment 10 Daniel Franke 2008-05-29 19:12:20 UTC
Implemented, but not yet fixed, in trunk. Closing.