Clarify prefs
[ardour.git] / tools / x-win / package.sh
1 #!/bin/bash
2
3 # we assume this script is <ardour-src>/tools/x-win/package.sh
4 pushd "`/usr/bin/dirname \"$0\"`" > /dev/null; this_script_dir="`pwd`"; popd > /dev/null
5 cd $this_script_dir
6
7 . ../define_versions.sh
8
9 cd $this_script_dir/../..
10
11 test -f gtk2_ardour/wscript || exit 1
12
13 # Defaults (overridden by environment)
14 : ${XARCH=i686} # or x86_64
15 : ${ROOT=/home/ardour}
16 : ${MAKEFLAGS=-j4}
17 : ${TMPDIR=/var/tmp}
18 : ${SRCCACHE=/var/tmp/winsrc}  # source-code tgz cache
19
20 : ${HARRISONCHANNELSTRIP=harrison_channelstrip}
21 : ${HARRISONLV2=harrison_lv2s-n}
22 : ${HARRISONDSPURL=http://www.harrisonconsoles.com/plugins/releases/public}
23
24 # see also wscript, video_tool_paths.cc, bundle_env_mingw.cc
25 # registry keys based on this are used there
26 PROGRAM_NAME=Ardour
27 PROGRAM_KEY=Ardour
28 PROGRAM_VERSION=${major_version}
29
30 PRODUCT_NAME=ardour
31 PRODUCT_VERSION=${major_version}
32
33 WITH_HARRISON_LV2=1 ;
34 WITH_X42_LV2=1 ;
35
36 # TODO: grep from build/config.log instead
37 while [ $# -gt 0 ] ; do
38         echo "arg = $1"
39         case $1 in
40                 --mixbus)
41                         MIXBUS=1
42                         WITH_HARRISON_LV2=1 ;
43                         WITH_X42_LV2=1 ;
44                         PROGRAM_NAME=Mixbus
45                         PROGRAM_KEY=Mixbus
46                         PRODUCT_NAME=mixbus
47                         MANUAL_NAME="mixbus${major_version}-live-manual"
48                         shift ;;
49                 --mixbus32c)
50                         MIXBUS=1
51                         WITH_HARRISON_LV2=1 ;
52                         WITH_X42_LV2=1 ;
53                         PRODUCT_NAME=mixbus32c
54                         PROGRAM_KEY=Mixbus32C
55                         PROGRAM_NAME=Mixbus32C-${PROGRAM_VERSION}
56                         PROGRAM_VERSION=""
57                         MANUAL_NAME="mixbus32c-${major_version}-live-manual"
58                         shift ;;
59                 --chanstrip) HARRISONCHANNELSTRIP=$2 ; shift; shift ;;
60         esac
61 done
62
63
64 LOWERCASE_DIRNAME=ardour${major_version}
65 STATEFILE_SUFFIX=ardour # see filename_extensions.cc
66
67
68 # derived variables
69 PRODUCT_ID=${PROGRAM_NAME}${PROGRAM_VERSION}
70 PRODUCT_EXE=${PRODUCT_NAME}.exe
71 PRODUCT_ICON=${PRODUCT_NAME}.ico
72
73 ###############################################################################
74
75 echo "Packaging $PRODUCT_ID"
76
77 if test "$XARCH" = "x86_64" -o "$XARCH" = "amd64"; then
78         echo "Target: 64bit Windows (x86_64)"
79         XPREFIX=x86_64-w64-mingw32
80         WARCH=w64
81 else
82         echo "Target: 32 Windows (i686)"
83         XPREFIX=i686-w64-mingw32
84         WARCH=w32
85 fi
86
87 : ${PREFIX=${ROOT}/win-stack-$WARCH}
88 export SRCCACHE
89
90 if [ "$(id -u)" = "0" ]; then
91         apt-get -y install nsis curl
92 fi
93
94
95 function download {
96 echo "--- Downloading.. $2"
97 test -f ${SRCCACHE}/$1 || curl -k -L -o ${SRCCACHE}/$1 $2
98 }
99
100 ################################################################################
101 set -e
102
103 ARDOURVERSION=${release_version}
104 ARDOURDATE=$(date -R)
105 if ! test -f build/gtk2_ardour/ardour-${ARDOURVERSION}.exe; then
106         echo "*** Please compile  ardour-${ARDOURVERSION}.exe first."
107         exit 1
108 fi
109
110 echo " === bundle to $DESTDIR"
111
112 ./waf install
113
114 ################################################################################
115
116 if test -z "$DESTDIR"; then
117         DESTDIR=`mktemp -d`
118         trap 'rm -rf $DESTDIR' exit SIGINT SIGTERM
119 fi
120
121 echo " === bundle to $DESTDIR"
122
123 ALIBDIR=$DESTDIR/lib/${LOWERCASE_DIRNAME}
124
125 rm -rf $DESTDIR
126 mkdir -p $DESTDIR/bin
127 mkdir -p $DESTDIR/share/
128 mkdir -p $ALIBDIR/surfaces
129 mkdir -p $ALIBDIR/backends
130 mkdir -p $ALIBDIR/panners
131 mkdir -p $ALIBDIR/vamp
132 mkdir -p $ALIBDIR/suil
133
134 cp build/libs/gtkmm2ext/gtkmm2ext-*.dll $DESTDIR/bin/
135 cp build/libs/midi++2/midipp-*.dll $DESTDIR/bin/
136 cp build/libs/evoral/evoral-*.dll $DESTDIR/bin/
137 cp build/libs/ardour/ardour-*.dll $DESTDIR/bin/
138 cp build/libs/timecode/timecode.dll $DESTDIR/bin/
139 cp build/libs/canvas/canvas-*.dll $DESTDIR/bin/
140 cp build/libs/pbd/pbd-*.dll $DESTDIR/bin/
141 cp build/libs/ptformat/ptformat-*.dll $DESTDIR/bin/
142 cp build/libs/audiographer/audiographer-*.dll $DESTDIR/bin/
143 cp build/libs/fst/ardour-vst-scanner.exe $DESTDIR/bin/ || true
144 cp build/session_utils/*-*.exe $DESTDIR/bin/ || true
145 cp `ls -t build/gtk2_ardour/ardour-*.exe | head -n1` $DESTDIR/bin/${PRODUCT_EXE}
146
147 mkdir -p $DESTDIR/lib/gtk-2.0/engines
148 cp build/libs/clearlooks-newer/clearlooks.dll $DESTDIR/lib/gtk-2.0/engines/libclearlooks.la
149
150 cp $PREFIX/bin/*dll $DESTDIR/bin/
151 cp $PREFIX/lib/*dll $DESTDIR/bin/
152 # special case libportaudio (wasapi), old stack has no wasapi and hence no .xp
153 cp $PREFIX/bin/libportaudio-2.xp $DESTDIR/bin/ || cp $PREFIX/bin/libportaudio-2.dll $DESTDIR/bin/libportaudio-2.xp
154 rm -rf $DESTDIR/bin/libjack*.dll
155
156 cp `find build/libs/surfaces/ -iname "*.dll"` $ALIBDIR/surfaces/
157 cp `find build/libs/backends/ -iname "*.dll"` $ALIBDIR/backends/
158 cp `find build/libs/panners/ -iname "*.dll"` $ALIBDIR/panners/
159
160 cp -r build/libs/LV2 $ALIBDIR/
161 cp -r build/libs/vamp-plugins/*ardourvampplugins*.dll $ALIBDIR/vamp/libardourvampplugins.dll
162 cp $PREFIX/lib/suil-*/*.dll $ALIBDIR/suil/ || true
163
164 # lv2 core, classifications etc - TODO check if we need the complete LV2 ontology
165 if test -d $PREFIX/lib/lv2/lv2core.lv2 ; then
166         cp -R $PREFIX/lib/lv2/lv2core.lv2 $ALIBDIR/LV2/
167 fi
168
169 mv $ALIBDIR/surfaces/ardourcp*.dll $DESTDIR/bin/
170
171 # TODO use -static-libgcc -static-libstdc++ -- but for .exe files only
172 if update-alternatives --query ${XPREFIX}-gcc | grep Value: | grep -q win32; then
173         cp /usr/lib/gcc/${XPREFIX}/*-win32/libgcc_s_*.dll $DESTDIR/bin/
174         cp /usr/lib/gcc/${XPREFIX}/*-win32/libstdc++-6.dll $DESTDIR/bin/
175 elif update-alternatives --query ${XPREFIX}-gcc | grep Value: | grep -q posix; then
176         cp /usr/lib/gcc/${XPREFIX}/*-posix/libgcc_s_*.dll $DESTDIR/bin/
177         cp /usr/lib/gcc/${XPREFIX}/*-posix/libstdc++-6.dll $DESTDIR/bin/
178 else
179         cp /usr/lib/gcc/${XPREFIX}/*/libgcc_s_sjlj-1.dll $DESTDIR/bin/
180         cp /usr/lib/gcc/${XPREFIX}/*/libstdc++-6.dll $DESTDIR/bin/
181 fi
182 #Ubuntu's 14.04's mingw needs this one for the std libs above
183 if test -f /usr/${XPREFIX}/lib/libwinpthread-1.dll; then
184         cp /usr/${XPREFIX}/lib/libwinpthread-1.dll $DESTDIR/bin/
185 fi
186
187 cp -r $PREFIX/share/${LOWERCASE_DIRNAME} $DESTDIR/share/
188 cp -r $PREFIX/share/locale $DESTDIR/share/
189 cp -r $PREFIX/etc/${LOWERCASE_DIRNAME}/* $DESTDIR/share/${LOWERCASE_DIRNAME}/
190
191 cp COPYING $DESTDIR/share/
192 cp gtk2_ardour/icons/${PRODUCT_ICON} $DESTDIR/share/
193 cp gtk2_ardour/icons/ardour_bug.ico $DESTDIR/share/
194
195 # replace default cursor with square version (sans hotspot file)
196 cp gtk2_ardour/icons/cursor_square/* $DESTDIR/share/${LOWERCASE_DIRNAME}/icons/
197
198 # clean build-dir after depoyment
199 echo " === bundle completed, cleaning up"
200 ./waf uninstall
201 echo " === complete"
202 du -sh $DESTDIR
203
204 ################################################################################
205 ### get video tools
206 if test -z "$NOVIDEOTOOLS"; then
207         echo " === Including video-tools"
208         HARVID_VERSION=$(curl -s -S http://ardour.org/files/video-tools/harvid_version.txt)
209         XJADEO_VERSION=$(curl -s -S http://ardour.org/files/video-tools/xjadeo_version.txt)
210
211         rsync -a -q --partial \
212                 rsync://ardour.org/video-tools/harvid_win-${HARVID_VERSION}.tar.xz \
213                 "${SRCCACHE}/harvid_win-${HARVID_VERSION}.tar.xz"
214
215         rsync -a -q --partial \
216                 rsync://ardour.org/video-tools/xjadeo_win-${XJADEO_VERSION}.tar.xz \
217                 "${SRCCACHE}/xjadeo_win-${XJADEO_VERSION}.tar.xz"
218
219         mkdir $DESTDIR/video
220         tar -xf "${SRCCACHE}/harvid_win-${HARVID_VERSION}.tar.xz" -C "$DESTDIR/video/"
221         tar -xf "${SRCCACHE}/xjadeo_win-${XJADEO_VERSION}.tar.xz" -C "$DESTDIR/video/"
222
223         echo " === unzipped"
224         du -sh $DESTDIR/video
225         du -sh $DESTDIR
226 fi
227
228 ################################################################################
229 ### include static gdb - re-zipped binaries from
230 ### http://sourceforge.net/projects/mingw/files/MinGW/Extension/gdb/gdb-7.6.1-1/gdb-7.6.1-1-mingw32-bin.tar.lzma
231 ### http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.9.1/threads-win32/sjlj/x86_64-4.9.1-release-win32-sjlj-rt_v3-rev1.7z
232 if ! grep " using ./waf configure" build/config.log | grep -q -- "--optimize"; then
233         download gdb-static-win3264.tar.xz http://robin.linuxaudio.org/gdb-static-win3264.tar.xz
234         cd ${SRCCACHE}
235         tar xf gdb-static-win3264.tar.xz
236         cd - > /dev/null
237
238         echo " === Creating debug.bat"
239         cp -r ${SRCCACHE}/gdb_$WARCH $DESTDIR/gdb
240         cat > $DESTDIR/debug.bat << EOF
241 cd bin
242 START ..\\gdb\\bin\\gdb.exe -iex "set logging overwrite on" -iex "set height 0" -iex "set logging on %UserProfile%\\${PRODUCT_NAME}-debug.log" -iex "target exec ${PRODUCT_EXE}" -iex "run"
243 EOF
244         OUTFILE="${TMPDIR}/${PRODUCT_NAME}-${ARDOURVERSION}-dbg-${WARCH}-Setup.exe"
245         VERSIONINFO="Debug Version."
246 else
247         OUTFILE="${TMPDIR}/${PRODUCT_NAME}-${ARDOURVERSION}-${WARCH}-Setup.exe"
248         VERSIONINFO="Optimized Version."
249 fi
250
251 ################################################################################
252 ### Mixbus plugins, etc
253 if true ; then
254         mkdir -p $ALIBDIR/LV2
255
256         echo "Adding General MIDI Synth LV2"
257
258         for proj in x42-gmsynth; do
259                 X42_VERSION=$(curl -s -S http://x42-plugins.com/x42/win/${proj}.latest.txt)
260                 rsync -a -q --partial \
261                         rsync://x42-plugins.com/x42/win/${proj}-lv2-${WARCH}-${X42_VERSION}.zip \
262                         "${SRCCACHE}/${proj}-lv2-${WARCH}-${X42_VERSION}.zip"
263                 unzip -q -d "$ALIBDIR/LV2/" "${SRCCACHE}/${proj}-lv2-${WARCH}-${X42_VERSION}.zip"
264         done
265 fi
266
267 if test x$WITH_X42_LV2 != x ; then
268         mkdir -p $ALIBDIR/LV2
269
270         echo "Adding x42 Plugins"
271
272         for proj in x42-meters x42-midifilter x42-midimap x42-stereoroute x42-eq setBfree x42-avldrums; do
273                 X42_VERSION=$(curl -s -S http://x42-plugins.com/x42/win/${proj}.latest.txt)
274                 rsync -a -q --partial \
275                         rsync://x42-plugins.com/x42/win/${proj}-lv2-${WARCH}-${X42_VERSION}.zip \
276                         "${SRCCACHE}/${proj}-lv2-${WARCH}-${X42_VERSION}.zip"
277                 unzip -q -d "$ALIBDIR/LV2/" "${SRCCACHE}/${proj}-lv2-${WARCH}-${X42_VERSION}.zip"
278         done
279 fi
280
281 if test x$WITH_HARRISON_LV2 != x ; then
282         mkdir -p $ALIBDIR/LV2
283
284         echo "Including Harrison LV2s"
285
286         curl -s -S --fail -# \
287                 -z "${SRCCACHE}/${HARRISONLV2}.${WARCH}.zip" \
288                 -o "${SRCCACHE}/${HARRISONLV2}.${WARCH}.zip" \
289                 "${HARRISONDSPURL}/${HARRISONLV2}.${WARCH}.zip"
290         unzip -q -d "$ALIBDIR/LV2/" "${SRCCACHE}/${HARRISONLV2}.${WARCH}.zip"
291 fi
292
293 if test -n "$MIXBUS"; then
294         echo "Deploying Harrison Mixbus Channelstrip"
295
296         mkdir -p $ALIBDIR/ladspa/strip
297         curl -s -S --fail -# \
298                 -z "${SRCCACHE}/${HARRISONCHANNELSTRIP}.${WARCH}.dll" \
299                 -o "${SRCCACHE}/${HARRISONCHANNELSTRIP}.${WARCH}.dll" \
300                 "${HARRISONDSPURL}/${HARRISONCHANNELSTRIP}.${WARCH}.dll"
301
302         cp "${SRCCACHE}/${HARRISONCHANNELSTRIP}.${WARCH}.dll" \
303                 "$ALIBDIR/ladspa/strip/${HARRISONCHANNELSTRIP}.dll"
304
305         echo "Deploying Harrison Vamp Plugins"
306         mkdir -p $ALIBDIR/vamp
307         curl -s -S --fail -# \
308                 -z "${SRCCACHE}/harrison_vamp.${WARCH}.dll" \
309                 -o "${SRCCACHE}/harrison_vamp.${WARCH}.dll" \
310                 "${HARRISONDSPURL}/harrison_vamp.${WARCH}.dll"
311
312         cp "${SRCCACHE}/harrison_vamp.${WARCH}.dll" \
313                 "$ALIBDIR/vamp/harrison_vamp.dll"
314 fi
315
316 ################################################################################
317
318 if test x$DEMO_SESSION_URL != x ; then
319         mkdir -p $Shared/sessions
320         DEMO_SESSIONS=$(curl -s -S --fail $DEMO_SESSION_URL/index.txt)
321         for demo in $DEMO_SESSIONS; do
322                 curl -s -S --fail -# -o $Shared/sessions/$demo $DEMO_SESSION_URL/$demo
323         done
324 fi
325
326 ################################################################################
327
328 ( cd $DESTDIR ; find . ) > ${TMPDIR}/file_list.txt
329
330 ################################################################################
331 echo " === Preparing Windows Installer"
332 NSISFILE=$DESTDIR/a3.nsis
333
334 if test "$WARCH" = "w64"; then
335         PGF=PROGRAMFILES64
336         SFX=
337 else
338         PGF=PROGRAMFILES
339         # TODO we should only add this for 32bit on 64bit windows!
340         SFX=" (x86)"
341 fi
342
343 if test -n "$QUICKZIP" ; then
344         cat > $NSISFILE << EOF
345 SetCompressor zlib
346 EOF
347 else
348         cat > $NSISFILE << EOF
349 SetCompressor /SOLID lzma
350 SetCompressorDictSize 32
351 EOF
352 fi
353
354 cat >> $NSISFILE << EOF
355 !addincludedir "${this_script_dir}\\nsis"
356 !include MUI2.nsh
357 !include FileAssociation.nsh
358 !include WinVer.nsh
359
360 Name "${PROGRAM_NAME}${PROGRAM_VERSION}"
361 OutFile "${OUTFILE}"
362 RequestExecutionLevel admin
363 InstallDir "\$${PGF}\\${PRODUCT_ID}"
364 InstallDirRegKey HKLM "Software\\${PRODUCT_NAME}\\${PRODUCT_ID}\\$WARCH" "Install_Dir"
365 !define MUI_ICON "share\\${PRODUCT_ICON}"
366
367 EOF
368
369 if test -n "$MIXBUS"; then
370
371 # TODO: proper welcome/finish text.
372         cat >> $NSISFILE << EOF
373 !define MUI_FINISHPAGE_TITLE "Welcome to Harrison Mixbus"
374 !define MUI_FINISHPAGE_TEXT "Thanks for your purchase of Mixbus!\$\\r\$\\nYou will find the Mixbus application in the Start Menu (or the All Apps panel for Windows 8) \$\\r\$\\nClick the link below to view the Mixbus manual, and learn ways to get involved with the Mixbus community."
375 !define MUI_FINISHPAGE_LINK "Mixbus Manual"
376 !define MUI_FINISHPAGE_LINK_LOCATION "http://www.harrisonconsoles.com/mixbus/${MANUAL_NAME}/"
377 !define MUI_FINISHPAGE_NOREBOOTSUPPORT
378 EOF
379
380 else
381
382         cat >> $NSISFILE << EOF
383 !define MUI_FINISHPAGE_TITLE "Welcome to Ardour"
384 !define MUI_FINISHPAGE_TEXT "This windows versions or Ardour is provided as-is.\$\\r\$\\nThe Ardour community currently has no expertise in supporting windows users, and there are no developers focusing on windows specific issues either.\$\\r\$\\nIf you like Ardour, please consider helping out."
385 !define MUI_FINISHPAGE_LINK "Ardour Manual"
386 !define MUI_FINISHPAGE_LINK_LOCATION "http://manual.ardour.org/"
387 #this would run as admin - see http://forums.winamp.com/showthread.php?t=353366
388 #!define MUI_FINISHPAGE_RUN "\$INSTDIR\\bin\\${PRODUCT_EXE}"
389 !define MUI_FINISHPAGE_NOREBOOTSUPPORT
390 EOF
391
392 fi
393
394 cat >> $NSISFILE << EOF
395 !define MUI_ABORTWARNING
396 !insertmacro MUI_PAGE_LICENSE "share\\COPYING"
397 !insertmacro MUI_PAGE_COMPONENTS
398 !insertmacro MUI_PAGE_DIRECTORY
399 !insertmacro MUI_PAGE_INSTFILES
400 !insertmacro MUI_PAGE_FINISH
401 !insertmacro MUI_UNPAGE_CONFIRM
402 !insertmacro MUI_UNPAGE_INSTFILES
403 !insertmacro MUI_LANGUAGE "English"
404
405 Section "${PROGRAM_NAME}${PROGRAM_VERSION} (required)" SecMainProg
406   SectionIn RO
407   SetOutPath \$INSTDIR
408   File /r bin
409   File /r lib
410   File /r share
411   File /nonfatal debug.bat
412   File /nonfatal /r gdb
413   WriteRegStr HKLM "Software\\${PROGRAM_KEY}\\v${major_version}\\$WARCH" "Install_Dir" "\$INSTDIR"
414   WriteRegStr HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" "DisplayName" "${PROGRAM_NAME}${PROGRAM_VERSION}"
415   WriteRegStr HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" "UninstallString" '"\$INSTDIR\\uninstall.exe"'
416   WriteRegDWORD HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" "NoModify" 1
417   WriteRegDWORD HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" "NoRepair" 1
418   WriteUninstaller "\$INSTDIR\uninstall.exe"
419   CreateShortCut "\$INSTDIR\\${PROGRAM_NAME}${PROGRAM_VERSION}.lnk" "\$INSTDIR\\bin\\${PRODUCT_EXE}" "" "\$INSTDIR\\bin\\${PRODUCT_EXE}" 0
420   \${registerExtension} "\$INSTDIR\\bin\\${STATEFILE_SUFFIX}" ".${PRODUCT_NAME}" "${PROGRAM_NAME} Session"
421 SectionEnd
422
423 Section "WASAPI sound driver" SecWASAPI
424 SectionEnd
425 EOF
426
427 if test -z "$NOVIDEOTOOLS"; then
428
429         cat >> $NSISFILE << EOF
430 Section "Videotimeline Tools" SecVideo
431   WriteRegStr HKLM "Software\\${PROGRAM_KEY}\\v${major_version}\\video" "Install_Dir" "\$INSTDIR\\video"
432   SetOutPath \$INSTDIR
433   File /r video
434 SectionEnd
435 EOF
436
437 fi
438
439 cat >> $NSISFILE << EOF
440 Section "Start Menu Shortcuts" SecMenu
441   SetShellVarContext all
442   CreateDirectory "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}"
443   CreateShortCut "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}\\${PROGRAM_NAME}${PROGRAM_VERSION}.lnk" "\$INSTDIR\\bin\\${PRODUCT_EXE}" "" "\$INSTDIR\\bin\\${PRODUCT_EXE}" 0
444 EOF
445
446 if test -f "$DESTDIR/debug.bat"; then
447         cat >> $NSISFILE << EOF
448   CreateShortCut "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}\\${PROGRAM_NAME}${PROGRAM_VERSION} GDB.lnk" "\$INSTDIR\\debug.bat" "" "\$INSTDIR\\share\\ardour_bug.ico" 0
449 EOF
450 fi
451
452 if test -z "$NOVIDEOTOOLS"; then
453         cat >> $NSISFILE << EOF
454   IfFileExists "\$INSTDIR\\video\\xjadeo\\xjadeo.exe" 0 +2
455   CreateShortCut "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}\\Video Monitor.lnk" "\$INSTDIR\\video\\xjadeo\\xjadeo.exe" "" "\$INSTDIR\\video\\xjadeo\\xjadeo.exe" 0
456 EOF
457 fi
458
459 cat >> $NSISFILE << EOF
460   CreateShortCut "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}\\Uninstall.lnk" "\$INSTDIR\\uninstall.exe" "" "\$INSTDIR\\uninstall.exe" 0
461 SectionEnd
462 LangString DESC_SecMainProg \${LANG_ENGLISH} "${PROGRAM_NAME} ${ARDOURVERSION}\$\\r\$\\n${VERSIONINFO}\$\\r\$\\n${ARDOURDATE}"
463 LangString DESC_SecWASAPI \${LANG_ENGLISH} "WASAPI Audio Driver\$\\r\$\\nOnly works on Vista or later. Windows 10 Users may currently also experience issues if this is installed."
464 EOF
465
466 if test -z "$NOVIDEOTOOLS"; then
467         cat >> $NSISFILE << EOF
468 LangString DESC_SecVideo \${LANG_ENGLISH} "Video Tools\$\\r\$\\nxjadeo-${XJADEO_VERSION}\$\\r\$\\nharvid-${HARVID_VERSION}"
469 EOF
470 fi
471
472 cat >> $NSISFILE << EOF
473 LangString DESC_SecMenu \${LANG_ENGLISH} "Create Start-Menu Shortcuts (recommended)."
474 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
475 !insertmacro MUI_DESCRIPTION_TEXT \${SecMainProg} \$(DESC_SecMainProg)
476 !insertmacro MUI_DESCRIPTION_TEXT \${SecWASAPI} \$(DESC_SecWASAPI)
477 EOF
478
479 if test -z "$NOVIDEOTOOLS"; then
480         cat >> $NSISFILE << EOF
481 !insertmacro MUI_DESCRIPTION_TEXT \${SecVideo} \$(DESC_SecVideo)
482 EOF
483 fi
484
485 cat >> $NSISFILE << EOF
486 !insertmacro MUI_DESCRIPTION_TEXT \${SecMenu} \$(DESC_SecMenu)
487 !insertmacro MUI_FUNCTION_DESCRIPTION_END
488 Section "Uninstall"
489   SetShellVarContext all
490   DeleteRegKey HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}"
491   DeleteRegKey HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}"
492   DeleteRegKey HKLM "Software\\${PROGRAM_KEY}\\v${major_version}"
493   RMDir /r "\$INSTDIR\\bin"
494   RMDir /r "\$INSTDIR\\lib"
495   RMDir /r "\$INSTDIR\\share"
496   RMDir /r "\$INSTDIR\\gdb"
497   RMDir /r "\$INSTDIR\\video"
498   Delete "\$INSTDIR\\debug.bat"
499   Delete "\$INSTDIR\\uninstall.exe"
500   Delete "\$INSTDIR\\${PROGRAM_NAME}${PROGRAM_VERSION}.lnk"
501   RMDir "\$INSTDIR"
502   Delete "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}\\*.*"
503   RMDir "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}"
504   \${unregisterExtension} ".${STATEFILE_SUFFIX}" "${PROGRAM_NAME} Session"
505 SectionEnd
506
507
508 Function .onInit
509
510   ReadRegStr \$R0 HKLM \
511     "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" \
512     "UninstallString"
513   StrCmp \$R0 "" done
514
515   MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
516     "${PROGRAM_NAME} is already installed. Click 'OK' to remove the previous version or 'Cancel' to cancel this upgrade." \
517     IDOK uninst
518     Abort
519
520   uninst:
521     ClearErrors
522     ExecWait '\$R0 _?=\$INSTDIR'
523     IfErrors uninstall_error
524
525     ReadRegStr \$R1 HKLM \
526       "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" \
527       "UninstallString"
528     StrCmp \$R1 "" 0 done
529
530     Delete "\$INSTDIR\\uninstall.exe"
531     RMDir "\$INSTDIR"
532     goto done
533
534   uninstall_error:
535
536     MessageBox MB_OK|MB_ICONEXCLAMATION \
537       "Uninstaller did not complete successfully. Continue at your own risk..." \
538       IDOK done
539
540   done:
541
542   \${If} \${AtMostWinXP}
543     SectionSetFlags \${SecWASAPI} \${SF_RO}
544   \${Else}
545     SectionSetFlags \${SecWASAPI} \${SF_SELECTED}
546   \${EndIf}
547
548 FunctionEnd
549
550 Function .onInstSuccess
551
552   \${If} \${AtMostWinXP}
553     goto pa_no_wasapi
554   \${EndIf}
555
556   SectionGetFlags \${SecWASAPI} \$R0
557
558   IntOp \$R0 \$R0 & \${SF_SELECTED}
559   IntCmp \$R0 \${SF_SELECTED} pa_with_wasapi pa_no_wasapi
560
561   pa_with_wasapi:
562 ; VISTA .. 9, libportaudio with WASAPI is good.
563   Delete "\$INSTDIR\\bin\\libportaudio-2.xp"
564   goto endportaudio
565
566 ; Windows XP lacks support for WASAPI, Windows10 on some system has issues
567 ; http://tracker.ardour.org/view.php?id=6507
568   pa_no_wasapi:
569   Delete "\$INSTDIR\\bin\\libportaudio-2.dll"
570   Rename "\$INSTDIR\\bin\\libportaudio-2.xp" "\$INSTDIR\\bin\\libportaudio-2.dll"
571
572   endportaudio:
573
574 FunctionEnd
575 EOF
576
577 rm -f ${OUTFILE}
578 echo " === OutFile: $OUTFILE"
579
580 if test -n "$QUICKZIP" ; then
581 echo " === Building Windows Installer (fast zip)"
582 else
583 echo " === Building Windows Installer (lzma compression takes ages)"
584 fi
585 time makensis -V2 $NSISFILE
586 rm -rf $DESTDIR
587 ls -lgGh "$OUTFILE"