]> Dogcows Code - chaz/yoink/blobdiff - win32/mkpackage.sh.in
preliminary AM_SILENT_RULES support
[chaz/yoink] / win32 / mkpackage.sh.in
diff --git a/win32/mkpackage.sh.in b/win32/mkpackage.sh.in
new file mode 100644 (file)
index 0000000..2051a22
--- /dev/null
@@ -0,0 +1,474 @@
+#!/bin/bash
+
+#
+# Yoink
+# Run this script to create a win32 installer.
+# This was blatantly yoinked and adapted from the Wormux Project.
+#
+
+# Programs
+MAKENSIS="@MAKENSIS@"
+STRIP="@STRIP@"
+
+# Anchor paths
+ROOT_DIR="$PWD/.."
+
+# Stuff
+COMPRESSION="/solid lzma"
+DEST="tmp-yoink-win32"
+SCRIPT="$DEST/yoink.nsi"
+OUT_FILE=${1:-yoinksetup-@VERSION@.exe}
+
+# DLL dependencies
+DLLS="SDL SDL_image zlib1 libpng12-0 OpenAL32 libvorbis-0 libogg-0"
+DLLS="$DLLS libvorbisfile-3 lua51"
+
+# Prepare
+${STRIP:-strip} "$ROOT_DIR/src/yoink.exe"
+rm -rf "$DEST"
+mkdir -p "$DEST"
+
+
+#
+# Set installer definitions and strings.
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+HKLM_PATH='SOFTWARE\Games\Yoink'
+UNINSTALL_KEY='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Yoink'
+APP_PATHS_KEY='SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\yoink.exe'
+START_RUN_KEY='SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
+
+
+PROMPT1="Not enough rights to install, aborting. :-("
+PROMPT2="Unable to uninstall the currently installed version of Yoink. The new version will be installed without removing the currently installed version."
+
+SEC_INSTALL="Install Yoink!"
+SEC_INSTALL_DESC="Installs Yoink to your computer."
+SEC_UNINSTALL="Uninstall previous version."
+SEC_SHORTCUTS="Install Shortcuts."
+SEC_SHORTCUTS_DESC="Install shortcuts at various locations."
+SEC_SHORTCUT1="Place a shortcut on the desktop."
+SEC_SHORTCUT2="Place a shortcut in the start menu."
+SEC_SHORTCUT3="Place an uninstall shortcut in the start menu."
+
+WEBSITE_LINK="Visit the Yoink website"
+
+
+#
+# Begin output of installer script.
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+cat > "$SCRIPT" <<EOF
+; based on MUI Welcome/Finish Page Example Script written by Joost Verburg
+!include "MUI2.nsh"
+!include "Sections.nsh"
+!include "LogicLib.nsh"
+!include "FileFunc.nsh"
+
+!insertmacro GetParent
+
+Name "Yoink"
+VIProductVersion       "@PVERSION@"
+VIAddVersionKey                "FileDescription"       "Yoink Setup"
+VIAddVersionKey                "ProductName"           "Yoink"
+VIAddVersionKey                "FileVersion"           "@VERSION@"
+VIAddVersionKey                "ProductVersion"        "@VERSION@"
+VIAddVersionKey                "LegalCopyright"        "Copyright 2009 Charles McGarvey et al."
+
+;General
+OutFile                                        "$ROOT_DIR/$OUT_FILE"
+SetCompressor                  $COMPRESSION
+ShowInstDetails                        show
+ShowUninstDetails              show
+SetDateSave                            on
+RequestExecutionLevel  highest
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Modern UI Configuration ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+!define MUI_ICON                                               "$ROOT_DIR/src/setup.ico"
+!define MUI_UNICON                                             "$ROOT_DIR/src/uninstall.ico"
+; Language
+!define MUI_LANGDLL_ALWAYSSHOW
+!define MUI_LANGDLL_REGISTRY_ROOT              "HKCU"
+!define MUI_LANGDLL_REGISTRY_KEY               "$HKLM_PATH"
+!define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
+; Misc stuff
+!define MUI_COMPONENTSPAGE_SMALLDESC
+!define MUI_ABORTWARNING
+; Do not close dialogs, allow to check installation result
+!define MUI_FINISHPAGE_NOAUTOCLOSE
+!define MUI_UNFINISHPAGE_NOAUTOCLOSE
+;Finish Page config
+!define MUI_FINISHPAGE_RUN                             "\$INSTDIR\\yoink.exe"
+!define MUI_FINISHPAGE_RUN_NOTCHECKED
+!define MUI_FINISHPAGE_LINK                            "$WEBSITE_LINK"
+!define MUI_FINISHPAGE_LINK_LOCATION   "http://www.dogcows.com/"
+
+;--------------------------------
+;Pages
+; Install
+!insertmacro MUI_PAGE_WELCOME
+!insertmacro MUI_PAGE_COMPONENTS
+!insertmacro MUI_PAGE_DIRECTORY
+!insertmacro MUI_PAGE_INSTFILES
+!insertmacro MUI_PAGE_FINISH
+; Uninstall
+!insertmacro MUI_UNPAGE_WELCOME
+!insertmacro MUI_UNPAGE_CONFIRM
+!insertmacro MUI_UNPAGE_INSTFILES
+!insertmacro MUI_UNPAGE_FINISH
+
+;--------------------------------
+;Languages
+!insertmacro MUI_LANGUAGE "English"
+
+;--------------------------------
+;Reserve Files
+;If you are using solid compression, files that are required before
+;the actual installation should be stored first in the data block,
+;because this will make your installer start faster.
+
+!insertmacro MUI_RESERVEFILE_LANGDLL
+
+;--------------------------------
+;Folder-selection page
+InstallDir "\$PROGRAMFILES\\Yoink"
+; Registry key to check for directory (so if you install again, it will 
+; overwrite the old one automatically)
+InstallDirRegKey HKLM "$HKLM_PATH" "Path"
+AutoCloseWindow false
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Start Install Sections ;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;-----------------------------------------
+;Create folder only if it doesnt exist yet
+!macro CreateDirectoryOnce FOLDER
+  IfFileExists "\${FOLDER}\\*.*" +1
+    CreateDirectory "\${FOLDER}"
+!macroend
+
+;--------------------------------
+;Check (un)install rights
+!macro CheckUserInstallRightsMacro UN
+Function \${UN}CheckUserInstallRights
+  Push \$0
+  Push \$1
+  ClearErrors
+  UserInfo::GetName
+  IfErrors Win9x
+  Pop \$0
+  UserInfo::GetAccountType
+  Pop \$1
+
+  StrCmp \$1 "Admin" 0 +3
+    StrCpy \$1 "HKLM"
+    Goto done
+  StrCmp \$1 "Power" 0 +3
+    StrCpy \$1 "HKLM"
+    Goto done
+  StrCmp \$1 "User" 0 +3
+    StrCpy \$1 "HKCU"
+    Goto done
+  StrCmp \$1 "Guest" 0 +3
+    StrCpy \$1 "NONE"
+    Goto done
+  ; Unknown error
+  StrCpy \$1 "NONE"
+  Goto done
+
+  Win9x:
+    StrCpy \$1 "HKLM"
+
+  done:
+    Exch \$1
+    Exch
+    Pop \$0
+FunctionEnd
+!macroend
+!insertmacro CheckUserInstallRightsMacro ""
+!insertmacro CheckUserInstallRightsMacro "un."
+
+;--------------------------------
+; Uninstall any old version of Yoink
+
+; Section hidden because automatically selected by the installer
+Section "$SEC_UNINSTALL" SecUninstallOldYoink
+  ; Check install rights..
+  StrCpy \$R3 $HKLM_PATH
+  StrCpy \$R4 $UNINSTALL_KEY
+  StrCpy \$R5 "uninstall.exe"
+  Call CheckUserInstallRights
+  Pop \$R0
+  ; "NONE" case already handled at start
+  StrCmp \$R0 "HKCU" _hkcu
+    ReadRegStr \$R1 HKLM \$R3 ""
+    ReadRegStr \$R2 HKLM "\$R4" "UninstallString"
+    Goto try_uninstall
+
+  _hkcu:
+    ReadRegStr \$R1 HKCU \$R3 ""
+    ReadRegStr \$R2 HKCU "\$R4" "UninstallString"
+
+  ; If a previous version exists, remove it
+  try_uninstall:
+    ; If first string is unavailable, Yoink was probably not installed
+    StrCmp \$R1 "" done
+      ; Check if we have uninstall string..
+      IfFileExists \$R2 0 no_file
+        ; Have uninstall string, go ahead and uninstall.
+        SetOverwrite on
+        ; Need to copy uninstaller outside of the install dir
+        ClearErrors
+        CopyFiles /SILENT \$R2 "\$TEMP\\\$R5"
+        SetOverwrite off
+        IfErrors uninstall_problem
+          ; Ready to uninstall..
+          ClearErrors
+          ExecWait '"\$TEMP\\\$R5" /S _?=\$R1'
+          IfErrors exec_error
+            Delete "\$TEMP\\\$R5"
+            Goto done
+
+          exec_error:
+            Delete "\$TEMP\\\$R5"
+            Goto uninstall_problem
+
+  no_file:
+    MessageBox MB_OK "No uninstaller exe found" /SD IDOK IDOK done
+
+  uninstall_problem:
+    ; We cant uninstall. Either the user must manually uninstall or
+    ; we ignore and reinstall over it.
+    MessageBox MB_OKCANCEL "$PROMPT2" /SD IDOK IDCANCEL done
+    Quit
+
+  done:
+SectionEnd
+
+;--------------------------------
+; Installer Sections
+
+Section "$SEC_INSTALL" SecInstallYoink
+  ; Create install and config folders
+  CreateDirectory "\$INSTDIR"
+  ; Set output path to the installation directory.
+  SetOutPath "\$INSTDIR"
+  File "$ROOT_DIR/src/yoink.ico"
+  ; Executing in tmpdir, looking for file in folder below
+  File "$ROOT_DIR/src/yoink.exe"
+  ; data
+  File /r /x Makefile* /x *.desktop "$ROOT_DIR/data"
+  ; documentation
+  File "$ROOT_DIR/AUTHORS" "$ROOT_DIR/ChangeLog" "$ROOT_DIR/COPYING"
+  File "$ROOT_DIR/README" "$ROOT_DIR/TODO" "$ROOT_DIR/doc/screenshot.jpg"
+  File /r "$ROOT_DIR/doc/licenses"
+  ; uninstall
+  WriteUninstaller "uninstall.exe"
+EOF
+
+
+#
+# Add DLL's to installer
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+for dll in $DLLS
+do
+       cat >> "$SCRIPT" <<EOF
+File "@prefix@/bin/$dll.dll"
+EOF
+done
+
+
+#
+# Continue writing the installer
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+cat >> "$SCRIPT" <<EOF
+  Call CheckUserInstallRights
+  Pop \$R0
+  ; "NONE" case already handled at start
+  StrCmp \$R0 "HKCU" _hkcu
+    WriteRegStr HKLM "$APP_PATHS_KEY" "" "\$INSTDIR\\yoink.exe"
+    WriteRegStr HKLM "$HKLM_PATH" "" "\$INSTDIR"
+    WriteRegStr HKLM "$HKLM_PATH" "Version" "@VERSION@"
+    WriteRegStr HKLM "$UNINSTALL_KEY" "DisplayName" "Yoink"
+    WriteRegStr HKLM "$UNINSTALL_KEY" "DisplayVersion" "@VERSION@"
+    WriteRegStr HKLM "$UNINSTALL_KEY" "UninstallString" "\$INSTDIR\\uninstall.exe"
+    ;Write language to the registry (for the uninstaller)
+    WriteRegStr HKLM "$HKLM_PATH" "Installer Language" \$LANGUAGE
+    ; Sets scope of the desktop and Start Menu entries for all users.
+    SetShellVarContext "all"
+    Goto _next
+
+  _hkcu:
+    WriteRegStr HKCU "$HKLM_PATH" "" "\$INSTDIR"
+    WriteRegStr HKCU "$HKLM_PATH" "Version" "@VERSION@"
+    WriteRegStr HKCU "$UNINSTALL_KEY" "DisplayName" "Yoink"
+    WriteRegStr HKCU "$UNINSTALL_KEY" "DisplayVersion" "@VERSION@"
+    WriteRegStr HKCU "$UNINSTALL_KEY" "UninstallString" "\$INSTDIR\\uninstall.exe"
+    ;Write language to the registry (for the uninstaller)
+    WriteRegStr HKCU "$HKLM_PATH" "Installer Language" \$LANGUAGE
+    ;SetShellVarContext "current"
+
+  _next:
+SectionEnd ; Installer section
+
+;--------------------------------
+;Shortcuts
+SectionGroup /e "$SEC_SHORTCUTS" SecShortcuts
+
+       ; Desktop shortcut
+Section /o "$SEC_SHORTCUT1" SecDesktopShortcut
+SetOverwrite on
+CreateShortCut "\$DESKTOP\\Yoink.lnk" "\$INSTDIR\\yoink.exe" \
+       "" "\$INSTDIR\\yoink.exe" 0
+SetOverwrite off
+SectionEnd
+
+       ; Yoink uninstall shortcut in start menu
+       ; Might be forced if user has no install rights,
+       ; because it would be complex otherwise:
+       ; - No uninstall available in Windows "Program uninstall"
+       ; - Folder lost in APPDATA, which can be hidden, etc
+Section "$SEC_SHORTCUT3" SecUninstallShortcut
+SetOverwrite on
+!insertmacro CreateDirectoryOnce "\$SMPROGRAMS\\Yoink"
+CreateShortCut  "\$SMPROGRAMS\\Yoink\\Uninstall.lnk" \
+       "\$INSTDIR\\uninstall.exe" "" "\$INSTDIR\\uninstall.exe" 0
+SetOverwrite off
+SectionEnd
+
+       ; Yoink shortcut in start menu
+Section "$SEC_SHORTCUT2" SecStartMenuShortcut
+SetOverwrite on
+!insertmacro CreateDirectoryOnce "\$SMPROGRAMS\\Yoink"
+CreateShortCut "\$SMPROGRAMS\\Yoink\\Play Yoink!.lnk" \
+       "\$INSTDIR\\yoink.exe" "" "\$INSTDIR\\yoink.exe" 0
+SetOverwrite off
+SectionEnd
+
+SectionGroupEnd
+
+
+;--------------------------------
+;Descriptions
+
+!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
+!insertmacro MUI_DESCRIPTION_TEXT \${SecInstallYoink}          "$SEC_INSTALL_DESC"
+!insertmacro MUI_DESCRIPTION_TEXT \${SecShortcuts}                     "$SEC_SHORTCUTS_DESC"
+!insertmacro MUI_DESCRIPTION_TEXT \${SecDesktopShortcut}       "$SEC_SHORTCUT1"
+!insertmacro MUI_DESCRIPTION_TEXT \${SecStartMenuShortcut}     "$SEC_SHORTCUT2"
+!insertmacro MUI_DESCRIPTION_TEXT \${SecUninstallShortcut}     "$SEC_SHORTCUT3"
+!insertmacro MUI_FUNCTION_DESCRIPTION_END
+
+
+;--------------------------------
+;Uninstaller Section
+
+Section "Uninstall"
+  ; Set install path according to user rights
+  Call un.CheckUserInstallRights
+  Pop \$R0
+  StrCmp \$R0 "HKLM" _hklm
+
+  ; Also used as fallback by HKLM case
+  _hkcu:
+    ReadRegStr \$R0 HKCU "$HKLM_PATH" ""
+    StrCmp \$R0 "\$INSTDIR" 0 _next
+      ; HKCU install path matches our INSTDIR so uninstall
+      DeleteRegKey HKCU "$HKLM_PATH"
+      DeleteRegKey HKCU "$UNINSTALL_KEY"
+      Goto _next
+
+  _hklm:
+    ReadRegStr \$R0 HKLM "$HKLM_PATH" ""
+    StrCmp \$R0 \$INSTDIR 0 _hkcu
+      ; HKLM install path matches our INSTDIR so uninstall
+      DeleteRegKey HKLM "$APP_PATHS_KEY"
+      DeleteRegKey HKLM "$HKLM_PATH"
+      DeleteRegKey HKLM "$UNINSTALL_KEY"
+      SetShellVarContext all
+
+  _next:
+    ; Remove Language preference info
+    DeleteRegValue HKCU "$HKLM_PATH" "Installer Language"
+    ; remove shortcuts, if any.
+    Delete "\$SMPROGRAMS\\Yoink\\*.*"
+    RMDir  "\$SMPROGRAMS\\Yoink"
+    Delete "\$SMPROGRAMS\\Yoink.lnk"
+    Delete "\$DESKTOP\\Yoink.lnk"
+    ; remove files
+    RMDir /r "\$INSTDIR"
+SectionEnd
+
+Function .onInit
+  ;Language selection
+  !insertmacro MUI_LANGDLL_DISPLAY
+
+  IntOp \$R0 \${SF_RO} | \${SF_SELECTED}
+  SectionSetFlags \${SecInstallYoink} \$R0
+  SectionSetFlags \${SecUninstallOldYoink} \$R0
+
+  ; Set install path according to user rights
+  Call CheckUserInstallRights
+  Pop \$R0
+  StrCmp \$R0 "NONE" _none
+  StrCmp \$R0 "HKLM" 0 _hkcu
+    StrCpy \$INSTDIR "\$PROGRAMFILES\\Yoink"
+    Goto _done
+
+  _hkcu:
+    Push \$SMPROGRAMS
+    \${GetParent} \$SMPROGRAMS \$R2
+    \${GetParent} \$R2 \$R2
+    StrCpy \$INSTDIR "\$R2\\Yoink"
+    ; In this case uninstall shortcut *must* be available because
+    ; the alternative are complex for the user
+    IntOp \$R0 \${SF_RO} | \${SF_SELECTED}
+    SectionSetFlags \${SecUninstallShortcut} \$R0
+    Goto _done
+
+  _none:
+   ; Not going to bother
+   MessageBox MB_OK "$PROMPT1" /SD IDOK
+   Quit
+
+  _done:
+FunctionEnd
+
+; INSTDIR will be determined by reading a registry key
+Function un.onInit
+  !insertmacro MUI_UNGETLANGUAGE
+  ; Set install path according to user rights
+  Call un.CheckUserInstallRights
+  Pop \$R0
+  StrCmp \$R0 "NONE" _none
+    Goto _end
+
+  _none:
+   ; Not going to bother
+   MessageBox MB_OK "$PROMPT1" /SD IDOK
+   Quit
+
+  _end:
+FunctionEnd
+EOF
+
+
+#
+# Compile the installer and cleanup.
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+if ! "${MAKENSIS:-makensis}" "$SCRIPT"
+then
+       echo "makensis failed, aborting..."
+       exit 1
+fi
+
+rm -rf "$DEST"
+
This page took 0.031735 seconds and 4 git commands to generate.