Difference between revisions of "Configuration file"

From Lazarus wiki
Jump to navigationJump to search
m (FPC user moved page fpc.cfg to Configuration file: better name)
m (Fixed syntax highlighting)
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Command line options for the Free Pascal compiler can be stored in a '''configuration file''' and will be used as if they had been typed on the command line. They can be combined with command line options, with configuration file being processed first, before the options given on the command line.
+
==Description==
  
The file is named fpc.cfg, unless it is located in the HOME directory on a Unix-like system, in which case it will follow convention and start with a '.' :  .fpc.cfg. The compiler looks for a configuration file in certain directories, and in a specific order:
+
To avoid having to include compiler options in build files or repeat them on the command line, Free Pascal allows them to be placed in a configuration file. The compiler options in the file will be read along with  options given on the command line, with the configuration file being processed first.
  
*Under a Unix or Unix-like operating systems (e.g. Linux, FreeBSD)
+
==Format==
 +
 
 +
One ''command line option'' is written per line with the same format as when used on the command line.
 +
 
 +
===Comments===
 +
 
 +
Comment lines are allowed. They follow the Unix shell/Python/Perl comment-style: a '#' signifies the start of a comment.
 +
 
 +
===Conditional Processing===
 +
 
 +
Special comment directives are available to allow a configuration file to be conditionally processed. Available directives are:
 +
* #CFGDIR - use the directory specified in this directive as the location to find files named in subsequent #INCLUDE directives.
 +
* #SECTION
 +
* #WRITE - print a string
 +
 
 +
Directives that are equivalent to Free Pascal source code compiler directives. For example, #DEFINE in a config file is equivalent to {$DEFINE } in source code.
 +
* #DEFINE
 +
* #ELSE
 +
* #ENDIF
 +
* #IFDEF -
 +
* #IFNDEF
 +
* #INCLUDE
 +
* #UNDEF
 +
 
 +
===Example===
 +
 
 +
<syntaxhighlight lang="pascal">
 +
# Perform range checking, IO checking, overflow checking, IEEE error checking
 +
-Crio3
 +
# compiler halts after warnings
 +
-Sew
 +
</syntaxhighlight>
 +
 
 +
==Name==
 +
The file is named '''fpc.cfg''', unless it is located in the HOME directory on a Unix-like system, in which case it will follow Unix configuration file convention and start with a '.' ( '''.fpc.cfg''' ) .
 +
 
 +
==Create==
 +
 
 +
Example for Windows:
 +
Open a command prompt and go to the directory where fpc.exe is. This command will create a fpc.cfg for your installation and it will be placed in the current directory.
 +
 
 +
fpcmkcfg -d basepath=C:\fpc\ -o .\fpc.cfg
 +
 
 +
See fpcmkcfg -? for meaning of commandline switches.
 +
 
 +
 
 +
==Location==
 +
 
 +
*Under a Unix or Unix-like operating systems (e.g. FreeBSD, Linux)
 
#The current directory.
 
#The current directory.
 
#Your home directory, it looks for .fpc.cfg.
 
#Your home directory, it looks for .fpc.cfg.
Line 13: Line 61:
 
#The directory where the compiler is.
 
#The directory where the compiler is.
  
NOTE: Unlike Unix shell configuration files, FPC configuration files are not combined. It will only use the first one that it finds and ignore any others that may also be on the system, including the configuration file that comes with Free Pascal.  
+
==Not Combined==
 +
 
 +
Unlike Unix shell configuration files, FPC configuration files are not automatically combined (user-specific and system-wide). It will only use the first one that it finds and ignore any others that may also be on the system, including the configuration file that comes with Free Pascal. However, you can use the #INCLUDE directive (identical to {$INCLUDE } in Free Pascal source code) to include another configuration file. For example, your personal fpc.cfg in the current directory file could include the /etc/fpc.cfg file that came with Free Pascal.
 +
 
 +
<syntaxhighlight lang="pascal">
 +
# To avoid having to duplicate options in the FPC-provided configuration file
 +
# that file can be included in a custom configuration file.
 +
# This is how the file would be included on a Unix-like system:
 +
 
 +
#INCLUDE /etc/fpc.cfg
 +
 
 +
# Then custom options can be added.
 +
 
 +
-Sew
 +
</syntaxhighlight>
 +
 
 +
You also can specify additional configuration files by specifying them on the command line, preceded by the @ symbol:
 +
 
 +
<syntaxhighlight lang="pascal">
 +
fpc @/dir1/dir2/configfile2.cfg @subdir/configfile3.txt @configfile3.txt my_program.pp
 +
</syntaxhighlight>
 +
 
 +
==Ignore==
  
 
You can tell the compiler to not use a configuration file by giving the '''-n''' command line option.
 
You can tell the compiler to not use a configuration file by giving the '''-n''' command line option.
  
In addition to command line options (one per line), the configuration file can have comment lines. They use the Unix shell/Python/Perl comment-style of a '#' signifying the start of a comment.
+
[[Category:FPC]]

Latest revision as of 05:14, 8 February 2020

Description

To avoid having to include compiler options in build files or repeat them on the command line, Free Pascal allows them to be placed in a configuration file. The compiler options in the file will be read along with options given on the command line, with the configuration file being processed first.

Format

One command line option is written per line with the same format as when used on the command line.

Comments

Comment lines are allowed. They follow the Unix shell/Python/Perl comment-style: a '#' signifies the start of a comment.

Conditional Processing

Special comment directives are available to allow a configuration file to be conditionally processed. Available directives are:

  • #CFGDIR - use the directory specified in this directive as the location to find files named in subsequent #INCLUDE directives.
  • #SECTION
  • #WRITE - print a string

Directives that are equivalent to Free Pascal source code compiler directives. For example, #DEFINE in a config file is equivalent to {$DEFINE } in source code.

  • #DEFINE
  • #ELSE
  • #ENDIF
  • #IFDEF -
  • #IFNDEF
  • #INCLUDE
  • #UNDEF

Example

# Perform range checking, IO checking, overflow checking, IEEE error checking
-Crio3
# compiler halts after warnings
-Sew

Name

The file is named fpc.cfg, unless it is located in the HOME directory on a Unix-like system, in which case it will follow Unix configuration file convention and start with a '.' ( .fpc.cfg ) .

Create

Example for Windows: Open a command prompt and go to the directory where fpc.exe is. This command will create a fpc.cfg for your installation and it will be placed in the current directory.

fpcmkcfg -d basepath=C:\fpc\ -o .\fpc.cfg

See fpcmkcfg -? for meaning of commandline switches.


Location

  • Under a Unix or Unix-like operating systems (e.g. FreeBSD, Linux)
  1. The current directory.
  2. Your home directory, it looks for .fpc.cfg.
  3. The directory specified in the environment variable PPC_CONFIG_PATH, and if it is not set, it will look in the etc directory above the compiler directory. (For instance, if the compiler is in /usr/local/bin, it will look in /usr/local/etc)
  4. The directory /etc.
  • Under all other operating systems:
  1. The current directory.
  2. If it is set, the directory specified in the environment variable PPC_CONFIG_PATH.
  3. The directory where the compiler is.

Not Combined

Unlike Unix shell configuration files, FPC configuration files are not automatically combined (user-specific and system-wide). It will only use the first one that it finds and ignore any others that may also be on the system, including the configuration file that comes with Free Pascal. However, you can use the #INCLUDE directive (identical to {$INCLUDE } in Free Pascal source code) to include another configuration file. For example, your personal fpc.cfg in the current directory file could include the /etc/fpc.cfg file that came with Free Pascal.

# To avoid having to duplicate options in the FPC-provided configuration file
# that file can be included in a custom configuration file.
# This is how the file would be included on a Unix-like system:

#INCLUDE /etc/fpc.cfg

# Then custom options can be added.

-Sew

You also can specify additional configuration files by specifying them on the command line, preceded by the @ symbol:

fpc @/dir1/dir2/configfile2.cfg @subdir/configfile3.txt @configfile3.txt my_program.pp

Ignore

You can tell the compiler to not use a configuration file by giving the -n command line option.