Exitcode fix
[mono.git] / monowiz.win32.nsi
1 ; =================================================================
2 ; mono.nsi - This NSIS script creates Mono Setup wizard for Windows
3 ;
4 ;            Requires NSIS 2.0 (Nullsoft Scriptable Install System)
5 ;            From http://nsis.sourceforge.net/site/index.php
6 ; =================================================================
7 ;
8 ; (C) Copyright 2003 by Johannes Roith
9 ; (C) Copyright 2003, 2004 by Daniel Morgan
10 ;
11 ; Authors: 
12 ;       Johannes Roith <johannes@jroith.de>
13 ;       Daniel Morgan <danielmorgan@verizon.net>
14 ;       Urs C Muff <umuff@quark.com>
15 ;
16 ; This .nsi includes code from the NSIS Archives:
17 ; function StrReplace and VersionCheck 
18 ; by Hendri Adriaens
19 ; HendriAdriaens@hotmail.com
20
21 ; =====================================================
22 ;
23 ; This script can build a binary setup wizard of mono.
24 ; It is released under the GNU GPL.
25 ;
26 ; =====================================================
27 ; SET MILESTONE & SOURCE DIR
28 ; =====================================================
29 ; set by makefile!!
30
31 !define MILESTONE 0.31.99
32 !define SOURCE_INSTALL_DIR ..\install\*.* 
33
34 ; =====================================================
35 ; SET LOGO
36 ; =====================================================
37 ;
38 ;  Beautification:
39 ;
40 ;  This adds a Mono-specific Image on the left
41 ;  You can choose between the light or dark one.
42 ;  
43 ;  If you wish no mono-specifi logo, please outcomment
44 ;  the lines.
45 ;  
46 ;  "light" is enabled.
47 ;
48 ;  !define MUI_SPECIALBITMAP "mono-win32-setup-dark.bmp"
49    !define MUI_SPECIALBITMAP "mono-win32-setup-light.bmp"
50
51 ; =====================================================
52 ; BUILDING
53 ; =====================================================
54 ;
55 ; 1. Build mono to a clean directory prefix.
56 ;
57 ; 2. In your install directory, delete the *.a files.
58 ;     Most people won't need them and it saves ~ 4 MB.
59 ;
60 ; 3. Type "make win32setup"
61 ;
62 ; 4. The output file is mono-[MILESTONE]-win32-1.exe
63 ;
64 ;
65 ; =====================================================
66 ; MONO & REGISTRY / DETECTING MONO
67 ; =====================================================
68 ;
69 ;
70 ; This setup creates several Registry Keys:
71 ;
72 ; HKEY_LOCAL_MACHINE SOFTWARE\Mono DefaultCLR
73 ; HKEY_LOCAL_MACHINE SOFTWARE\Mono\${MILESTONE} SdkInstallRoot
74 ; HKEY_LOCAL_MACHINE SOFTWARE\Mono\${MILESTONE} FrameworkAssemblyDirectory
75 ; HKEY_LOCAL_MACHINE SOFTWARE\Mono\${MILESTONE} MonoConfigDir
76 ;
77 ; =====================================================
78 ;
79 ; To get the current Mono Install Directory:
80 ;
81 ; 1. Get DefaultCLR
82 ; 2. Get HKEY_LOCAL_MACHINE SOFTWARE\Mono\$THE_DEFAULT_CLR_VALUE SdkInstallRoot
83 ;
84 ; =====================================================
85 ;
86 ; To get the current Mono assembly Directory:
87 ;
88 ; 1. Get DefaultCLR
89 ; 2. Get HKEY_LOCAL_MACHINE SOFTWARE\Mono\$THE_DEFAULT_CLR_VALUE FrameworkAssemblyDirectory
90
91 ; =====================================================
92 ; Do not edit below
93 ; =====================================================
94 ;
95 ;
96 ; =====================================================
97 ; GENERAL SETTING - NEED NOT TO BE CHANGED
98 ; =====================================================
99
100 !define NAME "Mono" 
101 !define TARGET_INSTALL_DIR "$PROGRAMFILES\Mono-${MILESTONE}" 
102 !define OUTFILE mono-${MILESTONE}-win32-1.exe
103
104 Name ${NAME}\r
105 Caption "Mono ${MILESTONE} Setup"\r
106
107 !include "MUI.nsh"\r
108 !include "Sections.nsh"\r
109
110 SetCompressor bzip2\r
111 SilentInstall normal\r
112 ShowInstDetails show\r
113 SetDateSave on\r
114 SetDatablockOptimize on\r
115 CRCCheck on\r
116 BGGradient 000000 800000 FFFFFF\r
117 InstallColors FF8080 000030\r
118 XPStyle on\r
119 AutoCloseWindow false
120
121 ; =====================================================
122 ; SCRIPT
123 ; =====================================================
124
125 #!define MUI_WELCOMEPAGE
126 #!define MUI_DIRECTORYPAGE
127 #!define MUI_DIRECTORYSELECTIONPAGE
128  
129 !define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the installation of Mono for Windows.\r\n\r\n\r\n$_CLICK"\r
130 \r
131 !insertmacro MUI_PAGE_WELCOME\r
132 !insertmacro MUI_PAGE_DIRECTORY\r
133 !insertmacro MUI_PAGE_INSTFILES\r
134 \r
135 !define MUI_FINISHPAGE_LINK "Visit Mono's website for the latest news"\r
136 !define MUI_FINISHPAGE_LINK_LOCATION "http://www.go-mono.com/"\r
137 \r
138 !define MUI_FINISHPAGE_NOREBOOTSUPPORT\r
139 \r
140 !insertmacro MUI_PAGE_FINISH\r
141 \r
142 !insertmacro MUI_UNPAGE_CONFIRM\r
143 !insertmacro MUI_UNPAGE_INSTFILES\r
144  
145 !insertmacro MUI_LANGUAGE "ENGLISH"
146
147 AutoCloseWindow false\r
148 ShowInstDetails show
149
150 OutFile ${OUTFILE}
151 InstallDir "${TARGET_INSTALL_DIR}"
152
153 ;========================
154 ; Uninstaller
155 ;========================
156
157 Section "Uninstall"
158
159   MessageBox MB_YESNO "Are you sure you want to uninstall Mono from your system?" IDNO NoUnInstall
160
161   Delete $INSTDIR\Uninst.exe ; delete Uninstaller
162   DeleteRegKey HKLM SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Mono-${MILESTONE} ; Remove Entry in Software List
163
164   MessageBox MB_YESNO "Mono was installed into $INSTDIR. Should this directory be removed completly?" IDNO GoNext1
165   RMDir /r $INSTDIR
166   GoNext1:
167
168   DeleteRegKey HKLM SOFTWARE\Mono\${MILESTONE}
169
170   ; If the Default-Key is the current Milestone, we just remove the wrappers
171
172   ReadRegStr $0 HKEY_LOCAL_MACHINE SOFTWARE\Mono\ DefaultCLR
173   StrCmp $0 ${MILESTONE} DeleteWrappers
174
175   MessageBox MB_YESNO "Mono ${MILESTONE} has been removed, but the default installation of Mono differs form this version. Should the wrappers and the Mono registry key be still be removed? This could disable other Mono installations." IDNO GoNext2
176
177   DeleteWrappers:
178
179   ; Complete Uninstall
180
181   DeleteRegKey HKLM SOFTWARE\Mono
182   Delete $WINDIR\monobasepath.bat
183   Delete $WINDIR\mcs.bat
184   Delete $WINDIR\mbas.bat
185   Delete $WINDIR\mint.bat
186   Delete $WINDIR\mono.bat
187   Delete $WINDIR\monodis.bat
188   Delete $WINDIR\monoilasm.bat
189   Delete $WINDIR\sqlsharp.bat
190   Delete $WINDIR\secutil.bat
191   Delete $WINDIR\cert2spc.bat
192   Delete $WINDIR\monoresgen.bat
193   Delete $WINDIR\monosn.bat
194   Delete $WINDIR\cilc.bat
195   Delete $WINDIR\monop.bat
196   Delete $WINDIR\xsp.bat
197
198   GoNext2:
199   NoUnInstall:
200
201 SectionEnd
202
203
204  Section
205
206  ; Warn people if a newer Mono is already installed
207
208  ReadRegStr $0 HKEY_LOCAL_MACHINE SOFTWARE\Mono\ DefaultCLR
209  Push $0
210  Push ${MILESTONE} 
211  Call VersionCheck
212  Pop $0
213  StrCmp $0 0 NoAskInstall
214  StrCmp $0 2 NoAskInstall
215  MessageBox MB_YESNO "A newer Mono version is already installed. Still continue?" IDNO NoInstall
216
217  NoAskInstall:
218
219  DetailPrint "Installing Mono Files..."
220  SetOverwrite on
221  SetOutPath $INSTDIR
222  File /r ${SOURCE_INSTALL_DIR}
223
224  WriteUninstaller Uninst.exe
225
226  WriteRegStr HKEY_LOCAL_MACHINE SOFTWARE\Mono\${MILESTONE} SdkInstallRoot $INSTDIR
227  WriteRegStr HKEY_LOCAL_MACHINE SOFTWARE\Mono\${MILESTONE} FrameworkAssemblyDirectory $INSTDIR\lib
228  WriteRegStr HKEY_LOCAL_MACHINE SOFTWARE\Mono\${MILESTONE} MonoConfigDir $INSTDIR\etc\mono
229  ;WriteRegStr HKEY_LOCAL_MACHINE SOFTWARE\Mono\${MILESTONE} GtkSharpLibPath $INSTDIR\lib
230  WriteRegStr HKEY_LOCAL_MACHINE SOFTWARE\Mono DefaultCLR ${MILESTONE}
231
232  ; Mono Uninstall Entry in Windows Software List in the Control panel
233  WriteRegStr HKEY_LOCAL_MACHINE SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Mono-${MILESTONE} DisplayName "Mono ${MILESTONE}"
234  WriteRegStr HKEY_LOCAL_MACHINE SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Mono-${MILESTONE} UninstallString $INSTDIR\uninst.exe
235
236  ;original string is like C:\mono-0.20\install
237  StrCpy $5 $INSTDIR 
238  Push $5
239  Push "\" ;search for this string
240  Push "/" ;replace with this string
241  Call StrReplace
242  ;resulting string which is like C:/mono-0.20/install
243  Pop $6
244
245 ;
246 ; These wrappers are copied to the windows directory.
247 ;
248
249 ;========================
250 ; Write the path file
251 ;========================
252
253 FileOpen $0 "$WINDIR\MonoBasePath.bat" "w"
254 FileWrite $0 'SET MONO_BASEPATH="$INSTDIR"$\r$\n'
255 FileWrite $0 'SET MONO_PATH=$INSTDIR\lib$\r$\n'
256 FileWrite $0 'SET MONO_CFG_DIR=$INSTDIR\etc'
257 FileClose $0
258
259 Push "mint"
260 Call windowsBatCore
261
262 Push "mono"
263 Call windowsBatCore
264
265 Push "mcs"
266 Call windowsBat
267
268 Push "mbas"
269 Call windowsBat
270
271 Push "monodis"
272 Call windowsBat
273
274 Push "monoilasm"
275 Call windowsBat
276
277 Push "sqlsharp"
278 Call windowsBat
279
280 Push "secutil"
281 Call windowsBat
282
283 Push "cert2spec"
284 Call windowsBat
285
286 Push "monoresgen"
287 Call windowsBat
288
289 Push "monosn"
290 Call windowsBat
291
292 Push "cilc"
293 Call windowsBat
294
295 Push "monop"
296 Call windowsBat
297
298 Push "xsp"
299 Call windowsBat
300
301 ; ============= glib-2.0.pc ===============\r
302 FileOpen $0 "$INSTDIR\lib\pkgconfig\glib-2.0.pc" "w"\r
303 FileWrite $0 "prefix=$6$\r$\n"\r
304 FileWrite $0 "exec_prefix=$${prefix}$\r$\n"\r
305 FileWrite $0 "libdir=$${exec_prefix}/lib$\r$\n"\r
306 FileWrite $0 "includedir=$${prefix}/include$\r$\n"\r
307 FileWrite $0 "$\r$\n"\r
308 FileWrite $0 "glib_genmarshal=glib-genmarshal$\r$\n"\r
309 FileWrite $0 "gobject_query=gobject-query$\r$\n"\r
310 FileWrite $0 "glib_mkenums=glib-mkenums$\r$\n"\r
311 FileWrite $0 "$\r$\n"\r
312 FileWrite $0 "Name: GLib$\r$\n"\r
313 FileWrite $0 "Description: C Utility Library$\r$\n"\r
314 FileWrite $0 "Version: 2.0.4$\r$\n"\r
315 FileWrite $0 "Libs: -L$${libdir} -lglib-2.0 -lintl -liconv $\r$\n"\r
316 FileWrite $0 "Cflags: -I$${includedir}/glib-2.0 -I$${libdir}/glib-2.0/include $\r$\n"\r
317 FileClose $0
318 \r
319 ; ============= gmodule-2.0.pc ===============\r
320 FileOpen $0 "$INSTDIR\lib\pkgconfig\gmodule-2.0.pc" "w"\r
321 FileWrite $0 "prefix=$6$\r$\n"\r
322 FileWrite $0 "exec_prefix=$${prefix}$\r$\n"\r
323 FileWrite $0 "libdir=$${exec_prefix}/lib$\r$\n"\r
324 FileWrite $0 "includedir=$${prefix}/include$\r$\n"\r
325 FileWrite $0 "$\r$\n"\r
326 FileWrite $0 "gmodule_supported=true$\r$\n"\r
327 FileWrite $0 "$\r$\n"\r
328 FileWrite $0 "Name: GModule$\r$\n"\r
329 FileWrite $0 "Description: Dynamic module loader for GLib$\r$\n"\r
330 FileWrite $0 "Requires: glib-2.0$\r$\n"\r
331 FileWrite $0 "Version: 2.0.4$\r$\n"\r
332 FileWrite $0 "Libs: -L$${libdir} -lgmodule-2.0 $\r$\n"\r
333 FileWrite $0 "Cflags:$\r$\n"\r
334 FileClose $0\r
335 \r
336 ; ============= gobject-2.0.pc ===============\r
337 FileOpen $0 "$INSTDIR\lib\pkgconfig\gobject-2.0.pc" "w"\r
338 FileWrite $0 "prefix=$6$\r$\n"\r
339 FileWrite $0 "exec_prefix=$${prefix}$\r$\n"\r
340 FileWrite $0 "libdir=$${exec_prefix}/lib$\r$\n"\r
341 FileWrite $0 "includedir=$${prefix}/include$\r$\n"\r
342 FileWrite $0 "$\r$\n"\r
343 FileWrite $0 "Name: GObject$\r$\n"\r
344 FileWrite $0 "Description: GLib Type, Object, Parameter and Signal Library$\r$\n"\r
345 FileWrite $0 "Requires: glib-2.0$\r$\n"\r
346 FileWrite $0 "Version: 2.0.4$\r$\n"\r
347 FileWrite $0 "Libs: -L$${libdir} -lgobject-2.0$\r$\n"\r
348 FileWrite $0 "Cflags:$\r$\n"\r
349 FileClose $0\r
350 \r
351 ; ============= gthread-2.0.pc ===============\r
352 FileOpen $0 "$INSTDIR\lib\pkgconfig\gthread-2.0.pc" "w"\r
353 FileWrite $0 "prefix=$6$\r$\n"\r
354 FileWrite $0 "exec_prefix=$${prefix}$\r$\n"\r
355 FileWrite $0 "libdir=$${exec_prefix}/lib$\r$\n"\r
356 FileWrite $0 "includedir=$${prefix}/include$\r$\n"\r
357 FileWrite $0 "$\r$\n"\r
358 FileWrite $0 "Name: GThread$\r$\n"\r
359 FileWrite $0 "Description: Thread support for GLib$\r$\n"\r
360 FileWrite $0 "Requires: glib-2.0$\r$\n"\r
361 FileWrite $0 "Version: 2.0.4$\r$\n"\r
362 FileWrite $0 "Libs: -L$${libdir} -lgthread-2.0 $\r$\n"\r
363 FileWrite $0 "Cflags: -D_REENTRANT$\r$\n"\r
364 FileClose $0\r
365
366 ; ============= libintl.pc ===============\r
367 FileOpen $0 "$INSTDIR\lib\pkgconfig\libintl.pc" "w"\r
368 FileWrite $0 "prefix=$6$\r$\n"\r
369 FileWrite $0 "exec_prefix=$${prefix}$\r$\n"\r
370 FileWrite $0 "libdir=$${exec_prefix}/lib$\r$\n"\r
371 FileWrite $0 "includedir=$${prefix}/include$\r$\n"\r
372 FileWrite $0 "$\r$\n"\r
373 FileWrite $0 "Name: libintl$\r$\n"\r
374 FileWrite $0 "Description: The intl library from GNU gettext$\r$\n"\r
375 FileWrite $0 "Version: 0.10.40-tml$\r$\n"\r
376 FileWrite $0 "Libs: -L$${libdir} -lintl$\r$\n"\r
377 FileWrite $0 "Cflags: -I$${includedir}$\r$\n"\r
378 FileClose $0\r
379
380 NoInstall:
381 SectionEnd
382
383 Function windowsBatCore
384         Exch $1 ;core exe name
385
386         FileOpen $0 "$WINDIR\$1.bat" "w"
387         FileWrite $0 "@ECHO OFF$\r$\n"
388         FileWrite $0 "CALL MonoBasePath.bat$\r$\n"
389         FileWrite $0 "SET MONOARGS=$\r$\n"
390         FileWrite $0 ":loop$\r$\n"
391         FileWrite $0 "IF x%1 == x goto :done$\r$\n"
392         FileWrite $0 "SET MONOARGS=%MONOARGS% %1$\r$\n"
393         FileWrite $0 "SHIFT$\r$\n"
394         FileWrite $0 "GOTO loop$\r$\n"
395         FileWrite $0 ":done$\r$\n"
396         FileWrite $0 "SETLOCAL$\r$\n"
397         FileWrite $0 'SET PATH="$INSTDIR\bin\;$INSTDIR\lib\;$INSTDIR\icu\bin;%PATH%"$\r$\n'
398         FileWrite $0 '"$INSTDIR\bin\$1.exe" %MONOARGS%$\r$\n'
399         FileWrite $0 "EXIT /B %ERRORLEVEL%$\r$\n"
400         FileWrite $0 "ENDLOCAL$\r$\n"
401         FileClose $0
402
403         FileOpen $0 "$INSTDIR\bin\$1" "w"
404         FileWrite $0 "#!/bin/sh$\r$\n"
405         FileWrite $0 "export MONO_PATH=$6/lib$\r$\n"
406         FileWrite $0 "export MONO_CFG_DIR=$6/etc/mono$\r$\n"
407         FileWrite $0 '$6/bin/$1.exe "$$@"'
408         FileClose $0
409
410         Pop $1
411 FunctionEnd
412
413 Function windowsBat
414         Exch $1 ;tool name
415
416         FileOpen $0 "$WINDIR\$1.bat" "w"
417         FileWrite $0 "@ECHO OFF$\r$\n"
418         FileWrite $0 "CALL monobasepath.bat$\r$\n"
419         FileWrite $0 "SET MONOARGS=$\r$\n"
420         FileWrite $0 ":loop$\r$\n"
421         FileWrite $0 "IF x%1 == x GOTO :done$\r$\n"
422         FileWrite $0 "SET MONOARGS=%MONOARGS% %1$\r$\n"
423         FileWrite $0 "SHIFT$\r$\n"
424         FileWrite $0 "GOTO loop$\r$\n"
425         FileWrite $0 ":done$\r$\n"
426         FileWrite $0 "SETLOCAL$\r$\n"
427         FileWrite $0 'SET PATH="$INSTDIR\bin\;$INSTDIR\lib\;$INSTDIR\icu\bin;%PATH%"$\r$\n'
428         FileWrite $0 '"$INSTDIR\bin\mono.exe" "$INSTDIR\lib\$1.exe" %MONOARGS%$\r$\n'
429         FileWrite $0 "EXIT /B %ERRORLEVEL%$\r$\n"
430         FileWrite $0 "ENDLOCAL$\r$\n"
431         FileClose $0
432
433         FileOpen $0 "$INSTDIR\bin\$1" "w"
434         FileWrite $0 "#!/bin/sh$\r$\n"
435         FileWrite $0 "export MONO_PATH=$6/lib$\r$\n"
436         FileWrite $0 "export MONO_CFG_DIR=$6/etc/mono$\r$\n"
437         FileWrite $0 '$6/bin/mono.exe $6/lib/$1.exe "$$@"'
438         FileClose $0
439
440         Pop $1
441 FunctionEnd
442
443 ; function StrReplace
444 ; by Hendri Adriaens
445 ; HendriAdriaens@hotmail.com
446 ; found in the NSIS Archives
447 function StrReplace
448   Exch $0 ;this will replace wrong characters
449   Exch
450   Exch $1 ;needs to be replaced
451   Exch
452   Exch 2
453   Exch $2 ;the orginal string
454   Push $3 ;counter
455   Push $4 ;temp character
456   Push $5 ;temp string
457   Push $6 ;length of string that need to be replaced
458   Push $7 ;length of string that will replace
459   Push $R0 ;tempstring
460   Push $R1 ;tempstring
461   Push $R2 ;tempstring
462   StrCpy $3 "-1"
463   StrCpy $5 ""
464   StrLen $6 $1
465   StrLen $7 $0
466   Loop:
467   IntOp $3 $3 + 1
468   StrCpy $4 $2 $6 $3
469   StrCmp $4 "" ExitLoop
470   StrCmp $4 $1 Replace
471   Goto Loop
472   Replace:
473   StrCpy $R0 $2 $3
474   IntOp $R2 $3 + $6
475   StrCpy $R1 $2 "" $R2
476   StrCpy $2 $R0$0$R1
477   IntOp $3 $3 + $7
478   Goto Loop
479   ExitLoop:
480   StrCpy $0 $2
481   Pop $R2
482   Pop $R1
483   Pop $R0
484   Pop $7
485   Pop $6
486   Pop $5
487   Pop $4
488   Pop $3
489   Pop $2
490   Pop $1
491   Exch $0
492 FunctionEnd
493
494 Function VersionCheck
495   Exch $0 ;second versionnumber
496   Exch
497   Exch $1 ;first versionnumber
498   Push $R0 ;counter for $0
499   Push $R1 ;counter for $1
500   Push $3 ;temp char
501   Push $4 ;temp string for $0
502   Push $5 ;temp string for $1
503   StrCpy $R0 "-1"
504   StrCpy $R1 "-1"
505   Start:
506   StrCpy $4 ""
507   DotLoop0:
508   IntOp $R0 $R0 + 1
509   StrCpy $3 $0 1 $R0
510   StrCmp $3 "" DotFound0
511   StrCmp $3 "." DotFound0
512   StrCpy $4 $4$3
513   Goto DotLoop0
514   DotFound0:
515   StrCpy $5 ""
516   DotLoop1:
517   IntOp $R1 $R1 + 1
518   StrCpy $3 $1 1 $R1
519   StrCmp $3 "" DotFound1
520   StrCmp $3 "." DotFound1
521   StrCpy $5 $5$3
522   Goto DotLoop1
523   DotFound1:
524   Strcmp $4 "" 0 Not4
525     StrCmp $5 "" Equal
526     Goto Ver2Less
527   Not4:
528   StrCmp $5 "" Ver2More
529   IntCmp $4 $5 Start Ver2Less Ver2More
530   Equal:
531   StrCpy $0 "0"
532   Goto Finish
533   Ver2Less:
534   StrCpy $0 "1"
535   Goto Finish
536   Ver2More:
537   StrCpy $0 "2"
538   Finish:
539   Pop $5
540   Pop $4
541   Pop $3
542   Pop $R1
543   Pop $R0
544   Pop $1
545   Exch $0
546 FunctionEnd