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