chiark / gitweb /
plugins: Support user configuration of default values
[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.6.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         $EXTRACT 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 if [ -z `which 7za` ]; then
122         EXTRACT=7z
123 else
124         EXTRACT=7za
125 fi
126
127 # Change working directory to the directory the script is in
128 # http://stackoverflow.com/a/246128
129 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
130 cd "$SCRIPT_DIR"
131
132 checkTool git "git: http://git-scm.com/"
133 checkTool curl "curl: http://curl.haxx.se/"
134 if [ $BUILD_TARGET = "win32" ]; then
135         checkTool avr-gcc "avr-gcc: http://winavr.sourceforge.net/ "
136         #Check if we have 7zip, needed to extract and packup a bunch of packages for windows.
137         checkTool $EXTRACT "7zip: http://www.7-zip.org/"
138         checkTool $MAKE "mingw: http://www.mingw.org/"
139 fi
140 #For building under MacOS we need gnutar instead of tar
141 if [ -z `which gnutar` ]; then
142         TAR=tar
143 else
144         TAR=gnutar
145 fi
146
147 #############################
148 # Build the required firmwares
149 #############################
150
151 gitClone "https://github.com/Ultimaker/cura-binary-data" _cura_binary_data
152
153 cp -v _cura_binary_data/cura/resources/firmware/* resources/firmware/
154
155 #############################
156 # Darwin
157 #############################
158
159 if [ "$BUILD_TARGET" = "darwin" ]; then
160     TARGET_DIR=Cura-${BUILD_VERSION}-MacOS
161
162         rm -rf scripts/darwin/build
163         rm -rf scripts/darwin/dist
164
165         python build_app.py py2app
166         rc=$?
167         if [[ $rc != 0 ]]; then
168                 echo "Cannot build app."
169                 exit 1
170         fi
171
172     #Add cura version file (should read the version from the bundle with pyobjc, but will figure that out later)
173     echo $BUILD_VERSION > scripts/darwin/dist/Cura.app/Contents/Resources/version
174         rm -rf CuraEngine
175         gitClone ${CURA_ENGINE_REPO} CuraEngine
176     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
177         $MAKE -C CuraEngine VERSION=${BUILD_VERSION}
178     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
179         cp CuraEngine/build/CuraEngine scripts/darwin/dist/Cura.app/Contents/Resources/CuraEngine
180
181         cd scripts/darwin
182
183         # Install QuickLook plugin
184         mkdir -p dist/Cura.app/Contents/Library/QuickLook
185         cp -a STLQuickLook.qlgenerator dist/Cura.app/Contents/Library/QuickLook/
186
187         # Archive app
188         cd dist
189         $TAR cfp - Cura.app | gzip --best -c > ../../../${TARGET_DIR}.tar.gz
190         cd ..
191
192         # Create sparse image for distribution
193         hdiutil detach /Volumes/Cura\ -\ Lulzbot/ || true
194         rm -rf Cura.dmg.sparseimage
195         hdiutil convert DmgTemplateCompressed.dmg -format UDSP -o Cura.dmg
196         hdiutil resize -size 500m Cura.dmg.sparseimage
197         hdiutil attach Cura.dmg.sparseimage
198         cp -a dist/Cura.app /Volumes/Cura\ -\ Lulzbot/Cura/
199         hdiutil detach /Volumes/Cura\ -\ Lulzbot
200         hdiutil convert Cura.dmg.sparseimage -format UDZO -imagekey zlib-level=9 -ov -o ../../${TARGET_DIR}.dmg
201         exit
202 fi
203
204 #############################
205 # FreeBSD part by CeDeROM
206 #############################
207
208 if [ "$BUILD_TARGET" = "freebsd" ]; then
209         export CXX="c++"
210         gitClone https://github.com/GreatFruitOmsk/Power Power
211         gitClone ${CURA_ENGINE_REPO} CuraEngine
212     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
213         gmake -j4 -C CuraEngine VERSION=${BUILD_VERSION}
214     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
215         rm -rf scripts/freebsd/dist
216         mkdir -p scripts/freebsd/dist/share/cura
217         mkdir -p scripts/freebsd/dist/share/applications
218         mkdir -p scripts/freebsd/dist/bin
219         cp -a Cura scripts/freebsd/dist/share/cura/
220         cp -a resources scripts/freebsd/dist/share/cura/
221         cp -a plugins scripts/freebsd/dist/share/cura/
222         cp -a CuraEngine/build/CuraEngine scripts/freebsd/dist/share/cura/
223         cp scripts/freebsd/cura.py scripts/freebsd/dist/share/cura/
224         cp scripts/freebsd/cura.desktop scripts/freebsd/dist/share/applications/
225         cp scripts/freebsd/cura scripts/freebsd/dist/bin/
226         cp -a Power/power scripts/freebsd/dist/share/cura/
227         echo $BUILD_VERSION > scripts/freebsd/dist/share/cura/Cura/version
228         #Create file list (pkg-plist)
229         cd scripts/freebsd/dist
230         find * -type f > ../pkg-plist
231         DIRLVL=20; while [ $DIRLVL -ge 0 ]; do
232                 DIRS=`find share/cura -type d -depth $DIRLVL`
233                 for DIR in $DIRS; do
234                         echo "@dirrm $DIR" >> ../pkg-plist
235                 done
236                 DIRLVL=`expr $DIRLVL - 1`
237         done
238         cd ..
239         # Create archive or package if root
240         if [ `whoami` == "root" ]; then
241             echo "Are you root? Use the Port Luke! :-)"
242         else
243             echo "You are not root, building simple package archive..."
244             pwd
245             $TAR czf ../../${TARGET_DIR}.tar.gz dist/**
246         fi
247         exit
248 fi
249
250 #############################
251 # Debian 32bit .deb
252 #############################
253
254 if [ "$BUILD_TARGET" = "debian_i386" ]; then
255     export CXX="g++ -m32"
256         gitClone https://github.com/GreatFruitOmsk/Power Power
257         gitClone ${CURA_ENGINE_REPO} CuraEngine
258     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
259         $MAKE -C CuraEngine VERSION=${BUILD_VERSION}
260     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
261         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
262         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
263         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
264         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
265         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
266         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
267         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
268         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
269         echo $BUILD_VERSION > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
270         cat scripts/linux/debian_control | sed "s/\[BUILD_VERSION\]/${FULL_VERSION}/" | sed 's/\[ARCH\]/i386/' > scripts/linux/${BUILD_TARGET}/DEBIAN/control
271         fakeroot sh -ec "
272          chown root:root scripts/linux/${BUILD_TARGET} -R
273          chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
274          chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
275          cd scripts/linux
276          dpkg-deb -Zgzip --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${FULL_VERSION}_i386.deb
277          chown `id -un`:`id -gn` ${BUILD_TARGET} -R
278         "
279         exit
280 fi
281
282 #############################
283 # Debian 64bit .deb
284 #############################
285
286 if [ "$BUILD_TARGET" = "debian_amd64" ]; then
287     export CXX="g++ -m64"
288         gitClone https://github.com/GreatFruitOmsk/Power Power
289         gitClone ${CURA_ENGINE_REPO} CuraEngine
290     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
291         $MAKE -C CuraEngine VERSION=${BUILD_VERSION}
292     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
293         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
294         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
295         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
296         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
297         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
298         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
299         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
300         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
301         echo $BUILD_VERSION > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
302         cat scripts/linux/debian_control | sed "s/\[BUILD_VERSION\]/${FULL_VERSION}/" | sed 's/\[ARCH\]/amd64/' > scripts/linux/${BUILD_TARGET}/DEBIAN/control
303         fakeroot sh -ec "
304          chown root:root scripts/linux/${BUILD_TARGET} -R
305          chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
306          chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
307          cd scripts/linux
308          dpkg-deb -Zgzip --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${FULL_VERSION}_amd64.deb
309          chown `id -un`:`id -gn` ${BUILD_TARGET} -R
310         "
311         exit
312 fi
313
314 #############################
315 # Debian armhf .deb
316 #############################
317
318 if [ "$BUILD_TARGET" = "debian_armhf" ]; then
319     export CXX="g++"
320         gitClone https://github.com/GreatFruitOmsk/Power Power
321         gitClone ${CURA_ENGINE_REPO} CuraEngine
322     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
323         $MAKE -C CuraEngine VERSION=${BUILD_VERSION}
324     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
325         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
326         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
327         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
328         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
329         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
330         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
331         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
332         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
333         echo $BUILD_VERSION > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
334         cat scripts/linux/debian_control | sed "s/\[BUILD_VERSION\]/${FULL_VERSION}/" | sed 's/\[ARCH\]/armhf/' > scripts/linux/${BUILD_TARGET}/DEBIAN/control
335         fakeroot sh -ec "
336          chown root:root scripts/linux/${BUILD_TARGET} -R
337          chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
338          chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
339          cd scripts/linux
340          dpkg-deb --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_VERSION}-${BUILD_TARGET}.deb
341          chown `id -un`:`id -gn` ${BUILD_TARGET} -R
342         "
343         exit
344 fi
345
346 #############################
347 # Fedora Generic
348 #############################
349
350 function sanitiseVersion() {
351   local _version="$1"
352   echo "${_version//-/.}"
353 }
354
355 function fedoraCreateSRPM() {
356   local _curaName="$1"
357   local _version="$(sanitiseVersion "$2")"
358   local _srcSpecFile="$3"
359   local _srcSpecFileRelease="$4"
360   local _dstSrpmDir="$5"
361
362   local _dstTarSources="$HOME/rpmbuild/SOURCES/$_curaName-$_version.tar.gz"
363   local _dstSpec="$HOME/rpmbuild/SPECS/$_curaName-$_version.spec"
364
365   local _namePower="Power"
366   local _nameCuraEngine="CuraEngine"
367
368   gitClone "https://github.com/GreatFruitOmsk/Power" "$_namePower"
369   gitClone "$CURA_ENGINE_REPO" "$_nameCuraEngine"
370
371   cd "$_namePower"
372   local _gitPower="$(git rev-list -1 HEAD)"
373   cd -
374
375   cd "$_nameCuraEngine"
376   local _gitCuraEngine="$(git rev-list -1 HEAD)"
377   cd -
378
379   local _gitCura="$(git rev-list -1 HEAD)"
380
381   rpmdev-setuptree
382
383   rm -fv "$_dstTarSources"
384   tar \
385     --exclude-vcs \
386     --transform "s#^#$_curaName-$_version/#" \
387     -zcvf "$_dstTarSources" \
388       "$_nameCuraEngine" \
389       "$_namePower" \
390       Cura \
391       resources \
392       plugins \
393       scripts/linux/cura.py \
394       scripts/linux/fedora/usr
395
396   sed \
397     -e "s#__curaName__#$_curaName#" \
398     -e "s#__version__#$_version#" \
399     -e "s#__gitCura__#$_gitCura#" \
400     -e "s#__gitCuraEngine__#$_gitCuraEngine#" \
401     -e "s#__gitPower__#$_gitPower#" \
402     -e "s#__basedir__#scripts/linux/fedora#" \
403     "$_srcSpecFile" \
404     > "$_dstSpec"
405
406   rpmbuild -bs "$_dstSpec"
407
408   mkdir -pv "$_dstSrpmDir"
409   cp -v \
410     "$HOME/rpmbuild/SRPMS/$_curaName-$_version-$_srcSpecFileRelease.src.rpm" \
411     "$_dstSrpmDir"
412 }
413
414 function buildFedora() {
415   local _nameForRpm="Cura"
416   local _versionForRpm="$(sanitiseVersion "$BUILD_VERSION")"
417
418   #
419   # SRPM
420   #
421
422   local _srcSpecFile="scripts/linux/fedora/rpm.spec"
423   local _srcSpecFileRelease="$(rpmspec -P "$_srcSpecFile" | grep -E '^Release:'|awk '{print $NF}')"
424   local _dstSrpmDir="scripts/linux/fedora/SRPMS"
425
426   fedoraCreateSRPM \
427     "$_nameForRpm" \
428     "$_versionForRpm" \
429     "$_srcSpecFile" \
430     "$_srcSpecFileRelease" \
431     "$_dstSrpmDir"
432
433   #
434   # RPM
435   #
436
437   local _srpmFile="$_dstSrpmDir/$_nameForRpm-$_versionForRpm-$_srcSpecFileRelease.src.rpm"
438   local _dstRpmDir="scripts/linux/fedora/RPMS"
439
440   while [ $# -ne 0 ]; do
441     local _mockRelease="$(basename "${1%\.cfg}")"
442     local _mockReleaseArg=""
443     if [ -n "$_mockRelease" ]; then
444       _mockReleaseArg="-r $_mockRelease"
445     fi
446
447     mkdir -pv "$_dstRpmDir/$_mockRelease"
448     # Need to use /usr/bin/mock because depending on $PATH, if /usr/sbin/mock is
449     # run instead, it will give an error.
450     /usr/bin/mock \
451       $_mockReleaseArg \
452       --resultdir="$_dstRpmDir/$_mockRelease" \
453       "$_srpmFile"
454
455     shift 1
456   done
457 }
458
459 #############################
460 # Fedora RPMs
461 #############################
462
463 if [ "$BUILD_TARGET" = "fedora" ]; then
464   shift 1 # skip "fedora" arg
465
466   if [ $# -eq 0 ]; then
467     "$0" "$BUILD_TARGET" ""
468   else
469     buildFedora "${@}"
470   fi
471
472   exit
473 fi
474
475 #############################
476 # Rest
477 #############################
478
479 #############################
480 # Download all needed files.
481 #############################
482
483 if [ $BUILD_TARGET = "win32" ]; then
484         #Get portable python for windows and extract it. (Linux and Mac need to install python themselfs)
485         downloadURL http://ftp.nluug.nl/languages/python/portablepython/v2.7/PortablePython_${WIN_PORTABLE_PY_VERSION}.exe
486         downloadURL http://sourceforge.net/projects/pyopengl/files/PyOpenGL/3.0.1/PyOpenGL-3.0.1.win32.exe
487         downloadURL http://videocapture.sourceforge.net/VideoCapture-0.9-5.zip
488         #downloadURL http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20120927-git-13f0cd6-win32-static.7z
489         downloadURL http://sourceforge.net/projects/comtypes/files/comtypes/0.6.2/comtypes-0.6.2.win32.exe
490         downloadURL http://www.uwe-sieber.de/files/ejectmedia.zip
491         #Get the power module for python
492         gitClone https://github.com/GreatFruitOmsk/Power Power
493     if [ $? != 0 ]; then echo "Failed to clone Power"; exit 1; fi
494         gitClone ${CURA_ENGINE_REPO} CuraEngine
495     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
496 fi
497
498 #############################
499 # Build the packages
500 #############################
501 rm -rf ${TARGET_DIR}
502 mkdir -p ${TARGET_DIR}
503
504 rm -f log.txt
505 if [ $BUILD_TARGET = "win32" ]; then
506         if [ -z `which i686-w64-mingw32-g++` ]; then
507                 CXX=g++
508         else
509                 CXX=i686-w64-mingw32-g++
510         fi
511         
512         #For windows extract portable python to include it.
513         extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe App
514         extract PyOpenGL-3.0.1.win32.exe PURELIB
515         extract VideoCapture-0.9-5.zip VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd
516         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe
517         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/licenses
518         extract comtypes-0.6.2.win32.exe
519         extract ejectmedia.zip Win32
520
521         mkdir -p ${TARGET_DIR}/python
522         mkdir -p ${TARGET_DIR}/Cura/
523         mv App/Lib/site-packages/ PURELIB/
524         mv App/* ${TARGET_DIR}/python
525         mkdir -p ${TARGET_DIR}/python/Lib/site-packages/
526         mv PURELIB/site-packages/setuptools* PURELIB/site-packages/site.py PURELIB/site-packages/easy_install.py ${TARGET_DIR}/python/Lib/site-packages/
527         mv PURELIB/site-packages/numpy* ${TARGET_DIR}/python/Lib/site-packages/
528         mv PURELIB/site-packages/serial* ${TARGET_DIR}/python/Lib/site-packages/
529         mv PURELIB/site-packages/pyserial* ${TARGET_DIR}/python/Lib/site-packages/
530         mv PURELIB/site-packages/wx* ${TARGET_DIR}/python/Lib/site-packages/
531         mv PURELIB/OpenGL ${TARGET_DIR}/python/Lib
532         mv PURELIB/comtypes ${TARGET_DIR}/python/Lib
533         mv Power/power ${TARGET_DIR}/python/Lib
534         mv VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd ${TARGET_DIR}/python/DLLs
535         #mv ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe ${TARGET_DIR}/Cura/
536         #mv ffmpeg-20120927-git-13f0cd6-win32-static/licenses ${TARGET_DIR}/Cura/ffmpeg-licenses/
537         mv Win32/EjectMedia.exe ${TARGET_DIR}/Cura/
538         cp -a scripts/win32/nsisPlugins/libgcc_s_dw2-1.dll ${TARGET_DIR}
539         cp -a scripts/win32/nsisPlugins/libstdc++-6.dll ${TARGET_DIR}
540         
541         rm -rf Power/
542         rm -rf App
543         rm -rf PURELIB
544         rm -rf VideoCapture-0.9-5
545         #rm -rf ffmpeg-20120927-git-13f0cd6-win32-static
546
547         #Clean up portable python a bit, to keep the package size down.
548         rm -rf ${TARGET_DIR}/python/PyScripter.*
549         rm -rf ${TARGET_DIR}/python/Doc
550         rm -rf ${TARGET_DIR}/python/locale
551         rm -rf ${TARGET_DIR}/python/tcl
552         rm -rf ${TARGET_DIR}/python/Lib/test
553         rm -rf ${TARGET_DIR}/python/Lib/distutils
554         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-3.0-msw/wx/tools
555         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-3.0-msw/wx/locale
556         #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.
557         rm -rf ${TARGET_DIR}/python/Lib/OpenGL/DLLS/gle*
558
559         # New in 2.7.6.1
560         rm -rf ${TARGET_DIR}/python/PyCharm/
561         rm -rf ${TARGET_DIR}/python/share/
562         rm -rf ${TARGET_DIR}/python/qt.conf
563
564         #Build the C++ engine
565         $MAKE -C CuraEngine VERSION=${BUILD_VERSION} OS=Windows_NT CXX=${CXX}
566     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
567 fi
568
569 #add Cura
570 mkdir -p ${TARGET_DIR}/Cura ${TARGET_DIR}/resources ${TARGET_DIR}/plugins
571 cp -a Cura/* ${TARGET_DIR}/Cura
572 cp -a resources/* ${TARGET_DIR}/resources
573 cp -a plugins/* ${TARGET_DIR}/plugins
574 #Add cura version file
575 echo $BUILD_VERSION > ${TARGET_DIR}/Cura/version
576
577 #add script files
578 if [ $BUILD_TARGET = "win32" ]; then
579     cp -a scripts/win32/cura.bat $TARGET_DIR/
580     cp CuraEngine/build/CuraEngine.exe $TARGET_DIR
581     #cp /usr/lib/gcc/i686-w64-mingw32/4.8/libgcc_s_sjlj-1.dll $TARGET_DIR
582     #cp /usr/i686-w64-mingw32/lib/libwinpthread-1.dll $TARGET_DIR
583     #cp /usr/lib/gcc/i686-w64-mingw32/4.8/libstdc++-6.dll $TARGET_DIR
584 fi
585
586 #package the result
587 if (( ${ARCHIVE_FOR_DISTRIBUTION} )); then
588         if [ $BUILD_TARGET = "win32" ]; then
589                 #rm ${TARGET_DIR}.zip
590                 #cd ${TARGET_DIR}
591                 #7z a ../${TARGET_DIR}.zip *
592                 #cd ..
593
594                 if [ ! -z `which wine` ]; then
595                         #if we have wine, try to run our nsis script.
596                         rm -rf scripts/win32/dist
597                         ln -sf `pwd`/${TARGET_DIR} scripts/win32/dist
598                         wine ~/.wine/drive_c/Program\ Files\ \(x86\)/NSIS/makensis.exe /DVERSION=${BUILD_VERSION} scripts/win32/installer.nsi
599                         if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
600                         mv scripts/win32/Cura_${FULL_VERSION}.exe ./
601                 fi
602                 if [ -f '/c/Program Files (x86)/NSIS/makensis.exe' ]; then
603                         rm -rf scripts/win32/dist
604                         mv "`pwd`/${TARGET_DIR}" scripts/win32/dist
605                         '/c/Program Files (x86)/NSIS/makensis.exe' -DVERSION=${BUILD_VERSION} 'scripts/win32/installer.nsi' >> log.txt
606                         if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
607                         mv scripts/win32/Cura_${BUILD_VERSION}.exe ./
608                 fi
609         else
610                 echo "Archiving to ${TARGET_DIR}.tar.gz"
611                 $TAR cfp - ${TARGET_DIR} | gzip --best -c > ${TARGET_DIR}.tar.gz
612         fi
613 else
614         echo "Installed into ${TARGET_DIR}"
615 fi