summaryrefslogtreecommitdiff
path: root/Docs/src/defines.but
blob: 948ff2e7b59be1f47f50e0cd402d7558ada4b0e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
\S0{compdefines} Conditional Compilation

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:

\c !define symbol_one ${symbol_two}

If symbol_two is defined when that line occurs, it will be replaced. Otherwise, any replacing will occur when $\{symbol_one\} is referenced.

Define/conditional compilation related commands:

\S1{define} !define

\c ([/date|/utcdate] gflag [value]) | (/math gflag val1 OP val2)

This command will add \e{gflag} to the global define list. This will have a similar effect as using the /D switch on the command line (only the define only becomes effective after the !define command).

If \e{/date} or \e{/utcdate} are used, \e{value} will be passed into strftime and the result will be used as the value of \e{gflag}. 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 \W{http://msdn.microsoft.com/}{MSDN}. On POSIX, you can get the list by using \c{man strftime}.

If \e{/math} is used, the result of 'val1 OP val2', where OP may be +,-,*,&,|,^,/ or % , will be used as the value of \e{gflag}. Note that val1 AND val2 MUST be integer values!

\c !define USE_SOMETHING
\c !define VERSION 1.2
\c !define /date NOW "%H:%M:%S %d %b, %Y"
\c !define /math RESULT 3 + 10
\c !define /math REST 15 % ${RESULT}

\S1{undef} !undef

\c gflag

Removes an item from the global define list. Note that $\{SYMBOL\} where SYMBOL is undefined will be translated to "$\{SYMBOL\}".

\c !define SOMETHING
\c !undef SOMETHING

\S1{ifdef} !ifdef

\c gflag [bcheck gflag [...]]]

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 & (boolean and) or | (boolean or) along with more gflags -- precedence is simple, left to right.

\c !define SOMETHING
\c !ifdef SOMETHING
\c   !echo "SOMETHING is defined"
\c !endif
\c !undef SOMETHING
\c !ifdef SOMETHING
\c   !echo "SOMETHING is defined" # will never be printed
\c !endif

\S1{ifndef} !ifndef

\c gflag [bcheck gflag [...]]]

The opposite of !ifdef. The lines will be compiled when the gflag has not been defined.

\S1{if} !if

\c [!] value [op value2]

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 != (string comparison), <=, < > or >= (float comparison), && or || (boolean comparison).
If [!] is set, return value will be switched from true to false and vice versa.

\c !if 1 < 2
\c   !echo "1 is smaller than 2!!"
\c !else if ! 3.1 > 1.99
\c   !error "this line should never appear"
\c !else
\c   !error "neither should this"
\c !endif

\S1{ifmacrodef} !ifmacrodef

\c gflag [bcheck gflag [...]]]

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 & (boolean and) or | (boolean or) along with more gflags -- precedence is simple, left to right.

\c !macro SomeMacro
\c !macroend
\c !ifmacrodef SomeMacro
\c   !echo "SomeMacro is defined"
\c !endif

\S1{ifmacrondef} !ifmacrondef

\c gflag [bcheck gflag [...]]]

The opposite of !ifmacrodef. The lines will be compiled when the macro gflag does not exist.

\S1{else} !else

\c [if|ifdef|ifndef|ifmacrodef|ifmacrondef [...]]

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.

\c !ifdef VERSION
\c OutFile installer-${VERSION}.exe
\c !else
\c OutFile installer.exe
\c !endif

\S1{endif} !endif

This command closes a block started with !if, !ifdef, !ifndef, !ifmacrodef or !ifmacrondef.

\S1{insertmacro} !insertmacro

\c macro_name [parameter] [...]

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.

\c !macro Print text
\c   DetailPrint "${text}"
\c !macroend
\c !insertmacro Print "some text"
\c !insertmacro Print "some more text"

\S1{macro} !macro

\c macro_name [parameter][...]

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.

\c !macro SomeMacro parm1 parm2 parm3
\c   DetailPrint "${parm1}"
\c   MessageBox MB_OK "${parm2}"
\c   File "${parm3}"
\c !macroend

\S1{macroend} !macroend

Ends a macro that was started with !macro.