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