Using the configuration file
Using the configuration file fpc.cfg is an alternative to command line options. When a configuration file is found, it is read, and the lines in it are treated as if you had typed them as options on the command line: Specify one option on each line of the configuration file. They are treated before the options that you type on the command line.
The installer of the FPC compiler generates a default configuration file in one of the places where the compiler looks for it (see also Compiler usage on page ). It sets the unit path to wherever the installer put the units, and sets some minor syntax options.
You can specify comments in the configuration file with the # sign. Everything from the # on will be ignored.
The algorithm to determine which file is used as a configuration file is described in Compiler usage on page .
When the compiler has finished reading the configuration file, it continues to treat the command line options.
One of the command line options allows you to specify a second configuration file: Specifying @foo on the command line will open file foo, and read further options from there. When the compiler has finished reading this file, it continues to process the command line.
Conditional processing of the config file
In addition to placeholder substitution, the configuration file allows a type of preprocessing. It understands the following directives, which you should place starting on the first column of a line:
- #CFGDIR
- #IFDEF
- #IFNDEF
- #ELSE
- #ENDIF
- #DEFINE
- #UNDEF
- #WRITE
- #INCLUDE
- #SECTION
They work the same way as their {$...} counterparts in Pascal source code. All the default defines used to compile source code are also defined while processing the configuration file. For example, if the target compiler is an intel 80x86 compatible linux platform, both cpu86 and linux will be defined while interpreting the configuration file. For the possible default defines when compiling, consult Appendix G of the Programmer’s Guide.
What follows is a description of the different directives.
#CFGDIR
Syntax:
#CFGDIR /path/to/config/dir
Sets the directory where the compiler looks for configuration files that it includes through the #INCLUDE directive. The path can contain the usual placeholders which will be replaced with appropriate values. The substituted values are the values at the moment the CFGDIR directive is encountered.
#IFDEF
Syntax:
#IFDEF name
Lines following #IFDEF are read only if the keyword name following it is defined.
They are read until the keywords #ELSE or #ENDIF are encountered, after which normal processing is resumed.
Example :
#IFDEF VER2_6_0 -Fu/usr/lib/fpc/2.6.0/linuxunits #ENDIF
In the above example, /usr/lib/fpc/2.6.0/linuxunits will be added to the path if you’re compiling with version 2.6.0 of the compiler.
#IFNDEF
Syntax:
#IFNDEF name
Lines following #IFNDEF are read only if the keyword name following it is not defined.
They are read until the keywords #ELSE or #ENDIF are encountered, after which normal processing is resumed.
Example :
#IFNDEF VER2_6_0 -Fu/usr/lib/fpc/2.6.0/linuxunits #ENDIF
In the above example, /usr/lib/fpc/2.6.0/linuxunits will be added to the path if you’re NOT compiling with version 2.6.0 of the compiler.
#ELSE
Syntax:
#ELSE
#ELSE can be specified after a #IFDEF or #IFNDEF directive as an alternative. Lines following #ELSE are read only if the preceding #IFDEF or #IFNDEF was not accepted.
They are skipped until the keyword #ENDIF is encountered, after which normal processing is resumed.
Example :
#IFDEF VER2_6_2 -Fu/usr/lib/fpc/2.6.2/linuxunits #ELSE -Fu/usr/lib/fpc/2.6.0/linuxunits #ENDIF
In the above example, /usr/lib/fpc/2.6.2/linuxunits will be added to the path if you’re compiling with version 2.6.2 of the compiler, otherwise /usr/lib/fpc/2.6.0/linuxunits will be added to the path.
#ENDIF
Syntax:
#ENDIF
#ENDIF marks the end of a block that started with #IF(N)DEF, possibly with an #ELSE between them.
#DEFINE
Syntax:
#DEFINE name
#DEFINE defines a new keyword. This has the same effect as a -dname command line option.
#UNDEF
Syntax:
#UNDEF name
#UNDEF un-defines a keyword if it existed. This has the same effect as a -uname command line option.
#WRITE
Syntax:
#WRITE Message Text
#WRITE writes Message Text to the screen. This can be useful to display warnings if certain options are set.
Example:
#IFDEF DEBUG #WRITE Setting debugging ON... -g #ENDIF
If DEBUG is defined, this will produce a line
Setting debugging ON...
and will then switch on debugging information in the compiler.
#INCLUDE
Syntax:
#INCLUDE filename
#INCLUDE instructs the compiler to read the contents of filename before continuing to process options in the current file.
This can be useful if you want to have a particular configuration file for a project (or, under Linux, in your home directory), but still want to have the global options that are set in a global configuration file.
Example:
#IFDEF LINUX #INCLUDE /etc/fpc.cfg #ELSE #IFDEF GO32V2 #INCLUDE c:\pp\bin\fpc.cfg #ENDIF #ENDIF
This will include /etc/fpc.cfg if you’re on a Linuxmachine, and will include c:\pp\bin\fpc.cfg on a DOSmachine.
#SECTION
Syntax:
#SECTION name
The #SECTION directive acts as a #IFDEF directive, only it doesn’t require an #ENDIF directive. The special name COMMON always exists, i.e. lines following #SECTION COMMON are always read.
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
