Chapter5.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns='http://www.w3.org/1999/xhtml'>
  4. <head>
  5. <title>Compile Time Commands</title>
  6. <meta name="generator" content="Halibut v1.0 (NSIS Custom Build, SVN:r?) xhtml-backend" />
  7. <link rel="stylesheet" href="style.css" type='text/css' />
  8. </head>
  9. <body>
  10. <p><a href='Chapter4.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='AppendixA.html'>Next</a></p>
  11. <ul>
  12. <li><a class="btitle" href="Chapter5.html#"><b>Chapter 5: </b>Compile Time Commands</a></li>
  13. <ul>
  14. <li><a href="Chapter5.html#compcommands">Compiler Utility Commands</a></li>
  15. <ul>
  16. <li><a href="Chapter5.html#include">!include</a></li>
  17. <li><a href="Chapter5.html#addincludedir">!addincludedir</a></li>
  18. <li><a href="Chapter5.html#addplugindir">!addplugindir</a></li>
  19. <li><a href="Chapter5.html#appendfile">!appendfile</a></li>
  20. <li><a href="Chapter5.html#cd">!cd</a></li>
  21. <li><a href="Chapter5.html#delfile">!delfile</a></li>
  22. <li><a href="Chapter5.html#echo">!echo</a></li>
  23. <li><a href="Chapter5.html#error">!error</a></li>
  24. <li><a href="Chapter5.html#execute">!execute</a></li>
  25. <li><a href="Chapter5.html#makensis">!makensis</a></li>
  26. <li><a href="Chapter5.html#packhdr">!packhdr</a></li>
  27. <li><a href="Chapter5.html#finalize">!finalize</a></li>
  28. <li><a href="Chapter5.html#system">!system</a></li>
  29. <li><a href="Chapter5.html#tempfile">!tempfile</a></li>
  30. <li><a href="Chapter5.html#ppgetdllversion">!getdllversion</a></li>
  31. <li><a href="Chapter5.html#warning">!warning</a></li>
  32. <li><a href="Chapter5.html#verbose">!verbose</a></li>
  33. </ul>
  34. <li><a href="Chapter5.html#comppredefines">Predefines</a></li>
  35. <ul>
  36. <li><a href="Chapter5.html#precounter">${__COUNTER__}</a></li>
  37. <li><a href="Chapter5.html#prefile">${__FILE__}</a></li>
  38. <li><a href="Chapter5.html#prefiledir">${__FILEDIR__}</a></li>
  39. <li><a href="Chapter5.html#preline">${__LINE__}</a></li>
  40. <li><a href="Chapter5.html#predate">${__DATE__}</a></li>
  41. <li><a href="Chapter5.html#pretime">${__TIME__}</a></li>
  42. <li><a href="Chapter5.html#pretimestamp">${__TIMESTAMP__}</a></li>
  43. <li><a href="Chapter5.html#prensisversion">${NSIS_VERSION}</a></li>
  44. <li><a href="Chapter5.html#prensispackedversion">${NSIS_PACKEDVERSION}</a></li>
  45. <li><a href="Chapter5.html#prensischarsize">${NSIS_CHAR_SIZE}</a></li>
  46. <li><a href="Chapter5.html#prensisptrsize">${NSIS_PTR_SIZE}</a></li>
  47. <li><a href="Chapter5.html#preunicodecodepoint">${U+1}...${U+10FFFF}</a></li>
  48. <li><a href="Chapter5.html#scopepredefines">Scope Predefines</a></li>
  49. </ul>
  50. <li><a href="Chapter5.html#compenvvarread">Read environment variables</a></li>
  51. <ul>
  52. <li><a href="Chapter5.html#compenvvar">$%envVarName%</a></li>
  53. </ul>
  54. <li><a href="Chapter5.html#compdefines">Conditional Compilation</a></li>
  55. <ul>
  56. <li><a href="Chapter5.html#define">!define</a></li>
  57. <li><a href="Chapter5.html#undef">!undef</a></li>
  58. <li><a href="Chapter5.html#ifdef">!ifdef</a></li>
  59. <li><a href="Chapter5.html#ifndef">!ifndef</a></li>
  60. <li><a href="Chapter5.html#if">!if</a></li>
  61. <li><a href="Chapter5.html#ifmacrodef">!ifmacrodef</a></li>
  62. <li><a href="Chapter5.html#ifmacrondef">!ifmacrondef</a></li>
  63. <li><a href="Chapter5.html#else">!else</a></li>
  64. <li><a href="Chapter5.html#endif">!endif</a></li>
  65. <li><a href="Chapter5.html#insertmacro">!insertmacro</a></li>
  66. <li><a href="Chapter5.html#macro">!macro</a></li>
  67. <li><a href="Chapter5.html#macroend">!macroend</a></li>
  68. <li><a href="Chapter5.html#macroundef">!macroundef</a></li>
  69. <li><a href="Chapter5.html#searchparse">!searchparse</a></li>
  70. <li><a href="Chapter5.html#searchreplace">!searchreplace</a></li>
  71. </ul>
  72. </ul>
  73. </ul>
  74. <a name="comptime"></a><h1>Chapter 5: Compile Time Commands</h1>
  75. <a name="compcommands"></a><h2>5.1 Compiler Utility Commands</h2>
  76. <p>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.</p>
  77. <p>Number literals support the <code>0b</code>, <code>0o</code>, <code>0n</code> and <code>0x</code> radix prefixes (base 2, 8, 10 and 16 respectively). Note: The deprecated plain <code>0</code> octal prefix is also supported in some places but its usage is discouraged.</p>
  78. <a name="include"></a><h3>5.1.1 !include</h3>
  79. <pre>[/NONFATAL] [/CHARSET=ACP|OEM|CP#|UTF8|UTF16LE|UTF16BE] file
  80. </pre>
  81. <p>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 <a href="Chapter5.html#addincludedir">!addincludedir</a> 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.</p>
  82. <pre>!include WinMessages.nsh
  83. !include Library.nsh
  84. !include /CHARSET=CP1252 C:\MyConfig.nsi
  85. !include ..\MyConfig.nsh
  86. !include /NONFATAL file_that_may_exist_or_not.nsh
  87. </pre>
  88. <a name="addincludedir"></a><h3>5.1.2 !addincludedir</h3>
  89. <pre>directory
  90. </pre>
  91. <p>Adds another include directory to the include directories list. This list is searched when <a href="Chapter5.html#include">!include</a> is used. This list's initial value is ${NSISDIR}\Include.</p>
  92. <pre>!addincludedir ..\include
  93. !include something.nsh
  94. </pre>
  95. <a name="addplugindir"></a><h3>5.1.3 !addplugindir</h3>
  96. <pre>[/x86-ansi | /x86-unicode] directory
  97. </pre>
  98. <p>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!</p>
  99. <pre>!addplugindir ..\myplugin
  100. MyPlugin::SomeFunction
  101. </pre>
  102. <a name="appendfile"></a><h3>5.1.4 !appendfile</h3>
  103. <pre>[/CHARSET=ACP|OEM|CP#|UTF8[SIG]|UTF16&lt;LE|BE&gt;[BOM]] [/RawNL] file text
  104. </pre>
  105. <p>Appends <em>text</em> to <em>file</em>. The text is written as ANSI (ACP) unless the file already has a BOM. Using /CHARSET will force a specific character encoding. <code>$\n</code> will be translated to <code>$\r$\n</code> on Windows unless you specify /RawNL.</p>
  106. <pre>!tempfile FILE
  107. !appendfile &quot;${FILE}&quot; &quot;XPStyle on$\n&quot;
  108. !appendfile &quot;${FILE}&quot; &quot;Name 'test'$\n&quot;
  109. !include &quot;${FILE}&quot;
  110. !delfile &quot;${FILE}&quot;
  111. !undef FILE
  112. </pre>
  113. <a name="cd"></a><h3>5.1.5 !cd</h3>
  114. <pre>new_path
  115. </pre>
  116. <p>This command will change the compiler to the new directory, new_path. new_path can be relative or absolute.</p>
  117. <pre>!cd ..\more-scripts\new
  118. </pre>
  119. <a name="delfile"></a><h3>5.1.6 !delfile</h3>
  120. <pre>[/nonfatal] file
  121. </pre>
  122. <p>This command deletes a file.</p>
  123. <pre>!tempfile FILE
  124. !delfile &quot;${FILE}&quot;
  125. !undef FILE
  126. </pre>
  127. <a name="echo"></a><h3>5.1.7 !echo</h3>
  128. <pre>message
  129. </pre>
  130. <p>This command will echo a message to the user compiling the script.</p>
  131. <pre>!echo &quot;hello world&quot;
  132. </pre>
  133. <a name="error"></a><h3>5.1.8 !error</h3>
  134. <pre>[message]
  135. </pre>
  136. <p>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.</p>
  137. <pre>!ifdef VERSION &amp; NOVERSION
  138. !error &quot;both VERSION and NOVERSION are defined&quot;
  139. !endif
  140. </pre>
  141. <a name="execute"></a><h3>5.1.9 !execute</h3>
  142. <pre>command [compare comparevalue | symbol]
  143. </pre>
  144. <p>This command will execute 'command' using a call to CreateProcess(). Unlike <a href="Chapter5.html#system">!system</a>, 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 <a href="Chapter5.html#execute">!execute</a> over <a href="Chapter5.html#system">!system</a> is that it does not give trouble when the current working directory is specified using UNC.</p>
  145. <p>On POSIX platforms, <a href="Chapter5.html#execute">!execute</a> will use system() just like <a href="Chapter5.html#system">!system</a>.</p>
  146. <pre>!execute '&quot;$%WINDIR%\notepad.exe&quot; /P &quot;${NSISDIR}\COPYING&quot;'
  147. </pre>
  148. <a name="makensis"></a><h3>5.1.10 !makensis</h3>
  149. <pre>parameters [compare comparevalue | symbol]
  150. </pre>
  151. <p>This command will <a href="Chapter5.html#execute">!execute</a> a new instance of MakeNSIS with the parameters you specify.</p>
  152. <pre>!makensis '-DGENERATEUNINST &quot;${__FILE__}&quot;' = 0
  153. !system '&quot;signtool&quot; sign ...' = 0
  154. </pre>
  155. <a name="packhdr"></a><h3>5.1.11 !packhdr</h3>
  156. <pre>tempfile command
  157. </pre>
  158. <p>This option makes the compiler use an external EXE packer (such as <a href="http://www.un4seen.com/petite/">Petite</a> or <a href="http://upx.sourceforge.net/">UPX</a>) to compress the executable header. Specify a temporary file name (such as &quot;temp.dat&quot;) and a command line (such as &quot;C:\program files\upx\upx -9 temp.dat&quot;) to compress the header.</p>
  159. <pre>!packhdr &quot;$%TEMP%\exehead.tmp&quot; '&quot;C:\Program Files\UPX\upx.exe&quot; &quot;$%TEMP%\exehead.tmp&quot;'
  160. </pre>
  161. <a name="finalize"></a><h3>5.1.12 !finalize</h3>
  162. <pre>command [compare comparevalue]
  163. </pre>
  164. <p>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.</p>
  165. <pre>!finalize 'sign.bat &quot;%1&quot; &quot;Product Installer&quot; http://example.com'
  166. </pre>
  167. <a name="system"></a><h3>5.1.13 !system</h3>
  168. <pre>command [compare comparevalue | symbol]
  169. </pre>
  170. <p>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 '&lt;' or '&gt;' or '&lt;&gt;' or '='.</p>
  171. <pre>!system '&quot;%WINDIR%\notepad.exe&quot; &quot;${NSISDIR}\COPYING&quot;'
  172. !system 'echo !define something &gt; newinclude.nsh'
  173. !include newinclude.nsh
  174. !ifdef something
  175. !echo &quot;something is defined&quot;
  176. !endif
  177. </pre>
  178. <a name="tempfile"></a><h3>5.1.14 !tempfile</h3>
  179. <pre>symbol
  180. </pre>
  181. <p>This command creates a temporary file. It puts its path into a define, named <em>symbol</em>.</p>
  182. <pre>!tempfile PACKHDRTEMP
  183. !packhdr &quot;${PACKHDRTEMP}&quot; '&quot;C:\Program Files\UPX\upx.exe&quot; &quot;${PACKHDRTEMP}&quot;'
  184. </pre>
  185. <pre>!tempfile FILE
  186. !define /date DATE &quot;%H:%M:%S %d %b, %Y&quot;
  187. !system 'echo built on ${DATE} &gt; &quot;${FILE}&quot;'
  188. !undef DATE
  189. File /oname=build.txt &quot;${FILE}&quot;
  190. !delfile &quot;${FILE}&quot;
  191. !undef FILE
  192. </pre>
  193. <a name="ppgetdllversion"></a><h3>5.1.15 !getdllversion</h3>
  194. <pre>localfilename define_basename
  195. </pre>
  196. <p>This is similar to <a href="Chapter4.html#getdllversionlocal">GetDLLVersionLocal</a>, only it stores the version number in defines and can therefore be used anywhere, not just inside functions and sections.</p>
  197. <pre>!getdllversion &quot;$%WINDIR%\Explorer.exe&quot; expv_
  198. !echo &quot;Explorer.exe version is ${expv_1}.${expv_2}.${expv_3}.${expv_4}&quot;
  199. </pre>
  200. <a name="warning"></a><h3>5.1.16 !warning</h3>
  201. <pre>[message]
  202. </pre>
  203. <p>This command will issue a warning to the script compiler. You can also add a message to this warning.</p>
  204. <pre>!ifdef USE_DANGEROUS_STUFF
  205. !warning &quot;using dangerous stuff&quot;
  206. !endif
  207. </pre>
  208. <a name="verbose"></a><h3>5.1.17 !verbose</h3>
  209. <pre>level | push | pop
  210. </pre>
  211. <p>This command will set the level of verbosity. 4=all, 3=no script, 2=no info, 1=no warnings, 0=none.</p>
  212. <p>Passing push will cause <a href="Chapter5.html#verbose">!verbose</a> to push the current verbosity level on a special stack. Passing pop will cause <a href="Chapter5.html#verbose">!verbose</a> to pop the current verbosity level from the same stack and use it.</p>
  213. <pre>!verbose push
  214. !verbose 1
  215. !include WinMessages.nsh
  216. !verbose pop
  217. </pre>
  218. <a name="comppredefines"></a><h2>5.2 Predefines</h2>
  219. <p>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.</p>
  220. <a name="precounter"></a><h3>5.2.1 ${__COUNTER__}</h3>
  221. <p>Expands to a number (Starting at 0 and incrementing by 1 every time it is used)</p>
  222. <a name="prefile"></a><h3>5.2.2 ${__FILE__}</h3>
  223. <p>Current script name.</p>
  224. <a name="prefiledir"></a><h3>5.2.3 ${__FILEDIR__}</h3>
  225. <p>Current script directory.</p>
  226. <a name="preline"></a><h3>5.2.4 ${__LINE__}</h3>
  227. <p>Current line number.</p>
  228. <a name="predate"></a><h3>5.2.5 ${__DATE__}</h3>
  229. <p>Date when the script started compiling according to the current locale.</p>
  230. <a name="pretime"></a><h3>5.2.6 ${__TIME__}</h3>
  231. <p>Time when the script started compiling according to the current locale.</p>
  232. <a name="pretimestamp"></a><h3>5.2.7 ${__TIMESTAMP__}</h3>
  233. <p>Date &amp; time of the last modification to the script file according to the current locale.</p>
  234. <a name="prensisversion"></a><h3>5.2.8 ${NSIS_VERSION}</h3>
  235. <p>NSIS version used to build the script.</p>
  236. <a name="prensispackedversion"></a><h3>5.2.9 ${NSIS_PACKEDVERSION}</h3>
  237. <p>NSIS version as a 32-bit number.</p>
  238. <pre>!if 0x3014000 &gt;= &quot;${NSIS_PACKEDVERSION}&quot;
  239. !error &quot;NSIS 3.15 or higher is required to build this installer!&quot;
  240. !endif
  241. </pre>
  242. <a name="prensischarsize"></a><h3>5.2.10 ${NSIS_CHAR_SIZE}</h3>
  243. <p>The size of a character code unit (in bytes). 1 in ANSI installers and 2 in Unicode installers.</p>
  244. <p>A <a href="http://unicode.org/glossary/#grapheme">grapheme</a> 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.</p>
  245. <a name="prensisptrsize"></a><h3>5.2.11 ${NSIS_PTR_SIZE}</h3>
  246. <p>The size of a pointer (in bytes) in the generated installer.</p>
  247. <a name="preunicodecodepoint"></a><h3>5.2.12 ${U+1}...${U+10FFFF}</h3>
  248. <p>A Unicode (UCS-4) character.</p>
  249. <pre>DetailPrint &quot;${U+2115}SIS&quot; # DOUBLE-STRUCK CAPITAL N + &quot;SIS&quot;
  250. </pre>
  251. <a name="scopepredefines"></a><h3>5.2.13 Scope Predefines</h3>
  252. <p>Standard predefines that contain information about the current code scope.</p>
  253. <a name="prescopeglobal"></a><h4>5.2.13.1 ${__GLOBAL__}</h4>
  254. <p>Defined in the global scope.</p>
  255. <pre>Section test
  256. !ifdef ${__GLOBAL__}
  257. !error &quot;this shouldn't be here!&quot;
  258. !endif
  259. SectionEnd
  260. PageEx instfiles
  261. !ifdef ${__GLOBAL__}
  262. !error &quot;this shouldn't be here!&quot;
  263. !endif
  264. PageExEnd
  265. </pre>
  266. <a name="prescopesection"></a><h4>5.2.13.2 ${__SECTION__}</h4>
  267. <p>Defined as the section name, without any prefixes, in <a href="Chapter4.html#ssection">section</a> scope.</p>
  268. <pre>!ifdef __SECTION__
  269. !error &quot;this shouldn't be here!&quot;
  270. !endif
  271. Section test
  272. !ifndef __SECTION__
  273. !error &quot;missing predefine!&quot;
  274. !endif
  275. !if ${__SECTION__} != test
  276. !error &quot;wrong predefine value!&quot;
  277. !endif
  278. SectionEnd
  279. Section !test
  280. !if ${__SECTION__} != test
  281. !error &quot;wrong predefine value!&quot;
  282. !endif
  283. SectionEnd
  284. Section un.test
  285. !if ${__SECTION__} != test
  286. !error &quot;wrong predefine value!&quot;
  287. !endif
  288. SectionEnd
  289. </pre>
  290. <a name="prescopefunction"></a><h4>5.2.13.3 ${__FUNCTION__}</h4>
  291. <p>Defined as the function name, without any prefixes, in <a href="Chapter4.html#ffunction">function</a> scope.</p>
  292. <pre>!ifdef __FUNCTION__
  293. !error &quot;this shouldn't be here!&quot;
  294. !endif
  295. Function test
  296. !ifndef __FUNCTION__
  297. !error &quot;missing predefine!&quot;
  298. !endif
  299. !if ${__FUNCTION__} != test
  300. !error &quot;wrong predefine value!&quot;
  301. !endif
  302. FunctionEnd
  303. Function un.test
  304. !if ${__FUNCTION__} != test
  305. !error &quot;wrong predefine value!&quot;
  306. !endif
  307. FunctionEnd
  308. </pre>
  309. <a name="prescopepageex"></a><h4>5.2.13.4 ${__PAGEEX__}</h4>
  310. <p>Defined as the page type in <a href="Chapter4.html#pageex">PageEx</a> scope.</p>
  311. <pre>!ifdef __PAGEEX__
  312. !error &quot;this shouldn't be here!&quot;
  313. !endif
  314. PageEx instfiles
  315. !ifndef __PAGEEX__
  316. !error &quot;missing predefine!&quot;
  317. !endif
  318. !if ${__PAGEEX__} != instfiles
  319. !error &quot;wrong page type&quot;
  320. !endif
  321. PageExEnd
  322. </pre>
  323. <a name="prescopeuninstall"></a><h4>5.2.13.5 ${__UNINSTALL__}</h4>
  324. <p>Defined in <a href="Chapter4.html#ssection">section</a>, <a href="Chapter4.html#ffunction">function</a> or <a href="Chapter4.html#pageex">PageEx</a> scopes of the uninstaller.</p>
  325. <pre>!ifdef __UNINSTALL__
  326. !error &quot;this shouldn't be here!&quot;
  327. !endif
  328. Function test
  329. !ifdef __UNINSTALL__
  330. !error &quot;this shouldn't be here!&quot;
  331. !endif
  332. FunctionEnd
  333. Function un.test
  334. !ifndef __UNINSTALL__
  335. !error &quot;missing predefine!&quot;
  336. !endif
  337. FunctionEnd
  338. </pre>
  339. <a name="prescopemacro"></a><h4>5.2.13.6 ${__MACRO__}</h4>
  340. <p>Defined as the name of the current macro.</p>
  341. <a name="compenvvarread"></a><h2>5.3 Read environment variables</h2>
  342. <a name="compenvvar"></a><h3>5.3.1 $%envVarName%</h3>
  343. <p>$%envVarName% will be replaced at compile time by the environment variable envVarName.</p>
  344. <a name="compdefines"></a><h2>5.4 Conditional Compilation</h2>
  345. <p>The compiler maintains a list of defined symbols, which can be defined using !define or the /D command line switch. These defined symbols can be used for conditional compilation (using !ifdef) or for symbol replacement (a simple form of macros). To replace a symbol with its value, use ${SYMBOL} (if SYMBOL is not defined, no translation will occur). The translation is first-come-first-served, meaning if you do:</p>
  346. <pre>!define symbol_one ${symbol_two}
  347. </pre>
  348. <p>If symbol_two is defined when that line occurs, it will be replaced. Otherwise, any replacing will occur when ${symbol_one} is referenced.</p>
  349. <p>Define/conditional compilation related commands:</p>
  350. <a name="define"></a><h3>5.4.1 !define</h3>
  351. <pre>[/ifndef | /redef] ([/date|/utcdate] gflag [value]) | (/math gflag val1 OP val2) | (/file gflag filename.txt)
  352. </pre>
  353. <p>This command will add <em>gflag</em> to the global define list. This will have a similar effect as using the /D switch on the command line (the define only becomes effective after the !define command).</p>
  354. <p>If <em>/date</em> or <em>/utcdate</em> are used, <em>value</em> will be passed to strftime() and the result will be used as the value of <em>gflag</em>. strftime converts special symbols into certain parts of the current time or date. For example, %H will be converted into the current hour in 24-hour format. For a complete list of available symbols, search for strftime on <a href="http://msdn.microsoft.com/">MSDN</a>. On POSIX, you can get the list by using <code>man strftime</code>.</p>
  355. <p>If <em>/math</em> is used, the result of 'val1 OP val2', where OP may be +,-,*,&amp;,|,^,/,&lt;&lt;,&gt;&gt;,&gt;&gt;&gt; or % , will be used as the value of <em>gflag</em>. Note that val1 AND val2 MUST be integer values!</p>
  356. <p>If <em>/file</em> is used, the entire text file specified (including whitespace and newlines) will be read and stuffed into <em>gflag</em>.</p>
  357. <pre>!define USE_SOMETHING
  358. !define VERSION 1.2
  359. !define /date NOW &quot;%H:%M:%S %d %b, %Y&quot;
  360. !define /math RESULT 3 + 10
  361. !define /math REST 15 % ${RESULT}
  362. !define /file BunchaStuff somesourcefile.cpp
  363. !define /redef USE_SOMETHING ${RESULT} ;redefine USE_SOMETHING
  364. </pre>
  365. <a name="undef"></a><h3>5.4.2 !undef</h3>
  366. <pre>gflag
  367. </pre>
  368. <p>Removes an item from the global define list. Note that ${SYMBOL} where SYMBOL is undefined will be translated to &quot;${SYMBOL}&quot;.</p>
  369. <pre>!define SOMETHING
  370. !undef SOMETHING
  371. </pre>
  372. <a name="ifdef"></a><h3>5.4.3 !ifdef</h3>
  373. <pre>gflag [bcheck gflag [...]]
  374. </pre>
  375. <p>This command, when paired with an !endif command, will tell the compiler whether or not to compile the lines in between the two lines. If gflag is globally defined (using !define or the /D switch), then the contained lines will be compiled. Otherwise, they will be skipped. 'bcheck' can be specified as &amp; (boolean and) or | (boolean or) along with more gflags -- precedence is simple, left to right.</p>
  376. <pre>!define SOMETHING
  377. !ifdef SOMETHING
  378. !echo &quot;SOMETHING is defined&quot;
  379. !endif
  380. !undef SOMETHING
  381. !ifdef SOMETHING
  382. !echo &quot;SOMETHING is defined&quot; # will never be printed
  383. !endif
  384. </pre>
  385. <a name="ifndef"></a><h3>5.4.4 !ifndef</h3>
  386. <pre>gflag [bcheck gflag [...]]]
  387. </pre>
  388. <p>The opposite of !ifdef. The lines will be compiled when the gflag has not been defined.</p>
  389. <a name="if"></a><h3>5.4.5 !if</h3>
  390. <pre>[!] value [op value2]
  391. [!] /FileExists &quot;c:\path\file.exe&quot;
  392. </pre>
  393. <p>This command, when paired with an !endif command, will tell the compiler whether or not to compile the lines in between the two lines. If value is non-zero, or the comparison of value and value2 depending on the operator results in true, the contained lines will be compiled. Otherwise, they will be skipped. op can be either == or != (case-insensitive string comparison), S== or S!= (case-sensitive string comparison), =, &lt;&gt;, &lt;=, &lt;, &gt; or &gt;= (int/hex/float comparison), &amp; (bitwise AND comparison), &amp;&amp; or || (boolean comparison). If [!] is set, the result will be flipped from true to false and vice versa.</p>
  394. <pre>!if 1 &lt; 0x2
  395. !echo &quot;1 is smaller than 2!!&quot;
  396. !else if ! 3.1 &gt; 1.99
  397. !error &quot;this line should never appear&quot;
  398. !else
  399. !error &quot;neither should this&quot;
  400. !endif
  401. </pre>
  402. <pre>!if /FileExists &quot;.\cert.pfx&quot;
  403. !finalize '&quot;.\sign.bat&quot; &quot;%1&quot;'
  404. !endif
  405. </pre>
  406. <a name="ifmacrodef"></a><h3>5.4.6 !ifmacrodef</h3>
  407. <pre>gflag [bcheck gflag [...]]]
  408. </pre>
  409. <p>This command, when paired with an !endif command, will tell the compiler whether or not to compile the lines in between the two lines. If the macro gflag exists, then the contained lines will be compiled. Otherwise, they will be skipped. 'bcheck' can be specified as &amp; (boolean and) or | (boolean or) along with more gflags -- precedence is simple, left to right.</p>
  410. <pre>!macro SomeMacro
  411. !macroend
  412. !ifmacrodef SomeMacro
  413. !echo &quot;SomeMacro is defined&quot;
  414. !endif
  415. </pre>
  416. <a name="ifmacrondef"></a><h3>5.4.7 !ifmacrondef</h3>
  417. <pre>gflag [bcheck gflag [...]]]
  418. </pre>
  419. <p>The opposite of !ifmacrodef. The lines will be compiled when the macro gflag does not exist.</p>
  420. <a name="else"></a><h3>5.4.8 !else</h3>
  421. <pre>[if|ifdef|ifndef|ifmacrodef|ifmacrondef [...]]
  422. </pre>
  423. <p>This command allows to easily insert different code when different defines or macros are set. You can create blocks like !ifdef/!else/!endif, !ifdef/!else ifdef/!else/!endif etc.</p>
  424. <pre>!ifdef VERSION
  425. OutFile installer-${VERSION}.exe
  426. !else
  427. OutFile installer.exe
  428. !endif
  429. </pre>
  430. <a name="endif"></a><h3>5.4.9 !endif</h3>
  431. <p>This command closes a block started with !if, !ifdef, !ifndef, !ifmacrodef or !ifmacrondef.</p>
  432. <a name="insertmacro"></a><h3>5.4.10 !insertmacro</h3>
  433. <pre>macro_name [parameter] [...]
  434. </pre>
  435. <p>Inserts the contents of a macro that was created with !macro. If the macro was created with parameters, then you must pass as many parameters to the macro as it requires.</p>
  436. <pre>!macro Print text
  437. DetailPrint &quot;${text}&quot;
  438. !macroend
  439. !insertmacro Print &quot;some text&quot;
  440. !insertmacro Print &quot;some more text&quot;
  441. </pre>
  442. <a name="macro"></a><h3>5.4.11 !macro</h3>
  443. <pre>macro_name [parameter][...]
  444. </pre>
  445. <p>Creates a macro named 'macro_name'. All lines between the !macro and the !macroend will be saved. To insert the macro later on, use !insertmacro. !macro definitions can have one or more parameters defined. The parameters may be accessed the same way a !define would (e.g. ${PARMNAME}) from inside the macro.</p>
  446. <pre>!macro SomeMacro parm1 parm2 parm3
  447. DetailPrint &quot;${parm1}&quot;
  448. MessageBox MB_OK &quot;${parm2}&quot;
  449. File &quot;${parm3}&quot;
  450. !macroend
  451. </pre>
  452. <a name="macroend"></a><h3>5.4.12 !macroend</h3>
  453. <p>Ends a macro that was started with !macro.</p>
  454. <a name="macroundef"></a><h3>5.4.13 !macroundef</h3>
  455. <pre>macro_name
  456. </pre>
  457. <p>Deletes a macro.</p>
  458. <a name="searchparse"></a><h3>5.4.14 !searchparse</h3>
  459. <pre>[/ignorecase] [/noerrors] [/file] source_string_or_file substring_start OUTPUTSYMBOL1 [substring [OUTPUTSYMBOL2 [substring ...]]]
  460. </pre>
  461. <p>Parses <em>source_string_or_file</em> (which is treated as a string, or as a filename if <em>/file</em> is set), looking for <em>substring_start</em>. If <em>substring_start</em> is found, then <em>OUTPUTSYMBOL1</em> is defined to the rest of the string (minus any other <em>substring</em> that may be found). Any number of <em>OUTPUTSYMBOLx</em> may be specified, and the final <em>substring</em> is optional.</p>
  462. <p>If <em>/noerrors</em> is specified, matching less than the full number of strings is allowed (all <em>OUTPUTSYMBOLx</em> after the not-found substring will be ignored).</p>
  463. <p>If <em>/file</em> is specified, the file is treated as a series of lines. The file is searched until all substrings are matched. If <em>/noerrors</em> is specified and not all strings are matched, the first line with the most symbols matched is used.</p>
  464. <pre># search filename.cpp for a line '#define APP_VERSION &quot;2.5&quot;' and set ${VER_MAJOR} to 2, ${VER_MINOR} to 5.
  465. !searchparse /file filename.cpp `#define APP_VERSION &quot;` VER_MAJOR `.` VER_MINOR `&quot;`
  466. </pre>
  467. <a name="searchreplace"></a><h3>5.4.15 !searchreplace</h3>
  468. <pre>[/ignorecase] symbol_out source_string searchfor replacewith
  469. </pre>
  470. <p>Searches <em>source_string</em>, looking for <em>searchfor</em> and replacing all instances of it with <em>replacewith</em>. Unlike !define, !searchreplace allows you to redefine <em>symbol_out</em> without warning or error.</p>
  471. <pre># defines ${blah} to &quot;i like ponies&quot;
  472. !searchreplace blah &quot;i love ponies&quot; &quot;love&quot; &quot;like&quot;
  473. </pre>
  474. <p><a href='Chapter4.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='AppendixA.html'>Next</a></p>
  475. <hr />
  476. <address>
  477. </address>
  478. </body>
  479. </html>