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