Compiler Utility Commands

Nullsoft Scriptable Install System

Previous | Contents | Next

5.1 Compiler Utility Commands

These commands are similar to the C preprocessor in terms of purpose and functionality. They allow file inclusion, conditional compilation, executable header packing and process execution during the build process. Note: None of these commands allow the use of variables.

Number literals support the 0b, 0o, 0n and 0x radix prefixes (base 2, 8, 10 and 16 respectively). Note: The deprecated plain 0 octal prefix is also supported in some places but its usage is discouraged.

5.1.1 !include

[/NONFATAL] [/CHARSET=ACP|OEM|CP#|UTF8|UTF16LE|UTF16BE] file

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 !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.

!include WinMessages.nsh
!include Library.nsh
!include /CHARSET=CP1252 C:\MyConfig.nsi
!include ..\MyConfig.nsh
!include /NONFATAL file_that_may_exist_or_not.nsh

5.1.2 !addincludedir

directory

Adds another include directory to the include directories list. This list is searched when !include is used. This list's initial value is ${NSISDIR}\Include.

!addincludedir ..\include
!include something.nsh

5.1.3 !addplugindir

[/x86-ansi | /x86-unicode] directory

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!

!addplugindir ..\myplugin
MyPlugin::SomeFunction

5.1.4 !appendfile

[/CHARSET=ACP|OEM|CP#|UTF8[SIG]|UTF16<LE|BE>[BOM]] [/RawNL] file text

Appends text to file. The text is written as ANSI (ACP) unless the file already has a BOM. Using /CHARSET will force a specific character encoding. $\n will be translated to $\r$\n on Windows unless you specify /RawNL.

!tempfile FILE
!appendfile "${FILE}" "XPStyle on$\n"
!appendfile "${FILE}" "Name 'test'$\n"
!include "${FILE}"
!delfile "${FILE}"
!undef FILE

5.1.5 !cd

new_path

This command will change the compiler to the new directory, new_path. new_path can be relative or absolute.

!cd ..\more-scripts\new

5.1.6 !delfile

[/nonfatal] file

This command deletes a file.

!tempfile FILE
!delfile "${FILE}"
!undef FILE

5.1.7 !echo

message

This command will echo a message to the user compiling the script.

!echo "hello world"

5.1.8 !error

[message]

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.

!ifdef VERSION & NOVERSION
  !error "both VERSION and NOVERSION are defined"
!endif

5.1.9 !execute

command [compare comparevalue | symbol]

This command will execute 'command' using a call to CreateProcess(). Unlike !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 !execute over !system is that it does not give trouble when the current working directory is specified using UNC.

On POSIX platforms, !execute will use system() just like !system.

!execute '"$%WINDIR%\notepad.exe" /P "${NSISDIR}\COPYING"'

5.1.10 !makensis

parameters [compare comparevalue | symbol]

This command will !execute a new instance of MakeNSIS with the parameters you specify.

!makensis '-DGENERATEUNINST "${__FILE__}"' = 0
!system '"signtool" sign ...' = 0

5.1.11 !packhdr

tempfile command

This option makes the compiler use an external EXE packer (such as Petite or 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.

!packhdr "$%TEMP%\exehead.tmp" '"C:\Program Files\UPX\upx.exe" "$%TEMP%\exehead.tmp"'

5.1.12 !finalize

command [compare comparevalue]

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 executables filename.

!finalize 'sign.bat "%1" "Product Installer" http://example.com'

5.1.13 !system

command [compare comparevalue | symbol]

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 '='.

!system '"%WINDIR%\notepad.exe" "${NSISDIR}\COPYING"'
!system 'echo !define something > newinclude.nsh'
!include newinclude.nsh
!ifdef something
  !echo "something is defined"
!endif

5.1.14 !tempfile

symbol

This command creates a temporary file. It puts its path into a define, named symbol.

!tempfile PACKHDRTEMP
!packhdr "${PACKHDRTEMP}" '"C:\Program Files\UPX\upx.exe" "${PACKHDRTEMP}"'
!tempfile FILE
!define /date DATE "%H:%M:%S %d %b, %Y"
!system 'echo built on ${DATE} > "${FILE}"'
!undef DATE
File /oname=build.txt "${FILE}"
!delfile "${FILE}"
!undef FILE

5.1.15 !getdllversion

localfilename define_basename

This is similar to GetDLLVersionLocal, only it stores the version number in defines and can therefore be used anywhere, not just inside functions and sections.

!getdllversion "$%WINDIR%\Explorer.exe" expv_
!echo "Explorer.exe version is ${expv_1}.${expv_2}.${expv_3}.${expv_4}"

5.1.16 !warning

[message]

This command will issue a warning to the script compiler. You can also add a message to this warning.

!ifdef USE_DANGEROUS_STUFF
  !warning "using dangerous stuff"
!endif

5.1.17 !pragma

warning <enable|disable|default> code
warning <push|pop>

The pragma commands allows you to change compiler features and behavior.

!pragma warning disable 9000 ; Disable warning about using "Setup.exe" as the name
OutFile "Setup.exe"

5.1.18 !verbose

level | push | pop

This command will set the level of verbosity. 4=all, 3=no script, 2=no info, 1=no warnings, 0=none.

Passing push will cause !verbose to push the current verbosity level on a special stack. Passing pop will cause !verbose to pop the current verbosity level from the same stack and use it.

!verbose push
!verbose 1
!include WinMessages.nsh
!verbose pop

Previous | Contents | Next