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