Sign in Join
Wiki copytemporary

IDE Macros in paths and filenames: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Types of Macros
22
33There are various types of macros:
44
55- **IDE macros**: they can be used in almost all IDE fields, e.g. search paths, custom options, file names, run parameters. They are replaced with their value before calling external tools like the compiler or the debugger. They are case insensitive.
66- **FPC symbols**: these are either defined (on) or undefined (off). They are passed via the command line option **-d**, which can be set under *Compiler Options / Custom Options*. For example *-dDEBUG -dVerbose* will define the FPC symbols DEBUG and Verbose, so you can use *{\$IFDEF Debug}*. They are case insensitive.
77- **FPC macros**: they are e.g. specified via code like {\$define MYFPCMACRO:=42}. An example of a predefined macro is FPC_FULLVERSION.
88- **Build macros**: they are IDE macros with a limited scope. They are defined by projects and packages and are case insensitive.
99- Some IDE plugins have their own macros.
1010
1111## IDE macro format
1212
1313IDE macros are used in the following format. Replace the *macro-name* part with one of the macros listed below.
1414
1515`$(macro-name)`
1616
1717For example: This "Unit Output directory" is often used for Lazarus Packages:
1818
1919`lib/$(TargetCPU)-$(TargetOS)`
2020
2121- under a x86 Linux 32-bit system that would equate to: **lib/i386-linux**
2222- under a x86 Linux 64-bit system that would equate to: **lib/x86_64-linux**
2323
2424There are also some **macro functions** that use the following format:
2525
2626`$macro_name(parameters)`
2727
2828For example
2929
3030`$Ext(unit1.pas)`
3131
3232will give *.pas*.
3333
3434***Windows:*** Compiling to a RamDrive where each project gets its own unit directory (Project\> Options\> Unit Output Directory)
3535
3636` R:\FPC\$NameOnly($(ProjFile))`
3737
3838***MacOS:*** A more complex example but very useful, when you want to compile on its name ***\$NameOnly(\$(ProjFile))*** on a specific CPU target ***-\$(TargetCPU)**'' saving the compiled file on the package path***.app/Contents/MacOS/**''
3939
4040`$NameOnly($(ProjFile))-$(TargetCPU).app/Contents/MacOS/$NameOnly($(ProjFile))-$(TargetCPU)`
4141
4242## General Purpose
4343
4444- **Col** - current column in source editor
4545- **Row** - current row in source editor (screen, can differ to byte position due to tabs and UTF-8)
4646- **CurToken** - current token at the cursor in the source editor
4747- **EdFile** - current filename in the source editor
4848- **Params** - run parameters of the current project
4949- **Prompt** - ask the user for a value. This is an interactive macro.
5050- **RunCmdLine** - the command to launch the project
5151- **Save** - save current file in source editor
5252- **SaveAll** - save all
5353- **TargetCmdLine** - the project executable (or host / i.e.: "\$TargetFile") plus run parameters
5454
5555## Filename Parts
5656
5757- **Ext(filename)** - macro function for ExtractFileExt. Example: will return .exe on Windows.
5858- **MakeDir(filename)** - macro function for AppendPathDelim
5959- **MakeFile(filename)** - macro function for ChompPathDelim
6060- **MakeExe(filename)** - change file extension to .exe under Windows, nothing under Linux, BSD, macOS. When cross compiling it will create a file name for the target OS. To get the file name of the host OS use \$MakeExe(ide,filename). To get the file name of a specific OS use \$MakeExe(os,filename). The two parameter variant exists since 1.1.
6161- **MakeLib(filename)** - change file extension to .dll under Windows, under Linux/BSD change to lowercase libname.so, under macOS to libname.so (since 0.9.29)
6262- **Name(filename)** - macro function for ExtractFileName
6363- **NameOnly(filename)** - macro function for ExtractFileNameOnly
6464- **Path(filename)** - macro function for ExtractFilePath
6565
6666## Paths and Parts
6767
6868- **CompPath** - compiler path. Before 1.3 it returned the value of the IDE option (*Tools / Options ...*). It cannot use the macros FPCVer, FPC_FULLVERSION, because these macros are retrieved from the compiler. You can use the macros TargetOS, TargetCPU, SrcOS **only** if you set them. You can use LazarusDir and Env macros. Since 1.3 the macro returns the compiler of the project. It returns the default IDE option value:
6969 - when using the parameter *IDE*: \$CompPath(IDE)
7070 - in the project compiler option itself
7171 - when the project compiler is disabled (*Build*, *Compile*)
7272 - when the project compiler is not fpc or ppcsomething
7373 - when the IDE is built
7474- **ConfDir** - directory where the IDE stores its config files (same as PrimaryConfigPath).
7575- **ExeExt** - executable file extension for the operation system, independent of project's target OS. To get the extension for the current project target OS use \$MakeExe().
7676- **FallbackOutputRoot** - the directory where the IDE puts ppu files if the output directory of a package is not writable. Default: \$(PrimaryConfigPath)/lib. Since 0.9.31.
7777- **FPCSrcDir** - FPC source directory set in environment options
7878- **FPCMsgFile** - compiler messages file set in the Lazarus environment options (since 0.9.31).
7979- **InstantFPCCache** - path of the instantfpccache. Output of running *instantfpc --get-cache* (since 0.9.31).
8080- **LazarusDir** - Lazarus source directory set in Lazarus environment options. No macros allowed.
8181- **Make** - path to the make utility (gmake under BSD) (since 0.9.29)
8282- **PrimaryConfigPath** - the directory of the IDE's configuration files (since 0.9.31). See **SecondaryConfigPath**.
8383- **ProjFile** - the full filename of the main source of the current project (.lpr)
8484- **ProjIncPath** - include path of project directory
8585- **ProjOutDir** - path of project output directory (e.g. where the .ppu files are created) (since 0.9.27)
8686- **ProjPath** - the project directory (the directory of the .lpi file)
8787- **ProjPublishDir** - publishing directory of the current project
8888- **ProjSrcPath** - source path of project directory
8989- **ProjUnitPath** - unit path of project directory
9090- **Project(param)** - macro function for various values:
9191 - **Project(UnitPath)** - unit path of project directory
9292 - **Project(SrcPath)** - source path of project directory
9393 - **Project(IncPath)** - include path of project directory
9494 - **Project(InfoFile)** - filename of the project information file (.lpi) (since r15287, 0.9.25)
9595 - **Project(OutputDir)** - directory where the project's ppu files are created (since 0.9.27)
9696- **Package macros** - these can be used in the fields of a package. For example in the search paths of a package. To use them elsewhere give a package name as parameter.
9797 - **\$(PkgName)** - in a package: gives the package name (since 0.9.31)
9898 - **\$PkgName(id)** - macro function for the name of a package ID given as parameter (since 0.9.31)
9999 - **\$(PkgDir)** - macro for the directory (location of the .lpk) of the package
100100 - **\$PkgDir(id)** - macro function for the directory (location of the .lpk) of a package ID given as parameter
101101 - **\$PkgIncPath(id)** - macro function for the include path of a package ID given as parameter
102102 - **\$PkgOutDir(id)** - macro function for the output directory of a package (e.g. where the ppu files are created)
103103 - **\$PkgSrcPath(id)** - macro function for the source path (unit path + src path) of a package ID given as parameter
104104 - **\$PkgUnitPath(id)** - macro function for the unit path of a package ID given as parameter
105105- **SecondaryConfigPath** - the directory of the IDE's configuration templates (since 0.9.31). See **PrimaryConfigPath**
106106- **OutputFile** - the output file (executable or library) of the current project build mode. This is the value from the "[[IDE Window: Project Options|Target file name]]" field of the Project Options (macros and relative paths are expanded).
107107- **TargetFile** - executable file (or script) for launching a project. This is the value of the "[[IDE Window: Run parameters|Host application]]" parameter from the "Run parameters" window (by default it is empty and **OutputFile** is used).
108108- **TestDir** - Test directory set in the Lazarus environment options
109109
110110## Environment
111111
112112- **BuildMode** - the name of the active build mode (since 1.1)
113113- **Env(name)** - macro function for environment variables given to the IDE (not project nor debugger) (see [GetEnvironmentVariableUTF8](http://lazarus-ccr.sourceforge.net/docs/lcl/fileutil/getenvironmentvariableutf8.html)) (since 0.9.27)
114114- **IDEBuildOptions** - the extra options of the 'Configure Build Lazarus' dialog (since 0.9.29). In Makefile: empty.
115115- **LanguageID** - IDE language, for example en for English, de for German
116116- **LanguageName** - IDE language name, the translated name of the current language. For instance: Deutsch for German.
117117- **LazVer** - Version string of the IDE (since 1.3).
118118- **FPCVer** - FPC version (since 0.9.25). For example '2.4.2'. This version is fetched from the compiler \$(CompPath), which path is set in the Lazarus environment options. **FPCVer** depends on project's compiler path.
119119- **FPC_FULLVERSION** - FPC version as one number (since 1.3). For example *20701*. This version is fetched from the compiler \$(CompPath), which path is set in the Lazarus environment options. **FPC_FullVersion** depends on project's compiler path.
120120- **SrcOS** - 'unix' for linux, darwin, bsd. 'win' for win32, win64, wince. Since 0.9.31: Use **\$SrcOS(SomeOS)** to get the SrcOS of a specific OS, for example **\$SrcOS(\$TargetOS(IDE))** to get the SrcOS of the IDE executable. **SrcOS** depends on *TargetOS*.
121121- **TargetOS** - Target OS of the current project. Since 0.9.31: Use **\$TargetOS(IDE)** to get the OS of the IDE executable. If the project has not set the **TargetOS** the IDE uses the default platform of the project's compiler (1.3 and below uses as default the IDE's platform). In Makefile it is converted to *%(OS_TARGET)*.
122122- **TargetCPU** - similar to *TargetOS*. In Makefile it is converted to *%(OS_TARGET)*.
123123- **Subtarget** - Subtarget of the current project. Since 3.99.
124124- **FPCTarget** - works similar to the FPC config macro *\$fpctarget*. It's a shortform of **\$TargetCPU(param)-\$TargetOS(param)-\$SubTarget(param)**. The -SubTarget is omitted if empty. **\$FPCTarget(IDE)** returns the IDE's target, otherwise the project's target platform. Since Lazarus 3.99.
125125- **LCLWidgetType** - LCL widgetset of the current project. In Makefile it is converted to *%(LCL_PLATFORM)*.
126126
127-\
128-
129127# Macros in IDE addons
130128
131129Here is an incomplete list of macros added by IDE packages:
132130
133131## Pas2jsDsgn
134132
135133- **Pas2JS** - Pas2JS executable
136134- **Pas2JSBrowser** - Pas2JS selected Browser executable
137135- **Pas2JSNodeJS** - Pas2JS selected NodeJS excutable
138136- **Pas2JSProjectURL** - Pas2JS current project URL
139137
140138## ProjectGroups
141139
142140- **PGSrcPaths** - source paths of all targets, i.e. projects, packages, etc. of the project group
143141
144142## Delphi compiler tool
145143
146144- **DCC** - The delphi compiler executable path, as set in the global settings.
147145- **DCCCONFIG** If the 'Generate compiler configuration' settting is checked, this contains the generated delphi compiler configuration file, prepended with @. If the setting is not set, the macro will be empty.
148146- **DCCARGS** The combined values of the global and project 'Extra compiler arguments' settings.
149147- **DCCCOMPILE** This is equivalent to \$(DCC) \$(DCCCONFIG) \$(DCCARGS).
150148
151149---
152150*From the Free Pascal wiki, page "IDE Macros in paths and filenames", as it stood on 2024-03-28 after a change by Mattias2, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
153151Category: IDE Macros
154152Category: Lazarus

Back to history