chiark / gitweb /
b3473d1a2c93030234b33f6b17a616cebcc78a4b
[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 ##Revision
26 export REVISION=1.18
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="https://github.com/alephobjects/CuraEngine"
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 checkTool avr-gcc "avr-gcc: http://winavr.sourceforge.net/ "
118 if [ $BUILD_TARGET = "win32" ]; then
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 else
138         ARDUINO_PATH=/usr/share/arduino
139         ARDUINO_VERSION=105
140 fi
141
142 #Build the Ultimaker Original firmwares.
143 gitClone git@github.com:Ultimaker/Marlin.git _UltimakerMarlin
144 cd _UltimakerMarlin/Marlin
145 git checkout Marlin_v1
146 $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"
147 $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"
148 $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"
149 $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"
150 git checkout Marlin_UM_HeatedBedUpgrade
151 $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"
152 $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"
153 $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"
154 $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"
155 git checkout Marlin_UM_Original_Plus
156 $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"
157 $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"
158 $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"
159 $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"
160 cd -
161
162 gitClone git@github.com:Ultimaker/Ultimaker2Marlin.git _Ultimaker2Marlin
163 cd _Ultimaker2Marlin/Marlin
164 $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"
165 $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"
166 cd -
167
168 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_250000/Marlin.hex resources/firmware/MarlinUltimaker-250000.hex
169 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_115200/Marlin.hex resources/firmware/MarlinUltimaker-115200.hex
170 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Dual_250000/Marlin.hex resources/firmware/MarlinUltimaker-250000-dual.hex
171 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Dual_115200/Marlin.hex resources/firmware/MarlinUltimaker-115200-dual.hex
172 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_250000/Marlin.hex resources/firmware/MarlinUltimaker-HBK-250000.hex
173 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_115200/Marlin.hex resources/firmware/MarlinUltimaker-HBK-115200.hex
174 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_Dual_250000/Marlin.hex resources/firmware/MarlinUltimaker-HBK-250000-dual.hex
175 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_Dual_115200/Marlin.hex resources/firmware/MarlinUltimaker-HBK-115200-dual.hex
176 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_250000/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-250000.hex
177 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_115200/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-115200.hex
178 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_Dual_250000/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-250000-dual.hex
179 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_Dual_115200/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-115200-dual.hex
180 cp _Ultimaker2Marlin/Marlin/_Ultimaker2/Marlin.hex resources/firmware/MarlinUltimaker2.hex
181 cp _Ultimaker2Marlin/Marlin/_Ultimaker2Dual/Marlin.hex resources/firmware/MarlinUltimaker2-dual.hex
182
183 #############################
184 # Darwin
185 #############################
186
187 if [ "$BUILD_TARGET" = "darwin" ]; then
188     TARGET_DIR=Cura-${BUILD_NAME}-MacOS
189
190         rm -rf scripts/darwin/build
191         rm -rf scripts/darwin/dist
192
193         python build_app.py py2app
194         rc=$?
195         if [[ $rc != 0 ]]; then
196                 echo "Cannot build app."
197                 exit 1
198         fi
199
200     #Add cura version file (should read the version from the bundle with pyobjc, but will figure that out later)
201     echo $BUILD_NAME > scripts/darwin/dist/Cura.app/Contents/Resources/version
202         rm -rf CuraEngine
203         gitClone ${CURA_ENGINE_REPO} CuraEngine
204     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
205         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
206     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
207         cp CuraEngine/build/CuraEngine scripts/darwin/dist/Cura.app/Contents/Resources/CuraEngine
208
209         cd scripts/darwin
210
211         # Install QuickLook plugin
212         mkdir -p dist/Cura.app/Contents/Library/QuickLook
213         cp -a STLQuickLook.qlgenerator dist/Cura.app/Contents/Library/QuickLook/
214
215         # Archive app
216         cd dist
217         $TAR cfp - Cura.app | gzip --best -c > ../../../${TARGET_DIR}.tar.gz
218         cd ..
219
220         # Create sparse image for distribution
221         hdiutil detach /Volumes/Cura\ -\ Lulzbot/
222         rm -rf Cura.dmg.sparseimage
223         hdiutil convert DmgTemplateCompressed.dmg -format UDSP -o Cura.dmg
224         hdiutil resize -size 500m Cura.dmg.sparseimage
225         hdiutil attach Cura.dmg.sparseimage
226         cp -a dist/Cura.app /Volumes/Cura\ -\ Lulzbot/Cura/
227         hdiutil detach /Volumes/Cura\ -\ Lulzbot
228         hdiutil convert Cura.dmg.sparseimage -format UDZO -imagekey zlib-level=9 -ov -o ../../${TARGET_DIR}.dmg
229         exit
230 fi
231
232 #############################
233 # FreeBSD part by CeDeROM
234 #############################
235
236 if [ "$BUILD_TARGET" = "freebsd" ]; then
237         export CXX="c++"
238         gitClone https://github.com/GreatFruitOmsk/Power Power
239         gitClone ${CURA_ENGINE_REPO} CuraEngine
240     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
241         gmake -j4 -C CuraEngine VERSION=${BUILD_NAME}
242     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
243         rm -rf scripts/freebsd/dist
244         mkdir -p scripts/freebsd/dist/share/cura
245         mkdir -p scripts/freebsd/dist/share/applications
246         mkdir -p scripts/freebsd/dist/bin
247         cp -a Cura scripts/freebsd/dist/share/cura/
248         cp -a resources scripts/freebsd/dist/share/cura/
249         cp -a plugins scripts/freebsd/dist/share/cura/
250         cp -a CuraEngine/build/CuraEngine scripts/freebsd/dist/share/cura/
251         cp scripts/freebsd/cura.py scripts/freebsd/dist/share/cura/
252         cp scripts/freebsd/cura.desktop scripts/freebsd/dist/share/applications/
253         cp scripts/freebsd/cura scripts/freebsd/dist/bin/
254         cp -a Power/power scripts/freebsd/dist/share/cura/
255         echo $BUILD_NAME > scripts/freebsd/dist/share/cura/Cura/version
256         #Create file list (pkg-plist)
257         cd scripts/freebsd/dist
258         find * -type f > ../pkg-plist
259         DIRLVL=20; while [ $DIRLVL -ge 0 ]; do
260                 DIRS=`find share/cura -type d -depth $DIRLVL`
261                 for DIR in $DIRS; do
262                         echo "@dirrm $DIR" >> ../pkg-plist
263                 done
264                 DIRLVL=`expr $DIRLVL - 1`
265         done
266         cd ..
267         # Create archive or package if root
268         if [ `whoami` == "root" ]; then
269             echo "Are you root? Use the Port Luke! :-)"
270         else
271             echo "You are not root, building simple package archive..."
272             pwd
273             $TAR czf ../../${TARGET_DIR}.tar.gz dist/**
274         fi
275         exit
276 fi
277
278 #############################
279 # Debian 32bit .deb
280 #############################
281
282 if [ "$BUILD_TARGET" = "debian_i386" ]; then
283     export CXX="g++ -m32"
284         gitClone https://github.com/GreatFruitOmsk/Power Power
285         gitClone ${CURA_ENGINE_REPO} CuraEngine
286     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
287         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
288     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
289         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
290         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
291         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
292         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
293         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
294         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
295         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
296         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
297         echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
298         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
299         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
300         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
301         cd scripts/linux
302         dpkg-deb -Zgzip --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${REVISION}-${GIT_HASH}_i386.deb
303         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
304         exit
305 fi
306
307 #############################
308 # Debian 64bit .deb
309 #############################
310
311 if [ "$BUILD_TARGET" = "debian_amd64" ]; then
312     export CXX="g++ -m64"
313         gitClone https://github.com/GreatFruitOmsk/Power Power
314         gitClone ${CURA_ENGINE_REPO} CuraEngine
315     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
316         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
317     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
318         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
319         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
320         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
321         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
322         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
323         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
324         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
325         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
326         echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
327         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
328         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
329         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
330         cd scripts/linux
331         dpkg-deb -Zgzip --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${REVISION}-${GIT_HASH}_amd64.deb
332         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
333         exit
334 fi
335
336 #############################
337 # Debian armhf .deb
338 #############################
339
340 if [ "$BUILD_TARGET" = "debian_armhf" ]; then
341     export CXX="g++"
342         gitClone https://github.com/GreatFruitOmsk/Power Power
343         gitClone ${CURA_ENGINE_REPO} CuraEngine
344     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
345         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
346     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
347         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
348         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
349         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
350         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
351         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
352         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
353         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
354         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
355         echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
356         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
357         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
358         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
359         cd scripts/linux
360         dpkg-deb --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${BUILD_TARGET}.deb
361         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
362         exit
363 fi
364
365 #############################
366 # Rest
367 #############################
368
369 #############################
370 # Download all needed files.
371 #############################
372
373 if [ $BUILD_TARGET = "win32" ]; then
374         #Get portable python for windows and extract it. (Linux and Mac need to install python themselfs)
375         downloadURL http://ftp.nluug.nl/languages/python/portablepython/v2.7/PortablePython_${WIN_PORTABLE_PY_VERSION}.exe
376         downloadURL http://sourceforge.net/projects/pyserial/files/pyserial/2.5/pyserial-2.5.win32.exe
377         downloadURL http://sourceforge.net/projects/pyopengl/files/PyOpenGL/3.0.1/PyOpenGL-3.0.1.win32.exe
378         downloadURL http://sourceforge.net/projects/numpy/files/NumPy/1.6.2/numpy-1.6.2-win32-superpack-python2.7.exe
379         downloadURL http://videocapture.sourceforge.net/VideoCapture-0.9-5.zip
380         #downloadURL http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20120927-git-13f0cd6-win32-static.7z
381         downloadURL http://sourceforge.net/projects/comtypes/files/comtypes/0.6.2/comtypes-0.6.2.win32.exe
382         downloadURL http://www.uwe-sieber.de/files/ejectmedia.zip
383         #Get the power module for python
384         gitClone https://github.com/GreatFruitOmsk/Power Power
385     if [ $? != 0 ]; then echo "Failed to clone Power"; exit 1; fi
386         gitClone ${CURA_ENGINE_REPO} CuraEngine
387     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
388 fi
389
390 #############################
391 # Build the packages
392 #############################
393 rm -rf ${TARGET_DIR}
394 mkdir -p ${TARGET_DIR}
395
396 rm -f log.txt
397 if [ $BUILD_TARGET = "win32" ]; then
398         if [ -z `which i686-w64-mingw32-g++` ]; then
399                 CXX=g++
400         else
401                 CXX=i686-w64-mingw32-g++
402         fi
403         
404         #For windows extract portable python to include it.
405         extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/App
406         extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/Lib/site-packages
407         extract pyserial-2.5.win32.exe PURELIB
408         extract PyOpenGL-3.0.1.win32.exe PURELIB
409         extract numpy-1.6.2-win32-superpack-python2.7.exe numpy-1.6.2-sse2.exe
410         extract numpy-1.6.2-sse2.exe PLATLIB
411         extract VideoCapture-0.9-5.zip VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd
412         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe
413         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/licenses
414         extract comtypes-0.6.2.win32.exe
415         extract ejectmedia.zip Win32
416
417         mkdir -p ${TARGET_DIR}/python
418         mkdir -p ${TARGET_DIR}/Cura/
419         mv \$_OUTDIR/App/* ${TARGET_DIR}/python
420         mv \$_OUTDIR/Lib/site-packages/wx* ${TARGET_DIR}/python/Lib/site-packages/
421         mv PURELIB/serial ${TARGET_DIR}/python/Lib
422         mv PURELIB/OpenGL ${TARGET_DIR}/python/Lib
423         mv PURELIB/comtypes ${TARGET_DIR}/python/Lib
424         mv PLATLIB/numpy ${TARGET_DIR}/python/Lib
425         mv Power/power ${TARGET_DIR}/python/Lib
426         mv VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd ${TARGET_DIR}/python/DLLs
427         #mv ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe ${TARGET_DIR}/Cura/
428         #mv ffmpeg-20120927-git-13f0cd6-win32-static/licenses ${TARGET_DIR}/Cura/ffmpeg-licenses/
429         mv Win32/EjectMedia.exe ${TARGET_DIR}/Cura/
430         cp -a scripts/win32/nsisPlugins/libgcc_s_dw2-1.dll ${TARGET_DIR}
431         cp -a scripts/win32/nsisPlugins/libstdc++-6.dll ${TARGET_DIR}
432         
433         rm -rf Power/
434         rm -rf \$_OUTDIR
435         rm -rf PURELIB
436         rm -rf PLATLIB
437         rm -rf VideoCapture-0.9-5
438         rm -rf numpy-1.6.2-sse2.exe
439         #rm -rf ffmpeg-20120927-git-13f0cd6-win32-static
440
441         #Clean up portable python a bit, to keep the package size down.
442         rm -rf ${TARGET_DIR}/python/PyScripter.*
443         rm -rf ${TARGET_DIR}/python/Doc
444         rm -rf ${TARGET_DIR}/python/locale
445         rm -rf ${TARGET_DIR}/python/tcl
446         rm -rf ${TARGET_DIR}/python/Lib/test
447         rm -rf ${TARGET_DIR}/python/Lib/distutils
448         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/tools
449         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/locale
450         #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.
451         rm -rf ${TARGET_DIR}/python/Lib/OpenGL/DLLS/gle*
452
453     #Build the C++ engine
454         $MAKE -C CuraEngine VERSION=${BUILD_NAME} OS=Windows_NT CXX=${CXX}
455     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
456 fi
457
458 #add Cura
459 mkdir -p ${TARGET_DIR}/Cura ${TARGET_DIR}/resources ${TARGET_DIR}/plugins
460 cp -a Cura/* ${TARGET_DIR}/Cura
461 cp -a resources/* ${TARGET_DIR}/resources
462 cp -a plugins/* ${TARGET_DIR}/plugins
463 #Add cura version file
464 echo $BUILD_NAME > ${TARGET_DIR}/Cura/version
465
466 #add script files
467 if [ $BUILD_TARGET = "win32" ]; then
468     cp -a scripts/${BUILD_TARGET}/*.bat $TARGET_DIR/
469     cp CuraEngine/build/CuraEngine.exe $TARGET_DIR
470         cp /usr/lib/gcc/i686-w64-mingw32/4.8/libgcc_s_sjlj-1.dll $TARGET_DIR
471     cp /usr/i686-w64-mingw32/lib/libwinpthread-1.dll $TARGET_DIR
472     cp /usr/lib/gcc/i686-w64-mingw32/4.8/libstdc++-6.dll $TARGET_DIR
473 else
474     cp -a scripts/${BUILD_TARGET}/*.sh $TARGET_DIR/
475 fi
476
477 #package the result
478 if (( ${ARCHIVE_FOR_DISTRIBUTION} )); then
479         if [ $BUILD_TARGET = "win32" ]; then
480                 #rm ${TARGET_DIR}.zip
481                 #cd ${TARGET_DIR}
482                 #7z a ../${TARGET_DIR}.zip *
483                 #cd ..
484
485                 if [ ! -z `which wine` ]; then
486                         #if we have wine, try to run our nsis script.
487                         rm -rf scripts/win32/dist
488                         ln -sf `pwd`/${TARGET_DIR} scripts/win32/dist
489                         wine ~/.wine/drive_c/Program\ Files\ \(x86\)/NSIS/makensis.exe /DVERSION=${BUILD_NAME} scripts/win32/installer.nsi
490             if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
491                         mv scripts/win32/Cura_${BUILD_NAME}-${REVISION}-${GIT_HASH}.exe ./
492                 fi
493                 if [ -f '/c/Program Files (x86)/NSIS/makensis.exe' ]; then
494                         rm -rf scripts/win32/dist
495                         mv `pwd`/${TARGET_DIR} scripts/win32/dist
496                         '/c/Program Files (x86)/NSIS/makensis.exe' -DVERSION=${BUILD_NAME} 'scripts/win32/installer.nsi' >> log.txt
497             if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
498                         mv scripts/win32/Cura_${BUILD_NAME}.exe ./
499                 fi
500         else
501                 echo "Archiving to ${TARGET_DIR}.tar.gz"
502                 $TAR cfp - ${TARGET_DIR} | gzip --best -c > ${TARGET_DIR}.tar.gz
503         fi
504 else
505         echo "Installed into ${TARGET_DIR}"
506 fi