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