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