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