2002-11-15 18:45:47 +00:00
\C{comptime} Compile Time Commands
\S0{compcommands} Compiler Utility Commands
2002-09-18 17:29:05 +00:00
2015-11-05 21:05:23 +00:00
These commands are similar to the C preprocessor in terms of purpose and functionality. They allow file inclusion, conditional compilation, executable header packing, and processes execution during the build process. Note: None of these commands allow the use of variables.
Number literals support the \c{0b}, \c{0o}, \c{0n} and \c{0x} radix prefixes (base 2, 8, 10 and 16 respectively). Note: The deprecated plain \c{0} octal prefix is also supported in some places but its usage is discouraged.
2002-09-18 17:29:05 +00:00
2002-11-15 18:45:47 +00:00
\S1{include} !include
2002-09-18 17:29:05 +00:00
2013-03-07 21:25:35 +00:00
\# NOTE: \NsisInputCharset define cannot be used in a \c block
2002-09-18 17:29:05 +00:00
2013-04-11 20:54:29 +00:00
\c [/NONFATAL] [/CHARSET=ACP|OEM|CP#|UTF8|UTF16LE|UTF16BE] file
2013-03-07 21:25:35 +00:00
This command will include 'file' as if it was part of the original script. Note that if a file is included in another directory, the current directory is still where the script was compiled from (not where the included file resides). If the compiler can't find the file it will look for it in every include directory. See \R{addincludedir}{!addincludedir} for more information. If the /nonfatal switch is used and no files are found, a warning will be issued instead of an error. /charset can be used to specify a codepage for plain text files without a BOM.
2003-02-08 22:42:09 +00:00
2004-10-10 18:41:43 +00:00
\c !include WinMessages.nsh
\c !include Library.nsh
2013-03-07 21:25:35 +00:00
\c !include /CHARSET=CP1252 C:\MyConfig.nsi
2004-10-10 18:41:43 +00:00
\c !include ..\MyConfig.nsh
2005-12-03 09:45:17 +00:00
\c !include /NONFATAL file_that_may_exist_or_not.nsh
2004-10-10 18:41:43 +00:00
2003-02-08 22:42:09 +00:00
\S1{addincludedir} !addincludedir
\c directory
2011-05-28 18:45:57 +00:00
Adds another include directory to the include directories list. This list is searched when \R{include}{!include} is used. This list's initial value is $\{NSISDIR\}\\Include alone.
2002-09-18 17:29:05 +00:00
2004-10-10 18:41:43 +00:00
\c !addincludedir ..\include
\c !include something.nsh
2003-04-03 14:27:38 +00:00
\S1{addplugindir} !addplugindir
2003-03-15 18:05:00 +00:00
2012-10-13 01:47:50 +00:00
\c [/x86-ansi | /x86-unicode] directory
2003-03-15 18:05:00 +00:00
2012-10-13 01:47:50 +00:00
Causes the NSIS compiler to scan the given directory for plug-in DLLs. If you don't specify the plug-in architecture it is assumed to match the current target architecture. If the architecture does not match the installer will probably crash!
2003-03-15 18:05:00 +00:00
2004-10-10 18:41:43 +00:00
\c !addplugindir myplugin
\c MyPlugin::SomeFunction
2005-10-12 14:24:21 +00:00
\S1{appendfile} !appendfile
2013-04-03 22:46:17 +00:00
\# NOTE: \NsisOutputCharset define cannot be used in a \c block
2005-10-12 14:24:21 +00:00
2015-02-26 18:19:37 +00:00
\c [/CHARSET=ACP|OEM|CP#|UTF8[SIG]|UTF16<LE|BE>[BOM]] [/RawNL] file text
2013-04-03 22:46:17 +00:00
2015-02-26 18:19:37 +00:00
Appends \e{text} to \e{file}. The text is written as ANSI (ACP) unless the file already has a BOM. Using /CHARSET will force a specific character encoding. \c{$\\n} will be translated to \c{$\\r$\\n} on Windows unless you specify /RawNL.
2005-10-12 14:24:21 +00:00
\c !tempfile FILE
\c !appendfile "${FILE}" "XPStyle on$\n"
\c !appendfile "${FILE}" "Name 'test'$\n"
\c !include "${FILE}"
\c !delfile "${FILE}"
\c !undef FILE
2002-11-15 18:45:47 +00:00
\S1{cd} !cd
2002-10-01 13:53:23 +00:00
2002-10-26 19:23:10 +00:00
\c new_path
2002-09-18 17:29:05 +00:00
2002-10-26 19:23:10 +00:00
This command will change the compiler to the new directory, new_path. new_path can be relative or absolute.
2002-09-18 17:29:05 +00:00
2004-10-10 18:41:43 +00:00
\c !cd ..\more-scripts\new
2005-10-07 13:08:44 +00:00
\S1{delfile} !delfile
\c file
This command deletes a file.
\c !tempfile FILE
\c !delfile "${FILE}"
\c !undef FILE
2002-11-15 18:45:47 +00:00
\S1{echo} !echo
2002-10-01 13:53:23 +00:00
2002-10-26 19:23:10 +00:00
\c message
2002-10-01 13:53:23 +00:00
2002-10-26 19:23:10 +00:00
This command will echo a message to the user compiling the script.
2002-10-01 13:53:23 +00:00
2004-10-10 18:41:43 +00:00
\c !echo "hello world"
2002-11-15 18:45:47 +00:00
\S1{error} !error
2002-10-01 13:53:23 +00:00
2002-10-26 19:23:10 +00:00
\c [message]
2002-10-01 13:53:23 +00:00
2002-11-10 21:41:10 +00:00
This command will issue an error to the script compiler and will stop execution of the script. You can also add a message to this error.
2002-10-01 13:53:23 +00:00
2004-10-10 18:41:43 +00:00
\c !ifdef VERSION & NOVERSION
\c !error "both VERSION and NOVERSION are defined"
\c !endif
2004-08-06 11:29:28 +00:00
\S1{execute} !execute
2014-04-13 17:49:39 +00:00
\c command [compare comparevalue | symbol]
2004-08-06 11:29:28 +00:00
2014-04-13 14:45:02 +00:00
This command will execute 'command' using a call to CreateProcess(). Unlike \R{system}{!system}, it does not use the command line processor, so input/output redirection and commands like 'cd', 'dir' and 'type' can not be used. Currently, the only known advantage of \R{execute}{!execute} over \R{system}{!system} is that it does not give trouble when the current working directory is specified using UNC.
2004-08-06 11:29:28 +00:00
2011-05-28 18:45:57 +00:00
On POSIX platforms, \R{execute}{!execute} will use system() just like \R{system}{!system}.
2004-08-06 11:29:28 +00:00
2004-10-10 18:41:43 +00:00
\c !execute '"%WINDIR%\notepad.exe" "${NSISDIR}\license.txt"'
2014-06-21 23:55:24 +00:00
\S1{makensis} !makensis
\c parameters [compare comparevalue | symbol]
This command will \R{execute}{!execute} a new instance of MakeNSIS with the parameters you specify.
\c !makensis '-DGENERATEUNINST "${__FILE__}"' = 0
\c !system '"signtool" sign ...' = 0
2002-11-15 18:45:47 +00:00
\S1{packhdr} !packhdr
2002-10-01 13:53:23 +00:00
2002-10-26 19:23:10 +00:00
\c tempfile command
2002-09-18 17:29:05 +00:00
2004-09-10 13:54:59 +00:00
This option makes the compiler use an external EXE packer (such as \W{http://www.un4seen.com/petite/}{Petite} or \W{http://upx.sourceforge.net/}{UPX}) to compress the executable header. Specify a temporary file name (such as "temp.dat") and a command line (such as "C:\\program files\\upx\\upx -9 temp.dat") to compress the header.
2002-09-19 16:31:22 +00:00
2005-06-28 19:57:16 +00:00
\c !packhdr "$%TEMP%\exehead.tmp" '"C:\Program Files\UPX\upx.exe" "$%TEMP%\exehead.tmp"'
2004-10-10 18:41:43 +00:00
2010-11-13 21:07:31 +00:00
\S1{finalize} !finalize
2010-06-16 14:19:51 +00:00
\c command
This option will execute 'command' using a call to system() after the output EXE has been generated. You can typically use it to sign (Authenticode) your installer. If 'command' contains a '%1' it will be replaced by the executable filename.
\c !finalize 'sign.bat "%1" "Product Installer" http://example.com'
2002-11-15 18:45:47 +00:00
\S1{system} !system
2002-09-19 16:31:22 +00:00
2014-04-13 17:49:39 +00:00
\c command [compare comparevalue | symbol]
2002-10-01 13:53:23 +00:00
2014-04-13 17:49:39 +00:00
This command will execute 'command' using a call to system(). You can store the return value in a define ('symbol') or halt execution if the return value compared (using 'compare') to 'comparevalue' is false. 'compare' can be '<' or '>' or '<>' or '='.
2002-10-01 13:53:23 +00:00
2004-10-10 18:41:43 +00:00
\c !system '"%WINDIR%\notepad.exe" "${NSISDIR}\license.txt"'
\c !system 'echo !define something > newinclude.nsh'
\c !include newinclude.nsh
\c !ifdef something
\c !echo "something is defined"
\c !endif
2005-10-07 13:08:44 +00:00
\S1{tempfile} !tempfile
\c symbol
This command creates a temporary file. It puts its path into a define, named \e{symbol}.
\c !tempfile PACKHDRTEMP
\c !packhdr "${PACKHDRTEMP}" '"C:\Program Files\UPX\upx.exe" "${PACKHDRTEMP}"'
\c !tempfile FILE
\c !define /date DATE "%H:%M:%S %d %b, %Y"
\c !system 'echo built on ${DATE} > "${FILE}"'
\c File /oname=build.txt "${FILE}"
\c !delfile "${FILE}"
\c !undef FILE
\c !undef DATE
2011-11-21 20:13:30 +00:00
\S1{ppgetdllversion} !getdllversion
\c localfilename define_basename
This is similar to \R{getdllversionlocal}{GetDLLVersionLocal}, only it stores the version number in defines and can therefore be used anywhere, not just inside functions and sections.
\c !getdllversion "$%windir%\explorer.exe" expv_
\c !echo "Explorer.exe version is ${expv_1}.${expv_2}.${expv_3}.${expv_4}"
2002-11-15 18:45:47 +00:00
\S1{warning} !warning
2002-09-19 16:31:22 +00:00
2002-10-26 19:23:10 +00:00
\c [message]
2002-09-19 16:31:22 +00:00
2002-10-26 19:23:10 +00:00
This command will issue a warning to the script compiler. You can also add a message to this warning.
2002-09-19 16:31:22 +00:00
2004-10-10 18:41:43 +00:00
\c !ifdef USE_DANGEROUS_STUFF
\c !warning "using dangerous stuff"
\c !endif
2002-11-15 18:45:47 +00:00
\S1{verbose} !verbose
2002-09-19 16:31:22 +00:00
2003-09-05 11:46:48 +00:00
\c level | push | pop
2002-09-19 16:31:22 +00:00
2003-09-05 11:46:48 +00:00
This command will set the level of verbosity. 4=all, 3=no script, 2=no info, 1=no warnings, 0=none.
2011-05-28 18:45:57 +00:00
Passing push will cause \R{verbose}{!verbose} to push the current verbosity level on a special stack. Passing pop will cause \R{verbose}{!verbose} to pop the current verbosity level from the same stack and use it.
2003-07-18 19:46:37 +00:00
2004-10-10 18:41:43 +00:00
\c !verbose push
\c !verbose 1
\c !include WinMessages.nsh
\c !verbose pop
2003-07-18 19:46:37 +00:00
\S0{comppredefines} Predefines
You can use these standard predefines to automatically add the build time to the title of development versions, add the date to the version number, etc.
2013-03-29 02:39:07 +00:00
\S1{precounter} $\{__COUNTER__\}
Expands to a number (Starting at 0 and incrementing by 1 every time it is used)
2003-07-18 19:46:37 +00:00
\S1{prefile} $\{__FILE__\}
Current script name.
2010-11-13 21:07:31 +00:00
\S1{prefiledir} $\{__FILEDIR__\}
2010-06-17 10:11:29 +00:00
Current script directory.
2003-07-18 19:46:37 +00:00
\S1{preline} $\{__LINE__\}
Current line number.
\S1{predate} $\{__DATE__\}
2004-11-19 15:11:17 +00:00
Date when the script started compiling according to the current locale.
2003-07-18 19:46:37 +00:00
\S1{pretime} $\{__TIME__\}
2004-11-19 15:11:17 +00:00
Time when the script started compiling according to the current locale.
2003-07-18 19:46:37 +00:00
\S1{pretimestamp} $\{__TIMESTAMP__\}
2004-11-19 15:11:17 +00:00
Date & time of the last modification to the script file according to the current locale.
2003-12-14 17:59:00 +00:00
2009-06-06 14:46:37 +00:00
\S1{prensisversion} $\{NSIS_VERSION\}
NSIS version used to build the script.
2011-12-15 20:07:37 +00:00
\S1{prensispackedversion} $\{NSIS_PACKEDVERSION\}
NSIS version as a 32 bit number.
\c !if 0x2046000 >= ${NSIS_PACKEDVERSION}
\c !error "NSIS 2.47 or higher is required to build this installer!"
\c !endif
2014-06-15 14:12:31 +00:00
\S1{preunicodecodepoint} $\{U+1\}...$\{U+10FFFF\}
2013-03-29 02:04:21 +00:00
A Unicode (UCS-4) character.
\c !define U+ABC "SIS" # Define will override
\c DetailPrint "${U+2115}${U+ABC}" # DOUBLE-STRUCK CAPITAL N + "SIS"
2007-02-17 11:22:47 +00:00
\S1{scopepredefines} Scope Predefines
2007-01-27 16:26:46 +00:00
Standard predefines that contain information of the current code scope.
2011-11-30 23:30:29 +00:00
\S2{prescopeglobal} $\{__GLOBAL__\}
2007-01-27 16:26:46 +00:00
Defined in the global scope.
\c Section test
\c
\c !ifdef ${__GLOBAL__}
\c !error "this shouldn't be here!"
\c !endif
\c
\c SectionEnd
\c
\c Function test
\c
\c !ifdef ${__GLOBAL__}
\c !error "this shouldn't be here!"
\c !endif
\c
\c FunctionEnd
\c
\c PageEx instfiles
\c
\c !ifdef ${__GLOBAL__}
\c !error "this shouldn't be here!"
\c !endif
\c
\c PageExEnd
2011-11-30 23:30:29 +00:00
\S2{prescopesection} $\{__SECTION__\}
2007-01-27 16:26:46 +00:00
Defined as the section name, without any prefixes, in \R{ssection}{section} scope.
\c !ifdef __SECTION__
\c !error "this shouldn't be here!"
\c !endif
\c
\c Section test
\c
\c !ifndef __SECTION__
\c !error "missing predefine!"
\c !endif
\c
\c !if ${__SECTION__} != test
\c !error "wrong predefine value!"
\c !endif
\c
\c SectionEnd
\c
\c Section !test
\c
\c !if ${__SECTION__} != test
\c !error "wrong predefine value!"
\c !endif
\c
\c SectionEnd
\c
\c Section un.test
\c
\c !if ${__SECTION__} != test
\c !error "wrong predefine value!"
\c !endif
\c
\c SectionEnd
2011-11-30 23:30:29 +00:00
\S2{prescopefunction} $\{__FUNCTION__\}
2007-01-27 16:26:46 +00:00
Defined as the function name, without any prefixes, in \R{ffunction}{function} scope.
\c !ifdef __FUNCTION__
\c !error "this shouldn't be here!"
\c !endif
\c
\c Function test
\c
\c !ifndef __FUNCTION__
\c !error "missing predefine!"
\c !endif
\c
\c !if ${__FUNCTION__} != test
\c !error "wrong predefine value!"
\c !endif
\c
\c FunctionEnd
\c
\c Function un.test
\c
\c !if ${__FUNCTION__} != test
\c !error "wrong predefine value!"
\c !endif
\c
\c FunctionEnd
2011-11-30 23:30:29 +00:00
\S2{prescopepageex} $\{__PAGEEX__\}
2007-01-27 16:26:46 +00:00
2007-03-18 18:33:28 +00:00
Defined as the page type in \R{pageex}{PageEx} scope.
2007-01-27 16:26:46 +00:00
\c !ifdef __PAGEEX__
\c !error "this shouldn't be here!"
\c !endif
\c
\c PageEx instfiles
\c
\c !ifndef __PAGEEX__
\c !error "missing predefine!"
\c !endif
2007-03-18 18:33:28 +00:00
\c
\c !if ${__PAGEEX__} != instfiles
\c !error "wrong page type"
\c !endif
2007-01-27 16:26:46 +00:00
\c
\c PageExEnd
2011-11-30 23:30:29 +00:00
\S2{prescopeuninstall} $\{__UNINSTALL__\}
2007-01-27 16:26:46 +00:00
Defined in \R{ssection}{section}, \R{ffunction}{function} or \R{pageex}{PageEx} scopes of the uninstaller.
\c !ifdef __UNINSTALL__
\c !error "this shouldn't be here!"
\c !endif
\c
\c Function test
\c
\c !ifdef __UNINSTALL__
\c !error "this shouldn't be here!"
\c !endif
\c
\c FunctionEnd
\c
\c Function un.test
\c
\c !ifndef __UNINSTALL__
\c !error "missing predefine!"
\c !endif
\c
\c FunctionEnd
2011-11-30 23:30:29 +00:00
\S2{prescopemacro} $\{__MACRO__\}
2011-11-13 17:31:14 +00:00
Defined as the name of the current macro.
2005-09-16 11:27:51 +00:00
\S0{compenvvarread} Read environment variables
2003-12-14 17:59:00 +00:00
\S1{compenvvar} $%envVarName%
2005-09-16 11:27:51 +00:00
$%envVarName% will be replaced on compile time by the environment variable envVarName.