summaryrefslogtreecommitdiff
path: root/Docs/src/compiler.but
blob: e344105702ed0741a68cf3681c6986b08bfe5013 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
\C{comptime} Compile Time Commands

\S0{compcommands} 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 processes execution during the build process. Note: none of these commands allow use of variables.

\S1{include} !include

\c [/NONFATAL] 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 \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.

\c !include WinMessages.nsh
\c !include Library.nsh
\c !include C:\MyConfig.nsi
\c !include ..\MyConfig.nsh
\c !include /NONFATAL file_that_may_exist_or_not.nsh

\S1{addincludedir} !addincludedir

\c 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 alone.

\c !addincludedir ..\include
\c !include something.nsh

\S1{addplugindir} !addplugindir

\c directory

Causes the NSIS compiler to scan the given directory for plug-in DLLs.

\c !addplugindir myplugin
\c MyPlugin::SomeFunction

\S1{appendfile} !appendfile

\c file text

Appends \e{text} to \e{file}.

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

\S1{cd} !cd

\c new_path

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

\c !cd ..\more-scripts\new

\S1{delfile} !delfile

\c file

This command deletes a file.

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

\S1{echo} !echo

\c message

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

\c !echo "hello world"

\S1{error} !error

\c [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.

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

\S1{execute} !execute

\c command

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. !execute also ignores the return value of the executed command. Currently, the only known advantage of !execute over \R{system}{!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 \R{system}{!system}.

\c !execute '"%WINDIR%\notepad.exe" "${NSISDIR}\license.txt"'

\S1{packhdr} !packhdr

\c tempfile command

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.

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

\S1{system} !system

\c command [compare comparevalue]

This command will execute 'command' using a call to system(), and if the return value compared (using 'compare') to 'comparevalue' is false, execution will halt. 'compare' can be '<' or '>' or '<>' or '='.

\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

\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

\S1{warning} !warning

\c [message]

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

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

\S1{verbose} !verbose

\c 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.

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

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

\S1{prefile} $\{__FILE__\}

Current script name.

\S1{preline} $\{__LINE__\}

Current line number.

\S1{predate} $\{__DATE__\}

Date when the script started compiling according to the current locale.

\S1{pretime} $\{__TIME__\}

Time when the script started compiling according to the current locale.

\S1{pretimestamp} $\{__TIMESTAMP__\}

Date & time of the last modification to the script file according to the current locale.

\S1{scopepredefines} Scope Predefines

Standard predefines that contain information of the current code scope.

\S2{} $\{__GLOBAL__\}

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

\S2{} $\{__SECTION__\}

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

\S2{} $\{__FUNCTION__\}

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

\S2{} $\{__PAGEEX__\}

Defined as the page type in \R{pageex}{PageEx} scope.

\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
\c
\c   !if ${__PAGEEX__} != instfiles
\c     !error "wrong page type"
\c   !endif
\c 
\c PageExEnd

\S2{} $\{__UNINSTALL__\}

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

\S0{compenvvarread} Read environment variables

\S1{compenvvar} $%envVarName%

$%envVarName% will be replaced on compile time by the environment variable envVarName.