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