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