Chapter5.html 28 KB

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