Go to the first, previous, next, last section, table of contents.


Adding Options

To add a new command-line option to g77, first decide what kind of option you wish to add. Search the g77 and gcc documentation for one or more options that is most closely like the one you want to add (in terms of what kind of effect it has, and so on) to help clarify its nature.

Fortran options are listed in the file `egcs/gcc/f/lang-options.h', which is used during the build of gcc to build a list of all options that are accepted by at least one language's compiler. This list goes into the lang_options array in `gcc/toplev.c', which uses this array to determine whether a particular option should be offered to the linked-in front end for processing by calling lang_option_decode, which, for g77, is in `egcs/gcc/f/com.c' and just calls ffe_decode_option.

If the linked-in front end "rejects" a particular option passed to it, `toplev.c' just ignores the option, because some language's compiler is willing to accept it.

This allows commands like `gcc -fno-asm foo.c bar.f' to work, even though Fortran compilation does not currently support the `-fno-asm' option; even though the f771 version of lang_decode_option rejects `-fno-asm', `toplev.c' doesn't produce a diagnostic because some other language (C) does accept it.

This also means that commands like `g77 -fno-asm foo.f' yield no diagnostics, despite the fact that no phase of the command was able to recognize and process `-fno-asm'---perhaps a warning about this would be helpful if it were possible.

Code that processes Fortran options is found in `egcs/gcc/f/top.c', function ffe_decode_option. This code needs to check positive and negative forms of each option.

The defaults for Fortran options are set in their global definitions, also found in `egcs/gcc/f/top.c'. Many of these defaults are actually macros defined in `egcs/gcc/f/target.h', since they might be machine-specific. However, since, in practice, GNU compilers should behave the same way on all configurations (especially when it comes to language constructs), the practice of setting defaults in `target.h' is likely to be deprecated and, ultimately, stopped in future versions of g77.

Accessor macros for Fortran options, used by code in the g77 FFE, are defined in `egcs/gcc/f/top.h'.

Compiler options are listed in `gcc/toplev.c' in the array f_options. An option not listed in lang_options is looked up in f_options and handled from there.

The defaults for compiler options are set in the global definitions for the corresponding variables, some of which are in `gcc/toplev.c'.

You can set different defaults for Fortran-oriented or Fortran-reticent compiler options by changing the source code of g77 and rebuilding. How to do this depends on the version of g77:

G77 0.5.24 (EGCS 1.1)
G77 0.5.25 (EGCS 1.2)
Change the lang_init_options routine in `egcs/gcc/f/com.c'. (Note that these versions of g77 perform internal consistency checking automatically when the `-fversion' option is specified.)
G77 0.5.23
G77 0.5.24 (EGCS 1.0)
Change the way f771 handles the `-fset-g77-defaults' option, which is always provided as the first option when called by g77 or gcc. This code is in ffe_decode_options in `egcs/gcc/f/top.c'. Have it change just the variables that you want to default to a different setting for Fortran compiles compared to compiles of other languages. The `-fset-g77-defaults' option is passed to f771 automatically because of the specification information kept in `egcs/gcc/f/lang-specs.h'. This file tells the gcc command how to recognize, in this case, Fortran source files (those to be preprocessed, and those that are not), and further, how to invoke the appropriate programs (including f771) to process those source files. It is in `egcs/gcc/f/lang-specs.h' that `-fset-g77-defaults', `-fversion', and other options are passed, as appropriate, even when the user has not explicitly specified them. Other "internal" options such as `-quiet' also are passed via this mechanism.


Go to the first, previous, next, last section, table of contents.