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:
.F90source files become.f90during source extraction..X90PSyclone algorithm files become.x90before PSyclone is applied (see PSyclone Transformation Scripts)..PFpFUnit test files become.pfbefore 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:
FPPFLAGSAppend (
+=) options the preprocessor always needs, such as-traditional-cppforcppor-Efornvfortran. This includes the option which suppresses line markers, which differs between preprocessors:-Pforcppbut-Wp,-Pfor the Intel drivers, whose own-Pinstead means “preprocess only”.FPP_INPUT_FLAGSOptions placed immediately before the input filename. The Intel drivers use
-free -fpp -Tfto force free-form preprocessing of nonstandard extensions such as.X90.-Tfmust immediately precede the input filename.FPP_DEFINES_COMPILER_MACROSNon-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_FLAGSOptions which enable OpenMP, defining
_OPENMP, such as-fopenmpforcppor-qopenmpfor the Intel drivers. These are added toFPPFLAGSwhenOPENMPis one of theFFLAG_GROUPS, so preprocessing matches compilation. The value of_OPENMPdepends 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 |
|---|---|
|
|
|
|
|
|
|
|
|
|
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