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