chiark / gitweb /
1969b9deb7e471bedf477665d634e9b11b32e975
[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-RC7
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 git checkout master
168 $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"
169 $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"
170 git checkout UM2go
171 $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"
172 git checkout UM2extended
173 $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"
174 $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"
175 cd -
176
177 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_250000/Marlin.hex resources/firmware/MarlinUltimaker-250000.hex
178 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_115200/Marlin.hex resources/firmware/MarlinUltimaker-115200.hex
179 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Dual_250000/Marlin.hex resources/firmware/MarlinUltimaker-250000-dual.hex
180 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Dual_115200/Marlin.hex resources/firmware/MarlinUltimaker-115200-dual.hex
181 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_250000/Marlin.hex resources/firmware/MarlinUltimaker-HBK-250000.hex
182 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_115200/Marlin.hex resources/firmware/MarlinUltimaker-HBK-115200.hex
183 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_Dual_250000/Marlin.hex resources/firmware/MarlinUltimaker-HBK-250000-dual.hex
184 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_Dual_115200/Marlin.hex resources/firmware/MarlinUltimaker-HBK-115200-dual.hex
185 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_250000/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-250000.hex
186 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_115200/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-115200.hex
187 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_Dual_250000/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-250000-dual.hex
188 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_Dual_115200/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-115200-dual.hex
189 cp _Ultimaker2Marlin/Marlin/_Ultimaker2/Marlin.hex resources/firmware/MarlinUltimaker2.hex
190 cp _Ultimaker2Marlin/Marlin/_Ultimaker2Dual/Marlin.hex resources/firmware/MarlinUltimaker2-dual.hex
191 cp _Ultimaker2Marlin/Marlin/_Ultimaker2go/Marlin.hex resources/firmware/MarlinUltimaker2go.hex
192 cp _Ultimaker2Marlin/Marlin/_Ultimaker2extended/Marlin.hex resources/firmware/MarlinUltimaker2extended.hex
193 cp _Ultimaker2Marlin/Marlin/_Ultimaker2extendedDual/Marlin.hex resources/firmware/MarlinUltimaker2extended-dual.hex
194
195 #############################
196 # Darwin
197 #############################
198
199 if [ "$BUILD_TARGET" = "darwin" ]; then
200     TARGET_DIR=Cura-${BUILD_NAME}-MacOS
201
202         rm -rf scripts/darwin/build
203         rm -rf scripts/darwin/dist
204
205         python build_app.py py2app
206         rc=$?
207         if [[ $rc != 0 ]]; then
208                 echo "Cannot build app."
209                 exit 1
210         fi
211
212     #Add cura version file (should read the version from the bundle with pyobjc, but will figure that out later)
213     echo $BUILD_NAME > scripts/darwin/dist/Cura.app/Contents/Resources/version
214         rm -rf CuraEngine
215         gitClone ${CURA_ENGINE_REPO} CuraEngine
216     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
217         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
218     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
219         cp CuraEngine/build/CuraEngine scripts/darwin/dist/Cura.app/Contents/Resources/CuraEngine
220
221         cd scripts/darwin
222
223         # Install QuickLook plugin
224         mkdir -p dist/Cura.app/Contents/Library/QuickLook
225         cp -a STLQuickLook.qlgenerator dist/Cura.app/Contents/Library/QuickLook/
226
227         # Archive app
228         cd dist
229         $TAR cfp - Cura.app | gzip --best -c > ../../../${TARGET_DIR}.tar.gz
230         cd ..
231
232         # Create sparse image for distribution
233         hdiutil detach /Volumes/Cura\ -\ Lulzbot/
234         rm -rf Cura.dmg.sparseimage
235         hdiutil convert DmgTemplateCompressed.dmg -format UDSP -o Cura.dmg
236         hdiutil resize -size 500m Cura.dmg.sparseimage
237         hdiutil attach Cura.dmg.sparseimage
238         cp -a dist/Cura.app /Volumes/Cura\ -\ Lulzbot/Cura/
239         hdiutil detach /Volumes/Cura\ -\ Lulzbot
240         hdiutil convert Cura.dmg.sparseimage -format UDZO -imagekey zlib-level=9 -ov -o ../../${TARGET_DIR}.dmg
241         exit
242 fi
243
244 #############################
245 # FreeBSD part by CeDeROM
246 #############################
247
248 if [ "$BUILD_TARGET" = "freebsd" ]; then
249         export CXX="c++"
250         gitClone https://github.com/GreatFruitOmsk/Power Power
251         gitClone ${CURA_ENGINE_REPO} CuraEngine
252     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
253         gmake -j4 -C CuraEngine VERSION=${BUILD_NAME}
254     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
255         rm -rf scripts/freebsd/dist
256         mkdir -p scripts/freebsd/dist/share/cura
257         mkdir -p scripts/freebsd/dist/share/applications
258         mkdir -p scripts/freebsd/dist/bin
259         cp -a Cura scripts/freebsd/dist/share/cura/
260         cp -a resources scripts/freebsd/dist/share/cura/
261         cp -a plugins scripts/freebsd/dist/share/cura/
262         cp -a CuraEngine/build/CuraEngine scripts/freebsd/dist/share/cura/
263         cp scripts/freebsd/cura.py scripts/freebsd/dist/share/cura/
264         cp scripts/freebsd/cura.desktop scripts/freebsd/dist/share/applications/
265         cp scripts/freebsd/cura scripts/freebsd/dist/bin/
266         cp -a Power/power scripts/freebsd/dist/share/cura/
267         echo $BUILD_NAME > scripts/freebsd/dist/share/cura/Cura/version
268         #Create file list (pkg-plist)
269         cd scripts/freebsd/dist
270         find * -type f > ../pkg-plist
271         DIRLVL=20; while [ $DIRLVL -ge 0 ]; do
272                 DIRS=`find share/cura -type d -depth $DIRLVL`
273                 for DIR in $DIRS; do
274                         echo "@dirrm $DIR" >> ../pkg-plist
275                 done
276                 DIRLVL=`expr $DIRLVL - 1`
277         done
278         cd ..
279         # Create archive or package if root
280         if [ `whoami` == "root" ]; then
281             echo "Are you root? Use the Port Luke! :-)"
282         else
283             echo "You are not root, building simple package archive..."
284             pwd
285             $TAR czf ../../${TARGET_DIR}.tar.gz dist/**
286         fi
287         exit
288 fi
289
290 #############################
291 # Debian 32bit .deb
292 #############################
293
294 if [ "$BUILD_TARGET" = "debian_i386" ]; then
295     export CXX="g++ -m32"
296         gitClone https://github.com/GreatFruitOmsk/Power Power
297         gitClone ${CURA_ENGINE_REPO} CuraEngine
298     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
299         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
300     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
301         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
302         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
303         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
304         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
305         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
306         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
307         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
308         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
309         echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
310         cat scripts/linux/debian_control | sed "s/\[BUILD_NAME\]/${BUILD_NAME}/" | sed 's/\[ARCH\]/i386/' > scripts/linux/${BUILD_TARGET}/DEBIAN/control
311         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
312         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
313         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
314         cd scripts/linux
315         dpkg-deb -Zgzip --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${REVISION}-${GIT_HASH}_i386.deb
316         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
317         exit
318 fi
319
320 #############################
321 # Debian 64bit .deb
322 #############################
323
324 if [ "$BUILD_TARGET" = "debian_amd64" ]; then
325     export CXX="g++ -m64"
326         gitClone https://github.com/GreatFruitOmsk/Power Power
327         gitClone ${CURA_ENGINE_REPO} CuraEngine
328     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
329         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
330     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
331         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
332         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
333         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
334         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
335         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
336         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
337         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
338         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
339         echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
340         cat scripts/linux/debian_control | sed "s/\[BUILD_NAME\]/${BUILD_NAME}/" | sed 's/\[ARCH\]/amd64/' > scripts/linux/${BUILD_TARGET}/DEBIAN/control
341         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
342         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
343         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
344         cd scripts/linux
345         dpkg-deb -Zgzip --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${REVISION}-${GIT_HASH}_amd64.deb
346         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
347         exit
348 fi
349
350 #############################
351 # Debian armhf .deb
352 #############################
353
354 if [ "$BUILD_TARGET" = "debian_armhf" ]; then
355     export CXX="g++"
356         gitClone https://github.com/GreatFruitOmsk/Power Power
357         gitClone ${CURA_ENGINE_REPO} CuraEngine
358     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
359         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
360     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
361         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
362         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
363         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
364         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
365         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
366         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
367         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
368         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
369         echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
370         cat scripts/linux/debian_control | sed "s/\[BUILD_NAME\]/${BUILD_NAME}/" | sed 's/\[ARCH\]/armhf/' > scripts/linux/${BUILD_TARGET}/DEBIAN/control
371         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
372         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
373         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
374         cd scripts/linux
375         dpkg-deb --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${BUILD_TARGET}.deb
376         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
377         exit
378 fi
379
380 #############################
381 # Rest
382 #############################
383
384 #############################
385 # Download all needed files.
386 #############################
387
388 if [ $BUILD_TARGET = "win32" ]; then
389         #Get portable python for windows and extract it. (Linux and Mac need to install python themselfs)
390         downloadURL http://ftp.nluug.nl/languages/python/portablepython/v2.7/PortablePython_${WIN_PORTABLE_PY_VERSION}.exe
391         downloadURL http://sourceforge.net/projects/pyserial/files/pyserial/2.5/pyserial-2.5.win32.exe
392         downloadURL http://sourceforge.net/projects/pyopengl/files/PyOpenGL/3.0.1/PyOpenGL-3.0.1.win32.exe
393         downloadURL http://sourceforge.net/projects/numpy/files/NumPy/1.6.2/numpy-1.6.2-win32-superpack-python2.7.exe
394         downloadURL http://videocapture.sourceforge.net/VideoCapture-0.9-5.zip
395         #downloadURL http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20120927-git-13f0cd6-win32-static.7z
396         downloadURL http://sourceforge.net/projects/comtypes/files/comtypes/0.6.2/comtypes-0.6.2.win32.exe
397         downloadURL http://www.uwe-sieber.de/files/ejectmedia.zip
398         #Get the power module for python
399         gitClone https://github.com/GreatFruitOmsk/Power Power
400     if [ $? != 0 ]; then echo "Failed to clone Power"; exit 1; fi
401         gitClone ${CURA_ENGINE_REPO} CuraEngine
402     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
403 fi
404
405 #############################
406 # Build the packages
407 #############################
408 rm -rf ${TARGET_DIR}
409 mkdir -p ${TARGET_DIR}
410
411 rm -f log.txt
412 if [ $BUILD_TARGET = "win32" ]; then
413         if [ -z `which i686-w64-mingw32-g++` ]; then
414                 CXX=g++
415         else
416                 CXX=i686-w64-mingw32-g++
417         fi
418         
419         #For windows extract portable python to include it.
420         extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/App
421         extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/Lib/site-packages
422         extract pyserial-2.5.win32.exe PURELIB
423         extract PyOpenGL-3.0.1.win32.exe PURELIB
424         extract numpy-1.6.2-win32-superpack-python2.7.exe numpy-1.6.2-sse2.exe
425         extract numpy-1.6.2-sse2.exe PLATLIB
426         extract VideoCapture-0.9-5.zip VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd
427         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe
428         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/licenses
429         extract comtypes-0.6.2.win32.exe
430         extract ejectmedia.zip Win32
431
432         mkdir -p ${TARGET_DIR}/python
433         mkdir -p ${TARGET_DIR}/Cura/
434         mv \$_OUTDIR/App/* ${TARGET_DIR}/python
435         mv \$_OUTDIR/Lib/site-packages/wx* ${TARGET_DIR}/python/Lib/site-packages/
436         mv PURELIB/serial ${TARGET_DIR}/python/Lib
437         mv PURELIB/OpenGL ${TARGET_DIR}/python/Lib
438         mv PURELIB/comtypes ${TARGET_DIR}/python/Lib
439         mv PLATLIB/numpy ${TARGET_DIR}/python/Lib
440         mv Power/power ${TARGET_DIR}/python/Lib
441         mv VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd ${TARGET_DIR}/python/DLLs
442         #mv ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe ${TARGET_DIR}/Cura/
443         #mv ffmpeg-20120927-git-13f0cd6-win32-static/licenses ${TARGET_DIR}/Cura/ffmpeg-licenses/
444         mv Win32/EjectMedia.exe ${TARGET_DIR}/Cura/
445         cp -a scripts/win32/nsisPlugins/libgcc_s_dw2-1.dll ${TARGET_DIR}
446         cp -a scripts/win32/nsisPlugins/libstdc++-6.dll ${TARGET_DIR}
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}-${REVISION}-${GIT_HASH}.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