chiark / gitweb /
Merge tag '15.01-RC10' into upstream
[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-RC10
26 TARGET_DIR=Cura-${BUILD_NAME}-${BUILD_TARGET}
27
28 ##Revision
29 export REVISION=1.19
30
31 ##Git commit
32 GIT_HASH=$(git rev-parse --short=4 HEAD)
33
34 ##Which versions of external programs to use
35 WIN_PORTABLE_PY_VERSION=2.7.2.1
36
37 ##Which CuraEngine to use
38 if [ -z ${CURA_ENGINE_REPO:-} ] ; then
39         CURA_ENGINE_REPO="git@github.com:alephobjects/CuraEngine.git"
40 fi
41
42 #############################
43 # Support functions
44 #############################
45 function checkTool
46 {
47         if [ -z "`which $1`" ]; then
48                 echo "The $1 command must be somewhere in your \$PATH."
49                 echo "Fix your \$PATH or install $2"
50                 exit 1
51         fi
52 }
53
54 function downloadURL
55 {
56         filename=`basename "$1"`
57         echo "Checking for $filename"
58         if [ ! -f "$filename" ]; then
59                 echo "Downloading $1"
60                 curl -L -O "$1"
61                 if [ $? != 0 ]; then
62                         echo "Failed to download $1"
63                         exit 1
64                 fi
65         fi
66 }
67
68 function extract
69 {
70         echo "Extracting $*"
71         echo "7z x -y $*" >> log.txt
72         7z x -y $* >> log.txt
73         if [ $? != 0 ]; then
74         echo "Failed to extract $*"
75         exit 1
76         fi
77 }
78
79 function gitClone
80 {
81         echo "Cloning $1 into $2"
82         if [ -d $2 ]; then
83                 cd $2
84                 git clean -dfx
85                 git reset --hard
86                 git pull
87                 cd -
88         else
89                 git clone $1 $2
90         fi
91 }
92
93 #############################
94 # Actual build script
95 #############################
96 if [ "$BUILD_TARGET" = "none" ]; then
97         echo "You need to specify a build target with:"
98         echo "$0 win32"
99         echo "$0 debian_i386"
100         echo "$0 debian_amd64"
101         echo "$0 debian_armhf"
102         echo "$0 darwin"
103         echo "$0 freebsd"
104         echo "$0 fedora                         # current   system"
105         echo "$0 fedora \"mock_config_file\" ...  # different system(s)"
106         exit 0
107 fi
108
109 if [ -z `which make` ]; then
110         MAKE=mingw32-make
111 else
112         MAKE=make
113 fi
114
115 # Change working directory to the directory the script is in
116 # http://stackoverflow.com/a/246128
117 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
118 cd "$SCRIPT_DIR"
119
120 checkTool git "git: http://git-scm.com/"
121 checkTool curl "curl: http://curl.haxx.se/"
122 if [ $BUILD_TARGET = "win32" ]; then
123         checkTool avr-gcc "avr-gcc: http://winavr.sourceforge.net/ "
124         #Check if we have 7zip, needed to extract and packup a bunch of packages for windows.
125         checkTool 7z "7zip: http://www.7-zip.org/"
126         checkTool $MAKE "mingw: http://www.mingw.org/"
127 fi
128 #For building under MacOS we need gnutar instead of tar
129 if [ -z `which gnutar` ]; then
130         TAR=tar
131 else
132         TAR=gnutar
133 fi
134
135 #############################
136 # Build the required firmwares
137 #############################
138
139 if [ -d "C:/arduino-1.0.3" ]; then
140         ARDUINO_PATH=C:/arduino-1.0.3
141         ARDUINO_VERSION=103
142 elif [ -d "/Applications/Arduino.app/Contents/Resources/Java" ]; then
143         ARDUINO_PATH=/Applications/Arduino.app/Contents/Resources/Java
144         ARDUINO_VERSION=105
145 else
146         ARDUINO_PATH=/usr/share/arduino
147         ARDUINO_VERSION=105
148 fi
149
150 if [ ! -d "$ARDUINO_PATH" ]; then
151   echo "Arduino path '$ARDUINO_PATH' doesn't exist"
152   exit 1
153 fi
154
155
156 #Build the Ultimaker Original firmwares.
157 gitClone git@github.com:Ultimaker/Marlin.git _UltimakerMarlin
158 cd _UltimakerMarlin/Marlin
159 git checkout Marlin_v1
160 git pull
161 $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"
162 $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"
163 $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"
164 $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"
165 git checkout Marlin_UM_HeatedBedUpgrade
166 git pull
167 $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"
168 $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"
169 $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"
170 $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"
171 git checkout Marlin_UM_Original_Plus
172 git pull
173 $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"
174 $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"
175 $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"
176 $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"
177 cd -
178
179 gitClone git@github.com:Ultimaker/Ultimaker2Marlin.git _Ultimaker2Marlin
180 cd _Ultimaker2Marlin/Marlin
181 git checkout master
182 git pull
183 $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"
184 $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"
185 git checkout UM2go
186 git pull
187 $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"
188 git checkout UM2extended
189 git pull
190 $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"
191 $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"
192 cd -
193
194 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_250000/Marlin.hex resources/firmware/MarlinUltimaker-250000.hex
195 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_115200/Marlin.hex resources/firmware/MarlinUltimaker-115200.hex
196 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Dual_250000/Marlin.hex resources/firmware/MarlinUltimaker-250000-dual.hex
197 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Dual_115200/Marlin.hex resources/firmware/MarlinUltimaker-115200-dual.hex
198 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_250000/Marlin.hex resources/firmware/MarlinUltimaker-HBK-250000.hex
199 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_115200/Marlin.hex resources/firmware/MarlinUltimaker-HBK-115200.hex
200 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_Dual_250000/Marlin.hex resources/firmware/MarlinUltimaker-HBK-250000-dual.hex
201 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_HBK_Dual_115200/Marlin.hex resources/firmware/MarlinUltimaker-HBK-115200-dual.hex
202 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_250000/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-250000.hex
203 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_115200/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-115200.hex
204 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_Dual_250000/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-250000-dual.hex
205 cp _UltimakerMarlin/Marlin/_UltimakerMarlin_Plus_Dual_115200/Marlin.hex resources/firmware/MarlinUltimaker-UMOP-115200-dual.hex
206 cp _Ultimaker2Marlin/Marlin/_Ultimaker2/Marlin.hex resources/firmware/MarlinUltimaker2.hex
207 cp _Ultimaker2Marlin/Marlin/_Ultimaker2Dual/Marlin.hex resources/firmware/MarlinUltimaker2-dual.hex
208 cp _Ultimaker2Marlin/Marlin/_Ultimaker2go/Marlin.hex resources/firmware/MarlinUltimaker2go.hex
209 cp _Ultimaker2Marlin/Marlin/_Ultimaker2extended/Marlin.hex resources/firmware/MarlinUltimaker2extended.hex
210 cp _Ultimaker2Marlin/Marlin/_Ultimaker2extendedDual/Marlin.hex resources/firmware/MarlinUltimaker2extended-dual.hex
211
212 #############################
213 # Darwin
214 #############################
215
216 if [ "$BUILD_TARGET" = "darwin" ]; then
217     TARGET_DIR=Cura-${BUILD_NAME}-MacOS
218
219         rm -rf scripts/darwin/build
220         rm -rf scripts/darwin/dist
221
222         python build_app.py py2app
223         rc=$?
224         if [[ $rc != 0 ]]; then
225                 echo "Cannot build app."
226                 exit 1
227         fi
228
229     #Add cura version file (should read the version from the bundle with pyobjc, but will figure that out later)
230     echo $BUILD_NAME > scripts/darwin/dist/Cura.app/Contents/Resources/version
231         rm -rf CuraEngine
232         gitClone ${CURA_ENGINE_REPO} CuraEngine
233     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
234         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
235     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
236         cp CuraEngine/build/CuraEngine scripts/darwin/dist/Cura.app/Contents/Resources/CuraEngine
237
238         cd scripts/darwin
239
240         # Install QuickLook plugin
241         mkdir -p dist/Cura.app/Contents/Library/QuickLook
242         cp -a STLQuickLook.qlgenerator dist/Cura.app/Contents/Library/QuickLook/
243
244         # Archive app
245         cd dist
246         $TAR cfp - Cura.app | gzip --best -c > ../../../${TARGET_DIR}.tar.gz
247         cd ..
248
249         # Create sparse image for distribution
250         hdiutil detach /Volumes/Cura\ -\ Lulzbot/ || true
251         rm -rf Cura.dmg.sparseimage
252         hdiutil convert DmgTemplateCompressed.dmg -format UDSP -o Cura.dmg
253         hdiutil resize -size 500m Cura.dmg.sparseimage
254         hdiutil attach Cura.dmg.sparseimage
255         cp -a dist/Cura.app /Volumes/Cura\ -\ Lulzbot/Cura/
256         hdiutil detach /Volumes/Cura\ -\ Lulzbot
257         hdiutil convert Cura.dmg.sparseimage -format UDZO -imagekey zlib-level=9 -ov -o ../../${TARGET_DIR}.dmg
258         exit
259 fi
260
261 #############################
262 # FreeBSD part by CeDeROM
263 #############################
264
265 if [ "$BUILD_TARGET" = "freebsd" ]; then
266         export CXX="c++"
267         gitClone https://github.com/GreatFruitOmsk/Power Power
268         gitClone ${CURA_ENGINE_REPO} CuraEngine
269     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
270         gmake -j4 -C CuraEngine VERSION=${BUILD_NAME}
271     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
272         rm -rf scripts/freebsd/dist
273         mkdir -p scripts/freebsd/dist/share/cura
274         mkdir -p scripts/freebsd/dist/share/applications
275         mkdir -p scripts/freebsd/dist/bin
276         cp -a Cura scripts/freebsd/dist/share/cura/
277         cp -a resources scripts/freebsd/dist/share/cura/
278         cp -a plugins scripts/freebsd/dist/share/cura/
279         cp -a CuraEngine/build/CuraEngine scripts/freebsd/dist/share/cura/
280         cp scripts/freebsd/cura.py scripts/freebsd/dist/share/cura/
281         cp scripts/freebsd/cura.desktop scripts/freebsd/dist/share/applications/
282         cp scripts/freebsd/cura scripts/freebsd/dist/bin/
283         cp -a Power/power scripts/freebsd/dist/share/cura/
284         echo $BUILD_NAME > scripts/freebsd/dist/share/cura/Cura/version
285         #Create file list (pkg-plist)
286         cd scripts/freebsd/dist
287         find * -type f > ../pkg-plist
288         DIRLVL=20; while [ $DIRLVL -ge 0 ]; do
289                 DIRS=`find share/cura -type d -depth $DIRLVL`
290                 for DIR in $DIRS; do
291                         echo "@dirrm $DIR" >> ../pkg-plist
292                 done
293                 DIRLVL=`expr $DIRLVL - 1`
294         done
295         cd ..
296         # Create archive or package if root
297         if [ `whoami` == "root" ]; then
298             echo "Are you root? Use the Port Luke! :-)"
299         else
300             echo "You are not root, building simple package archive..."
301             pwd
302             $TAR czf ../../${TARGET_DIR}.tar.gz dist/**
303         fi
304         exit
305 fi
306
307 #############################
308 # Debian 32bit .deb
309 #############################
310
311 if [ "$BUILD_TARGET" = "debian_i386" ]; then
312     export CXX="g++ -m32"
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         cat scripts/linux/debian_control | sed "s/\[BUILD_NAME\]/${BUILD_NAME}/" | sed 's/\[ARCH\]/i386/' > scripts/linux/${BUILD_TARGET}/DEBIAN/control
328         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
329         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
330         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
331         cd scripts/linux
332         dpkg-deb -Zgzip --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${REVISION}-${GIT_HASH}_i386.deb
333         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
334         exit
335 fi
336
337 #############################
338 # Debian 64bit .deb
339 #############################
340
341 if [ "$BUILD_TARGET" = "debian_amd64" ]; then
342     export CXX="g++ -m64"
343         gitClone https://github.com/GreatFruitOmsk/Power Power
344         gitClone ${CURA_ENGINE_REPO} CuraEngine
345     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
346         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
347     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
348         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
349         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
350         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
351         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
352         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
353         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
354         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
355         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
356         echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
357         cat scripts/linux/debian_control | sed "s/\[BUILD_NAME\]/${BUILD_NAME}/" | sed 's/\[ARCH\]/amd64/' > scripts/linux/${BUILD_TARGET}/DEBIAN/control
358         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
359         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
360         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
361         cd scripts/linux
362         dpkg-deb -Zgzip --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${REVISION}-${GIT_HASH}_amd64.deb
363         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
364         exit
365 fi
366
367 #############################
368 # Debian armhf .deb
369 #############################
370
371 if [ "$BUILD_TARGET" = "debian_armhf" ]; then
372     export CXX="g++"
373         gitClone https://github.com/GreatFruitOmsk/Power Power
374         gitClone ${CURA_ENGINE_REPO} CuraEngine
375     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
376         $MAKE -C CuraEngine VERSION=${BUILD_NAME}
377     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
378         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
379         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
380         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
381         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
382         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
383         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
384         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
385         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
386         echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
387         cat scripts/linux/debian_control | sed "s/\[BUILD_NAME\]/${BUILD_NAME}/" | sed 's/\[ARCH\]/armhf/' > scripts/linux/${BUILD_TARGET}/DEBIAN/control
388         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
389         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
390         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
391         cd scripts/linux
392         dpkg-deb --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${BUILD_TARGET}.deb
393         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
394         exit
395 fi
396
397 #############################
398 # Fedora Generic
399 #############################
400
401 function sanitiseVersion() {
402   local _version="$1"
403   echo "${_version//-/.}"
404 }
405
406 function fedoraCreateSRPM() {
407   local _curaName="$1"
408   local _version="$(sanitiseVersion "$2")"
409   local _srcSpecFile="$3"
410   local _srcSpecFileRelease="$4"
411   local _dstSrpmDir="$5"
412
413   local _dstTarSources="$HOME/rpmbuild/SOURCES/$_curaName-$_version.tar.gz"
414   local _dstSpec="$HOME/rpmbuild/SPECS/$_curaName-$_version.spec"
415
416   local _namePower="Power"
417   local _nameCuraEngine="CuraEngine"
418
419   gitClone "https://github.com/GreatFruitOmsk/Power" "$_namePower"
420   gitClone "$CURA_ENGINE_REPO" "$_nameCuraEngine"
421
422   cd "$_namePower"
423   local _gitPower="$(git rev-list -1 HEAD)"
424   cd -
425
426   cd "$_nameCuraEngine"
427   local _gitCuraEngine="$(git rev-list -1 HEAD)"
428   cd -
429
430   local _gitCura="$(git rev-list -1 HEAD)"
431
432   rpmdev-setuptree
433
434   rm -fv "$_dstTarSources"
435   tar \
436     --exclude-vcs \
437     --transform "s#^#$_curaName-$_version/#" \
438     -zcvf "$_dstTarSources" \
439       "$_nameCuraEngine" \
440       "$_namePower" \
441       Cura \
442       resources \
443       plugins \
444       scripts/linux/cura.py \
445       scripts/linux/fedora/usr
446
447   sed \
448     -e "s#__curaName__#$_curaName#" \
449     -e "s#__version__#$_version#" \
450     -e "s#__gitCura__#$_gitCura#" \
451     -e "s#__gitCuraEngine__#$_gitCuraEngine#" \
452     -e "s#__gitPower__#$_gitPower#" \
453     -e "s#__basedir__#scripts/linux/fedora#" \
454     "$_srcSpecFile" \
455     > "$_dstSpec"
456
457   rpmbuild -bs "$_dstSpec"
458
459   mkdir -pv "$_dstSrpmDir"
460   cp -v \
461     "$HOME/rpmbuild/SRPMS/$_curaName-$_version-$_srcSpecFileRelease.src.rpm" \
462     "$_dstSrpmDir"
463 }
464
465 function buildFedora() {
466   local _nameForRpm="Cura"
467   local _versionForRpm="$(sanitiseVersion "$BUILD_NAME")"
468
469   #
470   # SRPM
471   #
472
473   local _srcSpecFile="scripts/linux/fedora/rpm.spec"
474   local _srcSpecFileRelease="$(rpmspec -P "$_srcSpecFile" | grep -E '^Release:'|awk '{print $NF}')"
475   local _dstSrpmDir="scripts/linux/fedora/SRPMS"
476
477   fedoraCreateSRPM \
478     "$_nameForRpm" \
479     "$_versionForRpm" \
480     "$_srcSpecFile" \
481     "$_srcSpecFileRelease" \
482     "$_dstSrpmDir"
483
484   #
485   # RPM
486   #
487
488   local _srpmFile="$_dstSrpmDir/$_nameForRpm-$_versionForRpm-$_srcSpecFileRelease.src.rpm"
489   local _dstRpmDir="scripts/linux/fedora/RPMS"
490
491   while [ $# -ne 0 ]; do
492     local _mockRelease="$(basename "${1%\.cfg}")"
493     local _mockReleaseArg=""
494     if [ -n "$_mockRelease" ]; then
495       _mockReleaseArg="-r $_mockRelease"
496     fi
497
498     mkdir -pv "$_dstRpmDir/$_mockRelease"
499     mock \
500       $_mockReleaseArg \
501       --resultdir="$_dstRpmDir/$_mockRelease" \
502       "$_srpmFile"
503
504     shift 1
505   done
506 }
507
508 #############################
509 # Fedora RPMs
510 #############################
511
512 if [ "$BUILD_TARGET" = "fedora" ]; then
513   shift 1 # skip "fedora" arg
514
515   if [ $# -eq 0 ]; then
516     "$0" "$BUILD_TARGET" ""
517   else
518     buildFedora "${@}"
519   fi
520
521   exit
522 fi
523
524 #############################
525 # Rest
526 #############################
527
528 #############################
529 # Download all needed files.
530 #############################
531
532 if [ $BUILD_TARGET = "win32" ]; then
533         #Get portable python for windows and extract it. (Linux and Mac need to install python themselfs)
534         downloadURL http://ftp.nluug.nl/languages/python/portablepython/v2.7/PortablePython_${WIN_PORTABLE_PY_VERSION}.exe
535         downloadURL http://sourceforge.net/projects/pyserial/files/pyserial/2.5/pyserial-2.5.win32.exe
536         downloadURL http://sourceforge.net/projects/pyopengl/files/PyOpenGL/3.0.1/PyOpenGL-3.0.1.win32.exe
537         downloadURL http://sourceforge.net/projects/numpy/files/NumPy/1.6.2/numpy-1.6.2-win32-superpack-python2.7.exe
538         downloadURL http://videocapture.sourceforge.net/VideoCapture-0.9-5.zip
539         #downloadURL http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20120927-git-13f0cd6-win32-static.7z
540         downloadURL http://sourceforge.net/projects/comtypes/files/comtypes/0.6.2/comtypes-0.6.2.win32.exe
541         downloadURL http://www.uwe-sieber.de/files/ejectmedia.zip
542         #Get the power module for python
543         gitClone https://github.com/GreatFruitOmsk/Power Power
544     if [ $? != 0 ]; then echo "Failed to clone Power"; exit 1; fi
545         gitClone ${CURA_ENGINE_REPO} CuraEngine
546     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
547 fi
548
549 #############################
550 # Build the packages
551 #############################
552 rm -rf ${TARGET_DIR}
553 mkdir -p ${TARGET_DIR}
554
555 rm -f log.txt
556 if [ $BUILD_TARGET = "win32" ]; then
557         if [ -z `which i686-w64-mingw32-g++` ]; then
558                 CXX=g++
559         else
560                 CXX=i686-w64-mingw32-g++
561         fi
562         
563         #For windows extract portable python to include it.
564         extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/App
565         extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/Lib/site-packages
566         extract pyserial-2.5.win32.exe PURELIB
567         extract PyOpenGL-3.0.1.win32.exe PURELIB
568         extract numpy-1.6.2-win32-superpack-python2.7.exe numpy-1.6.2-sse2.exe
569         extract numpy-1.6.2-sse2.exe PLATLIB
570         extract VideoCapture-0.9-5.zip VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd
571         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe
572         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/licenses
573         extract comtypes-0.6.2.win32.exe
574         extract ejectmedia.zip Win32
575
576         mkdir -p ${TARGET_DIR}/python
577         mkdir -p ${TARGET_DIR}/Cura/
578         mv \$_OUTDIR/App/* ${TARGET_DIR}/python
579         mv \$_OUTDIR/Lib/site-packages/wx* ${TARGET_DIR}/python/Lib/site-packages/
580         mv PURELIB/serial ${TARGET_DIR}/python/Lib
581         mv PURELIB/OpenGL ${TARGET_DIR}/python/Lib
582         mv PURELIB/comtypes ${TARGET_DIR}/python/Lib
583         mv PLATLIB/numpy ${TARGET_DIR}/python/Lib
584         mv Power/power ${TARGET_DIR}/python/Lib
585         mv VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd ${TARGET_DIR}/python/DLLs
586         #mv ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe ${TARGET_DIR}/Cura/
587         #mv ffmpeg-20120927-git-13f0cd6-win32-static/licenses ${TARGET_DIR}/Cura/ffmpeg-licenses/
588         mv Win32/EjectMedia.exe ${TARGET_DIR}/Cura/
589         cp -a scripts/win32/nsisPlugins/libgcc_s_dw2-1.dll ${TARGET_DIR}
590         cp -a scripts/win32/nsisPlugins/libstdc++-6.dll ${TARGET_DIR}
591         
592         rm -rf Power/
593         rm -rf \$_OUTDIR
594         rm -rf PURELIB
595         rm -rf PLATLIB
596         rm -rf VideoCapture-0.9-5
597         rm -rf numpy-1.6.2-sse2.exe
598         #rm -rf ffmpeg-20120927-git-13f0cd6-win32-static
599
600         #Clean up portable python a bit, to keep the package size down.
601         rm -rf ${TARGET_DIR}/python/PyScripter.*
602         rm -rf ${TARGET_DIR}/python/Doc
603         rm -rf ${TARGET_DIR}/python/locale
604         rm -rf ${TARGET_DIR}/python/tcl
605         rm -rf ${TARGET_DIR}/python/Lib/test
606         rm -rf ${TARGET_DIR}/python/Lib/distutils
607         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/tools
608         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/locale
609         #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.
610         rm -rf ${TARGET_DIR}/python/Lib/OpenGL/DLLS/gle*
611
612     #Build the C++ engine
613         $MAKE -C CuraEngine VERSION=${BUILD_NAME} OS=Windows_NT CXX=${CXX}
614     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
615 fi
616
617 #add Cura
618 mkdir -p ${TARGET_DIR}/Cura ${TARGET_DIR}/resources ${TARGET_DIR}/plugins
619 cp -a Cura/* ${TARGET_DIR}/Cura
620 cp -a resources/* ${TARGET_DIR}/resources
621 cp -a plugins/* ${TARGET_DIR}/plugins
622 #Add cura version file
623 echo $BUILD_NAME > ${TARGET_DIR}/Cura/version
624
625 #add script files
626 if [ $BUILD_TARGET = "win32" ]; then
627     cp -a scripts/${BUILD_TARGET}/*.bat $TARGET_DIR/
628     cp CuraEngine/build/CuraEngine.exe $TARGET_DIR
629         cp /usr/lib/gcc/i686-w64-mingw32/4.8/libgcc_s_sjlj-1.dll $TARGET_DIR
630     cp /usr/i686-w64-mingw32/lib/libwinpthread-1.dll $TARGET_DIR
631     cp /usr/lib/gcc/i686-w64-mingw32/4.8/libstdc++-6.dll $TARGET_DIR
632 fi
633
634 #package the result
635 if (( ${ARCHIVE_FOR_DISTRIBUTION} )); then
636         if [ $BUILD_TARGET = "win32" ]; then
637                 #rm ${TARGET_DIR}.zip
638                 #cd ${TARGET_DIR}
639                 #7z a ../${TARGET_DIR}.zip *
640                 #cd ..
641
642                 if [ ! -z `which wine` ]; then
643                         #if we have wine, try to run our nsis script.
644                         rm -rf scripts/win32/dist
645                         ln -sf `pwd`/${TARGET_DIR} scripts/win32/dist
646                         wine ~/.wine/drive_c/Program\ Files\ \(x86\)/NSIS/makensis.exe /DVERSION=${BUILD_NAME} scripts/win32/installer.nsi
647             if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
648                         mv scripts/win32/Cura_${BUILD_NAME}-${REVISION}-${GIT_HASH}.exe ./
649                 fi
650                 if [ -f '/c/Program Files (x86)/NSIS/makensis.exe' ]; then
651                         rm -rf scripts/win32/dist
652                         mv "`pwd`/${TARGET_DIR}" scripts/win32/dist
653                         '/c/Program Files (x86)/NSIS/makensis.exe' -DVERSION=${BUILD_NAME} 'scripts/win32/installer.nsi' >> log.txt
654             if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
655                         mv scripts/win32/Cura_${BUILD_NAME}.exe ./
656                 fi
657         else
658                 echo "Archiving to ${TARGET_DIR}.tar.gz"
659                 $TAR cfp - ${TARGET_DIR} | gzip --best -c > ${TARGET_DIR}.tar.gz
660         fi
661 else
662         echo "Installed into ${TARGET_DIR}"
663 fi