Difference between revisions of "IDE Macros in paths and filenames"

From Lazarus wiki
Jump to navigationJump to search
(Typos, clarified Lazarus environment options to distinguish from OS environment variables; sorted macros)
Line 9: Line 9:
 
=IDE macro format=
 
=IDE macro format=
  
IDE macros are used in the following format. Replacing the ''macro-name'' part with one of the macros listed below.
+
IDE macros are used in the following format. Replace the ''macro-name'' part with one of the macros listed below.
  
 
  $(macro-name)
 
  $(macro-name)
Line 41: Line 41:
  
 
=Filename Parts=
 
=Filename Parts=
* '''Ext(filename)''' - macro function for ExtractFileExt
+
* '''Ext(filename)''' - macro function for ExtractFileExt. Example: will return .exe on Windows.
 
* '''MakeDir(filename)''' - macro function for AppendPathDelim
 
* '''MakeDir(filename)''' - macro function for AppendPathDelim
 
* '''MakeFile(filename)''' - macro function for ChompPathDelim
 
* '''MakeFile(filename)''' - macro function for ChompPathDelim
* '''MakeExe(filename)''' - change file extension to .exe under Windows, nothing under Linux, BSD, OS X. When cross compiling it will create a file name of 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.
+
* '''MakeExe(filename)''' - change file extension to .exe under Windows, nothing under Linux, BSD, OS X. 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.
 
* '''MakeLib(filename)''' - change file extension to .dll under Windows, under Linux/BSD change to lowercase libname.so, under OS X to libname.so (since 0.9.29)
 
* '''MakeLib(filename)''' - change file extension to .dll under Windows, under Linux/BSD change to lowercase libname.so, under OS X to libname.so (since 0.9.29)
 
* '''Name(filename)''' - macro function for ExtractFileName
 
* '''Name(filename)''' - macro function for ExtractFileName
Line 55: Line 55:
 
* '''ConfDir''' - directory where the IDE stores its config files (same as PrimaryConfigPath).
 
* '''ConfDir''' - directory where the IDE stores its config files (same as PrimaryConfigPath).
 
* '''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().
 
* '''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().
 +
* '''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.
 
* '''FPCSrcDir''' - FPC source directory set in environment options
 
* '''FPCSrcDir''' - FPC source directory set in environment options
* '''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 environment options.
+
* '''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.
* '''FPCMsgFile''' - compiler messages file set in the environment options (since 0.9.31).
+
* '''FPCMsgFile''' - compiler messages file set in the Lazarus environment options (since 0.9.31).
 +
* '''IDEBuildOptions''' - the extra options of the 'Configure Build Lazarus' dialog (since 0.9.29). In Makefile: empty.
 
* '''InstantFPCCache''' - path of the instantfpccache. Output of running ''instantfpc --get-cache'' (since 0.9.31).
 
* '''InstantFPCCache''' - path of the instantfpccache. Output of running ''instantfpc --get-cache'' (since 0.9.31).
* '''LanguageID''' - IDE language, for example en for english, de for german
+
* '''LanguageID''' - IDE language, for example en for English, de for German
* '''LanguageName''' - IDE language name, the translated name of the current language. For instance: Deutsch for german.
+
* '''LanguageName''' - IDE language name, the translated name of the current language. For instance: Deutsch for German.
* '''LazarusDir''' - Lazarus source directory set in environment options. No macros allowed.
+
* '''LazarusDir''' - Lazarus source directory set in Lazarus environment options. No macros allowed.
* '''LCLWidgetType''' - LCL widgetset of the current project
+
* '''LCLWidgetType''' - LCL widgetset of the current project. In Makefile: %(LCL_PLATFORM)
 +
* '''Make''' - path to the make utility (gmake under BSD) (since 0.9.29)
 +
* '''PrimaryConfigPath''' - the directory of the IDE's configuration files (since 0.9.31). See '''SecondaryConfigPath'''.
 
* '''ProjFile''' - the full filename of the main source of the current project (.lpr)
 
* '''ProjFile''' - the full filename of the main source of the current project (.lpr)
* '''ProjPath''' - the project directory (the directory of the .lpi file)
 
* '''TargetFile''' - the output file of the current project (e.g. the executable or the library)
 
* '''TestDir''' - Test directory set in the environment options
 
* '''TargetCPU''' - Target CPU of the current project. In Makefile: %(CPU_TARGET). Since 0.9.31: Use '''$TargetOS(IDE)''' to get the OS of the IDE executable.
 
* '''TargetOS''' - Target OS of the current project. In Makefile: %(OS_TARGET). Since 0.9.31: Use '''$TargetCPU(IDE)''' to get the CPU of the IDE executable.
 
* '''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.
 
* '''LCLWidgetType''' - LCL widget type of the current project. In Makefile: %(LCL_PLATFORM)
 
* '''Make''' - path to the make utility (gmake under BSD) (since 0.9.29)
 
 
* '''ProjIncPath''' - include path of project directory
 
* '''ProjIncPath''' - include path of project directory
 
* '''ProjOutDir''' - path of project output directory (e.g. where the .ppu files are created) (since 0.9.27)
 
* '''ProjOutDir''' - path of project output directory (e.g. where the .ppu files are created) (since 0.9.27)
 +
* '''ProjPath''' - the project directory (the directory of the .lpi file)
 
* '''ProjPublishDir''' - publishing directory of the current project
 
* '''ProjPublishDir''' - publishing directory of the current project
 
* '''ProjSrcPath''' - source path of project directory
 
* '''ProjSrcPath''' - source path of project directory
Line 92: Line 89:
 
** '''$PkgSrcPath(id)''' - macro function for the source path (unit path + src path) of a package ID given as parameter
 
** '''$PkgSrcPath(id)''' - macro function for the source path (unit path + src path) of a package ID given as parameter
 
** '''$PkgUnitPath(id)''' - macro function for the unit path of a package ID given as parameter
 
** '''$PkgUnitPath(id)''' - macro function for the unit path of a package ID given as parameter
* '''IDEBuildOptions''' - the extra options of the 'Configure Build Lazarus' dialog (since 0.9.29). In Makefile empty.
+
* '''SecondaryConfigPath''' - the directory of the IDE's configuration templates (since 0.9.31). See '''PrimaryConfigPath'''
* '''PrimaryConfigPath''' - the directory of the IDE's configuration files (since 0.9.31)
+
* '''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.
* '''SecondaryConfigPath''' - the directory of the IDE's configuration templates (since 0.9.31)
+
* '''TargetFile''' - the output file of the current project (e.g. the executable or the library)
* '''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.
+
* '''TestDir''' - Test directory set in the Lazarus environment options
 +
* '''TargetCPU''' - Target CPU of the current project. In Makefile: %(CPU_TARGET). Since 0.9.31: Use '''$TargetOS(IDE)''' to get the OS of the IDE executable.
 +
* '''TargetOS''' - Target OS of the current project. In Makefile: %(OS_TARGET). Since 0.9.31: Use '''$TargetCPU(IDE)''' to get the CPU of the IDE executable.
 +
 
  
 
[[Category:Lazarus]]
 
[[Category:Lazarus]]

Revision as of 08:47, 30 July 2012

Deutsch (de) English (en) español (es) français (fr) português (pt) русский (ru)

There are various types of macros:

  • 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.
  • FPC macros: 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 macros DEBUG and Verbose. They are case insensitive.
  • Build macros: they are IDE macros with a limited scope. They are defined by projects and packages and are case insensitive.
  • Some IDE plugins have their own macros.

IDE macro format

IDE macros are used in the following format. Replace the macro-name part with one of the macros listed below.

$(macro-name)

For example: This "Unit Output directory" is often used for Lazarus Packages:

lib/$(TargetCPU)-$(TargetOS)
  • under a x86 Linux 32-bit system that would equate to: lib/i386-linux
  • under a x86 Linux 64-bit system that would equate to: lib/x86_64-linux

There are also some macro functions that use the following format:

$macro_name(parameters)

For example

$Ext(unit1.pas)

will give .pas.

General Purpose

  • Col - current column in source editor
  • Row - current row in source editor (screen, can differ to byte position due to tabs and UTF-8)
  • CurToken - current token at the cursor in the source editor
  • EdFile - current filename in the source editor
  • Params - run parameters of the current project
  • Prompt - ask the user for a value. This is an interactive macro.
  • RunCmdLine - the command to launch the project
  • Save - save current file in source editor
  • SaveAll - save all
  • TargetCmdLine - the project executable plus run parameters

Filename Parts

  • Ext(filename) - macro function for ExtractFileExt. Example: will return .exe on Windows.
  • MakeDir(filename) - macro function for AppendPathDelim
  • MakeFile(filename) - macro function for ChompPathDelim
  • MakeExe(filename) - change file extension to .exe under Windows, nothing under Linux, BSD, OS X. 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.
  • MakeLib(filename) - change file extension to .dll under Windows, under Linux/BSD change to lowercase libname.so, under OS X to libname.so (since 0.9.29)
  • Name(filename) - macro function for ExtractFileName
  • NameOnly(filename) - macro function for ExtractFileNameOnly
  • Path(filename) - macro function for ExtractFilePath

Paths and Parts

  • Env(name) - macro function for environment variables given to the IDE (not project nor debugger) (see GetEnvironmentVariableUTF8) (since 0.9.27)
  • CompPath - compiler path set in the environment options. Can not use the macro FPCVer, but you can use LazarusDir and Env macros.
  • ConfDir - directory where the IDE stores its config files (same as PrimaryConfigPath).
  • 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().
  • 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.
  • FPCSrcDir - FPC source directory set in environment options
  • 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.
  • FPCMsgFile - compiler messages file set in the Lazarus environment options (since 0.9.31).
  • IDEBuildOptions - the extra options of the 'Configure Build Lazarus' dialog (since 0.9.29). In Makefile: empty.
  • InstantFPCCache - path of the instantfpccache. Output of running instantfpc --get-cache (since 0.9.31).
  • LanguageID - IDE language, for example en for English, de for German
  • LanguageName - IDE language name, the translated name of the current language. For instance: Deutsch for German.
  • LazarusDir - Lazarus source directory set in Lazarus environment options. No macros allowed.
  • LCLWidgetType - LCL widgetset of the current project. In Makefile: %(LCL_PLATFORM)
  • Make - path to the make utility (gmake under BSD) (since 0.9.29)
  • PrimaryConfigPath - the directory of the IDE's configuration files (since 0.9.31). See SecondaryConfigPath.
  • ProjFile - the full filename of the main source of the current project (.lpr)
  • ProjIncPath - include path of project directory
  • ProjOutDir - path of project output directory (e.g. where the .ppu files are created) (since 0.9.27)
  • ProjPath - the project directory (the directory of the .lpi file)
  • ProjPublishDir - publishing directory of the current project
  • ProjSrcPath - source path of project directory
  • ProjUnitPath - unit path of project directory
  • Project(param) - macro function for various values:
    • Project(UnitPath) - unit path of project directory
    • Project(SrcPath) - source path of project directory
    • Project(IncPath) - include path of project directory
    • Project(InfoFile) - filename of the project information file (.lpi) (since r15287, 0.9.25)
    • Project(OutputDir) - directory where the project's ppu files are created (since 0.9.27)
  • 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.
    • $(PkgName) - in a package: gives the package name (since 0.9.31)
    • $PkgName(id) - macro function for the name of a package ID given as parameter (since 0.9.31)
    • $(PkgDir) - macro for the directory (location of the .lpk) of the package
    • $PkgDir(id) - macro function for the directory (location of the .lpk) of a package ID given as parameter
    • $PkgIncPath(id) - macro function for the include path of a package ID given as parameter
    • $PkgOutDir(id) - macro function for the output directory of a package (e.g. where the ppu files are created)
    • $PkgSrcPath(id) - macro function for the source path (unit path + src path) of a package ID given as parameter
    • $PkgUnitPath(id) - macro function for the unit path of a package ID given as parameter
  • SecondaryConfigPath - the directory of the IDE's configuration templates (since 0.9.31). See PrimaryConfigPath
  • 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.
  • TargetFile - the output file of the current project (e.g. the executable or the library)
  • TestDir - Test directory set in the Lazarus environment options
  • TargetCPU - Target CPU of the current project. In Makefile: %(CPU_TARGET). Since 0.9.31: Use $TargetOS(IDE) to get the OS of the IDE executable.
  • TargetOS - Target OS of the current project. In Makefile: %(OS_TARGET). Since 0.9.31: Use $TargetCPU(IDE) to get the CPU of the IDE executable.