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