* support/scripts/sdcc.nsi: added asranlib.exe to the install package
[fw/sdcc] / support / scripts / sdcc.nsi
index b85acea9d95422efe4593969b5b2932ee6a49875..35622c858c9fb5c5fbdfe4e21dd24bb74d56757d 100644 (file)
@@ -31,8 +31,8 @@
 # - copy files sdcc/support/scripts/sdcc.ico and sdcc/support/scripts/sdcc.nsi
 #   (this file) from the sdcc Subversion snapshot to the PKGDIR directory
 # - copy file COPYING from the sdcc Subversion snapshot to the PKGDIR directory,
-#   rename it to COPYING.TXT and convert it to DOS format:
-#   unix2dos COPYING.TXT
+#   rename it to COPYING.txt and convert it to DOS format:
+#   unix2dos COPYING.txt
 # - copy readline5.dll to PKGDIR/bin/readline5.dll
 # - run NSIS installer from PKGDIR directory:
 #   "c:\Program Files\NSIS\makensis.exe" -DVER_MAJOR=<SDCC_VER_MAJOR> -DVER_MINOR=<SDCC_VER_MINOR> -DVER_REVISION=<SDCC_VER_DEVEL> -DVER_BUILD=<SDCC_REVISION> sdcc.nsi
 # - unpack WIN32 mingw daily snapshot sdcc-snapshot-i586-mingw32msvc-yyyymmdd-rrrr.zip
 #   to a clean directory (the option to create directories should be enabled).
 #   A sub directory sdcc is created (referenced as PKGDIR in continuation).
-# - remove the PKGDIR/doc/README.TXT file
+# - remove the PKGDIR/doc/ directory
 # - unpack sdcc-doc-yyyymmdd-rrrr.zip to the PKGDIR/doc directory
 # - copy files sdcc/support/scripts/sdcc.ico and sdcc/support/scripts/sdcc.nsi
 #   (this file) from the sdcc Subversion snapshot to the PKGDIR directory
 # - copy file COPYING from the sdcc Subversion snapshot to the PKGDIR directory,
-#   rename it to COPYING.TXT and it to DOS format:
-#   unix2dos COPYING.TXT
+#   rename it to COPYING.txt and convert it to DOS format:
+#   unix2dos COPYING.txt
 # - copy readline5.dll to PKGDIR/bin/readline5.dll
 # - run NSIS installer from PKGDIR directory:
 #   "c:\Program Files\NSIS\makensis.exe" -DFULL_DOC -DVER_MAJOR=<VER_MAJOR> -DVER_MINOR=<VER_MINOR> -DVER_REVISION=<VER_PATCH> -DVER_BUILD=<REVISION> sdcc.nsi
 
 !ifdef SDCC.DEBUG
   Var SDCC.FunctionName
+  Var SDCC.StrStack0
+  Var SDCC.StrStack1
+  Var SDCC.StrStack2
+  Var SDCC.StrStack3
+  Var SDCC.StrStack4
+
+!define SDCC.PushStr "!insertmacro MACRO_SDCC_PushStr"
+!macro MACRO_SDCC_PushStr NAME
+  StrCpy $SDCC.StrStack4 $SDCC.StrStack3
+  StrCpy $SDCC.StrStack3 $SDCC.StrStack2
+  StrCpy $SDCC.StrStack2 $SDCC.StrStack1
+  StrCpy $SDCC.StrStack1 $SDCC.StrStack0
+  StrCpy $SDCC.StrStack0 $SDCC.FunctionName
+  StrCpy $SDCC.FunctionName "${NAME}"
+!macroend
+
+!define SDCC.PopStr "!insertmacro MACRO_SDCC_PopStr"
+!macro MACRO_SDCC_PopStr
+  StrCpy $SDCC.FunctionName $SDCC.StrStack0
+  StrCpy $SDCC.StrStack0 $SDCC.StrStack1
+  StrCpy $SDCC.StrStack1 $SDCC.StrStack2
+  StrCpy $SDCC.StrStack2 $SDCC.StrStack3
+  StrCpy $SDCC.StrStack3 $SDCC.StrStack4
+!macroend
 !endif
 
 !define DebugMsg "!insertmacro MACRO_SDCC_DebugMsg"
 !macro MACRO_SDCC_Function NAME
   Function "${NAME}"
   !ifdef SDCC.DEBUG
-    StrCpy $SDCC.FunctionName ${NAME}
+    ${SDCC.PushStr} ${NAME}
   !endif
 !macroend
 
 !define FunctionEnd "!insertmacro MACRO_SDCC_FunctionEnd"
 !macro MACRO_SDCC_FunctionEnd
   !ifdef SDCC.DEBUG
-    StrCpy $SDCC.FunctionName ""
+    ${SDCC.PopStr}
   !endif
   FunctionEnd
 !macroend
 
+!define Section "!insertmacro MACRO_SDCC_Section"
+!macro MACRO_SDCC_Section NAME ID
+  Section "${NAME}" "${ID}"
+  !ifdef SDCC.DEBUG
+    ${SDCC.PushStr} "${NAME}"
+  !endif
+!macroend
+
+!define UnselectedSection "!insertmacro MACRO_SDCC_UnselectedSection"
+!macro MACRO_SDCC_UnselectedSection NAME ID
+  Section /o ${NAME} ${ID}
+  !ifdef SDCC.DEBUG
+    ${SDCC.PushStr} "${NAME}"
+  !endif
+!macroend
+
+!define SectionEnd "!insertmacro MACRO_SDCC_SectionEnd"
+!macro MACRO_SDCC_SectionEnd
+  !ifdef SDCC.DEBUG
+    ${SDCC.PopStr}
+  !endif
+  SectionEnd
+!macroend
+
 
 !define PRODUCT_NAME "SDCC"
 
@@ -121,13 +169,24 @@ SetCompressor /SOLID lzma
 
 !define DEV_ROOT "${SDCC_ROOT}"
 
+!ifdef FULL_DOC
+!system "unix2dos ${SDCC_ROOT}\doc\ChangeLog.txt" = 0
+!else
 !system "unix2dos ${SDCC_ROOT}\doc\ChangeLog_head.txt" = 0
+!endif
 !system "unix2dos ${SDCC_ROOT}\doc\README.TXT" = 0
 
 InstType "Full (Bin, ucSim, SDCDB, Doc, Lib, Src)"
 InstType "Medium (Bin, ucSim, SDCDB, Doc, Lib)"
 InstType "Compact (Bin, ucSim, SDCDB, Doc)"
 
+;--------------------------------
+; Configuration
+
+!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
+!define UNINST_ROOT_KEY HKLM
+!define SDCC_ROOT_KEY HKLM
+
 ;--------------------------------
 ; Header Files
 
@@ -152,16 +211,15 @@ Var SDCC.PathToRemove
 ;--------------------------------
 ; Configuration
 
-!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
-
 ; MUI Settings
 !define MUI_ABORTWARNING
+!define MUI_ICON ".\sdcc.ico"
 
 ; Welcome page
 !insertmacro MUI_PAGE_WELCOME
 
 ; License page
-!insertmacro MUI_PAGE_LICENSE "${SDCC_ROOT}\COPYING.TXT"
+!insertmacro MUI_PAGE_LICENSE "${SDCC_ROOT}\COPYING.txt"
 
 ; Uninstall/reinstall page
 !ifdef VER_MAJOR & VER_MINOR & VER_REVISION & VER_BUILD
@@ -170,7 +228,7 @@ Page custom SDCC.PageReinstall SDCC.PageLeaveReinstall
 
 ; StartMenu page
 !define MUI_STARTMENUPAGE_DEFAULTFOLDER ${PRODUCT_NAME}
-!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM"
+!define MUI_STARTMENUPAGE_REGISTRY_ROOT ${UNINST_ROOT_KEY}
 !define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "NSIS:StartMenuDir"
 !define MUI_STARTMENUPAGE_NODISABLE
@@ -197,10 +255,15 @@ ${Function} SDCC.InstFilesLeave
   ${EndIf}
 ${FunctionEnd}
 
-; Finish page
+; Finish page - add to path
+!define MUI_FINISHPAGE_TEXT "Confirm the checkbox if you want to add SDCC binary directory to the PATH environment variable"
 !define MUI_FINISHPAGE_SHOWREADME_TEXT "Add $INSTDIR\bin to the PATH"
 !define MUI_FINISHPAGE_SHOWREADME_FUNCTION SDCC.AddBinToPath
 !define MUI_FINISHPAGE_SHOWREADME
+!define MUI_FINISHPAGE_BUTTON "Next"
+!insertmacro MUI_PAGE_FINISH
+
+; Finish page - reboot
 !insertmacro MUI_PAGE_FINISH
 
 ${Function} SDCC.AddBinToPath
@@ -213,6 +276,7 @@ ${FunctionEnd}
 ; Uninstaller pages
 !insertmacro MUI_UNPAGE_CONFIRM
 !insertmacro MUI_UNPAGE_INSTFILES
+!insertmacro MUI_UNPAGE_FINISH
 
 ; Language files
 !insertmacro MUI_LANGUAGE "English"
@@ -231,7 +295,7 @@ ${Function} .onInit
 !ifndef VER_MAJOR & VER_MINOR & VER_REVISION & VER_BUILD
   ; Old unistallation method
   ; Uninstall the old version, if present
-  ReadRegStr $R0 HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
+  ReadRegStr $R0 ${UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString"
   StrCmp $R0 "" inst
 
   MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
@@ -243,7 +307,7 @@ ${Function} .onInit
 uninst:
   ; Run the uninstaller
   ClearErrors
-  ExecWait '$R0 _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
+  ExecWait '$R0'
 
   Goto done
 inst:
@@ -256,15 +320,15 @@ done:
 !else
   ; If the registry key exists it is an uninstallation or reinstallation:
   ;  take the old installation directory
-  Push $R2
+  Push $R0
 
-  ReadRegStr $R2 HKLM "${PRODUCT_UNINST_KEY}" "InstallLocation"
+  ReadRegStr $R0 ${UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstallLocation"
   ${IfNot} ${Errors}
-    StrCpy $INSTDIR $R2
+    StrCpy $INSTDIR $R0
     StrCpy $SDCC.PathToRemove "$INSTDIR\bin"
   ${EndIf}
 
-  Pop $R2
+  Pop $R0
 !endif
   ${DebugMsg} "Post INSTDIR = $INSTDIR"
 ${FunctionEnd}
@@ -273,24 +337,24 @@ ${Function} un.onInit
 
   ${DebugMsg} "Pre INSTDIR = $INSTDIR"
 
-  Push $R2
-  ReadRegStr $R2 HKLM "${PRODUCT_UNINST_KEY}" "InstallLocation"
+  Push $R0
+  ReadRegStr $R0 ${UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstallLocation"
   ${IfNot} ${Errors}
-    StrCpy $INSTDIR $R2
+    StrCpy $INSTDIR $R0
   ${EndIf}
-  Pop $R2
+  Pop $R0
 
   ${DebugMsg} "Post INSTDIR = $INSTDIR"
 
 ${FunctionEnd}
 
-Section -Common
+${Section} -Common SECCOMMON
   SetOutPath "$INSTDIR"
   File ".\sdcc.ico"
-  File "${SDCC_ROOT}\COPYING.TXT"
-SectionEnd
+  File "${SDCC_ROOT}\COPYING.txt"
+${SectionEnd}
 
-Section "SDCC application files" SEC01
+${Section} "SDCC application files" SEC01
   SectionIn 1 2 3 RO
   SetOutPath "$INSTDIR\bin"
   File "${SDCC_ROOT}\bin\as-gbz80.exe"
@@ -298,6 +362,7 @@ Section "SDCC application files" SEC01
   File "${SDCC_ROOT}\bin\as-z80.exe"
   File "${SDCC_ROOT}\bin\asx8051.exe"
   File "${SDCC_ROOT}\bin\aslink.exe"
+  File "${SDCC_ROOT}\bin\asranlib.exe"
   File "${SDCC_ROOT}\bin\link-gbz80.exe"
   File "${SDCC_ROOT}\bin\link-hc08.exe"
   File "${SDCC_ROOT}\bin\link-z80.exe"
@@ -307,25 +372,25 @@ Section "SDCC application files" SEC01
   File "${SDCC_ROOT}\bin\sdcclib.exe"
   File "${SDCC_ROOT}\bin\sdcpp.exe"
   File "${SDCC_ROOT}\bin\readline5.dll"
-SectionEnd
+${SectionEnd}
 
-Section "ucSim application files" SEC02
+${Section} "ucSim application files" SEC02
   SectionIn 1 2 3
   SetOutPath "$INSTDIR\bin"
   File "${SDCC_ROOT}\bin\s51.exe"
   File "${SDCC_ROOT}\bin\savr.exe"
   File "${SDCC_ROOT}\bin\shc08.exe"
   File "${SDCC_ROOT}\bin\sz80.exe"
-SectionEnd
+${SectionEnd}
 
-Section "SDCDB files" SEC03
+${Section} "SDCDB files" SEC03
   SectionIn 1 2 3
   File "${SDCC_ROOT}\bin\sdcdb.exe"
   File "${SDCC_ROOT}\bin\sdcdb.el"
   File "${SDCC_ROOT}\bin\sdcdbsrc.el"
-SectionEnd
+${SectionEnd}
 
-Section "SDCC documentation" SEC04
+${Section} "SDCC documentation" SEC04
   SectionIn 1 2 3
   SetOutPath "$INSTDIR\doc"
 !ifdef FULL_DOC
@@ -334,9 +399,9 @@ Section "SDCC documentation" SEC04
   File "${SDCC_ROOT}\doc\ChangeLog_head.txt"
   File "${SDCC_ROOT}\doc\README.TXT"
 !endif
-SectionEnd
+${SectionEnd}
 
-Section "SDCC include files" SEC05
+${Section} "SDCC include files" SEC05
   SectionIn 1 2
   SetOutPath "$INSTDIR\include\asm\default"
   File "${DEV_ROOT}\include\asm\default\features.h"
@@ -362,89 +427,90 @@ Section "SDCC include files" SEC05
   File "${DEV_ROOT}\include\pic\*.inc"
   SetOutPath "$INSTDIR\include\pic16"
   File "${DEV_ROOT}\include\pic16\*.h"
+  File "${DEV_ROOT}\include\pic16\*.txt"
   SetOutPath "$INSTDIR\include\z80"
   File "${DEV_ROOT}\include\z80\*.h"
   SetOutPath "$INSTDIR\include"
   File "${DEV_ROOT}\include\*.h"
-SectionEnd
+${SectionEnd}
 
-Section "SDCC DS390 library" SEC06
+${Section} "SDCC DS390 library" SEC06
   SectionIn 1 2
   SetOutPath "$INSTDIR\lib\ds390"
   File "${DEV_ROOT}\lib\ds390\*.rel"
   File "${DEV_ROOT}\lib\ds390\*.lib"
-SectionEnd
+${SectionEnd}
 
-Section "SDCC DS400 library" SEC07
+${Section} "SDCC DS400 library" SEC07
   SectionIn 1 2
   SetOutPath "$INSTDIR\lib\ds400"
   File "${DEV_ROOT}\lib\ds400\*.rel"
   File "${DEV_ROOT}\lib\ds400\*.lib"
-SectionEnd
+${SectionEnd}
 
-Section "SDCC GBZ80 library" SEC08
+${Section} "SDCC GBZ80 library" SEC08
   SectionIn 1 2
   SetOutPath "$INSTDIR\lib\gbz80"
   File "${DEV_ROOT}\lib\gbz80\*.o"
   File "${DEV_ROOT}\lib\gbz80\*.lib"
-SectionEnd
+${SectionEnd}
 
-Section "SDCC Z80 library" SEC09
+${Section} "SDCC Z80 library" SEC09
   SectionIn 1 2
   SetOutPath "$INSTDIR\lib\z80"
   File "${DEV_ROOT}\lib\z80\*.o"
   File "${DEV_ROOT}\lib\z80\*.lib"
-SectionEnd
+${SectionEnd}
 
-Section "SDCC small model library" SEC10
+${Section} "SDCC small model library" SEC10
   SectionIn 1 2
   SetOutPath "$INSTDIR\lib\small"
   File "${DEV_ROOT}\lib\small\*.rel"
   File "${DEV_ROOT}\lib\small\*.lib"
-SectionEnd
+${SectionEnd}
 
-Section "SDCC medium model library" SEC11
+${Section} "SDCC medium model library" SEC11
   SectionIn 1 2
   SetOutPath "$INSTDIR\lib\medium"
   File "${DEV_ROOT}\lib\medium\*.rel"
   File "${DEV_ROOT}\lib\medium\*.lib"
-SectionEnd
+${SectionEnd}
 
-Section "SDCC large model library" SEC12
+${Section} "SDCC large model library" SEC12
   SectionIn 1 2
   SetOutPath "$INSTDIR\lib\large"
   File "${DEV_ROOT}\lib\large\*.rel"
   File "${DEV_ROOT}\lib\large\*.lib"
-SectionEnd
+${SectionEnd}
 
-Section "SDCC small-stack-auto model library" SEC13
+${Section} "SDCC small-stack-auto model library" SEC13
   SectionIn 1 2
   SetOutPath "$INSTDIR\lib\small-stack-auto"
   File "${DEV_ROOT}\lib\small-stack-auto\*.rel"
   File "${DEV_ROOT}\lib\small-stack-auto\*.lib"
-SectionEnd
+${SectionEnd}
 
-Section "SDCC HC08 library" SEC14
+${Section} "SDCC HC08 library" SEC14
   SectionIn 1 2
   SetOutPath "$INSTDIR\lib\hc08"
   File "${DEV_ROOT}\lib\hc08\*.rel"
   File "${DEV_ROOT}\lib\hc08\*.lib"
-SectionEnd
+${SectionEnd}
 
-Section "SDCC PIC16 library" SEC15
+${Section} "SDCC PIC16 library" SEC15
   SectionIn 1 2
   SetOutPath "$INSTDIR\lib\pic16"
   File "${DEV_ROOT}\lib\pic16\*.o"
   File "${DEV_ROOT}\lib\pic16\*.lib"
-SectionEnd
+${SectionEnd}
 
-Section "SDCC PIC library" SEC16
+${Section} "SDCC PIC library" SEC16
   SectionIn 1 2
   SetOutPath "$INSTDIR\lib\pic"
   File "${DEV_ROOT}\lib\pic\*.lib"
-SectionEnd
+${SectionEnd}
 
-Section "SDCC library sources" SEC17
+${Section} "SDCC library sources" SEC17
   SectionIn 1
   SetOutPath "$INSTDIR\lib\src\ds390\examples"
   File "${DEV_ROOT}\lib\src\ds390\examples\MOVED"
@@ -463,7 +529,6 @@ Section "SDCC library sources" SEC17
 #  File "${DEV_ROOT}\lib\src\gbz80\Makefile"
 
   SetOutPath "$INSTDIR\lib\src\z80"
-  File "${DEV_ROOT}\lib\src\z80\*.c"
   File "${DEV_ROOT}\lib\src\z80\*.s"
 #  File "${DEV_ROOT}\lib\src\z80\Makefile"
 
@@ -626,7 +691,7 @@ Section "SDCC library sources" SEC17
 
   SetOutPath "$INSTDIR\lib\src"
   File "${DEV_ROOT}\lib\src\*.c"
-SectionEnd
+${SectionEnd}
 
 ;--------------------------------
 ;Descriptions
@@ -672,52 +737,72 @@ LangString DESC_SEC17 ${LANG_ENGLISH} "SDCC library sources"
 !insertmacro MUI_FUNCTION_DESCRIPTION_END
 ;--------------------------------
 
-Section -Icons
+${Section} -Icons SECICONS
 !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
   CreateDirectory "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE"
-  CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\SDCC on the Web.lnk" "$INSTDIR\sdcc.url" 
   CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Uninstall SDCC.lnk" "$INSTDIR\uninstall.exe" 
+!ifdef FULL_DOC
+  CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Documentation.lnk" "$INSTDIR\doc\sdccman.pdf" "" "$INSTDIR\sdcc.ico" "" "" "" ""
+  CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\README.lnk" "$INSTDIR\doc\README.TXT" "" "$INSTDIR\sdcc.ico" "" "" "" ""
+  CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Change Log.lnk" "$INSTDIR\doc\ChangeLog.txt" "" "$INSTDIR\sdcc.ico" "" "" "" ""
+!else
   CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Documentation.lnk" "$INSTDIR\doc\README.TXT" "" "$INSTDIR\sdcc.ico" "" "" "" ""
   CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Change Log.lnk" "$INSTDIR\doc\ChangeLog_head.txt" "" "$INSTDIR\sdcc.ico" "" "" "" ""
-  CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\GPL 2 License.lnk" "$INSTDIR\COPYING.TXT" 
+!endif
+  CreateShortCut "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\GPL 2 License.lnk" "$INSTDIR\COPYING.txt"
 !insertmacro MUI_STARTMENU_WRITE_END
-SectionEnd
+${SectionEnd}
 
-Section -INI
-  WriteIniStr "$INSTDIR\sdcc.url" "InternetShortcut" "URL" "http://sdcc.sourceforge.net/"
-SectionEnd
+${Section} -INI SECINI
+  WriteIniStr "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\SDCC on the Web.url" "InternetShortcut" "URL" "http://sdcc.sourceforge.net/"
+!ifdef FULL_DOC
+  WriteIniStr "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Latest Changes.url" "InternetShortcut" "URL" "http://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc/ChangeLog"
+!endif
+${SectionEnd}
 
-Section -PostInstall
-  WriteRegStr HKLM "Software\${PRODUCT_NAME}" "" $INSTDIR
+${Section} -PostInstall SECPOSTINSTALL
+  WriteRegStr ${SDCC_ROOT_KEY} "Software\${PRODUCT_NAME}" "" $INSTDIR
 !ifdef VER_MAJOR & VER_MINOR & VER_REVISION & VER_BUILD
-  WriteRegDword HKLM "Software\${PRODUCT_NAME}" "VersionMajor" "${VER_MAJOR}"
-  WriteRegDword HKLM "Software\${PRODUCT_NAME}" "VersionMinor" "${VER_MINOR}"
-  WriteRegDword HKLM "Software\${PRODUCT_NAME}" "VersionRevision" "${VER_REVISION}"
-  WriteRegDword HKLM "Software\${PRODUCT_NAME}" "VersionBuild" "${VER_BUILD}"
+  WriteRegDword ${SDCC_ROOT_KEY} "Software\${PRODUCT_NAME}" "VersionMajor" "${VER_MAJOR}"
+  WriteRegDword ${SDCC_ROOT_KEY} "Software\${PRODUCT_NAME}" "VersionMinor" "${VER_MINOR}"
+  WriteRegDword ${SDCC_ROOT_KEY} "Software\${PRODUCT_NAME}" "VersionRevision" "${VER_REVISION}"
+  WriteRegDword ${SDCC_ROOT_KEY} "Software\${PRODUCT_NAME}" "VersionBuild" "${VER_BUILD}"
 !endif
 
-  WriteRegExpandStr HKLM "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninstall.exe"
-  WriteRegExpandStr HKLM "${PRODUCT_UNINST_KEY}" "InstallLocation" "$INSTDIR"
-  WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayName" "${PRODUCT_NAME}"
-  WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "Publisher" "sdcc.sourceforge.net"
-  WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "http://sdcc.sourceforge.net/"
-  WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "HelpLink" "http://sdcc.sourceforge.net/"
-  WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "URLUpdateInfo" "http://sdcc.sourceforge.net/"
+  WriteRegExpandStr ${UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninstall.exe"
+  WriteRegExpandStr ${UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "InstallLocation" "$INSTDIR"
+  WriteRegStr ${UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "${PRODUCT_NAME}"
+  WriteRegStr ${UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "sdcc.sourceforge.net"
+  WriteRegStr ${UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "http://sdcc.sourceforge.net/"
+  WriteRegStr ${UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "HelpLink" "http://sdcc.sourceforge.net/"
+  WriteRegStr ${UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLUpdateInfo" "http://sdcc.sourceforge.net/"
 
   WriteUninstaller "$INSTDIR\uninstall.exe"
-SectionEnd
+${SectionEnd}
 
 
 ;;;; Uninstaller code ;;;;
 
-Section Uninstall
+${Section} Uninstall SECUNINSTALL
   !insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_STARTMENUPAGE_VARIABLE
 
+  ${DebugMsg} "removing path $INSTDIR\bin"
+  Push "$INSTDIR\bin"
+  Call un.SDCC.RemoveFromPath
+
+; Clean the registry
+  DeleteRegKey ${UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
+  DeleteRegKey ${SDCC_ROOT_KEY} "Software\${PRODUCT_NAME}"
+
   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\GPL 2 License.lnk"
   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Change Log.lnk"
+!ifdef FULL_DOC
+  Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Latest Changes.url"
+  Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\README.lnk"
+!endif
   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Documentation.lnk"
   Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\Uninstall SDCC.lnk"
-  Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\SDCC on the Web.lnk"
+  Delete "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE\SDCC on the Web.url"
 
   RMDir "$SMPROGRAMS\$MUI_STARTMENUPAGE_VARIABLE"
 
@@ -735,7 +820,6 @@ Section Uninstall
   Delete "$INSTDIR\lib\src\hc08\hc08.lib"
   Delete "$INSTDIR\lib\src\hc08\Makefile"
 
-  Delete "$INSTDIR\lib\src\z80\*.c"
   Delete "$INSTDIR\lib\src\z80\*.s"
   Delete "$INSTDIR\lib\src\z80\z80.lib"
   Delete "$INSTDIR\lib\src\z80\README"
@@ -805,6 +889,7 @@ Section Uninstall
   Delete "$INSTDIR\include\pic\*.txt"
   Delete "$INSTDIR\include\pic\*.inc"
   Delete "$INSTDIR\include\pic16\*.h"
+  Delete "$INSTDIR\include\pic16\*.txt"
   Delete "$INSTDIR\include\mcs51\*.h"
   Delete "$INSTDIR\include\hc08\*.h"
   Delete "$INSTDIR\include\*.h"
@@ -819,6 +904,7 @@ Section Uninstall
   Delete "$INSTDIR\bin\as-z80.exe"
   Delete "$INSTDIR\bin\asx8051.exe"
   Delete "$INSTDIR\bin\aslink.exe"
+  Delete "$INSTDIR\bin\asranlib.exe"
   Delete "$INSTDIR\bin\link-gbz80.exe"
   Delete "$INSTDIR\bin\link-hc08.exe"
   Delete "$INSTDIR\bin\link-z80.exe"
@@ -839,9 +925,8 @@ Section Uninstall
   Delete "$INSTDIR\bin\sdcdb.el"
   Delete "$INSTDIR\bin\sdcdbsrc.el"
 
-  Delete "$INSTDIR\COPYING.TXT"
+  Delete "$INSTDIR\COPYING.txt"
   Delete "$INSTDIR\sdcc.ico"
-  Delete "$INSTDIR\sdcc.url"
   Delete "$INSTDIR\uninstall.exe"
 
   RMDir /r "$INSTDIR\lib\src\pic"
@@ -895,17 +980,8 @@ Section Uninstall
   RMDir "$INSTDIR\bin"
 
   RMDir "$INSTDIR"
-
-  ${DebugMsg} "removing path $INSTDIR\bin"
-  Push "$INSTDIR\bin"
-  Call un.SDCC.RemoveFromPath
-
-; Clean the registry
-  DeleteRegValue HKLM "${PRODUCT_UNINST_KEY}" "NSIS:StartMenuDir"
-  DeleteRegKey HKLM "${PRODUCT_UNINST_KEY}"
-  DeleteRegKey HKLM "Software\${PRODUCT_NAME}"
 ;;;;  SetAutoClose true
-SectionEnd
+${SectionEnd}
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Path Manipulation functions                                                 ;
@@ -927,61 +1003,65 @@ ${Function} SDCC.AddToPath
   Push $4
 
   ; don't add if the path doesn't exist
-  IfFileExists $0 "" AddToPath_done
-
-  Call SDCC.IsNT
-  Pop $4
-  StrCmp $4 1 +3
-    ; Not on NT: read PATH from environment variable
-    ReadEnvStr $1 PATH
-    Goto +2
-    ; On NT: read PATH from registry
-    ReadRegStr $1 HKCU "Environment" "PATH"
-  ${StrStr} $2 "$1;" "$0;"
-  StrCmp $2 "" "" AddToPath_done
-
-  ${StrStr} $2 "$1;" "$0\;"
-  StrCmp $2 "" "" AddToPath_done
-
-  GetFullPathName /SHORT $3 $0
-  ${StrStr} $2 "$1;" "$3;"
-  StrCmp $2 "" "" AddToPath_done
-
-  ${StrStr} $2 "$1;" "$03\;"
-  StrCmp $2 "" "" AddToPath_done
-
-  StrCmp $4 1 AddToPath_NT
-    ; Not on NT
-    StrCpy $1 $WINDIR 2
-    FileOpen $1 "$1\autoexec.bat" a
-    FileSeek $1 -1 END
-    FileReadByte $1 $2
-    IntCmp $2 26 0 +2 +2 ; DOS EOF
-      FileSeek $1 -1 END ; write over EOF
-    FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
-    FileClose $1
-    SetRebootFlag true
-    Goto AddToPath_done
+  ${If} ${FileExists} $0
+    Call SDCC.IsNT
+    Pop $4
+    ${If} $4 != 1
+      ; Not on NT: read PATH from environment variable
+      ReadEnvStr $1 PATH
+    ${Else}
+      ; On NT: read PATH from registry
+      ReadRegStr $1 HKCU "Environment" "PATH"
+    ${EndIf}
 
-  AddToPath_NT:
-    ;System PATH variable is at:
-    ;HKLM "/SYSTEM/CurrentControlSet/Control/Session Manager/Environment" "Path"
-    ReadRegStr $1 HKCU "Environment" "PATH"
-    StrCpy $2 $1 1 -1  ; copy last char
-    StrCmp $2 ";" 0 +2 ; if last char == ;
-      StrCpy $1 $1 -1  ; remove last char
-    StrCmp $1 "" AddToPath_NTdoIt
-      StrCpy $0 "$1;$0"
-    AddToPath_NTdoIt:
-      WriteRegExpandStr HKCU "Environment" "PATH" $0
-      SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
+    ${StrStr} $2 "$1;" "$0;"
+    ${If} $2 == ""
+      ${StrStr} $2 "$1;" "$0\;"
+      ${If} $2 == ""
+        GetFullPathName /SHORT $3 $0
+        ${StrStr} $2 "$1;" "$3;"
+        ${If} $2 == ""
+          ${StrStr} $2 "$1;" "$03\;"
+          ${If} $2 == ""
+            ${If} $4 != 1
+              ; Not on NT
+              StrCpy $1 $WINDIR 2
+              FileOpen $1 "$1\autoexec.bat" a
+              FileSeek $1 -1 END
+              FileReadByte $1 $2
+              ${If} $2 = 26        ; DOS EOF
+                FileSeek $1 -1 END ; write over EOF
+              ${Endif}
+              ${DebugMsg} "adding line $\r$\nSET PATH=%PATH%;$3$\r$\n"
+              FileWrite $1 "$\r$\nSET PATH=%PATH%;$3$\r$\n"
+              FileClose $1
+              ${DebugMsg} "SetRebootFlag true"
+              SetRebootFlag true
+            ${Else}
+              ;System PATH variable is at:
+              ;HKLM "/SYSTEM/CurrentControlSet/Control/Session Manager/Environment" "Path"
+              ReadRegStr $1 HKCU "Environment" "PATH"
+              StrCpy $2 $1 1 -1  ; copy last char
+              ${If} $2 == ";"    ; if last char == ;
+                StrCpy $1 $1 -1  ; remove last char
+              ${Endif}
+              ${If} $1 != ""
+                StrCpy $0 "$1;$0"
+              ${Endif}
+              WriteRegExpandStr HKCU "Environment" "PATH" $0
+              SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
+            ${Endif}
+          ${Endif}
+        ${Endif}
+      ${Endif}
+    ${Endif}
+  ${EndIf}
 
-  AddToPath_done:
-    Pop $4
-    Pop $3
-    Pop $2
-    Pop $1
-    Pop $0
+  Pop $4
+  Pop $3
+  Pop $2
+  Pop $1
+  Pop $0
 ${FunctionEnd}
 
 ; RemoveFromPath - Remove a given dir from the path
@@ -1001,7 +1081,7 @@ ${Function} ${un}SDCC.RemoveFromPath
 
   Call ${un}SDCC.IsNT
   Pop $1
-  StrCmp $1 1 unRemoveFromPath_NT
+  ${If} $1 != 1
     ; Not on NT
     StrCpy $1 $WINDIR 2
     FileOpen $1 "$1\autoexec.bat" r
@@ -1009,45 +1089,52 @@ ${Function} ${un}SDCC.RemoveFromPath
     FileOpen $2 $4 w
     GetFullPathName /SHORT $0 $0
     StrCpy $0 "SET PATH=%PATH%;$0"
-    Goto unRemoveFromPath_dosLoop
 
-    unRemoveFromPath_dosLoop:
-      FileRead $1 $3
+  nextLine:
+    ; copy all lines except the line containing "SET PATH=%PATH%;$0"
+    ; from autoexec.bat to the temporary file
+    ClearErrors
+    FileRead $1 $3
+    ${IfNot} ${Errors}
       StrCpy $5 $3 1 -1 ; read last char
-      StrCmp $5 $6 0 +2 ; if DOS EOF
+      ${If} $5 == $6    ; if DOS EOF
         StrCpy $3 $3 -1 ; remove DOS EOF so we can compare
-      StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoopRemoveLine
-      StrCmp $3 "$0$\n" unRemoveFromPath_dosLoopRemoveLine
-      StrCmp $3 "$0" unRemoveFromPath_dosLoopRemoveLine
-      StrCmp $3 "" unRemoveFromPath_dosLoopEnd
-      FileWrite $2 $3
-      Goto unRemoveFromPath_dosLoop
-      unRemoveFromPath_dosLoopRemoveLine:
+      ${EndIf}
+      ${If} $3 != "$0$\r$\n"
+        ${AndIf} $3 != "$0$\n"
+        ${AndIf} $3 != "$0"
+        FileWrite $2 $3
+        Goto nextLine
+      ${Else}
+        ; This is the line I'm looking for:
+        ; don't copy it
+        ${DebugMsg} "removing line $0"
+        ${DebugMsg} "SetRebootFlag true"
         SetRebootFlag true
-        Goto unRemoveFromPath_dosLoop
-
-    unRemoveFromPath_dosLoopEnd:
-      FileClose $2
-      FileClose $1
-      StrCpy $1 $WINDIR 2
-      Delete "$1\autoexec.bat"
-      CopyFiles /SILENT $4 "$1\autoexec.bat"
-      Delete $4
-      Goto unRemoveFromPath_done
-
-  unRemoveFromPath_NT:
+        Goto nextLine
+      ${EndIf}
+    ${EndIf}
+
+    FileClose $2
+    FileClose $1
+    StrCpy $1 $WINDIR 2
+    Delete "$1\autoexec.bat"
+    CopyFiles /SILENT $4 "$1\autoexec.bat"
+    Delete $4
+  ${Else}
     ;System PATH variable is at:
     ;HKLM "/SYSTEM/CurrentControlSet/Control/Session Manager/Environment" "Path"
     ReadRegStr $1 HKCU "Environment" "PATH"
     StrCpy $5 $1 1 -1 ; copy last char
-    StrCmp $5 ";" +2  ; if last char != ;
+    ${If} $5 != ";"   ; if last char != ;
       StrCpy $1 "$1;" ; append ;
+    ${EndIf}
     Push $1
     Push "$0;"
     Call ${un}StrStr  ; Find `$0;` in $1
     Pop $2            ; pos of our dir
-    StrCmp $2 "" unRemoveFromPath_done
-      ; else, it is in path
+    ${If} $2 != ""
+      ; it is in path:
       ; $0 - path to add
       ; $1 - path var
       StrLen $3 "$0;"
@@ -1057,25 +1144,27 @@ ${Function} ${un}SDCC.RemoveFromPath
       StrCpy $3 $5$6
 
       StrCpy $5 $3 1 -1  ; copy last char
-      StrCmp $5 ";" 0 +2 ; if last char == ;
+      ${If} $5 == ";"    ; if last char == ;
         StrCpy $3 $3 -1  ; remove last char
-
-      StrCmp $3 "" +3
+      ${EndIf}
+      ${If} $3 != ""
         ; New PATH not empty: update the registry
         WriteRegExpandStr HKCU "Environment" "PATH" $3
-        Goto +2
+      ${Else}
         ; New PATH empty: remove from the registry
         DeleteRegValue HKCU "Environment" "PATH"
+      ${EndIf}
       SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
+    ${Endif}
+  ${Endif}
 
-  unRemoveFromPath_done:
-    Pop $6
-    Pop $5
-    Pop $4
-    Pop $3
-    Pop $2
-    Pop $1
-    Pop $0
+  Pop $6
+  Pop $5
+  Pop $4
+  Pop $3
+  Pop $2
+  Pop $1
+  Pop $0
 ${FunctionEnd}
 !macroend
 !insertmacro SDCC.RemoveFromPath ""
@@ -1097,7 +1186,7 @@ ${FunctionEnd}
 !macro SDCC.IsNT un
 ${Function} ${un}SDCC.IsNT
   Push $R0
-  ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
+  ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
   ${If} $R0 == ""
     ; we are not NT.
     Pop $R0
@@ -1122,19 +1211,19 @@ Var ReinstallPageCheck
 
 ${Function} SDCC.PageReinstall
 
-  ReadRegStr $R0 HKLM "Software\${PRODUCT_NAME}" ""
+  ReadRegStr $R0 ${SDCC_ROOT_KEY} "Software\${PRODUCT_NAME}" ""
 
   ${If} $R0 == ""
-    ReadRegStr $R0 HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
+    ReadRegStr $R0 ${UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString"
     ${If} $R0 == ""
       Abort
     ${EndIf}
   ${EndIf}
 
-  ReadRegDWORD $R0 HKLM "Software\${PRODUCT_NAME}" "VersionMajor"
-  ReadRegDWORD $R1 HKLM "Software\${PRODUCT_NAME}" "VersionMinor"
-  ReadRegDWORD $R2 HKLM "Software\${PRODUCT_NAME}" "VersionRevision"
-  ReadRegDWORD $R3 HKLM "Software\${PRODUCT_NAME}" "VersionBuild"
+  ReadRegDWORD $R0 ${SDCC_ROOT_KEY} "Software\${PRODUCT_NAME}" "VersionMajor"
+  ReadRegDWORD $R1 ${SDCC_ROOT_KEY} "Software\${PRODUCT_NAME}" "VersionMinor"
+  ReadRegDWORD $R2 ${SDCC_ROOT_KEY} "Software\${PRODUCT_NAME}" "VersionRevision"
+  ReadRegDWORD $R3 ${SDCC_ROOT_KEY} "Software\${PRODUCT_NAME}" "VersionBuild"
   StrCpy $R0 $R0.$R1.$R2.$R3
 
   ${VersionCompare} ${VER_MAJOR}.${VER_MINOR}.${VER_REVISION}.${VER_BUILD} $R0 $R0
@@ -1213,23 +1302,22 @@ ${Function} SDCC.PageLeaveReinstall
     Goto reinst_done
   ${EndIf}
 
-  ReadRegStr $R1 HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
+  ReadRegStr $R1 ${UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString"
 
   ;Run uninstaller
   HideWindow
 
-  ClearErrors
-  ExecWait '$R1 _?=$INSTDIR'
-
-  ${IfNot} ${Errors}
-    ${AndIfNot} ${FileExists} "$INSTDIR\bin\${PRODUCT_NAME}.exe"
-    ${DebugMsg} "deleting file $R1 and directory $INSTDIR"
-    Delete $R1
-    RMDir $INSTDIR
-  ${EndIf}
-
   ${If} $R0 == "2"
+    ; Uninstall only: uninstaller should be removed
+    ClearErrors
+    ; ExecWait doesn't wait if _?=$INSTDIR is not defined!
+    ExecWait '$R1'
     Quit
+  ${Else}
+    ; Uninstal & Reinstall: uninstaller will be rewritten
+    ClearErrors
+    ; ExecWait doesn't wait if _?=$INSTDIR is not defined!
+    ExecWait '$R1 _?=$INSTDIR'
   ${EndIf}
 
   BringToFront