-
Notifications
You must be signed in to change notification settings - Fork 39
/
installer.nsi.template
335 lines (290 loc) · 15.1 KB
/
installer.nsi.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# NSIS installer script for the Pololu AVR C/C++ Library.
# Detects WinAVR and various versions of AVR/Atmel studio and adds the
# library's .h and .a files in the appropriate directories.
#
# When "make zip" is run, installer.nsi.template is edited slightly, saved
# as installer.nsi, and added to the library zip file
# (e.g. libpololu-avr-120209.zip).
# To compile the Windows NSIS installer, unzip the zip file,
# right click on installer.nsi, and select "Compile NSIS Script".
# You will need NSIS 2.46+ installed.
!define LIB_VER "YYMMDD"
!define libpololu-avr "."
SetCompressor /solid lzma
!include LogicLib.nsh
!include nsDialogs.nsh
!include FileFunc.nsh
RequestExecutionLevel admin
OutFile "libpololu-avr-${LIB_VER}.exe"
Name "Pololu AVR C/C++ Library"
InstallDir "C:\libpololu-avr"
ShowInstDetails show
AllowSkipFiles on
XPStyle on
Page directory "" "" checkDirectory
Page custom optionsPage optionsPageLeave
Page instfiles
Var VS10ShellPath
Var VS14ShellPath
Var Dialog
DirText "Setup will install the Pololu AVR C/C++ Library (version ${LIB_VER}) in the following folder. To install in a different folder, click Browse and select another folder. Click Next to continue."
# Toolchain variables
Var WinAVRPath
Var AS60Path
Var AS61Path
Var AS61PathAvr
Var AS62Path
Var AS62PathAvr
Var AS70Path
Var WinAVRBox
Var AS60Box
Var AS61Box
Var AS62Box
Var AS70Box
Var WinAVRIntegrate
Var AS60Integrate
Var AS61Integrate
Var AS62Integrate
Var AS70Integrate
# When the installer starts, detect the different things we need to detect.
Function .onInit
Call WinAVRCheck
Call AS60Check
Call AS61Check
Call AS62Check
Call AS70Check
Call VS10ShellCheck
Call VS14ShellCheck
# Check the assumptions we make when calling NSD_GetState and NSD_SetState.
${If} ${BST_CHECKED} != 1
Abort
${EndIf}
${If} ${BST_UNCHECKED} != 0
Abort
${EndIf}
# By default, any checkbox that is available will be checked.
StrCpy $WinAVRIntegrate "1"
StrCpy $AS60Integrate "1"
StrCpy $AS61Integrate "1"
StrCpy $AS62Integrate "1"
StrCpy $AS70Integrate "1"
FunctionEnd
!macro CreateToolchainCheckBox Name Path Checked Box Y
${If} "${Path}" != ""
StrCpy $1 "${Name} (${Path})"
StrCpy $2 1 # enable the checkbox
StrCpy $3 "${Checked}" # check the box if appropriate
${Else}
StrCpy $1 "${Name} (not detected)"
StrCpy $2 0 # disable the checkbox
StrCpy $3 0 # uncheck the checkbox
${Endif}
${NSD_CreateCheckBox} 0 ${Y} 100% 12u $1
Pop ${Box}
EnableWindow ${Box} $2 # disable/enable the checkbox
${NSD_SetState} ${Box} $3
!macroend
# Creates the optionsPage and all the checkboxes in it.
Function optionsPage
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
GetFunctionAddress $0 "optionsPageLeave"
nsDialogs::OnBack $0
${NSD_CreateLabel} 0 0 100% 12u "Install the library into the following toolchains:"
Pop $0
!insertmacro CreateToolchainCheckBox "WinAVR" $WinAVRPath $WinAVRIntegrate $WinAVRBox 20u
!insertmacro CreateToolchainCheckBox "Atmel Studio 6.0" $AS60Path $AS60Integrate $AS60Box 40u
!insertmacro CreateToolchainCheckBox "Atmel Studio 6.1" $AS61Path $AS61Integrate $AS61Box 60u
!insertmacro CreateToolchainCheckBox "Atmel Studio 6.2" $AS62Path $AS62Integrate $AS62Box 80u
!insertmacro CreateToolchainCheckBox "Atmel Studio 7.0" $AS70Path $AS70Integrate $AS70Box 100u
nsDialogs::Show
FunctionEnd
# Gets called when leaving the options page (forward or back)
# Stores the user's choices from the check boxes.
Function optionsPageLeave
${NSD_GetState} $WinAVRBox $WinAVRIntegrate
${NSD_GetState} $AS60Box $AS60Integrate
${NSD_GetState} $AS61Box $AS61Integrate
${NSD_GetState} $AS62Box $AS62Integrate
${NSD_GetState} $AS70Box $AS70Integrate
FunctionEnd
# Install the header (.h) and archive (.a) files that allow
# compilation of programs that use the library.
# We check the existence of the directories here because the toolchain location
# might change and we'd like to give useful error messages.
!macro InstallIntoToolChain AvrPath
${if} ${FileExists} "${AvrPath}\lib"
SetOutPath "${AvrPath}\lib"
File "${libpololu-avr}\libpololu_*.a"
${else}
DetailPrint "AVR lib folder not found: ${AvrPath}\lib"
MessageBox MB_OK|MB_ICONEXCLAMATION "The folder ${AvrPath}\lib was not found. You might have to find the correct lib folder for your toolchain and copy the $INSTDIR\libpololu_*.a files to it manually. Please report this problem at http://forum.pololu.com/."
${endif}
${if} ${FileExists} "${AvrPath}\include"
SetOutPath "${AvrPath}\include"
File /r "${libpololu-avr}\pololu"
${else}
DetailPrint "AVR include folder not found: ${AvrPath}\include"
MessageBox MB_OK|MB_ICONEXCLAMATION "The folder ${AvrPath}\include was not found. You might have to find the correct include folder for your toolchain and copy the $INSTDIR\pololu folder to it manually. Please report this problem at http://forum.pololu.com/."
${endif}
!macroend
!macro InstallSTK500Xml Path
# Install the STK500 XML files needed for programming, but don't
# overwrite any existing XML files.
SetOutPath "${Path}"
SetOverwrite off
File "${libpololu-avr}\atmel_studio\stk500_xml\*.xml"
SetOverwrite on
!macroend
Section
SetOutPath "$INSTDIR"
File /r /x libpololu-avr-*.exe "${libpololu-avr}\*.*"
StrCmp $WinAVRPath "" end_winavr
IntCmp $WinAVRIntegrate 0 end_winavr
DetailPrint "Installing library into WinAVR..."
!insertmacro InstallIntoToolChain "$WinAVRPath\avr"
end_winavr:
StrCmp $AS60Path "" end_as60
IntCmp $AS60Integrate 0 end_as60
DetailPrint "Installing library into Atmel Studio 6.0..."
${if} ${FileExists} "$AS60Path\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\avr"
DetailPrint "Detect Atmel Studio 6.0 build 1996" # released November 2012
!insertmacro InstallIntoToolChain "$AS60Path\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\avr"
${elseif} ${FileExists} "$AS60Path\extensions\Atmel\AVRGCC\3.4.0.65\AVRToolchain\avr"
DetailPrint "Detect Atmel Studio 6.0 build 1843"
!insertmacro InstallIntoToolChain "$AS60Path\extensions\Atmel\AVRGCC\3.4.0.65\AVRToolchain\avr"
${else}
DetailPrint "Unable to detect Atmel Studio 6.0 build version."
MessageBox MB_OK|MB_ICONEXCLAMATION "The Pololu AVR C/C++ Library installer was unable to find the avr folder for Atmel Studio 6.0's AVR toolchain. You might have to find your AVR toolchain's avr folder (probably inside $AS60Path\extensions\Atmel\AVRGCC\ ) and then manually copy the $INSTDIR\libpololu_*.a files to avr\lib and copy the $INSTDIR\pololu folder to avr\include. Please report this problem at http://forum.pololu.com/."
${endif}
!insertmacro InstallSTK500Xml "$AS60Path\tools\STK500\xml"
ExecWait "$\"$VS10ShellPath\Common7\IDE\vsixinstaller.exe$\" /skuName:AtmelStudio /skuVersion:6.0 /quiet $\"$INSTDIR\atmel_studio\extension.vsix$\""
end_as60:
StrCmp $AS61Path "" end_as61
IntCmp $AS61Integrate 0 end_as61
DetailPrint "Installing library into Atmel Studio 6.1..."
${if} ${FileExists} $AS61PathAvr
!insertmacro InstallIntoToolChain $AS61PathAvr
${else}
DetailPrint "Unable to find Atmel Studio 6.1 toolchain. Looked in $AS61PathAvr"
MessageBox MB_OK|MB_ICONEXCLAMATION "The Pololu AVR C/C++ Library installer was unable to find the avr folder for Atmel Studio 6.1's 8-bit GNU toolchain. You might have to find your AVR toolchain's avr folder (probably near $AS61Path ) and then manually copy the $INSTDIR\libpololu_*.a files to avr\lib and copy the $INSTDIR\pololu folder to avr\include. Please report this problem at http://forum.pololu.com/."
${endif}
!insertmacro InstallSTK500Xml "$AS61Path\tools\STK500\xml"
ExecWait "$\"$VS10ShellPath\Common7\IDE\vsixinstaller.exe$\" /skuName:AtmelStudio /skuVersion:6.1 /quiet $\"$INSTDIR\atmel_studio\extension.vsix$\""
end_as61:
StrCmp $AS62Path "" end_as62
IntCmp $AS62Integrate 0 end_as62
DetailPrint "Installing library into Atmel Studio 6.2..."
${if} ${FileExists} $AS62PathAvr
!insertmacro InstallIntoToolChain $AS62PathAvr
${else}
DetailPrint "Unable to find Atmel Studio 6.2 toolchain. Looked in $AS62PathAvr"
MessageBox MB_OK|MB_ICONEXCLAMATION "The Pololu AVR C/C++ Library installer was unable to find the avr folder for Atmel Studio 6.2's 8-bit GNU toolchain. You might have to find your AVR toolchain's avr folder (probably near $AS62Path ) and then manually copy the $INSTDIR\libpololu_*.a files to avr\lib and copy the $INSTDIR\pololu folder to avr\include. Please report this problem at http://forum.pololu.com/."
${endif}
!insertmacro InstallSTK500Xml "$AS62Path\tools\STK500\xml"
ExecWait "$\"$VS10ShellPath\Common7\IDE\vsixinstaller.exe$\" /skuName:AtmelStudio /skuVersion:6.2 /quiet $\"$INSTDIR\atmel_studio\extension.vsix$\""
end_as62:
StrCmp $AS70Path "" end_as70
IntCmp $AS70Integrate 0 end_as70
DetailPrint "Installing library into Atmel Studio 7.0..."
${if} ${FileExists} "$AS70Path\toolchain\avr8\avr8-gnu-toolchain\avr"
!insertmacro InstallIntoToolChain "$AS70Path\toolchain\avr8\avr8-gnu-toolchain\avr"
${else}
DetailPrint "Unable to find Atmel Studio 7.0 toolchain. Looked in $AS70Path\toolchain\avr8\avr8-gnu-toolchain\avr"
MessageBox MB_OK|MB_ICONEXCLAMATION "The Pololu AVR C/C++ Library installer was unable to find the avr folder for Atmel Studio 7.0's 8-bit GNU toolchain. You might have to find your AVR toolchain's avr folder (probably near $AS70Path ) and then manually copy the $INSTDIR\libpololu_*.a files to avr\lib and copy the $INSTDIR\pololu folder to avr\include. Please report this problem at http://forum.pololu.com/."
${endif}
ExecWait "$\"$VS14ShellPath\Common7\IDE\vsixinstaller.exe$\" /skuName:AtmelStudio /skuVersion:7.0 /quiet $\"$INSTDIR\atmel_studio\extension.vsix$\""
end_as70:
SectionEnd
# Checks to see if WinAVR is installed.
# Sets $WinAVRPath to the path or "" if not found.
Function WinAVRCheck
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WinAVR" 'UninstallString'
${GetParent} $0 $WinAVRPath
FunctionEnd
Function AS60Check
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\AppEnv\10.0\Apps\AtmelStudio_6.0" 'StubExePath'
${GetParent} $0 $AS60Path
StrCmp $AS60Path "" 0 AS60Done # If we found it, then we are done.
ReadRegStr $AS60Path HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{51CC3953-2D06-47FA-832A-B7FD24D01322}" 'InstallLocation'
StrCmp $AS60Path "" AS60Done # If Atmel Studio 6.0 really isn't there, we are done.
# I'm not sure if this case can happen, but it could for AVR Studio 5.1 if
# you uninstalled AVR Studio 5.0.
MessageBox MB_OK "Your Atmel Studio 6.0 installation appears to be corrupted. You can still install the Pololu AVR C/C++ library into Atmel Studio 6.0 but the installation of the project templates will probably not work. You should be able to fix this problem by reinstalling or repairing Atmel Studio 6.0 and then running this installer again."
AS60Done:
FunctionEnd
# Typically, AS61Path is:
# C:\Program Files (x86)\Atmel\Atmel Studio 6.1
# Typically, AS61PathAvr is:
# C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\avr
Function AS61Check
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\AppEnv\10.0\Apps\AtmelStudio_6.1" 'StubExePath'
${GetParent} $0 $AS61Path
StrCmp $AS61Path "" AS61Done # If we cannot find it, then we are done.
# Knowing the path of Atmel Studio 6.1 is not good enough. We need to find the 8-bit toolchain.
ReadRegStr $0 HKLM "SOFTWARE\Atmel\AVR8 GCC\6.1\Native" 'InstallDir'
StrCmp $0 "" AS61Done # If we can't find this key, give up.
ReadRegStr $1 HKLM "SOFTWARE\Atmel\AVR8 GCC\6.1\Native" 'Version'
StrCmp $1 "" AS61Done # If we can't find this key, give up.
StrCpy $AS61PathAvr "$0Atmel Toolchain\AVR8 GCC\Native\$1\avr8-gnu-toolchain\avr"
AS61Done:
FunctionEnd
# Typically, AS62Path is:
# C:\Program Files (x86)\Atmel\Atmel Studio 6.2
# Typically, AS62PathAvr is:
# C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.2.939\avr8-gnu-toolchain\avr
Function AS62Check
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\AppEnv\10.0\Apps\AtmelStudio_6.2" 'StubExePath'
${GetParent} $0 $AS62Path
StrCmp $AS62Path "" AS62Done # If we cannot find it, then we are done.
# Knowing the path of Atmel Studio 6.2 is not good enough. We need to find the 8-bit toolchain.
ReadRegStr $0 HKLM "SOFTWARE\Atmel\AVR8 GCC\6.2\Native" 'InstallDir'
StrCmp $0 "" AS62Done # If we can't find this key, give up.
ReadRegStr $1 HKLM "SOFTWARE\Atmel\AVR8 GCC\6.2\Native" 'Version'
StrCmp $1 "" AS62Done # If we can't find this key, give up.
StrCpy $AS62PathAvr "$0Atmel Toolchain\AVR8 GCC\Native\$1\avr8-gnu-toolchain\avr"
AS62Done:
FunctionEnd
# The location of Atmel Studio 7.0 is stored in several places:
# HKLM "SOFTWARE\Microsoft\AppEnv\14.0\Apps\AtmelStudio_7.0" 'StubExePath' (requires GetParent)
# HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\atmelstudio.exe" (requires GetParent)
# HKCU "SOFTWARE\Atmel\AtmelStudio\7.0_Config" 'InstallDir'
Function AS70Check
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\AppEnv\14.0\Apps\AtmelStudio_7.0" 'StubExePath'
${GetParent} $0 $AS70Path
FunctionEnd
# We need to find the location of the Visual Studio 2010 (10.0) isolated
# shell (used by Atmel Studio 6.x) so we can install our extension using vsixinstaller.exe.
# Some other possibilities we aren't usin are documented here:
# http://osherove.com/blog/2010/4/9/finding-the-location-of-vsixinstallerexe-programmatically.html
# http://msdn.microsoft.com/en-us/library/bb932484.aspx
Function VS10ShellCheck
ReadRegStr $VS10ShellPath HKLM "Software\Microsoft\VisualStudio\10.0\Setup\IsoShell\1033" 'ProductDir'
StrCmp $VS10ShellPath "" 0 VS10ShellCheckDone
ReadRegStr $VS10ShellPath HKCU "Software\Atmel\AtmelStudio\6.0_Config" 'ShellFolder'
StrCmp $VS10ShellPath "" 0 VS10ShellCheckDone
ReadRegStr $VS10ShellPath HKCU "Software\Atmel\AtmelStudio\6.1_Config" 'ShellFolder'
StrCmp $VS10ShellPath "" 0 VS10ShellCheckDone
ReadRegStr $VS10ShellPath HKCU "Software\Atmel\AtmelStudio\6.2_Config" 'ShellFolder'
VS10ShellCheckDone:
FunctionEnd
# We need to find the location of the Visual Studio 2015 (14.0)
# isolated shell (used by Atmel Studio 6.x) so we can install our
# extension using vsixinstaller.exe.
Function VS14ShellCheck
ReadRegStr $VS14ShellPath HKLM "Software\Microsoft\AppEnv\14.0" 'ShellFolder'
StrCmp $VS14ShellPath "" 0 VS14ShellCheckDone
ReadRegStr $VS14ShellPath HKCU "Software\Atmel\AtmelStudio\7.0_Config" 'ShellFolder'
VS14ShellCheckDone:
FunctionEnd
Function checkDirectory
# Warn the user if they choose an existing directory.
${if} ${FileExists} $INSTDIR
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "The folder $INSTDIR already exists. Installing to this directory could overwrite existing files." /SD IDOK IDOK dirOk
Abort
dirOk:
${endif}
FunctionEnd