Preprocessing#

Source files with a capitalised extension are preprocessed by the build system, producing a file of the same name with a lowercase extension in the working directory. For example:

  • .F90 source files become .f90 during source extraction.

  • .X90 PSyclone algorithm files become .x90 before PSyclone is applied (see PSyclone Transformation Scripts).

  • .PF pFUnit test files become .pf before pFUnit processing.

Files with a lowercase extension are not preprocessed. All preprocessing uses the FPP and FPPFLAGS variables, with -o specifying the output filename. The dependency analyser preprocesses in the same way, so it sees the same source as the compiler.

Preprocessor settings#

Preprocessor-specific settings are read from infrastructure/build/fpp/<name>.mk, where <name> is the FPP command without any path (for example cpp or ifx). FPP should name only the program, e.g. FPP=cpp rather than FPP="cpp -traditional-cpp"; options it always needs belong in that file. The build stops with an error if FPP is unset or no such file exists, so to support a new preprocessor, add a file there which may set:

FPPFLAGS

Append (+=) options the preprocessor always needs, such as -traditional-cpp for cpp or -E for nvfortran. This includes the option which suppresses line markers, which differs between preprocessors: -P for cpp but -Wp,-P for the Intel drivers, whose own -P instead means “preprocess only”.

FPP_INPUT_FLAGS

Options placed immediately before the input filename. The Intel drivers use -free -fpp -Tf to force free-form preprocessing of nonstandard extensions such as .X90. -Tf must immediately precede the input filename.

FPP_DEFINES_COMPILER_MACROS

Non-empty if the preprocessor defines the compiler identification macros itself. It defaults to true when the preprocessor is the Fortran compiler in use.

FPP_OPENMP_FLAGS

Options which enable OpenMP, defining _OPENMP, such as -fopenmp for cpp or -qopenmp for the Intel drivers. These are added to FPPFLAGS when OPENMP is one of the FFLAG_GROUPS, so preprocessing matches compilation. The value of _OPENMP depends on the preprocessor rather than the compiler.

Compiler identification macros#

Each compiler’s makefile lists its identification macros, such as -D__INTEL_LLVM_COMPILER, in FPP_COMPILER_MACROS. These are added to FPPFLAGS unless FPP_DEFINES_COMPILER_MACROS is set, so cpp gets them but ifx preprocessing for an ifx build does not.

Compiler version macros#

Each compiler’s makefile also sets FPP_VERSION_MACROS, which are always added to FPPFLAGS since no compiler defines these itself. The version is encoded as major*1000000 + minor*1000 + patch, so version 12.2.0 is 12002000, allowing tests such as #if defined(GNU_FORTRAN) && (GNU_FORTRAN < 13000000).

Compiler

Macros

gfortran

GNU_FORTRAN

ifx

INTEL_FORTRAN

ifort

INTEL_FORTRAN, IFORT_VERSION

crayftn

CRAY_FORTRAN, CRAYFTN_VERSION

nvfortran

NVIDIA_FORTRAN

Example#

When ifx is the preprocessor for an ifx build, an algorithm file is preprocessed with a command of the form:

ifx -P -Wp,-P -DINTEL_FORTRAN=2025001000 -o working/example.x90 -free -fpp -Tf source/example.X90