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