Debian Codegraph @

Docs/src/compiler.but

raw
1 \C{comptime} Compile Time Commands
2
3 \S0{compcommands} Compiler Utility Commands
4
5 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 \R{variables}{variables}.
6
7 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.
8
9 \S1{include} !include
10
11 \# NOTE: \NsisInputCharset define cannot be used in a \c block
12
13 \c [/NONFATAL] [/CHARSET=ACP|OEM|CP#|UTF8|UTF16LE|UTF16BE] file
14
15 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.
16
17 \c !include WinMessages.nsh
18 \c !include Library.nsh
19 \c !include /CHARSET=CP1252 C:\MyConfig.nsi
20 \c !include ..\MyConfig.nsh
21 \c !include /NONFATAL file_that_may_exist_or_not.nsh
22
23 \S1{addincludedir} !addincludedir
24
25 \c directory
26
27 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.
28
29 \c !addincludedir ..\include
30 \c !include something.nsh
31
32 \S1{addplugindir} !addplugindir
33
34 \c [/x86-ansi | /x86-unicode] directory
35
36 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!
37
38 \c !addplugindir ..\myplugin
39 \c MyPlugin::SomeFunction
40
41 \S1{appendfile} !appendfile
42
43 \# NOTE: \NsisOutputCharset define cannot be used in a \c block
44
45 \c [/CHARSET=ACP|OEM|CP#|UTF8[SIG]|UTF16<LE|BE>[BOM]] [/RawNL] file text
46
47 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.
48
49 \c !tempfile FILE
50 \c !appendfile "${FILE}" "XPStyle on$\n"
51 \c !appendfile "${FILE}" "Name 'test'$\n"
52 \c !include "${FILE}"
53 \c !delfile "${FILE}"
54 \c !undef FILE
55
56 \S1{cd} !cd
57
58 \c new_path
59
60 This command will change the compiler to the new directory, new_path. new_path can be relative or absolute.
61
62 \c !cd ..\more-scripts\new
63
64 \S1{delfile} !delfile
65
66 \c [/nonfatal] file
67
68 This command deletes a file.
69
70 \c !tempfile FILE
71 \c !delfile "${FILE}"
72 \c !undef FILE
73
74 \S1{echo} !echo
75
76 \c message
77
78 This command will echo a message to the user compiling the script.
79
80 \c !echo "hello world"
81
82 \S1{error} !error
83
84 \c [message]
85
86 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.
87
88 \c !ifdef VERSION & NOVERSION
89 \c !error "both VERSION and NOVERSION are defined"
90 \c !endif
91
92 \S1{assert} !assert
93
94 \c value [op value2] message
95
96 This command will stop the compiler if the expression is not true. The expression is evaluated in a similar fashion to \R{if}{!if}.
97
98 \c !assert ${NSIS_CHAR_SIZE} = 2 "Unicode required"
99
100 \S1{execute} !execute
101
102 \c command [compare comparevalue | symbol]
103
104 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.
105
106 On POSIX platforms, \R{execute}{!execute} will use system() just like \R{system}{!system}.
107
108 \c !execute '"$%WINDIR%\notepad.exe" /P "${NSISDIR}\COPYING"'
109
110 \S1{makensis} !makensis
111
112 \c parameters [compare comparevalue | symbol]
113
114 This command will \R{execute}{!execute} a new instance of MakeNSIS with the parameters you specify.
115
116 \c !makensis '-DGENERATEUNINST "${__FILE__}"' = 0
117 \c !system '"signtool" sign ...' = 0
118
119 \S1{packhdr} !packhdr
120
121 \c tempfile command
122
123 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.
124
125 \c !packhdr "$%TEMP%\exehead.tmp" '"C:\Program Files\UPX\upx.exe" "$%TEMP%\exehead.tmp"'
126
127 \S1{finalize} !finalize
128
129 \c command [compare comparevalue]
130
131 This option will execute 'command' using a call to system() after the installer 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.
132
133 \c !finalize 'sign.bat "%1" "MyProduct Installer" http://example.com'
134
135 \S1{uninstfinalize} !uninstfinalize
136
137 \c command [compare comparevalue]
138
139 This option will execute 'command' using a call to system() after the uninstaller EXE has been generated. You can typically use it to sign (Authenticode) your uninstaller. If 'command' contains a '%1' it will be replaced by the executables filename.
140
141 \c !uninstfinalize 'sign.bat "%1" "MyProduct Installer" http://example.com'
142
143 \S1{system} !system
144
145 \c command [compare comparevalue | symbol]
146
147 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 '='.
148
149 \c !system '"%WINDIR%\notepad.exe" "${NSISDIR}\COPYING"'
150 \c !system 'echo !define something > newinclude.nsh'
151 \c !include newinclude.nsh
152 \c !ifdef something
153 \c !echo "something is defined"
154 \c !endif
155 \c !system 'attrib +H Secret.txt' = 0
156 \c !system 'ping localhost' ERRLVL
157 \c !echo "Ping returned ${ERRLVL}"
158
159 \S1{tempfile} !tempfile
160
161 \c symbol
162
163 This command creates a temporary file. It puts its path into a define, named \e{symbol}.
164
165 \c !tempfile PACKHDRTEMP
166 \c !packhdr "${PACKHDRTEMP}" '"C:\Program Files\UPX\upx.exe" "${PACKHDRTEMP}"'
167
168 \c !tempfile FILE
169 \c !define /date DATE "%H:%M:%S %d %b, %Y"
170 \c !system 'echo built on ${DATE} > "${FILE}"'
171 \c !undef DATE
172 \c File /oname=build.txt "${FILE}"
173 \c !delfile "${FILE}"
174 \c !undef FILE
175
176 \S1{ppgetdllversion} !getdllversion
177
178 \c [/noerrors] [/packed] [/productversion] localfilename define_basename
179
180 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. /packed returns the information in two DWORDs.
181
182 \c !getdllversion "$%WINDIR%\Explorer.exe" Expv_
183 \c !echo "Explorer.exe version is ${Expv_1}.${Expv_2}.${Expv_3}.${Expv_4}"
184
185 \S1{ppgettlbversion} !gettlbversion
186
187 \c [/noerrors] [/packed] localfilename define_basename
188
189 Get the version information from a .TLB file.
190
191 \c !gettlbversion /packed "$%WINDIR%\System32\stdole32.tlb" TLBVER_
192 \c !echo "${TLBVER_HIGH}.${TLBVER_LOW}"
193
194 \S1{warning} !warning
195
196 \c [message]
197
198 This command will issue a warning to the script compiler. You can also add a message to this warning.
199
200 \c !ifdef USE_DANGEROUS_STUFF
201 \c !warning "using dangerous stuff"
202 \c !endif
203
204 \S1{pragma} !pragma
205
206 \c warning <enable|disable|default|error|warning> <code|all>
207 \c warning <push|pop>
208
209 The pragma commands allows you to change compiler features and behavior.
210
211 \c !pragma warning disable 9000 ; Disable warning about using "Setup.exe" as the name
212 \c OutFile "Setup.exe"
213
214 \S1{verbose} !verbose
215
216 \c level | push | pop
217
218 This command will set the level of verbosity: 4=all, 3=no script, 2=no info, 1=no warnings, 0=none.
219
220 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.
221
222 \c !verbose push
223 \c !verbose 1
224 \c !include WinMessages.nsh
225 \c !verbose pop
226
227 \S0{comppredefines} Predefines
228
229 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.
230
231 \S1{precounter} $\{__COUNTER__\}
232
233 Expands to a number (Starting at 0 and incrementing by 1 every time it is used)
234
235 \S1{prefile} $\{__FILE__\}
236
237 Current script name.
238
239 \S1{prefiledir} $\{__FILEDIR__\}
240
241 Current script directory.
242
243 \S1{preline} $\{__LINE__\}
244
245 Current line number.
246
247 \S1{predate} $\{__DATE__\}
248
249 Date when the script started compiling according to the current locale.
250
251 \S1{pretime} $\{__TIME__\}
252
253 Time when the script started compiling according to the current locale.
254
255 \S1{pretimestamp} $\{__TIMESTAMP__\}
256
257 Date & time of the last modification to the script file according to the current locale.
258
259 \S1{prensisversion} $\{NSIS_VERSION\}
260
261 NSIS version used to build the script.
262
263 \S1{prensispackedversion} $\{NSIS_PACKEDVERSION\}
264
265 NSIS version as a 32-bit number.
266
267 \c !if 0x3014000 >= "${NSIS_PACKEDVERSION}"
268 \c !error "NSIS 3.15 or higher is required to build this installer!"
269 \c !endif
270
271 \S1{prensischarsize} $\{NSIS_CHAR_SIZE\}
272
273 The size of a character code unit (in bytes). 1 in ANSI installers and 2 in Unicode installers.
274
275 A \W{http://unicode.org/glossary/#grapheme}{grapheme} cluster consists of a base character plus optional combining characters and diacritics and is defined as one or more code points. One or more code units is required to encode a single code point.
276
277 \S1{prensisptrsize} $\{NSIS_PTR_SIZE\}
278
279 The size of a pointer (in bytes) in the generated installer.
280
281 \S1{preunicodecodepoint} $\{U+1\}...$\{U+10FFFF\}
282
283 A Unicode (UCS-4) character.
284
285 \c DetailPrint "${U+2115}SIS" # DOUBLE-STRUCK CAPITAL N + "SIS"
286
287 \S1{scopepredefines} Scope Predefines
288
289 Standard predefines that contain information about the current code scope.
290
291 \S2{prescopeglobal} $\{__GLOBAL__\}
292
293 Defined in the global scope.
294
295 \c Section test
296 \c !ifdef __GLOBAL__
297 \c !error "this shouldn't be here!"
298 \c !endif
299 \c SectionEnd
300 \c
301 \c PageEx instfiles
302 \c !ifdef __GLOBAL__
303 \c !error "this shouldn't be here!"
304 \c !endif
305 \c PageExEnd
306
307 \S2{prescopesection} $\{__SECTION__\}
308
309 Defined as the section name, without any prefixes, in \R{ssection}{section} scope.
310
311 \c !ifdef __SECTION__
312 \c !error "this shouldn't be here!"
313 \c !endif
314 \c
315 \c Section test
316 \c !ifndef __SECTION__
317 \c !error "missing predefine!"
318 \c !endif
319 \c
320 \c !if ${__SECTION__} != test
321 \c !error "wrong predefine value!"
322 \c !endif
323 \c SectionEnd
324 \c
325 \c Section !test
326 \c !if ${__SECTION__} != test
327 \c !error "wrong predefine value!"
328 \c !endif
329 \c SectionEnd
330 \c
331 \c Section un.test
332 \c !if ${__SECTION__} != test
333 \c !error "wrong predefine value!"
334 \c !endif
335 \c SectionEnd
336
337 \S2{prescopefunction} $\{__FUNCTION__\}
338
339 Defined as the function name, without any prefixes, in \R{ffunction}{function} scope.
340
341 \c !ifdef __FUNCTION__
342 \c !error "this shouldn't be here!"
343 \c !endif
344 \c
345 \c Function test
346 \c !ifndef __FUNCTION__
347 \c !error "missing predefine!"
348 \c !endif
349 \c
350 \c !if ${__FUNCTION__} != test
351 \c !error "wrong predefine value!"
352 \c !endif
353 \c FunctionEnd
354 \c
355 \c Function un.test
356 \c !if ${__FUNCTION__} != test
357 \c !error "wrong predefine value!"
358 \c !endif
359 \c FunctionEnd
360
361 \S2{prescopepageex} $\{__PAGEEX__\}
362
363 Defined as the page type in \R{pageex}{PageEx} scope.
364
365 \c !ifdef __PAGEEX__
366 \c !error "this shouldn't be here!"
367 \c !endif
368 \c
369 \c PageEx instfiles
370 \c !ifndef __PAGEEX__
371 \c !error "missing predefine!"
372 \c !endif
373 \c
374 \c !if ${__PAGEEX__} != instfiles
375 \c !error "wrong page type"
376 \c !endif
377 \c PageExEnd
378
379 \S2{prescopeuninstall} $\{__UNINSTALL__\}
380
381 Defined in \R{ssection}{section}, \R{ffunction}{function} or \R{pageex}{PageEx} scopes of the uninstaller.
382
383 \c !ifdef __UNINSTALL__
384 \c !error "this shouldn't be here!"
385 \c !endif
386 \c
387 \c Function test
388 \c !ifdef __UNINSTALL__
389 \c !error "this shouldn't be here!"
390 \c !endif
391 \c FunctionEnd
392 \c
393 \c Function un.test
394 \c !ifndef __UNINSTALL__
395 \c !error "missing predefine!"
396 \c !endif
397 \c FunctionEnd
398
399 \S2{prescopemacro} $\{__MACRO__\}
400
401 Defined as the name of the current macro.
402
403 \S0{compenvvarread} Read environment variables
404
405 \S1{compenvvar} $%envVarName%
406
407 $%envVarName% will be replaced at compile time by the environment variable envVarName.