windows: automatically log gdb output
[ardour.git] / tools / x-win / package.sh
1 #!/bin/bash
2
3 # we assuem this script is <ardour-src>/tools/x-win/package
4 pushd "`/usr/bin/dirname \"$0\"`" > /dev/null; this_script_dir="`pwd`"; popd > /dev/null
5 cd $this_script_dir/../..
6 test -f gtk2_ardour/wscript || exit 1
7
8 : ${XARCH=i686} # or x86_64
9 : ${ROOT=/home/ardour}
10 : ${MAKEFLAGS=-j4}
11 : ${TMPDIR=/var/tmp}
12 : ${SRCDIR=/var/tmp/winsrc}  # source-code tgz cache
13
14 if test "$XARCH" = "x86_64" -o "$XARCH" = "amd64"; then
15         echo "Target: 64bit Windows (x86_64)"
16         XPREFIX=x86_64-w64-mingw32
17         WARCH=w64
18 else
19         echo "Target: 32 Windows (i686)"
20         XPREFIX=i686-w64-mingw32
21         WARCH=w32
22 fi
23
24 : ${PREFIX=${ROOT}/win-stack-$WARCH}
25 export SRCDIR
26
27 if [ "$(id -u)" = "0" ]; then
28         apt-get -y install nsis curl
29 fi
30
31
32 function download {
33 echo "--- Downloading.. $2"
34 test -f ${SRCDIR}/$1 || curl -k -L -o ${SRCDIR}/$1 $2
35 }
36
37 ################################################################################
38 set -e
39
40 ARDOURVERSION=$(git describe | sed 's/-g.*$//')
41 ARDOURDATE=$(date -R)
42 BINVERSION=$(git describe | sed 's/-g.*$//' | sed 's/-/./')
43 if ! test -f build/gtk2_ardour/ardour-${BINVERSION}.exe; then
44         echo "*** Please compile ardour ${ARDOURVERSION} first."
45         exit 1
46 fi
47 ./waf install
48
49 ################################################################################
50
51 if test -z "$DESTDIR"; then
52         DESTDIR=`mktemp -d`
53         trap 'rm -rf $DESTDIR' exit SIGINT SIGTERM
54 fi
55
56 echo " === bundle to $DESTDIR"
57
58 ALIBDIR=$DESTDIR/lib/ardour3
59
60 rm -rf $DESTDIR
61 mkdir -p $DESTDIR/bin
62 mkdir -p $DESTDIR/share/
63 mkdir -p $ALIBDIR/surfaces
64 mkdir -p $ALIBDIR/backends
65 mkdir -p $ALIBDIR/panners
66 mkdir -p $ALIBDIR/vamp
67
68 cp build/libs/gtkmm2ext/gtkmm2ext-*.dll $DESTDIR/bin/
69 cp build/libs/midi++2/midipp-*.dll $DESTDIR/bin/
70 cp build/libs/evoral/evoral-*.dll $DESTDIR/bin/
71 cp build/libs/ardour/ardour-*.dll $DESTDIR/bin/
72 cp build/libs/timecode/timecode.dll $DESTDIR/bin/
73 cp build/libs/qm-dsp/qmdsp-*.dll $DESTDIR/bin/
74 cp build/libs/canvas/canvas-*.dll $DESTDIR/bin/
75 cp build/libs/pbd/pbd-*.dll $DESTDIR/bin/
76 cp build/libs/audiographer/audiographer-*.dll $DESTDIR/bin/
77 cp build/libs/fst/ardour-vst-scanner.exe $DESTDIR/bin/ || true
78 cp `ls -t build/gtk2_ardour/ardour-*.exe | head -n1` $DESTDIR/bin/ardour.exe
79
80 mkdir -p $DESTDIR/lib/gtk-2.0/engines
81 cp build/libs/clearlooks-newer/clearlooks.dll $DESTDIR/lib/gtk-2.0/engines/libclearlooks.la
82
83 cp $PREFIX/bin/*dll $DESTDIR/bin/
84 cp $PREFIX/lib/*dll $DESTDIR/bin/
85 rm -rf $DESTDIR/bin/libjack*.dll
86
87 cp `find build/libs/surfaces/ -iname "*.dll"` $ALIBDIR/surfaces/
88 cp `find build/libs/backends/ -iname "*.dll"` $ALIBDIR/backends/
89 cp `find build/libs/panners/ -iname "*.dll"` $ALIBDIR/panners/
90
91 cp -r build/libs/LV2 $ALIBDIR/
92 cp -r build/libs/vamp-plugins/*ardourvampplugins*.dll $ALIBDIR/vamp/libardourvampplugins.dll
93
94 mv $ALIBDIR/surfaces/ardourcp-*.dll $DESTDIR/bin/
95
96 # TODO use -static-libgcc -static-libstdc++ -- but for .exe files only
97 if update-alternatives --query ${XPREFIX}-gcc | grep Value: | grep -q win32; then
98         cp /usr/lib/gcc/${XPREFIX}/*-win32/libgcc_s_*.dll $DESTDIR/bin/
99         cp /usr/lib/gcc/${XPREFIX}/*-win32/libstdc++-6.dll $DESTDIR/bin/
100 elif update-alternatives --query ${XPREFIX}-gcc | grep Value: | grep -q posix; then
101         cp /usr/lib/gcc/${XPREFIX}/*-posix/libgcc_s_*.dll $DESTDIR/bin/
102         cp /usr/lib/gcc/${XPREFIX}/*-posix/libstdc++-6.dll $DESTDIR/bin/
103 else
104         cp /usr/lib/gcc/${XPREFIX}/*/libgcc_s_sjlj-1.dll $DESTDIR/bin/
105         cp /usr/lib/gcc/${XPREFIX}/*/libstdc++-6.dll $DESTDIR/bin/
106 fi
107 #Ubuntu's 14.04's mingw needs this one for the std libs above
108 if test -f /usr/${XPREFIX}/lib/libwinpthread-1.dll; then
109         cp /usr/${XPREFIX}/lib/libwinpthread-1.dll $DESTDIR/bin/
110 fi
111
112 cp -r $PREFIX/share/ardour3 $DESTDIR/share/
113 cp -r $PREFIX/etc/ardour3/* $DESTDIR/share/ardour3/
114
115 cp COPYING $DESTDIR/share/
116 cp gtk2_ardour/icons/ardour.ico $DESTDIR/share/
117 cp gtk2_ardour/icons/ardour_bug.ico $DESTDIR/share/
118
119 # replace default cursor with square version (sans hotspot file)
120 cp gtk2_ardour/icons/cursor_square/* $DESTDIR/share/ardour3/icons/
121
122 # clean build-dir after depoyment
123 ./waf uninstall
124 echo " === complete"
125 du -sh $DESTDIR
126
127 ################################################################################
128 ### get video tools
129 if test -z "$NOVIDEOTOOLS"; then
130         echo " === Including video-tools"
131         HARVID_VERSION=$(curl -s -S http://ardour.org/files/video-tools/harvid_version.txt)
132         XJADEO_VERSION=$(curl -s -S http://ardour.org/files/video-tools/xjadeo_version.txt)
133
134         rsync -a -q --partial \
135                 rsync://ardour.org/video-tools/harvid_win-${HARVID_VERSION}.tar.xz \
136                 "${SRCDIR}/harvid_win-${HARVID_VERSION}.tar.xz"
137
138         rsync -a -q --partial \
139                 rsync://ardour.org/video-tools/xjadeo_win-${XJADEO_VERSION}.tar.xz \
140                 "${SRCDIR}/xjadeo_win-${XJADEO_VERSION}.tar.xz"
141
142         mkdir $DESTDIR/video
143         tar -xf "${SRCDIR}/harvid_win-${HARVID_VERSION}.tar.xz" -C "$DESTDIR/video/"
144         tar -xf "${SRCDIR}/xjadeo_win-${XJADEO_VERSION}.tar.xz" -C "$DESTDIR/video/"
145
146         echo " === unzipped"
147         du -sh $DESTDIR/video
148         du -sh $DESTDIR
149 fi
150
151 ################################################################################
152 ### include static gdb - re-zipped binaries from
153 ### http://sourceforge.net/projects/mingw/files/MinGW/Extension/gdb/gdb-7.6.1-1/gdb-7.6.1-1-mingw32-bin.tar.lzma
154 ### 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
155 if ! grep " using ./waf configure" build/config.log | grep -q -- "--optimize"; then
156         download gdb-static-win3264.tar.xz http://robin.linuxaudio.org/gdb-static-win3264.tar.xz
157         cd ${SRCDIR}
158         tar xf gdb-static-win3264.tar.xz
159         cd - > /dev/null
160
161         echo " === Creating ardbg.bat"
162         cp -r ${SRCDIR}/gdb_$WARCH $DESTDIR/gdb
163         cat > $DESTDIR/ardbg.bat << EOF
164 cd bin
165 START ..\\gdb\\bin\\gdb.exe -iex "set logging overwrite on" -iex "set height 0" -iex "set logging on %UserProfile%\\ardour-debug.log" ardour.exe
166 EOF
167         OUTFILE="${TMPDIR}/ardour-${ARDOURVERSION}-dbg-${WARCH}-Setup.exe"
168         VERSIONINFO="Debug Version."
169 else
170         OUTFILE="${TMPDIR}/ardour-${ARDOURVERSION}-${WARCH}-Setup.exe"
171         VERSIONINFO="Optimized Version."
172 fi
173
174 ################################################################################
175 echo " === Preparing Windows Installer"
176 NSISFILE=$DESTDIR/a3.nsis
177
178 if test "$WARCH" = "w64"; then
179         PGF=PROGRAMFILES64
180 else
181         PGF=PROGRAMFILES
182 fi
183
184 if test -n "$QUICKZIP" ; then
185         cat > $NSISFILE << EOF
186 SetCompressor zlib
187 EOF
188 else
189         cat > $NSISFILE << EOF
190 SetCompressor /SOLID lzma
191 SetCompressorDictSize 32
192 EOF
193 fi
194
195 cat >> $NSISFILE << EOF
196 !include MUI2.nsh
197 Name "Ardour3"
198 OutFile "${OUTFILE}"
199 RequestExecutionLevel admin
200 InstallDir "\$${PGF}\\ardour3"
201 InstallDirRegKey HKLM "Software\\Ardour\\ardour3\\$WARCH" "Install_Dir"
202
203 !define MUI_ICON "share\\ardour.ico"
204 !define MUI_FINISHPAGE_TITLE "Welcome to Ardour"
205 !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."
206 !define MUI_FINISHPAGE_LINK "Ardour Manual"
207 !define MUI_FINISHPAGE_LINK_LOCATION "http://manual.ardour.org"
208 #this would run as admin - see http://forums.winamp.com/showthread.php?t=353366
209 #!define MUI_FINISHPAGE_RUN "\$INSTDIR\\bin\\ardour.exe"
210 !define MUI_FINISHPAGE_NOREBOOTSUPPORT
211
212 !define MUI_ABORTWARNING
213 !insertmacro MUI_PAGE_LICENSE "share\\COPYING"
214 !insertmacro MUI_PAGE_COMPONENTS
215 !insertmacro MUI_PAGE_DIRECTORY
216 !insertmacro MUI_PAGE_INSTFILES
217 !insertmacro MUI_PAGE_FINISH
218 !insertmacro MUI_UNPAGE_CONFIRM
219 !insertmacro MUI_UNPAGE_INSTFILES
220 !insertmacro MUI_LANGUAGE "English"
221
222 Section "Ardour3 (required)" SecArdour
223   SectionIn RO
224   SetOutPath \$INSTDIR
225   File /r bin
226   File /r lib
227   File /r share
228   File /nonfatal ardbg.bat
229   File /nonfatal /r gdb
230   WriteRegStr HKLM SOFTWARE\\Ardour\\ardour3\\$WARCH "Install_Dir" "\$INSTDIR"
231   WriteRegStr HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ardour3" "DisplayName" "Ardour3"
232   WriteRegStr HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ardour3" "UninstallString" '"\$INSTDIR\\uninstall.exe"'
233   WriteRegDWORD HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ardour3" "NoModify" 1
234   WriteRegDWORD HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ardour3" "NoRepair" 1
235   WriteUninstaller "\$INSTDIR\uninstall.exe"
236   CreateShortCut "\$INSTDIR\\Ardour3.lnk" "\$INSTDIR\\bin\\ardour.exe" "" "\$INSTDIR\\bin\\ardour.exe" 0
237 SectionEnd
238 EOF
239
240 if test -z "$NOVIDEOTOOLS"; then
241
242         cat >> $NSISFILE << EOF
243 Section "Videotimeline Tools" SecVideo
244   WriteRegStr HKLM SOFTWARE\\Ardour\\video "Install_Dir" "\$INSTDIR\\video"
245   SetOutPath \$INSTDIR
246   File /r video
247 SectionEnd
248 EOF
249
250 fi
251
252 cat >> $NSISFILE << EOF
253 Section "Start Menu Shortcuts" SecMenu
254   SetShellVarContext all
255   CreateDirectory "\$SMPROGRAMS\\ardour3"
256   CreateShortCut "\$SMPROGRAMS\\ardour3\\Ardour3.lnk" "\$INSTDIR\\bin\\ardour.exe" "" "\$INSTDIR\\bin\\ardour.exe" 0
257 EOF
258
259 if test -f "$DESTDIR/ardbg.bat"; then
260         cat >> $NSISFILE << EOF
261   CreateShortCut "\$SMPROGRAMS\\ardour3\\Ardour3 GDB.lnk" "\$INSTDIR\\ardbg.bat" "" "\$INSTDIR\\share\\ardour_bug.ico" 0
262 EOF
263 fi
264
265 if test -z "$NOVIDEOTOOLS"; then
266         cat >> $NSISFILE << EOF
267         IfFileExists "\$INSTDIR\\video\\xjadeo\\xjadeo.exe" 0 +2
268   CreateShortCut "\$SMPROGRAMS\\ardour3\\Video Monitor.lnk" "\$INSTDIR\\video\\xjadeo\\xjadeo.exe" "" "\$INSTDIR\\video\\xjadeo\\xjadeo.exe" 0
269 EOF
270 fi
271
272 cat >> $NSISFILE << EOF
273   CreateShortCut "\$SMPROGRAMS\\ardour3\\Uninstall.lnk" "\$INSTDIR\\uninstall.exe" "" "\$INSTDIR\\uninstall.exe" 0
274 SectionEnd
275 LangString DESC_SecArdour \${LANG_ENGLISH} "Ardour ${ARDOURVERSION}\$\\r\$\\n${VERSIONINFO}\$\\r\$\\n${ARDOURDATE}"
276 EOF
277
278 if test -z "$NOVIDEOTOOLS"; then
279         cat >> $NSISFILE << EOF
280 LangString DESC_SecVideo \${LANG_ENGLISH} "Video Tools\$\\r\$\\nxjadeo-${XJADEO_VERSION}\$\\r\$\\nharvid-${HARVID_VERSION}"
281 EOF
282 fi
283
284 cat >> $NSISFILE << EOF
285 LangString DESC_SecMenu \${LANG_ENGLISH} "Create Start-Menu Shortcuts (recommended)."
286 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
287 !insertmacro MUI_DESCRIPTION_TEXT \${SecArdour} \$(DESC_SecArdour)
288 EOF
289
290 if test -z "$NOVIDEOTOOLS"; then
291         cat >> $NSISFILE << EOF
292 !insertmacro MUI_DESCRIPTION_TEXT \${SecVideo} \$(DESC_SecVideo)
293 EOF
294 fi
295
296 cat >> $NSISFILE << EOF
297 !insertmacro MUI_DESCRIPTION_TEXT \${SecMenu} \$(DESC_SecMenu)
298 !insertmacro MUI_FUNCTION_DESCRIPTION_END
299 Section "Uninstall"
300   SetShellVarContext all
301   DeleteRegKey HKLM "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ardour"
302   DeleteRegKey HKLM SOFTWARE\\Ardour\\ardour3
303   RMDir /r "\$INSTDIR\\bin"
304   RMDir /r "\$INSTDIR\\lib"
305   RMDir /r "\$INSTDIR\\share"
306   RMDir /r "\$INSTDIR\\gdb"
307   RMDir /r "\$INSTDIR\\video"
308   Delete "\$INSTDIR\\ardbg.bat"
309   Delete "\$INSTDIR\\uninstall.exe"
310   Delete "\$INSTDIR\\Ardour3.lnk"
311   RMDir "\$INSTDIR"
312   Delete "\$SMPROGRAMS\\ardour3\\*.*"
313   RMDir "\$SMPROGRAMS\\ardour3"
314 SectionEnd
315 EOF
316
317 rm -f ${OUTFILE}
318 echo " === OutFile: $OUTFILE"
319
320 if test -n "$QUICKZIP" ; then
321 echo " === Building Windows Installer (fast zip)"
322 else
323 echo " === Building Windows Installer (lzma compression takes ages)"
324 fi
325 time makensis -V2 $NSISFILE
326 rm -rf $DESTDIR
327 ls -lh "$OUTFILE"