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
56 !insertmacro MUI_PAGE_WELCOME
57 !insertmacro MUI_PAGE_LICENSE "${SDCC_ROOT}\COPYING.TXT"
58 !define MUI_STARTMENUPAGE_DEFAULTFOLDER "SDCC"
59 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
60 !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC"
61 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "NSIS:StartMenuDir"
62 !define MUI_STARTMENUPAGE_NODISABLE
63 !insertmacro MUI_PAGE_STARTMENU Application $MUI_STARTMENUPAGE_VARIABLE
64 !insertmacro MUI_PAGE_COMPONENTS
65 !insertmacro MUI_PAGE_DIRECTORY
66 !insertmacro MUI_PAGE_INSTFILES
67 !insertmacro MUI_PAGE_FINISH
68 !insertmacro MUI_UNPAGE_INSTFILES
69 !insertmacro MUI_LANGUAGE "English"
74 InstallDir "$PROGRAMFILES\SDCC"
76 ShowUnInstDetails show
79 MessageBox MB_YESNO|MB_ICONQUESTION "This will install $(^Name). Do you wish to continue?" IDYES +2
86 File "${SDCC_ROOT}\COPYING.TXT"
89 Section "SDCC application files"
91 SetOutPath "$INSTDIR\bin"
92 File "${SDCC_ROOT}\bin\*.exe"
95 Section "SDCC documentation"
97 SetOutPath "$INSTDIR\doc"
98 File "${SDCC_ROOT}\doc\ChangeLog_head.txt"
99 File "${SDCC_ROOT}\doc\README.TXT"
102 Section "SDCC include files"
104 SetOutPath "$INSTDIR\include\asm\default"
105 File "${DEV_ROOT}\include\asm\default\features.h"
106 SetOutPath "$INSTDIR\include\asm\gbz80"
107 File "${DEV_ROOT}\include\asm\gbz80\features.h"
108 SetOutPath "$INSTDIR\include\asm\z80"
109 File "${DEV_ROOT}\include\asm\z80\features.h"
110 SetOutPath "$INSTDIR\include"
111 File "${DEV_ROOT}\include\*.h"
114 Section "SDCC DS390 library"
116 SetOutPath "$INSTDIR\lib\ds390"
117 File "${DEV_ROOT}\lib\ds390\*.asm"
118 File "${DEV_ROOT}\lib\ds390\*.rel"
119 File "${DEV_ROOT}\lib\ds390\*.lib"
122 Section "SDCC DS400 library"
124 SetOutPath "$INSTDIR\lib\ds400"
125 File "${DEV_ROOT}\lib\ds400\*.asm"
126 File "${DEV_ROOT}\lib\ds400\*.rel"
127 File "${DEV_ROOT}\lib\ds400\*.lib"
130 Section "SDCC GBZ80 library"
132 SetOutPath "$INSTDIR\lib\gbz80"
133 File "${DEV_ROOT}\lib\gbz80\*.asm"
134 File "${DEV_ROOT}\lib\gbz80\*.o"
135 File "${DEV_ROOT}\lib\gbz80\*.lib"
138 Section "SDCC Z80 library"
140 SetOutPath "$INSTDIR\lib\z80"
141 File "${DEV_ROOT}\lib\z80\*.asm"
142 File "${DEV_ROOT}\lib\z80\*.o"
143 File "${DEV_ROOT}\lib\z80\*.lib"
146 Section "SDCC large model library"
148 SetOutPath "$INSTDIR\lib\large"
149 File "${DEV_ROOT}\lib\large\*.asm"
150 File "${DEV_ROOT}\lib\large\*.rel"
151 File "${DEV_ROOT}\lib\large\*.lib"
154 Section "SDCC small model library"
156 SetOutPath "$INSTDIR\lib\small"
157 File "${DEV_ROOT}\lib\small\*.asm"
158 File "${DEV_ROOT}\lib\small\*.rel"
159 File "${DEV_ROOT}\lib\small\*.lib"
162 Section "SDCC HC08 library"
164 SetOutPath "$INSTDIR\lib\hc08"
165 File "${DEV_ROOT}\lib\hc08\*.asm"
166 File "${DEV_ROOT}\lib\hc08\*.rel"
167 File "${DEV_ROOT}\lib\hc08\*.lib"
170 Section "SDCC library sources"
172 SetOutPath "$INSTDIR\lib\src\ds390\examples"
173 File "${DEV_ROOT}\lib\src\ds390\examples\MOVED"
175 SetOutPath "$INSTDIR\lib\src\ds390"
176 File "${DEV_ROOT}\lib\src\ds390\*.c"
177 File "${DEV_ROOT}\lib\src\ds390\libds390.lib"
178 File "${DEV_ROOT}\lib\src\ds390\Makefile"
179 File "${DEV_ROOT}\lib\src\ds390\Makefile.dep"
181 SetOutPath "$INSTDIR\lib\src\ds400"
182 File "${DEV_ROOT}\lib\src\ds400\*.c"
183 File "${DEV_ROOT}\lib\src\ds400\libds400.lib"
184 File "${DEV_ROOT}\lib\src\ds400\Makefile"
185 File "${DEV_ROOT}\lib\src\ds400\Makefile.dep"
187 SetOutPath "$INSTDIR\lib\src\gbz80"
188 File "${DEV_ROOT}\lib\src\gbz80\*.c"
189 File "${DEV_ROOT}\lib\src\gbz80\*.s"
190 File "${DEV_ROOT}\lib\src\gbz80\gbz80.lib"
191 File "${DEV_ROOT}\lib\src\gbz80\Makefile"
192 File "${DEV_ROOT}\lib\src\gbz80\README"
194 SetOutPath "$INSTDIR\lib\src\z80"
195 File "${DEV_ROOT}\lib\src\z80\*.c"
196 File "${DEV_ROOT}\lib\src\z80\*.s"
197 File "${DEV_ROOT}\lib\src\z80\Makefile"
198 File "${DEV_ROOT}\lib\src\z80\README"
199 File "${DEV_ROOT}\lib\src\z80\z80.lib"
201 SetOutPath "$INSTDIR\lib\src\hc08"
202 File "${DEV_ROOT}\lib\src\hc08\*.c"
203 File "${DEV_ROOT}\lib\src\hc08\Makefile"
204 File "${DEV_ROOT}\lib\src\hc08\hc08.lib"
206 SetOutPath "$INSTDIR\lib\src"
207 File "${DEV_ROOT}\lib\src\*.c"
211 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
212 CreateDirectory "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE"
213 CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\SDCC on the Web.lnk" "$INSTDIR\sdcc.url"
214 CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Uninstall SDCC.lnk" "$INSTDIR\uninstall.exe"
215 CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Documentation.lnk" "$INSTDIR\doc\README.TXT" "" "$INSTDIR\sdcc.ico" "" "" "" ""
216 CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Change Log.lnk" "$INSTDIR\doc\ChangeLog_head.txt" "" "$INSTDIR\sdcc.ico" "" "" "" ""
217 CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\GPL 2 License.lnk" "$INSTDIR\COPYING.TXT"
218 !insertmacro MUI_STARTMENU_WRITE_END
222 WriteIniStr "$INSTDIR\sdcc.url" "InternetShortcut" "URL" "http://sdcc.sourceforge.net/"
226 MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Do you want to add $INSTDIR\bin to the PATH?" IDNO +3
232 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "DisplayName" "SDCC"
233 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "UninstallString" "$INSTDIR\uninstall.exe"
234 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "Publisher" "sdcc.sourceforge.net"
235 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "URLInfoAbout" "http://sdcc.sourceforge.net/"
236 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "HelpLink" "http://sdcc.sourceforge.net/"
237 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "URLUpdateInfo" "http://sdcc.sourceforge.net/"
238 WriteUninstaller "$INSTDIR\uninstall.exe"
242 #### Uninstaller code ####
245 MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
249 Function un.onUninstSuccess
251 MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
255 !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_STARTMENUPAGE_VARIABLE
257 Delete "$INSTDIR\sdcc.url"
259 DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC" "NSIS:StartMenuDir"
260 DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\SDCC"
262 Delete "$INSTDIR\uninstall.exe"
263 Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\GPL 2 License.lnk"
264 Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Change Log.lnk"
265 Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Documentation.lnk"
266 Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Uninstall SDCC.lnk"
267 Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\SDCC on the Web.lnk"
269 Delete "$INSTDIR\lib\src\hc08\*.c"
270 Delete "$INSTDIR\lib\src\hc08\hc08.lib"
271 Delete "$INSTDIR\lib\src\hc08\Makefile"
273 Delete "$INSTDIR\lib\src\z80\*.c"
274 Delete "$INSTDIR\lib\src\z80\*.s"
275 Delete "$INSTDIR\lib\src\z80\z80.lib"
276 Delete "$INSTDIR\lib\src\z80\README"
277 Delete "$INSTDIR\lib\src\z80\Makefile"
279 Delete "$INSTDIR\lib\src\gbz80\*.c"
280 Delete "$INSTDIR\lib\src\gbz80\*.s"
281 Delete "$INSTDIR\lib\src\gbz80\gbz80.lib"
282 Delete "$INSTDIR\lib\src\gbz80\README"
283 Delete "$INSTDIR\lib\src\gbz80\Makefile"
285 Delete "$INSTDIR\lib\src\ds390\*.c"
286 Delete "$INSTDIR\lib\src\ds390\libds390.lib"
287 Delete "$INSTDIR\lib\src\ds390\Makefile.dep"
288 Delete "$INSTDIR\lib\src\ds390\Makefile"
289 Delete "$INSTDIR\lib\src\ds390\examples\MOVED"
291 Delete "$INSTDIR\lib\src\ds400\*.c"
292 Delete "$INSTDIR\lib\src\ds400\libds400.lib"
293 Delete "$INSTDIR\lib\src\ds400\Makefile.dep"
294 Delete "$INSTDIR\lib\src\ds400\Makefile"
296 Delete "$INSTDIR\lib\src\*.c"
298 Delete "$INSTDIR\lib\hc08\*.rel"
299 Delete "$INSTDIR\lib\hc08\*.asm"
300 Delete "$INSTDIR\lib\hc08\*.lib"
302 Delete "$INSTDIR\lib\z80\*.o"
303 Delete "$INSTDIR\lib\z80\*.asm"
304 Delete "$INSTDIR\lib\z80\*.lib"
306 Delete "$INSTDIR\lib\small\*.asm"
307 Delete "$INSTDIR\lib\small\*.rel"
308 Delete "$INSTDIR\lib\small\*.lib"
310 Delete "$INSTDIR\lib\large\*.asm"
311 Delete "$INSTDIR\lib\large\*.rel"
312 Delete "$INSTDIR\lib\large\*.lib"
314 Delete "$INSTDIR\lib\gbz80\*.asm"
315 Delete "$INSTDIR\lib\gbz80\*.o"
316 Delete "$INSTDIR\lib\gbz80\*.lib"
318 Delete "$INSTDIR\lib\ds390\*.asm"
319 Delete "$INSTDIR\lib\ds390\*.rel"
320 Delete "$INSTDIR\lib\ds390\*.lib"
322 Delete "$INSTDIR\lib\ds400\*.asm"
323 Delete "$INSTDIR\lib\ds400\*.rel"
324 Delete "$INSTDIR\lib\ds400\*.lib"
326 Delete "$INSTDIR\include\asm\z80\*.h"
327 Delete "$INSTDIR\include\asm\gbz80\*.h"
328 Delete "$INSTDIR\include\asm\default\*.h"
329 Delete "$INSTDIR\include\*.h"
331 Delete "$INSTDIR\doc\README.TXT"
332 Delete "$INSTDIR\doc\ChangeLog_head.txt"
334 Delete "$INSTDIR\bin\*.exe"
336 Delete "$INSTDIR\COPYING.TXT"
337 Delete "$INSTDIR\sdcc.ico"
339 RMDir "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE"
341 RMDir "$INSTDIR\lib\src\z80"
342 RMDir "$INSTDIR\lib\src\gbz80"
343 RMDir "$INSTDIR\lib\src\ds390\examples"
344 RMDir "$INSTDIR\lib\src\ds390"
345 RMDir "$INSTDIR\lib\src\ds400"
346 RMDir "$INSTDIR\lib\src\hc08"
347 RMDir "$INSTDIR\lib\src"
349 RMDir "$INSTDIR\lib\z80"
350 RMDir "$INSTDIR\lib\small"
351 RMDir "$INSTDIR\lib\large"
352 RMDir "$INSTDIR\lib\gbz80"
353 RMDir "$INSTDIR\lib\ds390"
354 RMDir "$INSTDIR\lib\ds400"
355 RMDir "$INSTDIR\lib\hc08"
358 RMDir "$INSTDIR\include\asm\z80"
359 RMDir "$INSTDIR\include\asm\gbz80"
360 RMDir "$INSTDIR\include\asm\default"
361 RMDir "$INSTDIR\include\asm"
362 RMDir "$INSTDIR\include"
371 Call un.RemoveFromPath
376 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
377 ; Path Manipulation functions ;
378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
381 !include "WinMessages.NSH"
384 ; AddToPath - Adds the given dir to the search path.
385 ; Input - head of the stack
386 ; Note - Win9x systems requires reboot
395 # don't add if the path doesn't exist
396 IfFileExists $0 "" AddToPath_done
401 ; Not on NT: read PATH from environment variable
404 ; On NT: read PATH from registry
405 ReadRegStr $1 HKCU "Environment" "PATH"
410 StrCmp $2 "" "" AddToPath_done
415 StrCmp $2 "" "" AddToPath_done
416 GetFullPathName /SHORT $3 $0
421 StrCmp $2 "" "" AddToPath_done
426 StrCmp $2 "" "" AddToPath_done
428 StrCmp $4 1 AddToPath_NT
431 FileOpen $1 "$1\autoexec.bat" a
434 IntCmp $2 26 0 +2 +2 # DOS EOF
435 FileSeek $1 -1 END # write over EOF
436 FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
442 ReadRegStr $1 HKCU "Environment" "PATH"
443 StrCpy $2 $1 1 -1 # copy last char
444 StrCmp $2 ";" 0 +2 # if last char == ;
445 StrCpy $1 $1 -1 # remove last char
446 StrCmp $1 "" AddToPath_NTdoIt
449 WriteRegExpandStr HKCU "Environment" "PATH" $0
450 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
460 ; RemoveFromPath - Remove a given dir from the path
461 ; Input: head of the stack
463 Function un.RemoveFromPath
472 IntFmt $6 "%c" 26 # DOS EOF
476 StrCmp $1 1 unRemoveFromPath_NT
479 FileOpen $1 "$1\autoexec.bat" r
482 GetFullPathName /SHORT $0 $0
483 StrCpy $0 "SET PATH=%PATH%;$0"
484 Goto unRemoveFromPath_dosLoop
486 unRemoveFromPath_dosLoop:
488 StrCpy $5 $3 1 -1 # read last char
489 StrCmp $5 $6 0 +2 # if DOS EOF
490 StrCpy $3 $3 -1 # remove DOS EOF so we can compare
491 StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
492 StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
493 StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
494 StrCmp $3 "" unRemoveFromPath_dosLoopEnd
496 Goto unRemoveFromPath_dosLoop
497 unRemoveFromPath_dosLoopRemoveLine:
499 Goto unRemoveFromPath_dosLoop
501 unRemoveFromPath_dosLoopEnd:
505 Delete "$1\autoexec.bat"
506 CopyFiles /SILENT $4 "$1\autoexec.bat"
508 Goto unRemoveFromPath_done
511 ReadRegStr $1 HKCU "Environment" "PATH"
512 StrCpy $5 $1 1 -1 # copy last char
513 StrCmp $5 ";" +2 # if last char != ;
514 StrCpy $1 "$1;" # append ;
517 Call un.StrStr ; Find `$0;` in $1
518 Pop $2 ; pos of our dir
519 StrCmp $2 "" unRemoveFromPath_done
520 ; else, it is in path
525 StrCpy $5 $1 -$4 # $5 is now the part before the path to remove
526 StrCpy $6 $2 "" $3 # $6 is now the part after the path to remove
529 StrCpy $5 $3 1 -1 # copy last char
530 StrCmp $5 ";" 0 +2 # if last char == ;
531 StrCpy $3 $3 -1 # remove last char
534 ; New PATH not empty: update the registry
535 WriteRegExpandStr HKCU "Environment" "PATH" $3
537 ; New PATH empty: remove from the registry
538 DeleteRegValue HKCU "Environment" "PATH"
539 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
541 unRemoveFromPath_done:
551 ###########################################
552 # Utility Functions #
553 ###########################################
557 ; output, top of the stack = 1 if NT or 0 if not
562 ; ($R0 at this point is 1 or 0)
567 ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
568 StrCmp $0 "" 0 IsNT_yes
581 !insertmacro IsNT "un."
584 ; input, top of stack = string to search for
585 ; top of stack-1 = string to search in
586 ; output, top of stack (replaces with the portion of the string remaining)
587 ; modifies no other variables.
590 ; Push "this is a long ass string"
594 ; ($R0 at this point is "ass string")
598 Exch $R1 ; st=haystack,old$R1, $R1=needle
599 Exch ; st=old$R1,haystack
600 Exch $R2 ; st=old$R1,old$R2, $R2=haystack
612 StrCpy $R5 $R2 $R3 $R4
618 StrCpy $R1 $R2 "" $R4
626 !insertmacro StrStr ""
627 !insertmacro StrStr "un."