summaryrefslogtreecommitdiffstats
path: root/contrib/mingw/rtems-autotools.nsi
blob: b97f2d6e0fa7943782712778220ae48c49adfb18 (plain) (blame)
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
; RTEMS Autotools Installer.
;
; Copyright Chris Johns (chrisj@rtems.org)
;

;!define EMPTY_INSTALLER

!define PRODUCT_NAME      "RTEMS Autotools"
!define PRODUCT_VERSION   ${RTEMS_VERSION}
!define PRODUCT_PUBLISHER "RTEM Project Team"
!define PRODUCT_WEB_SITE  "http://www.rtems.org/"
!define PRODUCT_TITLE     "${PRODUCT_NAME} ${PRODUCT_VERSION} (${RTEMS_TARGET})"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_TITLE}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir"

; MUI 1.66 compatible ------
!include "MUI.nsh"

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\win-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\win-uninstall.ico"

!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "${RTEMS_LOGO}"

!define MUI_COMPONENTSPAGE_SMALLDESC

; Start Menu Support
!include "${RTEMS_SOURCE}/sm-dummy.nsi"
var smfolder
!define MUI_STARTMENUPAGE_DISABLE
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "RTEMS ${PRODUCT_VERSION}"
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${PRODUCT_STARTMENU_REGVAL}"
!insertmacro MUI_PAGE_STARTMENU_DUMMY Application $smfolder

; Instfiles page
!insertmacro MUI_PAGE_INSTFILES

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"

; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

; MUI end ------

ReserveFile "rtems.ini"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

Name "${PRODUCT_NAME} ${PRODUCT_VERSION} (${RTEMS_TARGET})"
OutFile "${RTEMS_BINARY}/rtems${PRODUCT_VERSION}-tools-${RTEMS_TARGET}-${RTEMS_BUILD_VERSION}.exe"
InstallDir "C:\opt\rtems-${PRODUCT_VERSION}"
ShowInstDetails show
ShowUnInstDetails show
BrandingText "RTEMS ${RTEMS_TARGET} Tools v${PRODUCT_VERSION}"
AllowRootDirInstall false
AutoCloseWindow true
CRCCheck force

!include "${RTEMS_SOURCE}/instance-check.nsi"
!include "${RTEMS_SOURCE}/mingw-path.nsi"
!include "${RTEMS_SOURCE}/msys-path.nsi"
!include "${RTEMS_SOURCE}/options.nsi"
!include "${RTEMS_SOURCE}/filewrite.nsi"

Section "RTEMS ${RTEMS_TARGET} Tools" SecTools
 SetDetailsView show
 AddSize ${RTEMS_TOOLS_SIZE}

 Call MSYSFstabUpdate

 /*
  * Detect if MSYS is installed.
  */
 Call MSYSDetect
 Pop $9
 StrCmp $9 "not-found" 0 +3
  MessageBox MB_OK "Could not find a valid MSYS. Please install from http://www.mingw.org/"
  Abort
 SetOutPath "$INSTDIR\Uninstall"
 SetOutPath "$INSTDIR\Packages\Build"
 SetOutPath "$INSTDIR\Packages\Build"
 SetOutPath "$INSTDIR\Packages\Source"
 File "${RTEMS_SOURCE}/build-autotools.sh"
 File "${RTEMS_SOURCE}/ba-wrap.sh"
 File "${RTEMS_PACKAGE_SOURCE}/${RTEMS_AUTOCONF_SOURCE}"
 File "${RTEMS_SOURCE}/autoconf.def"
 File "${RTEMS_SOURCE}/automake.def"
 !insertmacro RTEMS_AUTOCONF_PATCHES
 File "${RTEMS_PACKAGE_SOURCE}/${RTEMS_AUTOMAKE_SOURCE}"
 !insertmacro RTEMS_AUTOMAKE_PATCHES

 Delete "$INSTDIR\Packages\Source\at-log.txt"

 /*
  * Need to fix the slashes when using a Unix type shell.
  */
 Push "$INSTDIR\Packages\Source\ba-wrap.sh"
 Push '\\'
 Pop $R0
 Call StrSlash
 Pop $R1
 Push "$INSTDIR\Packages\Build"
 Push '\\'
 Pop $R0
 Call StrSlash
 Pop $R2

 /*
  * Build Autoconf.
  */
 Push "$INSTDIR\Packages\Source\autoconf.def"
 Push '\\'
 Pop $R0
 Call StrSlash
 Pop $R0
 DetailPrint "Building automake. Command window closes automatically. Debug:$DebugScriptOption"
 ExecWait '"$9\bin\sh" --login -c "$R1 $DebugScriptOption -p /opt/rtems-${PRODUCT_VERSION} -b $R2 -c $R0"' $0
 BringToFront
 IntCmp $0 0 +3
  MessageBox MB_OK "Autoconf build failed. See $INSTDIR\Packages\Source\at-log.txt"
  Abort

 BringToFront

 Push "$INSTDIR\Uninstall\${RTEMS_AUTOCONF}-files"
 call InstallFilesFromFile

 /*
  * Build Automake.
  */
 Push "$INSTDIR\Packages\Source\automake.def"
 Push '\\'
 Pop $R0
 Call StrSlash
 Pop $R0
 DetailPrint "Building automake. Command window closes automatically. Debug:$DebugScriptOption"
 ExecWait '"$9\bin\sh" --login -c "$R1 $DebugScriptOption -p /opt/rtems-${PRODUCT_VERSION} -b $R2 -c $R0"' $0
 BringToFront
 IntCmp $0 0 +3
  MessageBox MB_OK "Automake build failed. See $INSTDIR\Packages\Source\at-log.txt"
  Abort

 BringToFront

 Push "$INSTDIR\Uninstall\${RTEMS_AUTOMAKE}-files"
 call InstallFilesFromFile

 DetailPrint "Removing Build directory"
 RMDir /r "$INSTDIR\Packages\Build"
SectionEnd

Function .onInit
  ;Check if we are the correct instance for our mode.
  Call CheckInstance
  ;Handle the Command line options
  Call CheckSilent
  Call CheckDebug
  ;See if MinGW and MSYS are installed
  Call MinGWDetect
  Call MSYSDetect
FunctionEnd

Var FileList

Function InstallFilesFromFile
  Pop $R6
  Push $R7
  Push $R8
  Push $R9
  DetailPrint "Installing file list: $R6"
  SetFileAttributes "$R6" NORMAL
  FileOpen $FileList "$R6" r
  IfErrors 0 +3
   MessageBox MB_OK "Internal error reading file list (0:$R6)."
   Abort
 ReadLoop:
  FileRead $FileList $R7
  IfErrors Done
  StrCpy $R7 $R7 -1 # has a \n only at the end
  StrCpy $R8 $R7
  StrCpy $R7 $R7 1  # first character on the line
  StrCpy $R8 $R8 256 2
  StrCmpS $R7 "D" ReadLoop
  StrCmpS $R7 "b" 0 +3
   StrCpy $R9 $R8
   Goto ReadLoop
  StrCmpS $R7 "d" 0 +3
   CreateDirectory "$INSTDIR\$R8"
   Goto ReadLoop
  StrCmpS $R7 "f" 0 +3
   CopyFiles /SILENT "$INSTDIR\Packages\Build\$R9\$R8" "$INSTDIR\$R8" 
   Goto ReadLoop
  MessageBox MB_OK "Internal error installing package (2:$R6)."
  Abort
 Done:
  FileClose $FileList
  ClearErrors
  Pop $R9
  Pop $R8
  Pop $R7
FunctionEnd

Function un.RemoveFilesFromFile
  ; Two passes, one to delete files then the directories
  ; This is due to the order in the *-files list. Plus
  ; RMDir seems to stuff things up (maybe a NSIS bug!)
  Pop $R6
  Push $R7
  Push $R8
  Push $R9
  DetailPrint "Delete file list: $R6"
  SetFileAttributes "$R6" NORMAL
  FileOpen $FileList "$R6" r
  IfErrors 0 +3
   MessageBox MB_OK "Internal error reading file list (0:$R6)."
   Abort
 ReadLoop:
  FileRead $FileList $R7
  IfErrors Pass2
  StrCpy $R7 $R7 -1 # has a \n only at the end
  StrCpy $R8 $R7
  StrCpy $R7 $R7 1  # first character on the line
  StrCpy $R8 $R8 256 2
  StrCmp $R7 "b" ReadLoop
  StrCmp $R7 "d" ReadLoop
  StrCmp $R7 "D" ReadLoop
  StrCmp $R7 "f" 0 +3
   Delete "$INSTDIR\$R8"
   Goto ReadLoop
  MessageBox MB_OK "Internal error removing package (2:$R6)."
  Abort
 Pass2:
  ClearErrors
  FileSeek $FileList 0 SET
 ReadLoop2:
  FileRead $FileList $R7
  IfErrors Done
  StrCpy $R7 $R7 -1 # has a \n only at the end
  StrCpy $R8 $R7
  StrCpy $R7 $R7 1  # first character on the line
  StrCpy $R8 $R8 256 2
  StrCmpS $R7 "b" ReadLoop2
  StrCmpS $R7 "d" ReadLoop2
  StrCmpS $R7 "f" ReadLoop2
  StrCmpS $R7 "D" 0 Fail
   ifFileExists "$INSTDIR\$R8\*.*" 0 ReadLoop2
    RMDir "$INSTDIR\$R8"  #is dir
   Delete "$INSTDIR\$R8"
   ClearErrors
   Goto ReadLoop2
 Fail:
  MessageBox MB_OK "Internal error removing package (2:$R6)."
  Abort
 Done:
  FileClose $FileList
  ClearErrors
  Delete $R6
  Pop $R9
  Pop $R8
  Pop $R7
FunctionEnd

Section -Post
 StrCpy $R0 "$INSTDIR\rtems${PRODUCT_VERSION}-${RTEMS_BUILD_VERSION}-tools-${RTEMS_TARGET}-uninst.exe"
 StrCpy $R1 "RTEMS ${RTEMS_TARGET} Tools.lnk"
 WriteUninstaller "$R0"
 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_TITLE}" \
                  "DisplayName" "$(^Name)"
 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_TITLE}" \
                  "UninstallString" "$R0"
 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_TITLE}" \
                  "DisplayVersion" "${PRODUCT_VERSION} Build-${RTEMS_BUILD_VERSION}"
 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_TITLE}" \
                  "URLInfoAbout" "${PRODUCT_WEB_SITE}"
 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_TITLE}" \
                  "Publisher" "${PRODUCT_PUBLISHER}"
 !insertmacro MUI_STARTMENU_GETFOLDER "Application" $R2
 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
 CreateDirectory "$SMPROGRAMS\$R2"
 CreateDirectory "$SMPROGRAMS\$R2\Uninstall"
 CreateShortCut "$SMPROGRAMS\$R2\Uninstall\$R1" "$R0"
 !insertmacro MUI_STARTMENU_WRITE_END
SectionEnd

Section Uninstall
 SetDetailsView show
 DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_TITLE}"
 DetailPrint "Delete the installed files"
 Push "$INSTDIR\Uninstall\${RTEMS_AUTOCONF}-files"
 call un.RemoveFilesFromFile 
 Push "$INSTDIR\Uninstall\${RTEMS_AUTOMAKE}-files"
 call un.RemoveFilesFromFile
 RMDir "$INSTDIR\Uninstall"
 Delete "$INSTDIR\Packages\Source\build-autotools.sh"
 Delete "$INSTDIR\Packages\Source\ba-wrap.sh"
 Delete "$INSTDIR\Packages\Source\${RTEMS_AUTOCONF_SOURCE}"
 Delete "$INSTDIR\Packages\Source\${RTEMS_AUTOMAKE_SOURCE}"
 Delete "$INSTDIR\Packages\Source\autoconf.def"
 Delete "$INSTDIR\Packages\Source\automake.def"
 Delete "$INSTDIR\Packages\Source\at-log.txt"
 !insertmacro RTEMS_DELETE_AUTOCONF_PATCHES
 !insertmacro RTEMS_DELETE_AUTOMAKE_PATCHES
 RMDir "$INSTDIR\Packages\Source"
 RMDir "$INSTDIR\Packages\Build"
 !insertmacro MUI_STARTMENU_GETFOLDER "Application" $smfolder
 Delete "$SMPROGRAMS\$smfolder\Uninstall\RTEMS ${RTEMS_TARGET} Tools.lnk"
 Delete $INSTDIR\rtems${PRODUCT_VERSION}-${RTEMS_BUILD_VERSION}-tools-${RTEMS_TARGET}-uninst.exe
 RMDir "$INSTDIR"
 DetailPrint "All done."
 SetAutoClose true
SectionEnd