1 # sdcc.nsi - NSIS installer script for SDCC
3 # Copyright (c) 2003,2004 Borut Razem
5 # This file is part of sdcc.
7 # This software is provided 'as-is', without any express or implied
8 # warranty. In no event will the authors be held liable for any damages
9 # arising from the use of this software.
11 # Permission is granted to anyone to use this software for any purpose,
12 # including commercial applications, and to alter it and redistribute it
13 # freely, subject to the following restrictions:
15 # 1. The origin of this software must not be misrepresented; you must not
16 # claim that you wrote the original software. If you use this software
17 # in a product, an acknowledgment in the product documentation would be
18 # appreciated but is not required.
19 # 2. Altered source versions must be plainly marked as such, and must not be
20 # misrepresented as being the original software.
21 # 3. This notice may not be removed or altered from any source distribution.
24 # borut.razem@siol.net
30 !define SDCC_ROOT "..\.."
35 !system "dir ${SDCC_ROOT}\device > NUL" <> 0
36 !define DEV_ROOT "${SDCC_ROOT}"
38 !system "dir ${SDCC_ROOT}\device > NUL" = 0
39 !define DEV_ROOT "${SDCC_ROOT}\device"
42 !system "unix2dos ${SDCC_ROOT}\doc\ChangeLog_head.txt" = 0
43 !system "unix2dos ${SDCC_ROOT}\doc\README.TXT" = 0
45 InstType "Full (Bin, Doc, Lib, Src)"
46 InstType "Medium (Bin, Doc, Lib)"
47 InstType "Compact (Bin, Doc)"
49 ;--------------------------------
52 Var MUI_STARTMENUPAGE_VARIABLE
54 ;--------------------------------
55 !define MUI_ABORTWARNING
57 !insertmacro MUI_PAGE_WELCOME
58 !insertmacro MUI_PAGE_LICENSE "${SDCC_ROOT}\COPYING.TXT"
59 !define MUI_STARTMENUPAGE_DEFAULTFOLDER "SDCC"
60 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
61 !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC"
62 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "NSIS:StartMenuDir"
63 !define MUI_STARTMENUPAGE_NODISABLE
64 !insertmacro MUI_PAGE_STARTMENU Application $MUI_STARTMENUPAGE_VARIABLE
65 !insertmacro MUI_PAGE_COMPONENTS
66 !insertmacro MUI_PAGE_DIRECTORY
67 !insertmacro MUI_PAGE_INSTFILES
68 !insertmacro MUI_PAGE_FINISH
70 !insertmacro MUI_UNPAGE_INSTFILES
72 !insertmacro MUI_LANGUAGE "English"
77 InstallDir "$PROGRAMFILES\SDCC"
79 ShowUnInstDetails show
82 ;Uninstall the old version, if present
84 "Software\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" \
88 MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
89 "$(^Name) is already installed. $\n$\nClick `OK` to remove the \
90 previous version or `Cancel` to cancel this upgrade." \
97 ExecWait '$R0 _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
99 ;IfErrors no_remove_uninstaller
100 ; ;You can either use Delete /REBOOTOK in the uninstaller or add some code
101 ; ;here to remove to remove the uninstaller. Use a registry key to check
102 ; ;whether the user has chosen to uninstall. If you are using an uninstaller
103 ; ;components page, make sure all sections are uninstalled.
104 ;no_remove_uninstaller:
109 ; install the new version
110 MessageBox MB_YESNO|MB_ICONQUESTION "This will install $(^Name). Do you wish to continue?" IDYES +2
117 SetOutPath "$INSTDIR"
119 File "${SDCC_ROOT}\COPYING.TXT"
122 Section "SDCC application files"
124 SetOutPath "$INSTDIR\bin"
125 File "${SDCC_ROOT}\bin\*.exe"
128 Section "SDCC documentation"
130 SetOutPath "$INSTDIR\doc"
131 File "${SDCC_ROOT}\doc\ChangeLog_head.txt"
132 File "${SDCC_ROOT}\doc\README.TXT"
135 Section "SDCC include files"
137 SetOutPath "$INSTDIR\include\asm\default"
138 File "${DEV_ROOT}\include\asm\default\features.h"
139 SetOutPath "$INSTDIR\include\asm\gbz80"
140 File "${DEV_ROOT}\include\asm\gbz80\features.h"
141 SetOutPath "$INSTDIR\include\asm\z80"
142 File "${DEV_ROOT}\include\asm\z80\features.h"
143 SetOutPath "$INSTDIR\include"
144 File "${DEV_ROOT}\include\*.h"
147 Section "SDCC DS390 library"
149 SetOutPath "$INSTDIR\lib\ds390"
150 File "${DEV_ROOT}\lib\ds390\*.asm"
151 File "${DEV_ROOT}\lib\ds390\*.rel"
152 File "${DEV_ROOT}\lib\ds390\*.lib"
155 Section "SDCC DS400 library"
157 SetOutPath "$INSTDIR\lib\ds400"
158 File "${DEV_ROOT}\lib\ds400\*.asm"
159 File "${DEV_ROOT}\lib\ds400\*.rel"
160 File "${DEV_ROOT}\lib\ds400\*.lib"
163 Section "SDCC GBZ80 library"
165 SetOutPath "$INSTDIR\lib\gbz80"
166 File "${DEV_ROOT}\lib\gbz80\*.asm"
167 File "${DEV_ROOT}\lib\gbz80\*.o"
168 File "${DEV_ROOT}\lib\gbz80\*.lib"
171 Section "SDCC Z80 library"
173 SetOutPath "$INSTDIR\lib\z80"
174 File "${DEV_ROOT}\lib\z80\*.asm"
175 File "${DEV_ROOT}\lib\z80\*.o"
176 File "${DEV_ROOT}\lib\z80\*.lib"
179 Section "SDCC large model library"
181 SetOutPath "$INSTDIR\lib\large"
182 File "${DEV_ROOT}\lib\large\*.asm"
183 File "${DEV_ROOT}\lib\large\*.rel"
184 File "${DEV_ROOT}\lib\large\*.lib"
187 Section "SDCC small model library"
189 SetOutPath "$INSTDIR\lib\small"
190 File "${DEV_ROOT}\lib\small\*.asm"
191 File "${DEV_ROOT}\lib\small\*.rel"
192 File "${DEV_ROOT}\lib\small\*.lib"
195 Section "SDCC HC08 library"
197 SetOutPath "$INSTDIR\lib\hc08"
198 File "${DEV_ROOT}\lib\hc08\*.asm"
199 File "${DEV_ROOT}\lib\hc08\*.rel"
200 File "${DEV_ROOT}\lib\hc08\*.lib"
203 Section "SDCC library sources"
205 SetOutPath "$INSTDIR\lib\src\ds390\examples"
206 File "${DEV_ROOT}\lib\src\ds390\examples\MOVED"
208 SetOutPath "$INSTDIR\lib\src\ds390"
209 File "${DEV_ROOT}\lib\src\ds390\*.c"
210 File "${DEV_ROOT}\lib\src\ds390\libds390.lib"
211 File "${DEV_ROOT}\lib\src\ds390\Makefile"
212 File "${DEV_ROOT}\lib\src\ds390\Makefile.dep"
214 SetOutPath "$INSTDIR\lib\src\ds400"
215 File "${DEV_ROOT}\lib\src\ds400\*.c"
216 File "${DEV_ROOT}\lib\src\ds400\libds400.lib"
217 File "${DEV_ROOT}\lib\src\ds400\Makefile"
218 File "${DEV_ROOT}\lib\src\ds400\Makefile.dep"
220 SetOutPath "$INSTDIR\lib\src\gbz80"
221 File "${DEV_ROOT}\lib\src\gbz80\*.c"
222 File "${DEV_ROOT}\lib\src\gbz80\*.s"
223 File "${DEV_ROOT}\lib\src\gbz80\gbz80.lib"
224 File "${DEV_ROOT}\lib\src\gbz80\Makefile"
225 File "${DEV_ROOT}\lib\src\gbz80\README"
227 SetOutPath "$INSTDIR\lib\src\z80"
228 File "${DEV_ROOT}\lib\src\z80\*.c"
229 File "${DEV_ROOT}\lib\src\z80\*.s"
230 File "${DEV_ROOT}\lib\src\z80\Makefile"
231 File "${DEV_ROOT}\lib\src\z80\README"
232 File "${DEV_ROOT}\lib\src\z80\z80.lib"
234 SetOutPath "$INSTDIR\lib\src\hc08"
235 File "${DEV_ROOT}\lib\src\hc08\*.c"
236 File "${DEV_ROOT}\lib\src\hc08\Makefile"
237 File "${DEV_ROOT}\lib\src\hc08\hc08.lib"
239 SetOutPath "$INSTDIR\lib\src"
240 File "${DEV_ROOT}\lib\src\*.c"
244 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
245 CreateDirectory "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE"
246 CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\SDCC on the Web.lnk" "$INSTDIR\sdcc.url"
247 CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Uninstall SDCC.lnk" "$INSTDIR\uninstall.exe"
248 CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Documentation.lnk" "$INSTDIR\doc\README.TXT" "" "$INSTDIR\sdcc.ico" "" "" "" ""
249 CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Change Log.lnk" "$INSTDIR\doc\ChangeLog_head.txt" "" "$INSTDIR\sdcc.ico" "" "" "" ""
250 CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\GPL 2 License.lnk" "$INSTDIR\COPYING.TXT"
251 !insertmacro MUI_STARTMENU_WRITE_END
255 WriteIniStr "$INSTDIR\sdcc.url" "InternetShortcut" "URL" "http://sdcc.sourceforge.net/"
259 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "DisplayName" "SDCC"
260 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "UninstallString" "$INSTDIR\uninstall.exe"
261 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "Publisher" "sdcc.sourceforge.net"
262 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "URLInfoAbout" "http://sdcc.sourceforge.net/"
263 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "HelpLink" "http://sdcc.sourceforge.net/"
264 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "URLUpdateInfo" "http://sdcc.sourceforge.net/"
265 WriteUninstaller "$INSTDIR\uninstall.exe"
269 MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Do you want to add $INSTDIR\bin to the PATH?" IDNO +3
275 ;;;; Uninstaller code ;;;;
278 MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
282 Function un.onUninstSuccess
284 MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
288 !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_STARTMENUPAGE_VARIABLE
290 Delete "$INSTDIR\sdcc.url"
292 DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "NSIS:StartMenuDir"
293 DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC"
295 Delete "$INSTDIR\uninstall.exe"
296 Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\GPL 2 License.lnk"
297 Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Change Log.lnk"
298 Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Documentation.lnk"
299 Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Uninstall SDCC.lnk"
300 Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\SDCC on the Web.lnk"
302 Delete "$INSTDIR\lib\src\hc08\*.c"
303 Delete "$INSTDIR\lib\src\hc08\hc08.lib"
304 Delete "$INSTDIR\lib\src\hc08\Makefile"
306 Delete "$INSTDIR\lib\src\z80\*.c"
307 Delete "$INSTDIR\lib\src\z80\*.s"
308 Delete "$INSTDIR\lib\src\z80\z80.lib"
309 Delete "$INSTDIR\lib\src\z80\README"
310 Delete "$INSTDIR\lib\src\z80\Makefile"
312 Delete "$INSTDIR\lib\src\gbz80\*.c"
313 Delete "$INSTDIR\lib\src\gbz80\*.s"
314 Delete "$INSTDIR\lib\src\gbz80\gbz80.lib"
315 Delete "$INSTDIR\lib\src\gbz80\README"
316 Delete "$INSTDIR\lib\src\gbz80\Makefile"
318 Delete "$INSTDIR\lib\src\ds390\*.c"
319 Delete "$INSTDIR\lib\src\ds390\libds390.lib"
320 Delete "$INSTDIR\lib\src\ds390\Makefile.dep"
321 Delete "$INSTDIR\lib\src\ds390\Makefile"
322 Delete "$INSTDIR\lib\src\ds390\examples\MOVED"
324 Delete "$INSTDIR\lib\src\ds400\*.c"
325 Delete "$INSTDIR\lib\src\ds400\libds400.lib"
326 Delete "$INSTDIR\lib\src\ds400\Makefile.dep"
327 Delete "$INSTDIR\lib\src\ds400\Makefile"
329 Delete "$INSTDIR\lib\src\*.c"
331 Delete "$INSTDIR\lib\hc08\*.rel"
332 Delete "$INSTDIR\lib\hc08\*.asm"
333 Delete "$INSTDIR\lib\hc08\*.lib"
335 Delete "$INSTDIR\lib\z80\*.o"
336 Delete "$INSTDIR\lib\z80\*.asm"
337 Delete "$INSTDIR\lib\z80\*.lib"
339 Delete "$INSTDIR\lib\small\*.asm"
340 Delete "$INSTDIR\lib\small\*.rel"
341 Delete "$INSTDIR\lib\small\*.lib"
343 Delete "$INSTDIR\lib\large\*.asm"
344 Delete "$INSTDIR\lib\large\*.rel"
345 Delete "$INSTDIR\lib\large\*.lib"
347 Delete "$INSTDIR\lib\gbz80\*.asm"
348 Delete "$INSTDIR\lib\gbz80\*.o"
349 Delete "$INSTDIR\lib\gbz80\*.lib"
351 Delete "$INSTDIR\lib\ds390\*.asm"
352 Delete "$INSTDIR\lib\ds390\*.rel"
353 Delete "$INSTDIR\lib\ds390\*.lib"
355 Delete "$INSTDIR\lib\ds400\*.asm"
356 Delete "$INSTDIR\lib\ds400\*.rel"
357 Delete "$INSTDIR\lib\ds400\*.lib"
359 Delete "$INSTDIR\include\asm\z80\*.h"
360 Delete "$INSTDIR\include\asm\gbz80\*.h"
361 Delete "$INSTDIR\include\asm\default\*.h"
362 Delete "$INSTDIR\include\*.h"
364 Delete "$INSTDIR\doc\README.TXT"
365 Delete "$INSTDIR\doc\ChangeLog_head.txt"
367 Delete "$INSTDIR\bin\*.exe"
369 Delete "$INSTDIR\COPYING.TXT"
370 Delete "$INSTDIR\sdcc.ico"
372 RMDir "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE"
374 RMDir "$INSTDIR\lib\src\z80"
375 RMDir "$INSTDIR\lib\src\gbz80"
376 RMDir "$INSTDIR\lib\src\ds390\examples"
377 RMDir "$INSTDIR\lib\src\ds390"
378 RMDir "$INSTDIR\lib\src\ds400"
379 RMDir "$INSTDIR\lib\src\hc08"
380 RMDir "$INSTDIR\lib\src"
382 RMDir "$INSTDIR\lib\z80"
383 RMDir "$INSTDIR\lib\small"
384 RMDir "$INSTDIR\lib\large"
385 RMDir "$INSTDIR\lib\gbz80"
386 RMDir "$INSTDIR\lib\ds390"
387 RMDir "$INSTDIR\lib\ds400"
388 RMDir "$INSTDIR\lib\hc08"
391 RMDir "$INSTDIR\include\asm\z80"
392 RMDir "$INSTDIR\include\asm\gbz80"
393 RMDir "$INSTDIR\include\asm\default"
394 RMDir "$INSTDIR\include\asm"
395 RMDir "$INSTDIR\include"
404 Call un.RemoveFromPath
409 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
410 ; Path Manipulation functions ;
411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
414 !include "WinMessages.NSH"
417 ; AddToPath - Adds the given dir to the search path.
418 ; Input - head of the stack
419 ; Note - Win9x systems requires reboot
428 ; don't add if the path doesn't exist
429 IfFileExists $0 "" AddToPath_done
434 ; Not on NT: read PATH from environment variable
437 ; On NT: read PATH from registry
438 ReadRegStr $1 HKCU "Environment" "PATH"
443 StrCmp $2 "" "" AddToPath_done
448 StrCmp $2 "" "" AddToPath_done
449 GetFullPathName /SHORT $3 $0
454 StrCmp $2 "" "" AddToPath_done
459 StrCmp $2 "" "" AddToPath_done
461 StrCmp $4 1 AddToPath_NT
464 FileOpen $1 "$1\autoexec.bat" a
467 IntCmp $2 26 0 +2 +2 ; DOS EOF
468 FileSeek $1 -1 END ; write over EOF
469 FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
475 ReadRegStr $1 HKCU "Environment" "PATH"
476 StrCpy $2 $1 1 -1 ; copy last char
477 StrCmp $2 ";" 0 +2 ; if last char == ;
478 StrCpy $1 $1 -1 ; remove last char
479 StrCmp $1 "" AddToPath_NTdoIt
482 WriteRegExpandStr HKCU "Environment" "PATH" $0
483 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
493 ; RemoveFromPath - Remove a given dir from the path
494 ; Input: head of the stack
496 Function un.RemoveFromPath
505 IntFmt $6 "%c" 26 ; DOS EOF
509 StrCmp $1 1 unRemoveFromPath_NT
512 FileOpen $1 "$1\autoexec.bat" r
515 GetFullPathName /SHORT $0 $0
516 StrCpy $0 "SET PATH=%PATH%;$0"
517 Goto unRemoveFromPath_dosLoop
519 unRemoveFromPath_dosLoop:
521 StrCpy $5 $3 1 -1 ; read last char
522 StrCmp $5 $6 0 +2 ; if DOS EOF
523 StrCpy $3 $3 -1 ; remove DOS EOF so we can compare
524 StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
525 StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
526 StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
527 StrCmp $3 "" unRemoveFromPath_dosLoopEnd
529 Goto unRemoveFromPath_dosLoop
530 unRemoveFromPath_dosLoopRemoveLine:
532 Goto unRemoveFromPath_dosLoop
534 unRemoveFromPath_dosLoopEnd:
538 Delete "$1\autoexec.bat"
539 CopyFiles /SILENT $4 "$1\autoexec.bat"
541 Goto unRemoveFromPath_done
544 ReadRegStr $1 HKCU "Environment" "PATH"
545 StrCpy $5 $1 1 -1 ; copy last char
546 StrCmp $5 ";" +2 ; if last char != ;
547 StrCpy $1 "$1;" ; append ;
550 Call un.StrStr ; Find `$0;` in $1
551 Pop $2 ; pos of our dir
552 StrCmp $2 "" unRemoveFromPath_done
553 ; else, it is in path
558 StrCpy $5 $1 -$4 ; $5 is now the part before the path to remove
559 StrCpy $6 $2 "" $3 ; $6 is now the part after the path to remove
562 StrCpy $5 $3 1 -1 ; copy last char
563 StrCmp $5 ";" 0 +2 ; if last char == ;
564 StrCpy $3 $3 -1 ; remove last char
567 ; New PATH not empty: update the registry
568 WriteRegExpandStr HKCU "Environment" "PATH" $3
570 ; New PATH empty: remove from the registry
571 DeleteRegValue HKCU "Environment" "PATH"
572 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
574 unRemoveFromPath_done:
584 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
585 ; Utility Functions ;
586 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
590 ; output, top of the stack = 1 if NT or 0 if not
595 ; ($R0 at this point is 1 or 0)
600 ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
601 StrCmp $0 "" 0 IsNT_yes
614 !insertmacro IsNT "un."
617 ; input, top of stack = string to search for
618 ; top of stack-1 = string to search in
619 ; output, top of stack (replaces with the portion of the string remaining)
620 ; modifies no other variables.
623 ; Push "this is a long ass string"
627 ; ($R0 at this point is "ass string")
631 Exch $R1 ; st=haystack,old$R1, $R1=needle
632 Exch ; st=old$R1,haystack
633 Exch $R2 ; st=old$R1,old$R2, $R2=haystack
645 StrCpy $R5 $R2 $R3 $R4
651 StrCpy $R1 $R2 "" $R4
659 !insertmacro StrStr ""
660 !insertmacro StrStr "un."