chiark / gitweb /
Renamed the build.sh to package.sh to better reflect what the script does.
[cura.git] / package.sh
1 #!/bin/bash
2
3 # This script is to build the SkeinPyPy package for Windows/Linux and OSx
4 # This script should run under Linux and OSx, as well as Windows with Cygwin.
5
6 #############################
7 # CONFIGURATION
8 #############################
9
10
11 ##Select the build target
12 BUILD_TARGET=${1:-win32}
13 #BUILD_TARGET=linux
14 #BUILD_TARGET=osx64
15
16 ##Do we need to create the final archive
17 ARCHIVE_FOR_DISTRIBUTION=1
18 ##Which version name are we appending to the final archive
19 BUILD_NAME=NewUI-Beta4
20 TARGET_DIR=${BUILD_TARGET}-SkeinPyPy-${BUILD_NAME}
21
22 ##Which versions of external programs to use
23 PYPY_VERSION=c-jit-latest
24 WIN_PORTABLE_PY_VERSION=2.7.2.1
25 WIN_PYSERIAL_VERSION=2.5
26
27 #############################
28 # Support functions
29 #############################
30 function checkTool
31 {
32         if [ -z `which $1` ]; then
33                 echo "The $1 command must be somewhere in your \$PATH."
34                 echo "Fix your \$PATH or install $2"
35                 exit 1
36         fi
37 }
38
39 #############################
40 # Actual build script
41 #############################
42
43 checkTool git "git: http://git-scm.com/"
44 checkTool curl "curl: http://curl.haxx.se/"
45 if [ $BUILD_TARGET = "win32" ]; then
46         #Check if we have 7zip, needed to extract and packup a bunch of packages for windows.
47         checkTool 7z "7zip: http://www.7-zip.org/"
48 fi
49 #For building under MacOS we need gnutar instead of tar
50 if [ -z `which gnutar` ]; then
51         TAR=tar
52 else
53         TAR=gnutar
54 fi
55
56 #############################
57 # Download all needed files.
58 #############################
59
60 if [ $BUILD_TARGET = "win32" ]; then
61         #Get portable python for windows and extract it. (Linux and Mac need to install python themselfs)
62         if [ ! -f "PortablePython_${WIN_PORTABLE_PY_VERSION}.exe" ]; then
63                 curl -L -O http://ftp.nluug.nl/languages/python/portablepython/v2.7/PortablePython_${WIN_PORTABLE_PY_VERSION}.exe
64         fi
65         if [ ! -f pyserial-${WIN_PYSERIAL_VERSION}.exe ]; then
66                 curl -L -O http://sourceforge.net/projects/pyserial/files/pyserial/${WIN_PYSERIAL_VERSION}/pyserial-${WIN_PYSERIAL_VERSION}.win32.exe/download
67                 mv download pyserial-${WIN_PYSERIAL_VERSION}.exe
68         fi
69         if [ ! -f PyOpenGL-3.0.1.win32.exe ]; then
70                 curl -L -O http://sourceforge.net/projects/pyopengl/files/PyOpenGL/3.0.1/PyOpenGL-3.0.1.win32.exe
71         fi
72         #Get pypy
73         if [ ! -f "pypy-${PYPY_VERSION}-win32.zip" ]; then
74         #       curl -L -O https://bitbucket.org/pypy/pypy/downloads/pypy-${PYPY_VERSION}-win32.zip
75                 curl -L -O http://buildbot.pypy.org/nightly/trunk/pypy-${PYPY_VERSION}-win32.zip
76         fi
77 else
78         if [ ! -f "pypy-${PYPY_VERSION}-${BUILD_TARGET}.tar.bz2" ]; then
79         #       curl -L -O https://bitbucket.org/pypy/pypy/downloads/pypy-${PYPY_VERSION}-${BUILD_TARGET}.tar.bz2
80                 curl -L -O http://buildbot.pypy.org/nightly/trunk/pypy-${PYPY_VERSION}-${BUILD_TARGET}.tar.bz2
81         fi
82 fi
83
84 #Get our own version of Printrun
85 if [ ! -d "Printrun" ]; then
86   git clone git://github.com/daid/Printrun.git
87 else
88   echo "Updating Printrun"
89   cd Printrun
90   git pull
91   cd ..
92 fi
93
94 #############################
95 # Build the packages
96 #############################
97 rm -rf ${TARGET_DIR}
98 mkdir -p ${TARGET_DIR}
99
100 if [ $BUILD_TARGET = "win32" ]; then
101         #For windows extract portable python to include it.
102         7z x PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/App
103         7z x PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/Lib/site-packages
104         7z x pyserial-${WIN_PYSERIAL_VERSION}.exe PURELIB
105         7z x PyOpenGL-3.0.1.win32.exe PURELIB
106
107         mkdir -p ${TARGET_DIR}/python
108         mv \$_OUTDIR/App/* ${TARGET_DIR}/python
109         mv \$_OUTDIR/Lib/site-packages/wx* ${TARGET_DIR}/python/Lib/site-packages/
110         mv PURELIB/serial ${TARGET_DIR}/python/Lib
111         mv PURELIB/OpenGL ${TARGET_DIR}/python/Lib
112         rm -rf \$_OUTDIR
113         rm -rf PURELIB
114         
115         #Clean up portable python a bit, to keep the package size down.
116         rm -rf ${TARGET_DIR}/python/PyScripter.*
117         rm -rf ${TARGET_DIR}/python/Doc
118         rm -rf ${TARGET_DIR}/python/locale
119         rm -rf ${TARGET_DIR}/python/tcl
120         rm -rf ${TARGET_DIR}/python/Lib/test
121         rm -rf ${TARGET_DIR}/python/Lib/distutils
122         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/tools
123         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/locale
124         #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.
125         rm -rf ${TARGET_DIR}/python/Lib/OpenGL/DLLS/gle*
126 fi
127
128 #Extract pypy
129 if [ $BUILD_TARGET = "win32" ]; then
130         7z x pypy-${PYPY_VERSION}-win32.zip -o${TARGET_DIR}
131         mv ${TARGET_DIR}/pypy-${PYPY_VERSION}* ${TARGET_DIR}/pypy
132 else
133         cd ${TARGET_DIR}; $TAR -xjf ../pypy-${PYPY_VERSION}-${BUILD_TARGET}.tar.bz2; cd ..
134         mv ${TARGET_DIR}/pypy-*-${BUILD_TARGET} ${TARGET_DIR}/pypy
135 fi
136 #Cleanup pypy
137 rm -rf ${TARGET_DIR}/pypy/lib-python/2.7/test
138
139 #add Skeinforge
140 cp -a SkeinPyPy_NewUI ${TARGET_DIR}/SkeinPyPy
141
142 #add printrun
143 cp -a Printrun ${TARGET_DIR}/Printrun
144 rm -rf ${TARGET_DIR}/Printrun/.git*
145
146 #add script files
147 if [ $BUILD_TARGET = "win32" ]; then
148     cp -a scripts/${BUILD_TARGET}/*.bat $TARGET_DIR/
149 else
150     cp -a scripts/${BUILD_TARGET}/*.sh $TARGET_DIR/
151 fi
152
153 #add readme file
154 cp README ${TARGET_DIR}/README.txt
155
156 #package the result
157 if (( ${ARCHIVE_FOR_DISTRIBUTION} )); then
158         if [ $BUILD_TARGET = "win32" ]; then
159                 rm ${TARGET_DIR}.zip
160                 cd ${TARGET_DIR}
161                 7z a ../${TARGET_DIR}.zip *
162                 cd ..
163         else
164                 echo "Archiving to ${TARGET_DIR}.tar.gz"
165                 $TAR cfp - ${TARGET_DIR} | gzip --best -c > ${TARGET_DIR}.tar.gz
166         fi
167 else
168         echo "Installed into ${TARGET_DIR}"
169 fi
170