chiark / gitweb /
Build the firmware from source when building an release.
[cura.git] / package.sh
1 #!/usr/bin/env bash
2
3 # This script is to package the Cura package for Windows/Linux and Mac OS X
4 # This script should run under Linux and Mac OS X, as well as Windows with Cygwin.
5
6 #############################
7 # CONFIGURATION
8 #############################
9
10 ##Select the build target
11 BUILD_TARGET=${1:-none}
12 #BUILD_TARGET=win32
13 #BUILD_TARGET=darwin
14 #BUILD_TARGET=debian_i386
15 #BUILD_TARGET=debian_amd64
16 #BUILD_TARGET=debian_armhf
17 #BUILD_TARGET=freebsd
18
19 ##Do we need to create the final archive
20 ARCHIVE_FOR_DISTRIBUTION=1
21 ##Which version name are we appending to the final archive
22 export BUILD_NAME=14.10-RC5
23 TARGET_DIR=Cura-${BUILD_NAME}-${BUILD_TARGET}
24
25 ##Which versions of external programs to use
26 WIN_PORTABLE_PY_VERSION=2.7.2.1
27
28 ##Which CuraEngine to use
29 if [ -z ${CURA_ENGINE_REPO} ] ; then
30         CURA_ENGINE_REPO="https://github.com/Ultimaker/CuraEngine"
31 fi
32
33 #############################
34 # Support functions
35 #############################
36 function checkTool
37 {
38         if [ -z "`which $1`" ]; then
39                 echo "The $1 command must be somewhere in your \$PATH."
40                 echo "Fix your \$PATH or install $2"
41                 exit 1
42         fi
43 }
44
45 function downloadURL
46 {
47         filename=`basename "$1"`
48         echo "Checking for $filename"
49         if [ ! -f "$filename" ]; then
50                 echo "Downloading $1"
51                 curl -L -O "$1"
52                 if [ $? != 0 ]; then
53                         echo "Failed to download $1"
54                         exit 1
55                 fi
56         fi
57 }
58
59 function extract
60 {
61         echo "Extracting $*"
62         echo "7z x -y $*" >> log.txt
63         7z x -y $* >> log.txt
64         if [ $? != 0 ]; then
65         echo "Failed to extract $*"
66         exit 1
67         fi
68 }
69
70 function gitClone
71 {
72         echo "Cloning $1 into $2"
73         if [ -d $2 ]; then
74                 cd $2
75                 git clean -dfx
76                 git reset --hard
77                 git pull
78                 cd -
79         else
80                 git clone $1 $2
81         fi
82 }
83
84 #############################
85 # Actual build script
86 #############################
87 if [ "$BUILD_TARGET" = "none" ]; then
88         echo "You need to specify a build target with:"
89         echo "$0 win32"
90         echo "$0 debian_i386"
91         echo "$0 debian_amd64"
92         echo "$0 debian_armhf"
93         echo "$0 darwin"
94         echo "$0 freebsd"
95         exit 0
96 fi
97
98 if [ -z `which make` ]; then
99         MAKE=mingw32-make
100 else
101         MAKE=make
102 fi
103
104 # Change working directory to the directory the script is in
105 # http://stackoverflow.com/a/246128
106 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
107 cd "$SCRIPT_DIR"
108
109 checkTool git "git: http://git-scm.com/"
110 checkTool curl "curl: http://curl.haxx.se/"
111 checkTool avr-gcc "avr-gcc: http://winavr.sourceforge.net/ "
112 if [ $BUILD_TARGET = "win32" ]; then
113         #Check if we have 7zip, needed to extract and packup a bunch of packages for windows.
114         checkTool 7z "7zip: http://www.7-zip.org/"
115         checkTool $MAKE "mingw: http://www.mingw.org/"
116 fi
117 #For building under MacOS we need gnutar instead of tar
118 if [ -z `which gnutar` ]; then
119         TAR=tar
120 else
121         TAR=gnutar
122 fi
123
124 #############################
125 # Build the required firmwares
126 #############################
127
128 if [ -d "C:/arduino-1.0.3" ]; then
129         ARDUINO_PATH=C:/arduino-1.0.3
130         ARDUINO_VERSION=103
131 else
132         ARDUINO_PATH=/usr/share/arduino
133         ARDUINO_VERSION=105
134 fi
135
136 #Build the Ultimaker Original firmwares.
137 gitClone git@github.com:Ultimaker/Marlin.git _UltimakerMarlin
138 cd _UltimakerMarlin/Marlin
139 git checkout Marlin_v1
140 $MAKE -j 3 HARDWARE_MOTHERBOARD=7 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_UltimakerMarlin_250000 DEFINES="'VERSION_BASE=\"Ultimaker:_${BUILD_NAME}\"' 'VERSION_PROFILE=\"250000_single\"' BAUDRATE=250000 TEMP_SENSOR_1=0 EXTRUDERS=1"
141 $MAKE -j 3 HARDWARE_MOTHERBOARD=7 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_UltimakerMarlin_115200 DEFINES="'VERSION_BASE=\"Ultimaker:_${BUILD_NAME}\"' 'VERSION_PROFILE=\"115200_single\"' BAUDRATE=115200 TEMP_SENSOR_1=0 EXTRUDERS=1"
142 $MAKE -j 3 HARDWARE_MOTHERBOARD=7 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_UltimakerMarlin_Dual_250000 DEFINES="'VERSION_BASE=\"Ultimaker:_${BUILD_NAME}\"' 'VERSION_PROFILE=\"250000_dual\"' BAUDRATE=250000 TEMP_SENSOR_1=-1 EXTRUDERS=2"
143 $MAKE -j 3 HARDWARE_MOTHERBOARD=7 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_UltimakerMarlin_Dual_115200 DEFINES="'VERSION_BASE=\"Ultimaker:_${BUILD_NAME}\"' 'VERSION_PROFILE=\"115200_dual\"' BAUDRATE=115200 TEMP_SENSOR_1=-1 EXTRUDERS=2"
144 git checkout Marlin_UM_HeatedBedUpgrade
145 $MAKE -j 3 HARDWARE_MOTHERBOARD=7 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_UltimakerMarlin_HBK_250000 DEFINES="'VERSION_BASE=\"Ultimaker:_${BUILD_NAME}\"' 'VERSION_PROFILE=\"250000_single_HB\"' BAUDRATE=250000 TEMP_SENSOR_1=0 EXTRUDERS=1"
146 $MAKE -j 3 HARDWARE_MOTHERBOARD=7 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_UltimakerMarlin_HBK_115200 DEFINES="'VERSION_BASE=\"Ultimaker:_${BUILD_NAME}\"' 'VERSION_PROFILE=\"115200_single_HB\"' BAUDRATE=115200 TEMP_SENSOR_1=0 EXTRUDERS=1"
147 $MAKE -j 3 HARDWARE_MOTHERBOARD=7 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_UltimakerMarlin_HBK_Dual_250000 DEFINES="'VERSION_BASE=\"Ultimaker:_${BUILD_NAME}\"' 'VERSION_PROFILE=\"250000_dual_HB\"' BAUDRATE=250000 TEMP_SENSOR_1=-1 EXTRUDERS=2"
148 $MAKE -j 3 HARDWARE_MOTHERBOARD=7 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_UltimakerMarlin_HBK_Dual_115200 DEFINES="'VERSION_BASE=\"Ultimaker:_${BUILD_NAME}\"' 'VERSION_PROFILE=\"115200_dual_HB\"' BAUDRATE=115200 TEMP_SENSOR_1=-1 EXTRUDERS=2"
149 git checkout Marlin_UM_Original_Plus
150 $MAKE -j 3 HARDWARE_MOTHERBOARD=72 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_UltimakerMarlin_Plus_250000 DEFINES="'VERSION_BASE=\"Ultimaker+:_${BUILD_NAME}\"' 'VERSION_PROFILE=\"250000_single\"' BAUDRATE=250000 TEMP_SENSOR_1=0 EXTRUDERS=1"
151 $MAKE -j 3 HARDWARE_MOTHERBOARD=72 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_UltimakerMarlin_Plus_115200 DEFINES="'VERSION_BASE=\"Ultimaker+:_${BUILD_NAME}\"' 'VERSION_PROFILE=\"115200_single\"' BAUDRATE=115200 TEMP_SENSOR_1=0 EXTRUDERS=1"
152 $MAKE -j 3 HARDWARE_MOTHERBOARD=72 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_UltimakerMarlin_Plus_Dual_250000 DEFINES="'VERSION_BASE=\"Ultimaker+:_${BUILD_NAME}\"' 'VERSION_PROFILE=\"250000_dual\"' BAUDRATE=250000 TEMP_SENSOR_1=-1 EXTRUDERS=2"
153 $MAKE -j 3 HARDWARE_MOTHERBOARD=72 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_UltimakerMarlin_Plus_Dual_115200 DEFINES="'VERSION_BASE=\"Ultimaker+:_${BUILD_NAME}\"' 'VERSION_PROFILE=\"115200_dual\"' BAUDRATE=115200 TEMP_SENSOR_1=-1 EXTRUDERS=2"
154 cd -
155
156 gitClone git@github.com:Ultimaker/Ultimaker2Marlin.git _Ultimaker2Marlin
157 cd _Ultimaker2Marlin/Marlin
158 $MAKE -j 3 HARDWARE_MOTHERBOARD=72 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_Ultimaker2 DEFINES="'STRING_CONFIG_H_AUTHOR=\"Version:_${BUILD_NAME}\"' TEMP_SENSOR_1=0 EXTRUDERS=1"
159 $MAKE -j 3 V=1 HARDWARE_MOTHERBOARD=72 ARDUINO_INSTALL_DIR=${ARDUINO_PATH} ARDUINO_VERSION=${ARDUINO_VERSION} BUILD_DIR=_Ultimaker2Dual DEFINES="'STRING_CONFIG_H_AUTHOR=\"Version:_${BUILD_NAME}\"' TEMP_SENSOR_1=20 EXTRUDERS=2"
160 cd -
161
162 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_250000/Marlin.hex resources/firmware/MarlinUltimaker-250000.hex
163 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_115200/Marlin.hex resources/firmware/MarlinUltimaker-115200.hex
164 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Dual_250000/Marlin.hex resources/firmware/MarlinUltimaker-250000-dual.hex
165 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Dual_115200/Marlin.hex resources/firmware/MarlinUltimaker-115200-dual.hex
166 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_250000/Marlin.hex resources/firmware/MarlinUltimaker-HBK-250000.hex
167 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_115200/Marlin.hex resources/firmware/MarlinUltimaker-HBK-115200.hex
168 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_Dual_250000/Marlin.hex resources/firmware/MarlinUltimaker-HBK-250000-dual.hex
169 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_Dual_115200/Marlin.hex resources/firmware/MarlinUltimaker-HBK-115200-dual.hex
170 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_250000/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-250000.hex
171 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_115200/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-115200.hex
172 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_Dual_250000/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-250000-dual.hex
173 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_Dual_115200/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-115200-dual.hex
174 cp _Ultimaker2Marlin/Marlin/_Ultimaker2/Marlin.hex resources/firmware/MarlinUltimaker2.hex
175 cp _Ultimaker2Marlin/Marlin/_Ultimaker2Dual/Marlin.hex resources/firmware/MarlinUltimaker2-dual.hex
176
177 #############################
178 # Darwin
179 #############################
180
181 if [ "$BUILD_TARGET" = "darwin" ]; then
182     TARGET_DIR=Cura-${BUILD_NAME}-MacOS
183
184         rm -rf scripts/darwin/build
185         rm -rf scripts/darwin/dist
186
187         python build_app.py py2app
188         rc=$?
189         if [[ $rc != 0 ]]; then
190                 echo "Cannot build app."
191                 exit 1
192         fi
193
194     #Add cura version file (should read the version from the bundle with pyobjc, but will figure that out later)
195     echo $BUILD_NAME > scripts/darwin/dist/Cura.app/Contents/Resources/version
196         rm -rf CuraEngine
197         gitClone ${CURA_ENGINE_REPO} CuraEngine
198     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
199         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
200     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
201         cp CuraEngine/build/CuraEngine scripts/darwin/dist/Cura.app/Contents/Resources/CuraEngine
202
203         cd scripts/darwin
204
205         # Install QuickLook plugin
206         mkdir -p dist/Cura.app/Contents/Library/QuickLook
207         cp -a STLQuickLook.qlgenerator dist/Cura.app/Contents/Library/QuickLook/
208
209         # Archive app
210         cd dist
211         $TAR cfp - Cura.app | gzip --best -c > ../../../${TARGET_DIR}.tar.gz
212         cd ..
213
214         # Create sparse image for distribution
215         hdiutil detach /Volumes/Cura\ -\ Ultimaker/
216         rm -rf Cura.dmg.sparseimage
217         hdiutil convert DmgTemplateCompressed.dmg -format UDSP -o Cura.dmg
218         hdiutil resize -size 500m Cura.dmg.sparseimage
219         hdiutil attach Cura.dmg.sparseimage
220         cp -a dist/Cura.app /Volumes/Cura\ -\ Ultimaker/Cura/
221         hdiutil detach /Volumes/Cura\ -\ Ultimaker
222         hdiutil convert Cura.dmg.sparseimage -format UDZO -imagekey zlib-level=9 -ov -o ../../${TARGET_DIR}.dmg
223         exit
224 fi
225
226 #############################
227 # FreeBSD part by CeDeROM
228 #############################
229
230 if [ "$BUILD_TARGET" = "freebsd" ]; then
231         export CXX="c++"
232         gitClone https://github.com/GreatFruitOmsk/Power Power
233         gitClone ${CURA_ENGINE_REPO} CuraEngine
234     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
235         gmake -j4 -C CuraEngine VERSION=${BUILD_NAME}
236     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
237         rm -rf scripts/freebsd/dist
238         mkdir -p scripts/freebsd/dist/share/cura
239         mkdir -p scripts/freebsd/dist/share/applications
240         mkdir -p scripts/freebsd/dist/bin
241         cp -a Cura scripts/freebsd/dist/share/cura/
242         cp -a resources scripts/freebsd/dist/share/cura/
243         cp -a plugins scripts/freebsd/dist/share/cura/
244         cp -a CuraEngine/build/CuraEngine scripts/freebsd/dist/share/cura/
245         cp scripts/freebsd/cura.py scripts/freebsd/dist/share/cura/
246         cp scripts/freebsd/cura.desktop scripts/freebsd/dist/share/applications/
247         cp scripts/freebsd/cura scripts/freebsd/dist/bin/
248         cp -a Power/power scripts/freebsd/dist/share/cura/
249         echo $BUILD_NAME > scripts/freebsd/dist/share/cura/Cura/version
250         #Create file list (pkg-plist)
251         cd scripts/freebsd/dist
252         find * -type f > ../pkg-plist
253         DIRLVL=20; while [ $DIRLVL -ge 0 ]; do
254                 DIRS=`find share/cura -type d -depth $DIRLVL`
255                 for DIR in $DIRS; do
256                         echo "@dirrm $DIR" >> ../pkg-plist
257                 done
258                 DIRLVL=`expr $DIRLVL - 1`
259         done
260         cd ..
261         # Create archive or package if root
262         if [ `whoami` == "root" ]; then
263             echo "Are you root? Use the Port Luke! :-)"
264         else
265             echo "You are not root, building simple package archive..."
266             pwd
267             $TAR czf ../../${TARGET_DIR}.tar.gz dist/**
268         fi
269         exit
270 fi
271
272 #############################
273 # Debian 32bit .deb
274 #############################
275
276 if [ "$BUILD_TARGET" = "debian_i386" ]; then
277     export CXX="g++ -m32"
278         gitClone https://github.com/GreatFruitOmsk/Power Power
279         gitClone ${CURA_ENGINE_REPO} CuraEngine
280     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
281         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
282     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
283         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
284         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
285         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
286         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
287         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
288         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
289         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
290         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
291         echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
292         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
293         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
294         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
295         cd scripts/linux
296         dpkg-deb --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${BUILD_TARGET}.deb
297         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
298         exit
299 fi
300
301 #############################
302 # Debian 64bit .deb
303 #############################
304
305 if [ "$BUILD_TARGET" = "debian_amd64" ]; then
306     export CXX="g++ -m64"
307         gitClone https://github.com/GreatFruitOmsk/Power Power
308         gitClone ${CURA_ENGINE_REPO} CuraEngine
309     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
310         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
311     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
312         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
313         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
314         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
315         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
316         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
317         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
318         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
319         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
320         echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
321         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
322         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
323         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
324         cd scripts/linux
325         dpkg-deb --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${BUILD_TARGET}.deb
326         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
327         exit
328 fi
329
330 #############################
331 # Debian armhf .deb
332 #############################
333
334 if [ "$BUILD_TARGET" = "debian_armhf" ]; then
335     export CXX="g++"
336         gitClone https://github.com/GreatFruitOmsk/Power Power
337         gitClone ${CURA_ENGINE_REPO} CuraEngine
338     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
339         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
340     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
341         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
342         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
343         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
344         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
345         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
346         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
347         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
348         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
349         echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
350         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
351         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
352         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
353         cd scripts/linux
354         dpkg-deb --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${BUILD_TARGET}.deb
355         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
356         exit
357 fi
358
359 #############################
360 # Rest
361 #############################
362
363 #############################
364 # Download all needed files.
365 #############################
366
367 if [ $BUILD_TARGET = "win32" ]; then
368         #Get portable python for windows and extract it. (Linux and Mac need to install python themselfs)
369         downloadURL http://ftp.nluug.nl/languages/python/portablepython/v2.7/PortablePython_${WIN_PORTABLE_PY_VERSION}.exe
370         downloadURL http://sourceforge.net/projects/pyserial/files/pyserial/2.5/pyserial-2.5.win32.exe
371         downloadURL http://sourceforge.net/projects/pyopengl/files/PyOpenGL/3.0.1/PyOpenGL-3.0.1.win32.exe
372         downloadURL http://sourceforge.net/projects/numpy/files/NumPy/1.6.2/numpy-1.6.2-win32-superpack-python2.7.exe
373         downloadURL http://videocapture.sourceforge.net/VideoCapture-0.9-5.zip
374         #downloadURL http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20120927-git-13f0cd6-win32-static.7z
375         downloadURL http://sourceforge.net/projects/comtypes/files/comtypes/0.6.2/comtypes-0.6.2.win32.exe
376         downloadURL http://www.uwe-sieber.de/files/ejectmedia.zip
377         #Get the power module for python
378         gitClone https://github.com/GreatFruitOmsk/Power Power
379     if [ $? != 0 ]; then echo "Failed to clone Power"; exit 1; fi
380         gitClone ${CURA_ENGINE_REPO} CuraEngine
381     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
382 fi
383
384 #############################
385 # Build the packages
386 #############################
387 rm -rf ${TARGET_DIR}
388 mkdir -p ${TARGET_DIR}
389
390 rm -f log.txt
391 if [ $BUILD_TARGET = "win32" ]; then
392         if [ -z `which i686-w64-mingw32-g++` ]; then
393                 CXX=g++
394         else
395                 CXX=i686-w64-mingw32-g++
396         fi
397         
398         #For windows extract portable python to include it.
399         extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/App
400         extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/Lib/site-packages
401         extract pyserial-2.5.win32.exe PURELIB
402         extract PyOpenGL-3.0.1.win32.exe PURELIB
403         extract numpy-1.6.2-win32-superpack-python2.7.exe numpy-1.6.2-sse2.exe
404         extract numpy-1.6.2-sse2.exe PLATLIB
405         extract VideoCapture-0.9-5.zip VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd
406         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe
407         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/licenses
408         extract comtypes-0.6.2.win32.exe
409         extract ejectmedia.zip Win32
410
411         mkdir -p ${TARGET_DIR}/python
412         mkdir -p ${TARGET_DIR}/Cura/
413         mv \$_OUTDIR/App/* ${TARGET_DIR}/python
414         mv \$_OUTDIR/Lib/site-packages/wx* ${TARGET_DIR}/python/Lib/site-packages/
415         mv PURELIB/serial ${TARGET_DIR}/python/Lib
416         mv PURELIB/OpenGL ${TARGET_DIR}/python/Lib
417         mv PURELIB/comtypes ${TARGET_DIR}/python/Lib
418         mv PLATLIB/numpy ${TARGET_DIR}/python/Lib
419         mv Power/power ${TARGET_DIR}/python/Lib
420         mv VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd ${TARGET_DIR}/python/DLLs
421         #mv ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe ${TARGET_DIR}/Cura/
422         #mv ffmpeg-20120927-git-13f0cd6-win32-static/licenses ${TARGET_DIR}/Cura/ffmpeg-licenses/
423         mv Win32/EjectMedia.exe ${TARGET_DIR}/Cura/
424         
425         rm -rf Power/
426         rm -rf \$_OUTDIR
427         rm -rf PURELIB
428         rm -rf PLATLIB
429         rm -rf VideoCapture-0.9-5
430         rm -rf numpy-1.6.2-sse2.exe
431         #rm -rf ffmpeg-20120927-git-13f0cd6-win32-static
432
433         #Clean up portable python a bit, to keep the package size down.
434         rm -rf ${TARGET_DIR}/python/PyScripter.*
435         rm -rf ${TARGET_DIR}/python/Doc
436         rm -rf ${TARGET_DIR}/python/locale
437         rm -rf ${TARGET_DIR}/python/tcl
438         rm -rf ${TARGET_DIR}/python/Lib/test
439         rm -rf ${TARGET_DIR}/python/Lib/distutils
440         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/tools
441         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/locale
442         #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.
443         rm -rf ${TARGET_DIR}/python/Lib/OpenGL/DLLS/gle*
444
445     #Build the C++ engine
446         $MAKE -C CuraEngine VERSION=${BUILD_NAME} OS=Windows_NT CXX=${CXX}
447     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
448 fi
449
450 #add Cura
451 mkdir -p ${TARGET_DIR}/Cura ${TARGET_DIR}/resources ${TARGET_DIR}/plugins
452 cp -a Cura/* ${TARGET_DIR}/Cura
453 cp -a resources/* ${TARGET_DIR}/resources
454 cp -a plugins/* ${TARGET_DIR}/plugins
455 #Add cura version file
456 echo $BUILD_NAME > ${TARGET_DIR}/Cura/version
457
458 #add script files
459 if [ $BUILD_TARGET = "win32" ]; then
460     cp -a scripts/${BUILD_TARGET}/*.bat $TARGET_DIR/
461     cp CuraEngine/build/CuraEngine.exe $TARGET_DIR
462         cp /usr/lib/gcc/i686-w64-mingw32/4.8/libgcc_s_sjlj-1.dll $TARGET_DIR
463     cp /usr/i686-w64-mingw32/lib/libwinpthread-1.dll $TARGET_DIR
464     cp /usr/lib/gcc/i686-w64-mingw32/4.8/libstdc++-6.dll $TARGET_DIR
465 else
466     cp -a scripts/${BUILD_TARGET}/*.sh $TARGET_DIR/
467 fi
468
469 #package the result
470 if (( ${ARCHIVE_FOR_DISTRIBUTION} )); then
471         if [ $BUILD_TARGET = "win32" ]; then
472                 #rm ${TARGET_DIR}.zip
473                 #cd ${TARGET_DIR}
474                 #7z a ../${TARGET_DIR}.zip *
475                 #cd ..
476
477                 if [ ! -z `which wine` ]; then
478                         #if we have wine, try to run our nsis script.
479                         rm -rf scripts/win32/dist
480                         ln -sf `pwd`/${TARGET_DIR} scripts/win32/dist
481                         wine ~/.wine/drive_c/Program\ Files\ \(x86\)/NSIS/makensis.exe /DVERSION=${BUILD_NAME} scripts/win32/installer.nsi
482             if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
483                         mv scripts/win32/Cura_${BUILD_NAME}.exe ./
484                 fi
485                 if [ -f '/c/Program Files (x86)/NSIS/makensis.exe' ]; then
486                         rm -rf scripts/win32/dist
487                         mv `pwd`/${TARGET_DIR} scripts/win32/dist
488                         '/c/Program Files (x86)/NSIS/makensis.exe' -DVERSION=${BUILD_NAME} 'scripts/win32/installer.nsi' >> log.txt
489             if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
490                         mv scripts/win32/Cura_${BUILD_NAME}.exe ./
491                 fi
492         else
493                 echo "Archiving to ${TARGET_DIR}.tar.gz"
494                 $TAR cfp - ${TARGET_DIR} | gzip --best -c > ${TARGET_DIR}.tar.gz
495         fi
496 else
497         echo "Installed into ${TARGET_DIR}"
498 fi