chiark / gitweb /
Fix pyserial 3.0 compatibility issue
[cura.git] / package.sh
1 #!/usr/bin/env bash
2
3 set -e
4 set -u
5
6 # This script is to package the Cura package for Windows/Linux and Mac OS X
7 # This script should run under Linux and Mac OS X, as well as Windows with Cygwin.
8
9 #############################
10 # CONFIGURATION
11 #############################
12
13 ##Select the build target
14 BUILD_TARGET=${1:-none}
15 #BUILD_TARGET=win32
16 #BUILD_TARGET=darwin
17 #BUILD_TARGET=debian_i386
18 #BUILD_TARGET=debian_amd64
19 #BUILD_TARGET=debian_armhf
20 #BUILD_TARGET=freebsd
21
22 ##Do we need to create the final archive
23 ARCHIVE_FOR_DISTRIBUTION=1
24 ##Which version name are we appending to the final archive
25
26
27 ##Version
28 version_file="./Cura/version"
29 while IFS= read -r line
30 do
31     export BUILD_VERSION="$line"
32 done <"$version_file"
33 TARGET_DIR=Cura-${BUILD_VERSION}-${BUILD_TARGET}
34
35 ##Git commit
36 GIT_HASH=$(git rev-parse --short=4 HEAD)
37
38 export FULL_VERSION=${BUILD_VERSION}-${GIT_HASH}
39
40 ##Which versions of external programs to use
41 WIN_PORTABLE_PY_VERSION=2.7.2.1
42
43 ##Which CuraEngine to use
44 if [ -z ${CURA_ENGINE_REPO:-} ] ; then
45         CURA_ENGINE_REPO="https://code.alephobjects.com/diffusion/CE/curaengine.git"
46 fi
47
48 #############################
49 # Support functions
50 #############################
51 function checkTool
52 {
53         if [ -z "`which $1`" ]; then
54                 echo "The $1 command must be somewhere in your \$PATH."
55                 echo "Fix your \$PATH or install $2"
56                 exit 1
57         fi
58 }
59
60 function downloadURL
61 {
62         filename=`basename "$1"`
63         echo "Checking for $filename"
64         if [ ! -f "$filename" ]; then
65                 echo "Downloading $1"
66                 curl -L -O "$1"
67                 if [ $? != 0 ]; then
68                         echo "Failed to download $1"
69                         exit 1
70                 fi
71         fi
72 }
73
74 function extract
75 {
76         echo "Extracting $*"
77         echo "7z x -y $*" >> log.txt
78         7z x -y $* >> log.txt
79         if [ $? != 0 ]; then
80         echo "Failed to extract $*"
81         exit 1
82         fi
83 }
84
85 function gitClone
86 {
87         echo "Cloning $1 into $2"
88         if [ -d $2 ]; then
89                 cd $2
90                 git clean -dfx
91                 git reset --hard
92                 git pull
93                 cd -
94         else
95                 git clone $1 $2
96         fi
97 }
98
99 #############################
100 # Actual build script
101 #############################
102 if [ "$BUILD_TARGET" = "none" ]; then
103         echo "You need to specify a build target with:"
104         echo "$0 win32"
105         echo "$0 debian_i386"
106         echo "$0 debian_amd64"
107         echo "$0 debian_armhf"
108         echo "$0 darwin"
109         echo "$0 freebsd"
110         echo "$0 fedora                         # current   system"
111         echo "$0 fedora \"mock_config_file\" ...  # different system(s)"
112         exit 0
113 fi
114
115 if [ -z `which make` ]; then
116         MAKE=mingw32-make
117 else
118         MAKE=make
119 fi
120
121 # Change working directory to the directory the script is in
122 # http://stackoverflow.com/a/246128
123 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
124 cd "$SCRIPT_DIR"
125
126 checkTool git "git: http://git-scm.com/"
127 checkTool curl "curl: http://curl.haxx.se/"
128 if [ $BUILD_TARGET = "win32" ]; then
129         checkTool avr-gcc "avr-gcc: http://winavr.sourceforge.net/ "
130         #Check if we have 7zip, needed to extract and packup a bunch of packages for windows.
131         checkTool 7z "7zip: http://www.7-zip.org/"
132         checkTool $MAKE "mingw: http://www.mingw.org/"
133 fi
134 #For building under MacOS we need gnutar instead of tar
135 if [ -z `which gnutar` ]; then
136         TAR=tar
137 else
138         TAR=gnutar
139 fi
140
141 #############################
142 # Build the required firmwares
143 #############################
144
145 gitClone "https://github.com/Ultimaker/cura-binary-data" _cura_binary_data
146
147 cp -v _cura_binary_data/cura/resources/firmware/* resources/firmware/
148
149 #############################
150 # Darwin
151 #############################
152
153 if [ "$BUILD_TARGET" = "darwin" ]; then
154     TARGET_DIR=Cura-${BUILD_VERSION}-MacOS
155
156         rm -rf scripts/darwin/build
157         rm -rf scripts/darwin/dist
158
159         python build_app.py py2app
160         rc=$?
161         if [[ $rc != 0 ]]; then
162                 echo "Cannot build app."
163                 exit 1
164         fi
165
166     #Add cura version file (should read the version from the bundle with pyobjc, but will figure that out later)
167     echo $BUILD_VERSION > scripts/darwin/dist/Cura.app/Contents/Resources/version
168         rm -rf CuraEngine
169         gitClone ${CURA_ENGINE_REPO} CuraEngine
170     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
171         $MAKE -C CuraEngine VERSION=${BUILD_VERSION}
172     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
173         cp CuraEngine/build/CuraEngine scripts/darwin/dist/Cura.app/Contents/Resources/CuraEngine
174
175         cd scripts/darwin
176
177         # Install QuickLook plugin
178         mkdir -p dist/Cura.app/Contents/Library/QuickLook
179         cp -a STLQuickLook.qlgenerator dist/Cura.app/Contents/Library/QuickLook/
180
181         # Archive app
182         cd dist
183         $TAR cfp - Cura.app | gzip --best -c > ../../../${TARGET_DIR}.tar.gz
184         cd ..
185
186         # Create sparse image for distribution
187         hdiutil detach /Volumes/Cura\ -\ Lulzbot/ || true
188         rm -rf Cura.dmg.sparseimage
189         hdiutil convert DmgTemplateCompressed.dmg -format UDSP -o Cura.dmg
190         hdiutil resize -size 500m Cura.dmg.sparseimage
191         hdiutil attach Cura.dmg.sparseimage
192         cp -a dist/Cura.app /Volumes/Cura\ -\ Lulzbot/Cura/
193         hdiutil detach /Volumes/Cura\ -\ Lulzbot
194         hdiutil convert Cura.dmg.sparseimage -format UDZO -imagekey zlib-level=9 -ov -o ../../${TARGET_DIR}.dmg
195         exit
196 fi
197
198 #############################
199 # FreeBSD part by CeDeROM
200 #############################
201
202 if [ "$BUILD_TARGET" = "freebsd" ]; then
203         export CXX="c++"
204         gitClone https://github.com/GreatFruitOmsk/Power Power
205         gitClone ${CURA_ENGINE_REPO} CuraEngine
206     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
207         gmake -j4 -C CuraEngine VERSION=${BUILD_VERSION}
208     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
209         rm -rf scripts/freebsd/dist
210         mkdir -p scripts/freebsd/dist/share/cura
211         mkdir -p scripts/freebsd/dist/share/applications
212         mkdir -p scripts/freebsd/dist/bin
213         cp -a Cura scripts/freebsd/dist/share/cura/
214         cp -a resources scripts/freebsd/dist/share/cura/
215         cp -a plugins scripts/freebsd/dist/share/cura/
216         cp -a CuraEngine/build/CuraEngine scripts/freebsd/dist/share/cura/
217         cp scripts/freebsd/cura.py scripts/freebsd/dist/share/cura/
218         cp scripts/freebsd/cura.desktop scripts/freebsd/dist/share/applications/
219         cp scripts/freebsd/cura scripts/freebsd/dist/bin/
220         cp -a Power/power scripts/freebsd/dist/share/cura/
221         echo $BUILD_VERSION > scripts/freebsd/dist/share/cura/Cura/version
222         #Create file list (pkg-plist)
223         cd scripts/freebsd/dist
224         find * -type f > ../pkg-plist
225         DIRLVL=20; while [ $DIRLVL -ge 0 ]; do
226                 DIRS=`find share/cura -type d -depth $DIRLVL`
227                 for DIR in $DIRS; do
228                         echo "@dirrm $DIR" >> ../pkg-plist
229                 done
230                 DIRLVL=`expr $DIRLVL - 1`
231         done
232         cd ..
233         # Create archive or package if root
234         if [ `whoami` == "root" ]; then
235             echo "Are you root? Use the Port Luke! :-)"
236         else
237             echo "You are not root, building simple package archive..."
238             pwd
239             $TAR czf ../../${TARGET_DIR}.tar.gz dist/**
240         fi
241         exit
242 fi
243
244 #############################
245 # Debian 32bit .deb
246 #############################
247
248 if [ "$BUILD_TARGET" = "debian_i386" ]; then
249     export CXX="g++ -m32"
250         gitClone https://github.com/GreatFruitOmsk/Power Power
251         gitClone ${CURA_ENGINE_REPO} CuraEngine
252     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
253         $MAKE -C CuraEngine VERSION=${BUILD_VERSION}
254     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
255         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
256         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
257         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
258         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
259         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
260         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
261         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
262         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
263         echo $BUILD_VERSION > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
264         cat scripts/linux/debian_control | sed "s/\[BUILD_VERSION\]/${FULL_VERSION}/" | sed 's/\[ARCH\]/i386/' > scripts/linux/${BUILD_TARGET}/DEBIAN/control
265         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
266         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
267         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
268         cd scripts/linux
269         dpkg-deb -Zgzip --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${FULL_VERSION}_i386.deb
270         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
271         exit
272 fi
273
274 #############################
275 # Debian 64bit .deb
276 #############################
277
278 if [ "$BUILD_TARGET" = "debian_amd64" ]; then
279     export CXX="g++ -m64"
280         gitClone https://github.com/GreatFruitOmsk/Power Power
281         gitClone ${CURA_ENGINE_REPO} CuraEngine
282     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
283         $MAKE -C CuraEngine VERSION=${BUILD_VERSION}
284     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
285         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
286         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
287         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
288         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
289         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
290         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
291         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
292         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
293         echo $BUILD_VERSION > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
294         cat scripts/linux/debian_control | sed "s/\[BUILD_VERSION\]/${FULL_VERSION}/" | sed 's/\[ARCH\]/amd64/' > scripts/linux/${BUILD_TARGET}/DEBIAN/control
295         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
296         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
297         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
298         cd scripts/linux
299         dpkg-deb -Zgzip --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${FULL_VERSION}_amd64.deb
300         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
301         exit
302 fi
303
304 #############################
305 # Debian armhf .deb
306 #############################
307
308 if [ "$BUILD_TARGET" = "debian_armhf" ]; then
309     export CXX="g++"
310         gitClone https://github.com/GreatFruitOmsk/Power Power
311         gitClone ${CURA_ENGINE_REPO} CuraEngine
312     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
313         $MAKE -C CuraEngine VERSION=${BUILD_VERSION}
314     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
315         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
316         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
317         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
318         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
319         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
320         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
321         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
322         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
323         echo $BUILD_VERSION > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
324         cat scripts/linux/debian_control | sed "s/\[BUILD_VERSION\]/${FULL_VERSION}/" | sed 's/\[ARCH\]/armhf/' > scripts/linux/${BUILD_TARGET}/DEBIAN/control
325         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
326         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
327         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
328         cd scripts/linux
329         dpkg-deb --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_VERSION}-${BUILD_TARGET}.deb
330         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
331         exit
332 fi
333
334 #############################
335 # Fedora Generic
336 #############################
337
338 function sanitiseVersion() {
339   local _version="$1"
340   echo "${_version//-/.}"
341 }
342
343 function fedoraCreateSRPM() {
344   local _curaName="$1"
345   local _version="$(sanitiseVersion "$2")"
346   local _srcSpecFile="$3"
347   local _srcSpecFileRelease="$4"
348   local _dstSrpmDir="$5"
349
350   local _dstTarSources="$HOME/rpmbuild/SOURCES/$_curaName-$_version.tar.gz"
351   local _dstSpec="$HOME/rpmbuild/SPECS/$_curaName-$_version.spec"
352
353   local _namePower="Power"
354   local _nameCuraEngine="CuraEngine"
355
356   gitClone "https://github.com/GreatFruitOmsk/Power" "$_namePower"
357   gitClone "$CURA_ENGINE_REPO" "$_nameCuraEngine"
358
359   cd "$_namePower"
360   local _gitPower="$(git rev-list -1 HEAD)"
361   cd -
362
363   cd "$_nameCuraEngine"
364   local _gitCuraEngine="$(git rev-list -1 HEAD)"
365   cd -
366
367   local _gitCura="$(git rev-list -1 HEAD)"
368
369   rpmdev-setuptree
370
371   rm -fv "$_dstTarSources"
372   tar \
373     --exclude-vcs \
374     --transform "s#^#$_curaName-$_version/#" \
375     -zcvf "$_dstTarSources" \
376       "$_nameCuraEngine" \
377       "$_namePower" \
378       Cura \
379       resources \
380       plugins \
381       scripts/linux/cura.py \
382       scripts/linux/fedora/usr
383
384   sed \
385     -e "s#__curaName__#$_curaName#" \
386     -e "s#__version__#$_version#" \
387     -e "s#__gitCura__#$_gitCura#" \
388     -e "s#__gitCuraEngine__#$_gitCuraEngine#" \
389     -e "s#__gitPower__#$_gitPower#" \
390     -e "s#__basedir__#scripts/linux/fedora#" \
391     "$_srcSpecFile" \
392     > "$_dstSpec"
393
394   rpmbuild -bs "$_dstSpec"
395
396   mkdir -pv "$_dstSrpmDir"
397   cp -v \
398     "$HOME/rpmbuild/SRPMS/$_curaName-$_version-$_srcSpecFileRelease.src.rpm" \
399     "$_dstSrpmDir"
400 }
401
402 function buildFedora() {
403   local _nameForRpm="Cura"
404   local _versionForRpm="$(sanitiseVersion "$BUILD_VERSION")"
405
406   #
407   # SRPM
408   #
409
410   local _srcSpecFile="scripts/linux/fedora/rpm.spec"
411   local _srcSpecFileRelease="$(rpmspec -P "$_srcSpecFile" | grep -E '^Release:'|awk '{print $NF}')"
412   local _dstSrpmDir="scripts/linux/fedora/SRPMS"
413
414   fedoraCreateSRPM \
415     "$_nameForRpm" \
416     "$_versionForRpm" \
417     "$_srcSpecFile" \
418     "$_srcSpecFileRelease" \
419     "$_dstSrpmDir"
420
421   #
422   # RPM
423   #
424
425   local _srpmFile="$_dstSrpmDir/$_nameForRpm-$_versionForRpm-$_srcSpecFileRelease.src.rpm"
426   local _dstRpmDir="scripts/linux/fedora/RPMS"
427
428   while [ $# -ne 0 ]; do
429     local _mockRelease="$(basename "${1%\.cfg}")"
430     local _mockReleaseArg=""
431     if [ -n "$_mockRelease" ]; then
432       _mockReleaseArg="-r $_mockRelease"
433     fi
434
435     mkdir -pv "$_dstRpmDir/$_mockRelease"
436     mock \
437       $_mockReleaseArg \
438       --resultdir="$_dstRpmDir/$_mockRelease" \
439       "$_srpmFile"
440
441     shift 1
442   done
443 }
444
445 #############################
446 # Fedora RPMs
447 #############################
448
449 if [ "$BUILD_TARGET" = "fedora" ]; then
450   shift 1 # skip "fedora" arg
451
452   if [ $# -eq 0 ]; then
453     "$0" "$BUILD_TARGET" ""
454   else
455     buildFedora "${@}"
456   fi
457
458   exit
459 fi
460
461 #############################
462 # Rest
463 #############################
464
465 #############################
466 # Download all needed files.
467 #############################
468
469 if [ $BUILD_TARGET = "win32" ]; then
470         #Get portable python for windows and extract it. (Linux and Mac need to install python themselfs)
471         downloadURL http://ftp.nluug.nl/languages/python/portablepython/v2.7/PortablePython_${WIN_PORTABLE_PY_VERSION}.exe
472         downloadURL http://sourceforge.net/projects/pyserial/files/pyserial/2.5/pyserial-2.5.win32.exe
473         downloadURL http://sourceforge.net/projects/pyopengl/files/PyOpenGL/3.0.1/PyOpenGL-3.0.1.win32.exe
474         downloadURL http://sourceforge.net/projects/numpy/files/NumPy/1.6.2/numpy-1.6.2-win32-superpack-python2.7.exe
475         downloadURL http://videocapture.sourceforge.net/VideoCapture-0.9-5.zip
476         #downloadURL http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20120927-git-13f0cd6-win32-static.7z
477         downloadURL http://sourceforge.net/projects/comtypes/files/comtypes/0.6.2/comtypes-0.6.2.win32.exe
478         downloadURL http://www.uwe-sieber.de/files/ejectmedia.zip
479         #Get the power module for python
480         gitClone https://github.com/GreatFruitOmsk/Power Power
481     if [ $? != 0 ]; then echo "Failed to clone Power"; exit 1; fi
482         gitClone ${CURA_ENGINE_REPO} CuraEngine
483     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
484 fi
485
486 #############################
487 # Build the packages
488 #############################
489 rm -rf ${TARGET_DIR}
490 mkdir -p ${TARGET_DIR}
491
492 rm -f log.txt
493 if [ $BUILD_TARGET = "win32" ]; then
494         if [ -z `which i686-w64-mingw32-g++` ]; then
495                 CXX=g++
496         else
497                 CXX=i686-w64-mingw32-g++
498         fi
499         
500         #For windows extract portable python to include it.
501         extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/App
502         extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/Lib/site-packages
503         extract pyserial-2.5.win32.exe PURELIB
504         extract PyOpenGL-3.0.1.win32.exe PURELIB
505         extract numpy-1.6.2-win32-superpack-python2.7.exe numpy-1.6.2-sse2.exe
506         extract numpy-1.6.2-sse2.exe PLATLIB
507         extract VideoCapture-0.9-5.zip VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd
508         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe
509         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/licenses
510         extract comtypes-0.6.2.win32.exe
511         extract ejectmedia.zip Win32
512
513         mkdir -p ${TARGET_DIR}/python
514         mkdir -p ${TARGET_DIR}/Cura/
515         mv \$_OUTDIR/App/* ${TARGET_DIR}/python
516         mv \$_OUTDIR/Lib/site-packages/wx* ${TARGET_DIR}/python/Lib/site-packages/
517         mv PURELIB/serial ${TARGET_DIR}/python/Lib
518         mv PURELIB/OpenGL ${TARGET_DIR}/python/Lib
519         mv PURELIB/comtypes ${TARGET_DIR}/python/Lib
520         mv PLATLIB/numpy ${TARGET_DIR}/python/Lib
521         mv Power/power ${TARGET_DIR}/python/Lib
522         mv VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd ${TARGET_DIR}/python/DLLs
523         #mv ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe ${TARGET_DIR}/Cura/
524         #mv ffmpeg-20120927-git-13f0cd6-win32-static/licenses ${TARGET_DIR}/Cura/ffmpeg-licenses/
525         mv Win32/EjectMedia.exe ${TARGET_DIR}/Cura/
526         cp -a scripts/win32/nsisPlugins/libgcc_s_dw2-1.dll ${TARGET_DIR}
527         cp -a scripts/win32/nsisPlugins/libstdc++-6.dll ${TARGET_DIR}
528         
529         rm -rf Power/
530         rm -rf \$_OUTDIR
531         rm -rf PURELIB
532         rm -rf PLATLIB
533         rm -rf VideoCapture-0.9-5
534         rm -rf numpy-1.6.2-sse2.exe
535         #rm -rf ffmpeg-20120927-git-13f0cd6-win32-static
536
537         #Clean up portable python a bit, to keep the package size down.
538         rm -rf ${TARGET_DIR}/python/PyScripter.*
539         rm -rf ${TARGET_DIR}/python/Doc
540         rm -rf ${TARGET_DIR}/python/locale
541         rm -rf ${TARGET_DIR}/python/tcl
542         rm -rf ${TARGET_DIR}/python/Lib/test
543         rm -rf ${TARGET_DIR}/python/Lib/distutils
544         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/tools
545         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/locale
546         #Remove the gle files because they require MSVCR71.dll, which is not included. We also don't need gle, so it's safe to remove it.
547         rm -rf ${TARGET_DIR}/python/Lib/OpenGL/DLLS/gle*
548
549     #Build the C++ engine
550         $MAKE -C CuraEngine VERSION=${BUILD_VERSION} OS=Windows_NT CXX=${CXX}
551     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
552 fi
553
554 #add Cura
555 mkdir -p ${TARGET_DIR}/Cura ${TARGET_DIR}/resources ${TARGET_DIR}/plugins
556 cp -a Cura/* ${TARGET_DIR}/Cura
557 cp -a resources/* ${TARGET_DIR}/resources
558 cp -a plugins/* ${TARGET_DIR}/plugins
559 #Add cura version file
560 echo $BUILD_VERSION > ${TARGET_DIR}/Cura/version
561
562 #add script files
563 if [ $BUILD_TARGET = "win32" ]; then
564     cp -a scripts/${BUILD_TARGET}/*.bat $TARGET_DIR/
565     cp CuraEngine/build/CuraEngine.exe $TARGET_DIR
566         cp /usr/lib/gcc/i686-w64-mingw32/4.8/libgcc_s_sjlj-1.dll $TARGET_DIR
567     cp /usr/i686-w64-mingw32/lib/libwinpthread-1.dll $TARGET_DIR
568     cp /usr/lib/gcc/i686-w64-mingw32/4.8/libstdc++-6.dll $TARGET_DIR
569 fi
570
571 #package the result
572 if (( ${ARCHIVE_FOR_DISTRIBUTION} )); then
573         if [ $BUILD_TARGET = "win32" ]; then
574                 #rm ${TARGET_DIR}.zip
575                 #cd ${TARGET_DIR}
576                 #7z a ../${TARGET_DIR}.zip *
577                 #cd ..
578
579                 if [ ! -z `which wine` ]; then
580                         #if we have wine, try to run our nsis script.
581                         rm -rf scripts/win32/dist
582                         ln -sf `pwd`/${TARGET_DIR} scripts/win32/dist
583                         wine ~/.wine/drive_c/Program\ Files\ \(x86\)/NSIS/makensis.exe /DVERSION=${BUILD_VERSION} scripts/win32/installer.nsi
584             if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
585                         mv scripts/win32/Cura_${FULL_VERSION}.exe ./
586                 fi
587                 if [ -f '/c/Program Files (x86)/NSIS/makensis.exe' ]; then
588                         rm -rf scripts/win32/dist
589                         mv "`pwd`/${TARGET_DIR}" scripts/win32/dist
590                         '/c/Program Files (x86)/NSIS/makensis.exe' -DVERSION=${BUILD_VERSION} 'scripts/win32/installer.nsi' >> log.txt
591             if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
592                         mv scripts/win32/Cura_${BUILD_VERSION}.exe ./
593                 fi
594         else
595                 echo "Archiving to ${TARGET_DIR}.tar.gz"
596                 $TAR cfp - ${TARGET_DIR} | gzip --best -c > ${TARGET_DIR}.tar.gz
597         fi
598 else
599         echo "Installed into ${TARGET_DIR}"
600 fi