summaryrefslogtreecommitdiff
path: root/tools/x-win/package.sh
blob: fdcd54584cf8e0601b1063ce2043e28b473181f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
#!/bin/bash

# we assume this script is <ardour-src>/tools/x-win/package.sh
pushd "`/usr/bin/dirname \"$0\"`" > /dev/null; this_script_dir="`pwd`"; popd > /dev/null
cd $this_script_dir

. ../define_versions.sh

cd $this_script_dir/../..

test -f gtk2_ardour/wscript || exit 1

# Defaults (overridden by environment)
: ${XARCH=i686} # or x86_64
: ${ROOT=/home/ardour}
: ${MAKEFLAGS=-j4}
: ${TMPDIR=/var/tmp}
: ${SRCCACHE=/var/tmp/winsrc}  # source-code tgz cache

: ${HARRISONCHANNELSTRIP=harrison_channelstrip}
: ${HARRISONLV2=harrison_lv2s-n}

# see also wscript, video_tool_paths.cc, bundle_env_mingw.cc
# registry keys based on this are used there
PROGRAM_NAME=Ardour
PROGRAM_KEY=Ardour
PROGRAM_VERSION=${major_version}

PRODUCT_NAME=ardour
PRODUCT_VERSION=${major_version}

WITH_HARRISON_LV2=1 ;
WITH_X42_LV2=1 ;

# TODO: grep from build/config.log instead
while [ $# -gt 0 ] ; do
	echo "arg = $1"
	case $1 in
		--mixbus)
			MIXBUS=1
			WITH_HARRISON_LV2=1 ;
			WITH_X42_LV2=1 ;
			PROGRAM_NAME=Mixbus
			PROGRAM_KEY=Mixbus
			PRODUCT_NAME=mixbus
			shift ;;
		--mixbus32c)
			MIXBUS=1
			WITH_HARRISON_LV2=1 ;
			WITH_X42_LV2=1 ;
			PRODUCT_NAME=mixbus32c
			PROGRAM_KEY=Mixbus32C
			PROGRAM_NAME=Mixbus32C-${PROGRAM_VERSION}
			PROGRAM_VERSION=""
			shift ;;
		--chanstrip) HARRISONCHANNELSTRIP=$2 ; shift; shift ;;
	esac
done


LOWERCASE_DIRNAME=ardour${major_version}
STATEFILE_SUFFIX=ardour # see filename_extensions.cc


# derived variables
PRODUCT_ID=${PROGRAM_NAME}${PROGRAM_VERSION}
PRODUCT_EXE=${PRODUCT_NAME}.exe
PRODUCT_ICON=${PRODUCT_NAME}.ico

###############################################################################

echo "Packaging $PRODUCT_ID"

if test "$XARCH" = "x86_64" -o "$XARCH" = "amd64"; then
	echo "Target: 64bit Windows (x86_64)"
	XPREFIX=x86_64-w64-mingw32
	WARCH=w64
else
	echo "Target: 32 Windows (i686)"
	XPREFIX=i686-w64-mingw32
	WARCH=w32
fi

: ${PREFIX=${ROOT}/win-stack-$WARCH}
export SRCCACHE

if [ "$(id -u)" = "0" ]; then
	apt-get -y install nsis curl
fi


function download {
echo "--- Downloading.. $2"
test -f ${SRCCACHE}/$1 || curl -k -L -o ${SRCCACHE}/$1 $2
}

################################################################################
set -e

ARDOURVERSION=${release_version}
ARDOURDATE=$(date -R)
if ! test -f build/gtk2_ardour/ardour-${ARDOURVERSION}.exe; then
	echo "*** Please compile  ardour-${ARDOURVERSION}.exe first."
	exit 1
fi

echo " === bundle to $DESTDIR"

./waf install

################################################################################

if test -z "$DESTDIR"; then
	DESTDIR=`mktemp -d`
	trap 'rm -rf $DESTDIR' exit SIGINT SIGTERM
fi

echo " === bundle to $DESTDIR"

ALIBDIR=$DESTDIR/lib/${LOWERCASE_DIRNAME}

rm -rf $DESTDIR
mkdir -p $DESTDIR/bin
mkdir -p $DESTDIR/share/
mkdir -p $ALIBDIR/surfaces
mkdir -p $ALIBDIR/backends
mkdir -p $ALIBDIR/panners
mkdir -p $ALIBDIR/vamp
mkdir -p $ALIBDIR/suil

cp build/libs/gtkmm2ext/gtkmm2ext-*.dll $DESTDIR/bin/
cp build/libs/midi++2/midipp-*.dll $DESTDIR/bin/
cp build/libs/evoral/evoral-*.dll $DESTDIR/bin/
cp build/libs/ardour/ardour-*.dll $DESTDIR/bin/
cp build/libs/timecode/timecode.dll $DESTDIR/bin/
cp build/libs/qm-dsp/qmdsp-*.dll $DESTDIR/bin/
cp build/libs/canvas/canvas-*.dll $DESTDIR/bin/
cp build/libs/pbd/pbd-*.dll $DESTDIR/bin/
cp build/libs/ptformat/ptformat-*.dll $DESTDIR/bin/
cp build/libs/audiographer/audiographer-*.dll $DESTDIR/bin/
cp build/libs/fst/ardour-vst-scanner.exe $DESTDIR/bin/ || true
cp `ls -t build/gtk2_ardour/ardour-*.exe | head -n1` $DESTDIR/bin/${PRODUCT_EXE}

mkdir -p $DESTDIR/lib/gtk-2.0/engines
cp build/libs/clearlooks-newer/clearlooks.dll $DESTDIR/lib/gtk-2.0/engines/libclearlooks.la

cp $PREFIX/bin/*dll $DESTDIR/bin/
cp $PREFIX/lib/*dll $DESTDIR/bin/
# special case libportaudio (wasapi), old stack has no wasapi and hence no .xp
cp $PREFIX/bin/libportaudio-2.xp $DESTDIR/bin/ || cp $PREFIX/bin/libportaudio-2.dll $DESTDIR/bin/libportaudio-2.xp
rm -rf $DESTDIR/bin/libjack*.dll

cp `find build/libs/surfaces/ -iname "*.dll"` $ALIBDIR/surfaces/
cp `find build/libs/backends/ -iname "*.dll"` $ALIBDIR/backends/
cp `find build/libs/panners/ -iname "*.dll"` $ALIBDIR/panners/

cp -r build/libs/LV2 $ALIBDIR/
cp -r build/libs/vamp-plugins/*ardourvampplugins*.dll $ALIBDIR/vamp/libardourvampplugins.dll
cp $PREFIX/lib/suil-*/*.dll $ALIBDIR/suil/ || true

# lv2 core, classifications etc - TODO check if we need the complete LV2 ontology
if test -d $PREFIX/lib/lv2/lv2core.lv2 ; then
	cp -R $PREFIX/lib/lv2/lv2core.lv2 $ALIBDIR/LV2/
fi

mv $ALIBDIR/surfaces/ardourcp*.dll $DESTDIR/bin/

# TODO use -static-libgcc -static-libstdc++ -- but for .exe files only
if update-alternatives --query ${XPREFIX}-gcc | grep Value: | grep -q win32; then
	cp /usr/lib/gcc/${XPREFIX}/*-win32/libgcc_s_*.dll $DESTDIR/bin/
	cp /usr/lib/gcc/${XPREFIX}/*-win32/libstdc++-6.dll $DESTDIR/bin/
elif update-alternatives --query ${XPREFIX}-gcc | grep Value: | grep -q posix; then
	cp /usr/lib/gcc/${XPREFIX}/*-posix/libgcc_s_*.dll $DESTDIR/bin/
	cp /usr/lib/gcc/${XPREFIX}/*-posix/libstdc++-6.dll $DESTDIR/bin/
else
	cp /usr/lib/gcc/${XPREFIX}/*/libgcc_s_sjlj-1.dll $DESTDIR/bin/
	cp /usr/lib/gcc/${XPREFIX}/*/libstdc++-6.dll $DESTDIR/bin/
fi
#Ubuntu's 14.04's mingw needs this one for the std libs above
if test -f /usr/${XPREFIX}/lib/libwinpthread-1.dll; then
	cp /usr/${XPREFIX}/lib/libwinpthread-1.dll $DESTDIR/bin/
fi

cp -r $PREFIX/share/${LOWERCASE_DIRNAME} $DESTDIR/share/
cp -r $PREFIX/share/locale $DESTDIR/share/
cp -r $PREFIX/etc/${LOWERCASE_DIRNAME}/* $DESTDIR/share/${LOWERCASE_DIRNAME}/

cp COPYING $DESTDIR/share/
cp gtk2_ardour/icons/${PRODUCT_ICON} $DESTDIR/share/
cp gtk2_ardour/icons/ardour_bug.ico $DESTDIR/share/

# replace default cursor with square version (sans hotspot file)
cp gtk2_ardour/icons/cursor_square/* $DESTDIR/share/${LOWERCASE_DIRNAME}/icons/

# clean build-dir after depoyment
echo " === bundle completed, cleaning up"
./waf uninstall
echo " === complete"
du -sh $DESTDIR

################################################################################
### get video tools
if test -z "$NOVIDEOTOOLS"; then
	echo " === Including video-tools"
	HARVID_VERSION=$(curl -s -S http://ardour.org/files/video-tools/harvid_version.txt)
	XJADEO_VERSION=$(curl -s -S http://ardour.org/files/video-tools/xjadeo_version.txt)

	rsync -a -q --partial \
		rsync://ardour.org/video-tools/harvid_win-${HARVID_VERSION}.tar.xz \
		"${SRCCACHE}/harvid_win-${HARVID_VERSION}.tar.xz"

	rsync -a -q --partial \
		rsync://ardour.org/video-tools/xjadeo_win-${XJADEO_VERSION}.tar.xz \
		"${SRCCACHE}/xjadeo_win-${XJADEO_VERSION}.tar.xz"

	mkdir $DESTDIR/video
	tar -xf "${SRCCACHE}/harvid_win-${HARVID_VERSION}.tar.xz" -C "$DESTDIR/video/"
	tar -xf "${SRCCACHE}/xjadeo_win-${XJADEO_VERSION}.tar.xz" -C "$DESTDIR/video/"

	echo " === unzipped"
	du -sh $DESTDIR/video
	du -sh $DESTDIR
fi

################################################################################
### include static gdb - re-zipped binaries from
### http://sourceforge.net/projects/mingw/files/MinGW/Extension/gdb/gdb-7.6.1-1/gdb-7.6.1-1-mingw32-bin.tar.lzma
### 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
if ! grep " using ./waf configure" build/config.log | grep -q -- "--optimize"; then
	download gdb-static-win3264.tar.xz http://robin.linuxaudio.org/gdb-static-win3264.tar.xz
	cd ${SRCCACHE}
	tar xf gdb-static-win3264.tar.xz
	cd - > /dev/null

	echo " === Creating debug.bat"
	cp -r ${SRCCACHE}/gdb_$WARCH $DESTDIR/gdb
	cat > $DESTDIR/debug.bat << EOF
cd bin
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"
EOF
	OUTFILE="${TMPDIR}/${PRODUCT_NAME}-${ARDOURVERSION}-dbg-${WARCH}-Setup.exe"
	VERSIONINFO="Debug Version."
else
	OUTFILE="${TMPDIR}/${PRODUCT_NAME}-${ARDOURVERSION}-${WARCH}-Setup.exe"
	VERSIONINFO="Optimized Version."
fi

################################################################################
### Mixbus plugins, etc
if test x$WITH_X42_LV2 != x ; then
	mkdir -p $ALIBDIR/LV2

	echo "Adding x42 Plugins"

	for proj in x42-meters x42-midifilter x42-midimap x42-stereoroute x42-eq setBfree; do
		X42_VERSION=$(curl -s -S http://x42-plugins.com/x42/win/${proj}.latest.txt)
		rsync -a -q --partial \
			rsync://x42-plugins.com/x42/win/${proj}-lv2-${WARCH}-${X42_VERSION}.zip \
			"${SRCCACHE}/${proj}-lv2-${WARCH}-${X42_VERSION}.zip"
		unzip -q -d "$ALIBDIR/LV2/" "${SRCCACHE}/${proj}-lv2-${WARCH}-${X42_VERSION}.zip"
	done
fi

if test x$WITH_HARRISON_LV2 != x ; then
	mkdir -p $ALIBDIR/LV2

	echo "Including Harrison LV2s"

	curl -s -S --fail -# \
		-z "${SRCCACHE}/${HARRISONLV2}.${WARCH}.zip" \
		-o "${SRCCACHE}/${HARRISONLV2}.${WARCH}.zip" \
		"http://www.harrisonconsoles.com/mixbus/mb3/beta/harrison-dsp/${HARRISONLV2}.${WARCH}.zip"
	unzip -q -d "$ALIBDIR/LV2/" "${SRCCACHE}/${HARRISONLV2}.${WARCH}.zip"
fi

if test -n "$MIXBUS"; then
	echo "Deploying Harrison Mixbus Channelstrip"

	mkdir -p $ALIBDIR/ladspa/strip
	curl -s -S --fail -# \
		-z "${SRCCACHE}/${HARRISONCHANNELSTRIP}.${WARCH}.dll" \
		-o "${SRCCACHE}/${HARRISONCHANNELSTRIP}.${WARCH}.dll" \
		"http://www.harrisonconsoles.com/mixbus/mb3/beta/harrison-dsp/${HARRISONCHANNELSTRIP}.${WARCH}.dll"

	cp "${SRCCACHE}/${HARRISONCHANNELSTRIP}.${WARCH}.dll" \
		"$ALIBDIR/ladspa/strip/${HARRISONCHANNELSTRIP}.dll"

	echo "Deploying Harrison Vamp Plugins"
	mkdir -p $ALIBDIR/vamp
	curl -s -S --fail -# \
		-z "${SRCCACHE}/harrison_vamp.${WARCH}.dll" \
		-o "${SRCCACHE}/harrison_vamp.${WARCH}.dll" \
		"http://www.harrisonconsoles.com/mixbus/mb3/beta/harrison-dsp/harrison_vamp.${WARCH}.dll"

	cp "${SRCCACHE}/harrison_vamp.${WARCH}.dll" \
		"$ALIBDIR/vamp/harrison_vamp.dll"
fi

################################################################################

if test x$DEMO_SESSION_URL != x ; then
	mkdir -p $Shared/sessions
	DEMO_SESSIONS=$(curl -s -S --fail $DEMO_SESSION_URL/index.txt)
	for demo in $DEMO_SESSIONS; do
		curl -s -S --fail -# -o $Shared/sessions/$demo $DEMO_SESSION_URL/$demo
	done
fi

################################################################################

( cd $DESTDIR ; find . ) > ${TMPDIR}/file_list.txt

################################################################################
echo " === Preparing Windows Installer"
NSISFILE=$DESTDIR/a3.nsis

if test "$WARCH" = "w64"; then
	PGF=PROGRAMFILES64
	SFX=
else
	PGF=PROGRAMFILES
	# TODO we should only add this for 32bit on 64bit windows!
	SFX=" (x86)"
fi

if test -n "$QUICKZIP" ; then
	cat > $NSISFILE << EOF
SetCompressor zlib
EOF
else
	cat > $NSISFILE << EOF
SetCompressor /SOLID lzma
SetCompressorDictSize 32
EOF
fi

cat >> $NSISFILE << EOF
!addincludedir "${this_script_dir}\\nsis"
!include MUI2.nsh
!include FileAssociation.nsh
!include WinVer.nsh

Name "${PROGRAM_NAME}${PROGRAM_VERSION}"
OutFile "${OUTFILE}"
RequestExecutionLevel admin
InstallDir "\$${PGF}\\${PRODUCT_ID}"
InstallDirRegKey HKLM "Software\\${PRODUCT_NAME}\\${PRODUCT_ID}\\$WARCH" "Install_Dir"
!define MUI_ICON "share\\${PRODUCT_ICON}"

EOF

if test -n "$MIXBUS"; then

# TODO: proper welcome/finish text.
	cat >> $NSISFILE << EOF
!define MUI_FINISHPAGE_TITLE "Welcome to Harrison Mixbus"
!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."
!define MUI_FINISHPAGE_LINK "Mixbus Manual"
!define MUI_FINISHPAGE_LINK_LOCATION "http://www.harrisonconsoles.com/mixbus/mixbus3-live-manual"
!define MUI_FINISHPAGE_NOREBOOTSUPPORT
EOF

else

	cat >> $NSISFILE << EOF
!define MUI_FINISHPAGE_TITLE "Welcome to Ardour"
!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."
!define MUI_FINISHPAGE_LINK "Ardour on Windows"
!define MUI_FINISHPAGE_LINK_LOCATION "http://ardour.org/windows.html"
#this would run as admin - see http://forums.winamp.com/showthread.php?t=353366
#!define MUI_FINISHPAGE_RUN "\$INSTDIR\\bin\\${PRODUCT_EXE}"
!define MUI_FINISHPAGE_NOREBOOTSUPPORT
EOF

fi

cat >> $NSISFILE << EOF
!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_LICENSE "share\\COPYING"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

Section "${PROGRAM_NAME}${PROGRAM_VERSION} (required)" SecMainProg
  SectionIn RO
  SetOutPath \$INSTDIR
  File /r bin
  File /r lib
  File /r share
  File /nonfatal debug.bat
  File /nonfatal /r gdb
  WriteRegStr HKLM "Software\\${PROGRAM_KEY}\\v${major_version}\\$WARCH" "Install_Dir" "\$INSTDIR"
  WriteRegStr HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" "DisplayName" "${PROGRAM_NAME}${PROGRAM_VERSION}"
  WriteRegStr HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" "UninstallString" '"\$INSTDIR\\uninstall.exe"'
  WriteRegDWORD HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" "NoModify" 1
  WriteRegDWORD HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" "NoRepair" 1
  WriteUninstaller "\$INSTDIR\uninstall.exe"
  CreateShortCut "\$INSTDIR\\${PROGRAM_NAME}${PROGRAM_VERSION}.lnk" "\$INSTDIR\\bin\\${PRODUCT_EXE}" "" "\$INSTDIR\\bin\\${PRODUCT_EXE}" 0
  \${registerExtension} "\$INSTDIR\\bin\\${STATEFILE_SUFFIX}" ".${PRODUCT_NAME}" "${PROGRAM_NAME} Session"
SectionEnd

Section "WASAPI sound driver" SecWASAPI
SectionEnd
EOF

if test -z "$NOVIDEOTOOLS"; then

	cat >> $NSISFILE << EOF
Section "Videotimeline Tools" SecVideo
  WriteRegStr HKLM "Software\\${PROGRAM_KEY}\\v${major_version}\\video" "Install_Dir" "\$INSTDIR\\video"
  SetOutPath \$INSTDIR
  File /r video
SectionEnd
EOF

fi

cat >> $NSISFILE << EOF
Section "Start Menu Shortcuts" SecMenu
  SetShellVarContext all
  CreateDirectory "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}"
  CreateShortCut "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}\\${PROGRAM_NAME}${PROGRAM_VERSION}.lnk" "\$INSTDIR\\bin\\${PRODUCT_EXE}" "" "\$INSTDIR\\bin\\${PRODUCT_EXE}" 0
EOF

if test -f "$DESTDIR/debug.bat"; then
	cat >> $NSISFILE << EOF
  CreateShortCut "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}\\${PROGRAM_NAME}${PROGRAM_VERSION} GDB.lnk" "\$INSTDIR\\debug.bat" "" "\$INSTDIR\\share\\ardour_bug.ico" 0
EOF
fi

if test -z "$NOVIDEOTOOLS"; then
	cat >> $NSISFILE << EOF
  IfFileExists "\$INSTDIR\\video\\xjadeo\\xjadeo.exe" 0 +2
  CreateShortCut "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}\\Video Monitor.lnk" "\$INSTDIR\\video\\xjadeo\\xjadeo.exe" "" "\$INSTDIR\\video\\xjadeo\\xjadeo.exe" 0
EOF
fi

cat >> $NSISFILE << EOF
  CreateShortCut "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}\\Uninstall.lnk" "\$INSTDIR\\uninstall.exe" "" "\$INSTDIR\\uninstall.exe" 0
SectionEnd
LangString DESC_SecMainProg \${LANG_ENGLISH} "${PROGRAM_NAME} ${ARDOURVERSION}\$\\r\$\\n${VERSIONINFO}\$\\r\$\\n${ARDOURDATE}"
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."
EOF

if test -z "$NOVIDEOTOOLS"; then
	cat >> $NSISFILE << EOF
LangString DESC_SecVideo \${LANG_ENGLISH} "Video Tools\$\\r\$\\nxjadeo-${XJADEO_VERSION}\$\\r\$\\nharvid-${HARVID_VERSION}"
EOF
fi

cat >> $NSISFILE << EOF
LangString DESC_SecMenu \${LANG_ENGLISH} "Create Start-Menu Shortcuts (recommended)."
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT \${SecMainProg} \$(DESC_SecMainProg)
!insertmacro MUI_DESCRIPTION_TEXT \${SecWASAPI} \$(DESC_SecWASAPI)
EOF

if test -z "$NOVIDEOTOOLS"; then
	cat >> $NSISFILE << EOF
!insertmacro MUI_DESCRIPTION_TEXT \${SecVideo} \$(DESC_SecVideo)
EOF
fi

cat >> $NSISFILE << EOF
!insertmacro MUI_DESCRIPTION_TEXT \${SecMenu} \$(DESC_SecMenu)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
Section "Uninstall"
  SetShellVarContext all
  DeleteRegKey HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}"
  DeleteRegKey HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}"
  DeleteRegKey HKLM "Software\\${PROGRAM_KEY}\\v${major_version}"
  RMDir /r "\$INSTDIR\\bin"
  RMDir /r "\$INSTDIR\\lib"
  RMDir /r "\$INSTDIR\\share"
  RMDir /r "\$INSTDIR\\gdb"
  RMDir /r "\$INSTDIR\\video"
  Delete "\$INSTDIR\\debug.bat"
  Delete "\$INSTDIR\\uninstall.exe"
  Delete "\$INSTDIR\\${PROGRAM_NAME}${PROGRAM_VERSION}.lnk"
  RMDir "\$INSTDIR"
  Delete "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}\\*.*"
  RMDir "\$SMPROGRAMS\\${PRODUCT_ID}${SFX}"
  \${unregisterExtension} ".${STATEFILE_SUFFIX}" "${PROGRAM_NAME} Session"
SectionEnd


Function .onInit

  ReadRegStr \$R0 HKLM \
    "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" \
    "UninstallString"
  StrCmp \$R0 "" done

  MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
    "${PROGRAM_NAME} is already installed. Click 'OK' to remove the previous version or 'Cancel' to cancel this upgrade." \
    IDOK uninst
    Abort

  uninst:
    ClearErrors
    ExecWait '\$R0 _?=\$INSTDIR'
    IfErrors uninstall_error

    ReadRegStr \$R1 HKLM \
      "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\${PRODUCT_ID}-${WARCH}" \
      "UninstallString"
    StrCmp \$R1 "" 0 done

    Delete "\$INSTDIR\\uninstall.exe"
    RMDir "\$INSTDIR"
    goto done

  uninstall_error:

    MessageBox MB_OK|MB_ICONEXCLAMATION \
      "Uninstaller did not complete successfully. Continue at your own risk..." \
      IDOK done

  done:

  \${If} \${AtMostWinXP}
    SectionSetFlags \${SecWASAPI} \${SF_RO}
  \${Else}
    SectionSetFlags \${SecWASAPI} \${SF_SELECTED}
  \${EndIf}

FunctionEnd

Function .onInstSuccess

  \${If} \${AtMostWinXP}
    goto pa_no_wasapi
  \${EndIf}

  SectionGetFlags \${SecWASAPI} \$R0

  IntOp \$R0 \$R0 & \${SF_SELECTED}
  IntCmp \$R0 \${SF_SELECTED} pa_with_wasapi pa_no_wasapi

  pa_with_wasapi:
; VISTA .. 9, libportaudio with WASAPI is good.
  Delete "\$INSTDIR\\bin\\libportaudio-2.xp"
  goto endportaudio

; Windows XP lacks support for WASAPI, Windows10 on some system has issues
; http://tracker.ardour.org/view.php?id=6507
  pa_no_wasapi:
  Delete "\$INSTDIR\\bin\\libportaudio-2.dll"
  Rename "\$INSTDIR\\bin\\libportaudio-2.xp" "\$INSTDIR\\bin\\libportaudio-2.dll"

  endportaudio:

FunctionEnd
EOF

rm -f ${OUTFILE}
echo " === OutFile: $OUTFILE"

if test -n "$QUICKZIP" ; then
echo " === Building Windows Installer (fast zip)"
else
echo " === Building Windows Installer (lzma compression takes ages)"
fi
time makensis -V2 $NSISFILE
rm -rf $DESTDIR
ls -lgGh "$OUTFILE"