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