Chapter5.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Compile Time Commands</title>
  4. <meta name="viewport" content="width=device-width, initial-scale=1" /><meta name="generator" content="Halibut v1.0 (NSIS Custom Build, SVN:r7318) xhtml-backend" />
  5. <link rel="stylesheet" href="style.css" type='text/css' />
  6. </head>
  7. <body>
  8. <p><a href='Chapter4.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='AppendixA.html'>Next</a></p>
  9. <ul>
  10. <li><a class="btitle" href="Chapter5.html#"><b>Chapter 5: </b>Compile Time Commands</a></li>
  11. <ul>
  12. <li><a href="Chapter5.html#compcommands">Compiler Utility Commands</a></li>
  13. <ul>
  14. <li><a href="Chapter5.html#include">!include</a></li>
  15. <li><a href="Chapter5.html#addincludedir">!addincludedir</a></li>
  16. <li><a href="Chapter5.html#addplugindir">!addplugindir</a></li>
  17. <li><a href="Chapter5.html#appendfile">!appendfile</a></li>
  18. <li><a href="Chapter5.html#cd">!cd</a></li>
  19. <li><a href="Chapter5.html#delfile">!delfile</a></li>
  20. <li><a href="Chapter5.html#echo">!echo</a></li>
  21. <li><a href="Chapter5.html#error">!error</a></li>
  22. <li><a href="Chapter5.html#execute">!execute</a></li>
  23. <li><a href="Chapter5.html#makensis">!makensis</a></li>
  24. <li><a href="Chapter5.html#packhdr">!packhdr</a></li>
  25. <li><a href="Chapter5.html#finalize">!finalize</a></li>
  26. <li><a href="Chapter5.html#uninstfinalize">!uninstfinalize</a></li>
  27. <li><a href="Chapter5.html#system">!system</a></li>
  28. <li><a href="Chapter5.html#tempfile">!tempfile</a></li>
  29. <li><a href="Chapter5.html#ppgetdllversion">!getdllversion</a></li>
  30. <li><a href="Chapter5.html#ppgettlbversion">!gettlbversion</a></li>
  31. <li><a href="Chapter5.html#warning">!warning</a></li>
  32. <li><a href="Chapter5.html#pragma">!pragma</a></li>
  33. <li><a href="Chapter5.html#verbose">!verbose</a></li>
  34. </ul>
  35. <li><a href="Chapter5.html#comppredefines">Predefines</a></li>
  36. <ul>
  37. <li><a href="Chapter5.html#precounter">${__COUNTER__}</a></li>
  38. <li><a href="Chapter5.html#prefile">${__FILE__}</a></li>
  39. <li><a href="Chapter5.html#prefiledir">${__FILEDIR__}</a></li>
  40. <li><a href="Chapter5.html#preline">${__LINE__}</a></li>
  41. <li><a href="Chapter5.html#predate">${__DATE__}</a></li>
  42. <li><a href="Chapter5.html#pretime">${__TIME__}</a></li>
  43. <li><a href="Chapter5.html#pretimestamp">${__TIMESTAMP__}</a></li>
  44. <li><a href="Chapter5.html#prensisversion">${NSIS_VERSION}</a></li>
  45. <li><a href="Chapter5.html#prensispackedversion">${NSIS_PACKEDVERSION}</a></li>
  46. <li><a href="Chapter5.html#prensischarsize">${NSIS_CHAR_SIZE}</a></li>
  47. <li><a href="Chapter5.html#prensisptrsize">${NSIS_PTR_SIZE}</a></li>
  48. <li><a href="Chapter5.html#preunicodecodepoint">${U+1}...${U+10FFFF}</a></li>
  49. <li><a href="Chapter5.html#scopepredefines">Scope Predefines</a></li>
  50. </ul>
  51. <li><a href="Chapter5.html#compenvvarread">Read environment variables</a></li>
  52. <ul>
  53. <li><a href="Chapter5.html#compenvvar">$%envVarName%</a></li>
  54. </ul>
  55. <li><a href="Chapter5.html#compdefines">Conditional Compilation</a></li>
  56. <ul>
  57. <li><a href="Chapter5.html#define">!define</a></li>
  58. <li><a href="Chapter5.html#undef">!undef</a></li>
  59. <li><a href="Chapter5.html#ifdef">!ifdef</a></li>
  60. <li><a href="Chapter5.html#ifndef">!ifndef</a></li>
  61. <li><a href="Chapter5.html#if">!if</a></li>
  62. <li><a href="Chapter5.html#ifmacrodef">!ifmacrodef</a></li>
  63. <li><a href="Chapter5.html#ifmacrondef">!ifmacrondef</a></li>
  64. <li><a href="Chapter5.html#else">!else</a></li>
  65. <li><a href="Chapter5.html#endif">!endif</a></li>
  66. <li><a href="Chapter5.html#insertmacro">!insertmacro</a></li>
  67. <li><a href="Chapter5.html#macro">!macro</a></li>
  68. <li><a href="Chapter5.html#macroend">!macroend</a></li>
  69. <li><a href="Chapter5.html#macroundef">!macroundef</a></li>
  70. <li><a href="Chapter5.html#searchparse">!searchparse</a></li>
  71. <li><a href="Chapter5.html#searchreplace">!searchreplace</a></li>
  72. </ul>
  73. </ul>
  74. </ul>
  75. <a name="comptime"></a><h1>Chapter 5: Compile Time Commands</h1>
  76. <a name="compcommands"></a><h2>5.1 Compiler Utility Commands</h2>
  77. <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 <a href="Chapter4.html#variables">variables</a>.</p>
  78. <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>
  79. <a name="include"></a><h3>5.1.1 !include</h3>
  80. <pre>[/NONFATAL] [/CHARSET=ACP|OEM|CP#|UTF8|UTF16LE|UTF16BE] file
  81. </pre>
  82. <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>
  83. <pre>!include WinMessages.nsh
  84. !include Library.nsh
  85. !include /CHARSET=CP1252 C:\MyConfig.nsi
  86. !include ..\MyConfig.nsh
  87. !include /NONFATAL file_that_may_exist_or_not.nsh
  88. </pre>
  89. <a name="addincludedir"></a><h3>5.1.2 !addincludedir</h3>
  90. <pre>directory
  91. </pre>
  92. <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>
  93. <pre>!addincludedir ..\include
  94. !include something.nsh
  95. </pre>
  96. <a name="addplugindir"></a><h3>5.1.3 !addplugindir</h3>
  97. <pre>[/x86-ansi | /x86-unicode] directory
  98. </pre>
  99. <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>
  100. <pre>!addplugindir ..\myplugin
  101. MyPlugin::SomeFunction
  102. </pre>
  103. <a name="appendfile"></a><h3>5.1.4 !appendfile</h3>
  104. <pre>[/CHARSET=ACP|OEM|CP#|UTF8[SIG]|UTF16&lt;LE|BE&gt;[BOM]] [/RawNL] file text
  105. </pre>
  106. <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>
  107. <pre>!tempfile FILE
  108. !appendfile &quot;${FILE}&quot; &quot;XPStyle on$\n&quot;
  109. !appendfile &quot;${FILE}&quot; &quot;Name 'test'$\n&quot;
  110. !include &quot;${FILE}&quot;
  111. !delfile &quot;${FILE}&quot;
  112. !undef FILE
  113. </pre>
  114. <a name="cd"></a><h3>5.1.5 !cd</h3>
  115. <pre>new_path
  116. </pre>
  117. <p>This command will change the compiler to the new directory, new_path. new_path can be relative or absolute.</p>
  118. <pre>!cd ..\more-scripts\new
  119. </pre>
  120. <a name="delfile"></a><h3>5.1.6 !delfile</h3>
  121. <pre>[/nonfatal] file
  122. </pre>
  123. <p>This command deletes a file.</p>
  124. <pre>!tempfile FILE
  125. !delfile &quot;${FILE}&quot;
  126. !undef FILE
  127. </pre>
  128. <a name="echo"></a><h3>5.1.7 !echo</h3>
  129. <pre>message
  130. </pre>
  131. <p>This command will echo a message to the user compiling the script.</p>
  132. <pre>!echo &quot;hello world&quot;
  133. </pre>
  134. <a name="error"></a><h3>5.1.8 !error</h3>
  135. <pre>[message]
  136. </pre>
  137. <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>
  138. <pre>!ifdef VERSION &amp; NOVERSION
  139. !error &quot;both VERSION and NOVERSION are defined&quot;
  140. !endif
  141. </pre>
  142. <a name="execute"></a><h3>5.1.9 !execute</h3>
  143. <pre>command [compare comparevalue | symbol]
  144. </pre>
  145. <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>
  146. <p>On POSIX platforms, <a href="Chapter5.html#execute">!execute</a> will use system() just like <a href="Chapter5.html#system">!system</a>.</p>
  147. <pre>!execute '&quot;$%WINDIR%\notepad.exe&quot; /P &quot;${NSISDIR}\COPYING&quot;'
  148. </pre>
  149. <a name="makensis"></a><h3>5.1.10 !makensis</h3>
  150. <pre>parameters [compare comparevalue | symbol]
  151. </pre>
  152. <p>This command will <a href="Chapter5.html#execute">!execute</a> a new instance of MakeNSIS with the parameters you specify.</p>
  153. <pre>!makensis '-DGENERATEUNINST &quot;${__FILE__}&quot;' = 0
  154. !system '&quot;signtool&quot; sign ...' = 0
  155. </pre>
  156. <a name="packhdr"></a><h3>5.1.11 !packhdr</h3>
  157. <pre>tempfile command
  158. </pre>
  159. <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>
  160. <pre>!packhdr &quot;$%TEMP%\exehead.tmp&quot; '&quot;C:\Program Files\UPX\upx.exe&quot; &quot;$%TEMP%\exehead.tmp&quot;'
  161. </pre>
  162. <a name="finalize"></a><h3>5.1.12 !finalize</h3>
  163. <pre>command [compare comparevalue]
  164. </pre>
  165. <p>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.</p>
  166. <pre>!finalize 'sign.bat &quot;%1&quot; &quot;MyProduct Installer&quot; http://example.com'
  167. </pre>
  168. <a name="uninstfinalize"></a><h3>5.1.13 !uninstfinalize</h3>
  169. <pre>command [compare comparevalue]
  170. </pre>
  171. <p>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.</p>
  172. <pre>!uninstfinalize 'sign.bat &quot;%1&quot; &quot;MyProduct Installer&quot; http://example.com'
  173. </pre>
  174. <a name="system"></a><h3>5.1.14 !system</h3>
  175. <pre>command [compare comparevalue | symbol]
  176. </pre>
  177. <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>
  178. <pre>!system '&quot;%WINDIR%\notepad.exe&quot; &quot;${NSISDIR}\COPYING&quot;'
  179. !system 'echo !define something &gt; newinclude.nsh'
  180. !include newinclude.nsh
  181. !ifdef something
  182. !echo &quot;something is defined&quot;
  183. !endif
  184. !system 'attrib +H Secret.txt' = 0
  185. !system 'ping localhost' ERRLVL
  186. !echo &quot;Ping returned ${ERRLVL}&quot;
  187. </pre>
  188. <a name="tempfile"></a><h3>5.1.15 !tempfile</h3>
  189. <pre>symbol
  190. </pre>
  191. <p>This command creates a temporary file. It puts its path into a define, named <em>symbol</em>.</p>
  192. <pre>!tempfile PACKHDRTEMP
  193. !packhdr &quot;${PACKHDRTEMP}&quot; '&quot;C:\Program Files\UPX\upx.exe&quot; &quot;${PACKHDRTEMP}&quot;'
  194. </pre>
  195. <pre>!tempfile FILE
  196. !define /date DATE &quot;%H:%M:%S %d %b, %Y&quot;
  197. !system 'echo built on ${DATE} &gt; &quot;${FILE}&quot;'
  198. !undef DATE
  199. File /oname=build.txt &quot;${FILE}&quot;
  200. !delfile &quot;${FILE}&quot;
  201. !undef FILE
  202. </pre>
  203. <a name="ppgetdllversion"></a><h3>5.1.16 !getdllversion</h3>
  204. <pre>[/noerrors] [/packed] [/productversion] localfilename define_basename
  205. </pre>
  206. <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. /packed returns the information in two DWORDs.</p>
  207. <pre>!getdllversion &quot;$%WINDIR%\Explorer.exe&quot; Expv_
  208. !echo &quot;Explorer.exe version is ${Expv_1}.${Expv_2}.${Expv_3}.${Expv_4}&quot;
  209. </pre>
  210. <a name="ppgettlbversion"></a><h3>5.1.17 !gettlbversion</h3>
  211. <pre>[/noerrors] [/packed] localfilename define_basename
  212. </pre>
  213. <p>Get the version information from a .TLB file.</p>
  214. <pre>!gettlbversion /packed &quot;$%WINDIR%\System32\stdole32.tlb&quot; TLBVER_
  215. !echo &quot;${TLBVER_HIGH}.${TLBVER_LOW}&quot;
  216. </pre>
  217. <a name="warning"></a><h3>5.1.18 !warning</h3>
  218. <pre>[message]
  219. </pre>
  220. <p>This command will issue a warning to the script compiler. You can also add a message to this warning.</p>
  221. <pre>!ifdef USE_DANGEROUS_STUFF
  222. !warning &quot;using dangerous stuff&quot;
  223. !endif
  224. </pre>
  225. <a name="pragma"></a><h3>5.1.19 !pragma</h3>
  226. <pre>warning &lt;enable|disable|default|error|warning&gt; &lt;code|all&gt;
  227. warning &lt;push|pop&gt;
  228. </pre>
  229. <p>The pragma commands allows you to change compiler features and behavior.</p>
  230. <pre>!pragma warning disable 9000 ; Disable warning about using &quot;Setup.exe&quot; as the name
  231. OutFile &quot;Setup.exe&quot;
  232. </pre>
  233. <a name="verbose"></a><h3>5.1.20 !verbose</h3>
  234. <pre>level | push | pop
  235. </pre>
  236. <p>This command will set the level of verbosity: 4=all, 3=no script, 2=no info, 1=no warnings, 0=none.</p>
  237. <p>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.</p>
  238. <pre>!verbose push
  239. !verbose 1
  240. !include WinMessages.nsh
  241. !verbose pop
  242. </pre>
  243. <a name="comppredefines"></a><h2>5.2 Predefines</h2>
  244. <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>
  245. <a name="precounter"></a><h3>5.2.1 ${__COUNTER__}</h3>
  246. <p>Expands to a number (Starting at 0 and incrementing by 1 every time it is used)</p>
  247. <a name="prefile"></a><h3>5.2.2 ${__FILE__}</h3>
  248. <p>Current script name.</p>
  249. <a name="prefiledir"></a><h3>5.2.3 ${__FILEDIR__}</h3>
  250. <p>Current script directory.</p>
  251. <a name="preline"></a><h3>5.2.4 ${__LINE__}</h3>
  252. <p>Current line number.</p>
  253. <a name="predate"></a><h3>5.2.5 ${__DATE__}</h3>
  254. <p>Date when the script started compiling according to the current locale.</p>
  255. <a name="pretime"></a><h3>5.2.6 ${__TIME__}</h3>
  256. <p>Time when the script started compiling according to the current locale.</p>
  257. <a name="pretimestamp"></a><h3>5.2.7 ${__TIMESTAMP__}</h3>
  258. <p>Date &amp; time of the last modification to the script file according to the current locale.</p>
  259. <a name="prensisversion"></a><h3>5.2.8 ${NSIS_VERSION}</h3>
  260. <p>NSIS version used to build the script.</p>
  261. <a name="prensispackedversion"></a><h3>5.2.9 ${NSIS_PACKEDVERSION}</h3>
  262. <p>NSIS version as a 32-bit number.</p>
  263. <pre>!if 0x3014000 &gt;= &quot;${NSIS_PACKEDVERSION}&quot;
  264. !error &quot;NSIS 3.15 or higher is required to build this installer!&quot;
  265. !endif
  266. </pre>
  267. <a name="prensischarsize"></a><h3>5.2.10 ${NSIS_CHAR_SIZE}</h3>
  268. <p>The size of a character code unit (in bytes). 1 in ANSI installers and 2 in Unicode installers.</p>
  269. <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>
  270. <a name="prensisptrsize"></a><h3>5.2.11 ${NSIS_PTR_SIZE}</h3>
  271. <p>The size of a pointer (in bytes) in the generated installer.</p>
  272. <a name="preunicodecodepoint"></a><h3>5.2.12 ${U+1}...${U+10FFFF}</h3>
  273. <p>A Unicode (UCS-4) character.</p>
  274. <pre>DetailPrint &quot;${U+2115}SIS&quot; # DOUBLE-STRUCK CAPITAL N + &quot;SIS&quot;
  275. </pre>
  276. <a name="scopepredefines"></a><h3>5.2.13 Scope Predefines</h3>
  277. <p>Standard predefines that contain information about the current code scope.</p>
  278. <a name="prescopeglobal"></a><h4>5.2.13.1 ${__GLOBAL__}</h4>
  279. <p>Defined in the global scope.</p>
  280. <pre>Section test
  281. !ifdef __GLOBAL__
  282. !error &quot;this shouldn't be here!&quot;
  283. !endif
  284. SectionEnd
  285. PageEx instfiles
  286. !ifdef __GLOBAL__
  287. !error &quot;this shouldn't be here!&quot;
  288. !endif
  289. PageExEnd
  290. </pre>
  291. <a name="prescopesection"></a><h4>5.2.13.2 ${__SECTION__}</h4>
  292. <p>Defined as the section name, without any prefixes, in <a href="Chapter4.html#ssection">section</a> scope.</p>
  293. <pre>!ifdef __SECTION__
  294. !error &quot;this shouldn't be here!&quot;
  295. !endif
  296. Section test
  297. !ifndef __SECTION__
  298. !error &quot;missing predefine!&quot;
  299. !endif
  300. !if ${__SECTION__} != test
  301. !error &quot;wrong predefine value!&quot;
  302. !endif
  303. SectionEnd
  304. Section !test
  305. !if ${__SECTION__} != test
  306. !error &quot;wrong predefine value!&quot;
  307. !endif
  308. SectionEnd
  309. Section un.test
  310. !if ${__SECTION__} != test
  311. !error &quot;wrong predefine value!&quot;
  312. !endif
  313. SectionEnd
  314. </pre>
  315. <a name="prescopefunction"></a><h4>5.2.13.3 ${__FUNCTION__}</h4>
  316. <p>Defined as the function name, without any prefixes, in <a href="Chapter4.html#ffunction">function</a> scope.</p>
  317. <pre>!ifdef __FUNCTION__
  318. !error &quot;this shouldn't be here!&quot;
  319. !endif
  320. Function test
  321. !ifndef __FUNCTION__
  322. !error &quot;missing predefine!&quot;
  323. !endif
  324. !if ${__FUNCTION__} != test
  325. !error &quot;wrong predefine value!&quot;
  326. !endif
  327. FunctionEnd
  328. Function un.test
  329. !if ${__FUNCTION__} != test
  330. !error &quot;wrong predefine value!&quot;
  331. !endif
  332. FunctionEnd
  333. </pre>
  334. <a name="prescopepageex"></a><h4>5.2.13.4 ${__PAGEEX__}</h4>
  335. <p>Defined as the page type in <a href="Chapter4.html#pageex">PageEx</a> scope.</p>
  336. <pre>!ifdef __PAGEEX__
  337. !error &quot;this shouldn't be here!&quot;
  338. !endif
  339. PageEx instfiles
  340. !ifndef __PAGEEX__
  341. !error &quot;missing predefine!&quot;
  342. !endif
  343. !if ${__PAGEEX__} != instfiles
  344. !error &quot;wrong page type&quot;
  345. !endif
  346. PageExEnd
  347. </pre>
  348. <a name="prescopeuninstall"></a><h4>5.2.13.5 ${__UNINSTALL__}</h4>
  349. <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>
  350. <pre>!ifdef __UNINSTALL__
  351. !error &quot;this shouldn't be here!&quot;
  352. !endif
  353. Function test
  354. !ifdef __UNINSTALL__
  355. !error &quot;this shouldn't be here!&quot;
  356. !endif
  357. FunctionEnd
  358. Function un.test
  359. !ifndef __UNINSTALL__
  360. !error &quot;missing predefine!&quot;
  361. !endif
  362. FunctionEnd
  363. </pre>
  364. <a name="prescopemacro"></a><h4>5.2.13.6 ${__MACRO__}</h4>
  365. <p>Defined as the name of the current macro.</p>
  366. <a name="compenvvarread"></a><h2>5.3 Read environment variables</h2>
  367. <a name="compenvvar"></a><h3>5.3.1 $%envVarName%</h3>
  368. <p>$%envVarName% will be replaced at compile time by the environment variable envVarName.</p>
  369. <a name="compdefines"></a><h2>5.4 Conditional Compilation</h2>
  370. <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>
  371. <pre>!define symbol_one ${symbol_two}
  372. </pre>
  373. <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>
  374. <p>Define/conditional compilation related commands:</p>
  375. <a name="define"></a><h3>5.4.1 !define</h3>
  376. <pre>[/ifndef | /redef] ([/date|/utcdate] gflag [value]) | (/file gflag filename.txt) | (/intfmt gflag fmtstr value) | (/math gflag val1 OP val2)
  377. </pre>
  378. <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>
  379. <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>
  380. <p>If <em>/file</em> is used, the entire text file specified (including whitespace and newlines) will be read and placed into <em>gflag</em>.</p>
  381. <p>If <em>/intfmt</em> is used, <em>value</em> is interpreted as a integer and formated using the same syntax as <a href="Chapter4.html#intfmt">IntFmt</a>.</p>
  382. <p>If <em>/math</em> is used, the result of 'val1 OP val2', where OP may be +,-,*,/,%,&lt;&lt;,&gt;&gt;,&gt;&gt;&gt;,&amp;,|,^,~,!,&amp;&amp; or ||, will be used as the value of <em>gflag</em>. Note that val1 AND val2 MUST be integer values!</p>
  383. <pre>!define USE_SOMETHING
  384. !define VERSION 1.2
  385. !define /date NOW &quot;%H:%M:%S %d %b, %Y&quot;
  386. !define /math RESULT 3 + 10
  387. !define /math REST 15 % ${RESULT}
  388. !define /file BunchaStuff somesourcefile.cpp
  389. !define /redef USE_SOMETHING ${RESULT} ;redefine USE_SOMETHING
  390. !define /intfmt HEX &quot;0x%X&quot; 3133078222
  391. </pre>
  392. <a name="undef"></a><h3>5.4.2 !undef</h3>
  393. <pre>[/noerrors] gflag [...]
  394. </pre>
  395. <p>Removes an item from the global define list. Note that ${SYMBOL} where SYMBOL is undefined will be translated to &quot;${SYMBOL}&quot;.</p>
  396. <pre>!define SOMETHING
  397. !undef SOMETHING
  398. </pre>
  399. <a name="ifdef"></a><h3>5.4.3 !ifdef</h3>
  400. <pre>gflag [bcheck gflag [...]]
  401. </pre>
  402. <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>
  403. <pre>!define SOMETHING
  404. !ifdef SOMETHING
  405. !echo &quot;SOMETHING is defined&quot;
  406. !endif
  407. !undef SOMETHING
  408. !ifdef SOMETHING
  409. !echo &quot;SOMETHING is defined&quot; # will never be printed
  410. !endif
  411. </pre>
  412. <a name="ifndef"></a><h3>5.4.4 !ifndef</h3>
  413. <pre>gflag [bcheck gflag [...]]]
  414. </pre>
  415. <p>The opposite of !ifdef. The lines will be compiled when the gflag has not been defined.</p>
  416. <a name="if"></a><h3>5.4.5 !if</h3>
  417. <pre>[!] value [op value2]
  418. [!] /FileExists &quot;c:\path\file.exe&quot;
  419. </pre>
  420. <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>
  421. <pre>!if 1 &lt; 0x2
  422. !echo &quot;1 is smaller than 2!!&quot;
  423. !else if ! 3.1 &gt; 1.99
  424. !error &quot;this line should never appear&quot;
  425. !else
  426. !error &quot;neither should this&quot;
  427. !endif
  428. </pre>
  429. <pre>!if /FileExists &quot;.\cert.pfx&quot;
  430. !finalize '&quot;.\sign.bat&quot; &quot;%1&quot;'
  431. !endif
  432. </pre>
  433. <a name="ifmacrodef"></a><h3>5.4.6 !ifmacrodef</h3>
  434. <pre>gflag [bcheck gflag [...]]]
  435. </pre>
  436. <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>
  437. <pre>!macro SomeMacro
  438. !macroend
  439. !ifmacrodef SomeMacro
  440. !echo &quot;SomeMacro is defined&quot;
  441. !endif
  442. </pre>
  443. <a name="ifmacrondef"></a><h3>5.4.7 !ifmacrondef</h3>
  444. <pre>gflag [bcheck gflag [...]]]
  445. </pre>
  446. <p>The opposite of !ifmacrodef. The lines will be compiled when the macro gflag does not exist.</p>
  447. <a name="else"></a><h3>5.4.8 !else</h3>
  448. <pre>[if|ifdef|ifndef|ifmacrodef|ifmacrondef [...]]
  449. </pre>
  450. <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>
  451. <pre>!ifdef VERSION
  452. OutFile installer-${VERSION}.exe
  453. !else
  454. OutFile installer.exe
  455. !endif
  456. </pre>
  457. <a name="endif"></a><h3>5.4.9 !endif</h3>
  458. <p>This command closes a block started with !if, !ifdef, !ifndef, !ifmacrodef or !ifmacrondef.</p>
  459. <a name="insertmacro"></a><h3>5.4.10 !insertmacro</h3>
  460. <pre>macro_name [parameter] [...]
  461. </pre>
  462. <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>
  463. <pre>!macro Print text
  464. DetailPrint &quot;${text}&quot;
  465. !macroend
  466. !insertmacro Print &quot;some text&quot;
  467. !insertmacro Print &quot;some more text&quot;
  468. </pre>
  469. <a name="macro"></a><h3>5.4.11 !macro</h3>
  470. <pre>macro_name [parameter][...]
  471. </pre>
  472. <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>
  473. <pre>!macro SomeMacro parm1 parm2 parm3
  474. DetailPrint &quot;${parm1}&quot;
  475. MessageBox MB_OK &quot;${parm2}&quot;
  476. File &quot;${parm3}&quot;
  477. !macroend
  478. </pre>
  479. <a name="macroend"></a><h3>5.4.12 !macroend</h3>
  480. <p>Ends a macro that was started with !macro.</p>
  481. <a name="macroundef"></a><h3>5.4.13 !macroundef</h3>
  482. <pre>macro_name
  483. </pre>
  484. <p>Deletes a macro.</p>
  485. <a name="searchparse"></a><h3>5.4.14 !searchparse</h3>
  486. <pre>[/ignorecase] [/noerrors] [/file] source_string_or_file substring_start OUTPUTSYMBOL1 [substring [OUTPUTSYMBOL2 [substring ...]]]
  487. </pre>
  488. <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>
  489. <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>
  490. <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>
  491. <pre># search filename.cpp for a line '#define APP_VERSION &quot;2.5&quot;' and set ${VER_MAJOR} to 2, ${VER_MINOR} to 5.
  492. !searchparse /file filename.cpp `#define APP_VERSION &quot;` VER_MAJOR `.` VER_MINOR `&quot;`
  493. </pre>
  494. <a name="searchreplace"></a><h3>5.4.15 !searchreplace</h3>
  495. <pre>[/ignorecase] symbol_out source_string searchfor replacewith
  496. </pre>
  497. <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>
  498. <pre># defines ${blah} to &quot;i like ponies&quot;
  499. !searchreplace blah &quot;i love ponies&quot; &quot;love&quot; &quot;like&quot;
  500. </pre>
  501. <p><a href='Chapter4.html'>Previous</a> | <a href='Contents.html'>Contents</a> | <a href='AppendixA.html'>Next</a></p>
  502. </body></html>