source: orange/install-scripts/mac/build-osx-app-template.sh @ 11634:7db03b53b160

Revision 11634:7db03b53b160, 7.7 KB checked in by Ales Erjavec <ales.erjavec@…>, 9 months ago (diff)

Renamed the osx application template build script.

Line 
1#!/bin/bash -e
2#
3# Create (build) an Orange application bundle template
4#
5# example usage:
6#
7#   $ build-osx-app-template.sh $HOME/Orange.app
8#
9
10
11SCRIPT_DIR_NAME=$(dirname "$0")
12
13BUNDLE_LITE=$SCRIPT_DIR_NAME/bundle-lite/Orange.app
14
15APP=$1
16
17if [[ ! $APP ]]; then
18    echo "Applicatition path must be specified"
19    echo "Usage: ./build-osx-app-template.sh ApplicationTemplate"
20    exit 1
21fi
22
23
24PYTHON=$APP/Contents/MacOS/python
25EASY_INSTALL=$APP/Contents/MacOS/easy_install
26PIP=$APP/Contents/MacOS/pip
27
28export MACOSX_DEPLOYMENT_TARGET=10.5
29
30SDK=/Developer/SDKs/MacOSX$MACOSX_DEPLOYMENT_TARGET.sdk
31
32function create_template {
33    # Create a minimal .app template with the expected dir structure
34    # Info.plist and icons.
35
36    mkdir -p "$APP"
37    mkdir -p "$APP"/Contents/MacOS
38    mkdir -p "$APP"/Contents/Resources
39
40    # Copy icons and Info.plist
41    cp "$BUNDLE_LITE"/Contents/Resources/* "$APP"/Contents/Resources
42    cp "$BUNDLE_LITE"/Contents/Info.plist "$APP"/Contents/Info.plist
43
44    #cp $BUNDLE_LITE/Contents/PkgInfo $APP/Contents/PkgInfo
45
46    cat <<-'EOF' > "$APP"/Contents/MacOS/ENV
47    # Create an environment for running python from the bundle
48    # Should be run as "source ENV"
49
50    BUNDLE_DIR=`dirname "$0"`/../
51    BUNDLE_DIR=`perl -MCwd=realpath -e 'print realpath($ARGV[0])' "$BUNDLE_DIR"`/
52    FRAMEWORKS_DIR="$BUNDLE_DIR"Frameworks/
53    RESOURCES_DIR="$BUNDLE_DIR"Resources/
54
55    PYVERSION="2.7"
56
57    PYTHONEXECUTABLE="$FRAMEWORKS_DIR"Python.framework/Resources/Python.app/Contents/MacOS/Python
58    PYTHONHOME="$FRAMEWORKS_DIR"Python.framework/Versions/"$PYVERSION"/
59
60    DYLD_FRAMEWORK_PATH="$FRAMEWORKS_DIR"${DYLD_FRAMEWORK_PATH:+:$DYLD_FRAMEWORK_PATH}
61
62    export PYTHONEXECUTABLE
63    export PYTHONHOME
64
65    export DYLD_FRAMEWORK_PATH
66
67    # Some non framework libraries are put in $FRAMEWORKS_DIR by machlib standalone
68    export DYLD_LIBRARY_PATH="$FRAMEWORKS_DIR"${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}
69EOF
70
71}
72
73function install_python() {
74    download_and_extract http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz
75
76    cd Python-2.7.5
77
78    # _hashlib import fails with  Symbol not found: _EVP_MD_CTX_md
79    # The 10.5 sdk's libssl does not define it (even though it is v 0.9.7)
80    patch setup.py -i - <<-'EOF'
81        834c834
82        <         min_openssl_ver = 0x00907000
83        ---
84        >         min_openssl_ver = 0x00908000
85EOF
86
87    ./configure --enable-framework="$APP"/Contents/Frameworks \
88                --prefix="$APP"/Contents/Resources \
89                --with-universal-archs=intel \
90                --enable-universalsdk="$SDK"
91
92    make
93    make install
94    cd ..
95
96    # PythonAppStart will be used for starting the application GUI.
97    # This needs to be symlinked here for Desktop services used the app's
98    # Info.plist and not the contained Python.app's
99    ln -fs ../Frameworks/Python.framework/Resources/Python.app/Contents/MacOS/Python "$APP"/Contents/MacOS/PythonAppStart
100    ln -fs ../Frameworks/Python.framework/Resources/Python.app "$APP"/Contents/Resources/Python.app
101
102    cat <<-'EOF' > "$APP"/Contents/MacOS/python
103        #!/bin/bash
104
105        DIRNAME=$(dirname "$0")
106
107        # Set the proper env variables
108        source "$DIRNAME"/ENV
109
110        exec -a "$0" "$PYTHONEXECUTABLE" "$@"
111EOF
112
113    chmod +x "$APP"/Contents/MacOS/python
114
115    $PYTHON -c"import sys"
116
117}
118
119function install_pip() {
120    download_and_extract "https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz"
121    cd pip-1.3.1
122
123    $PYTHON setup.py install
124    create_shell_start_script pip
125
126    $PIP --version
127}
128
129function install_distribute() {
130    download_and_extract "https://pypi.python.org/packages/source/d/distribute/distribute-0.6.45.tar.gz"
131    cd distribute-0.6.45
132
133    $PYTHON setup.py install
134    create_shell_start_script easy_install
135
136    $EASY_INSTALL --version
137}
138
139function install_ipython {
140    # install with easy_install (does not work with pip)
141    $EASY_INSTALL ipython
142    create_shell_start_script ipython
143}
144
145function install_qt4 {
146    download_and_extract "http://download.qt-project.org/archive/qt/4.7/qt-everywhere-opensource-src-4.7.4.tar.gz"
147    cd qt-everywhere-opensource-src-4.7.4
148
149    yes yes | ./configure -prefix "$APP"/Contents/Resources/Qt4 \
150                -libdir "$APP"/Contents/Frameworks \
151                -framework \
152                -release \
153                -opensource \
154                -no-qt3support \
155                -arch x86 -arch x86_64 \
156                -no-sql-psql \
157                -no-sql-ibase \
158                -no-sql-mysql \
159                -no-sql-odbc \
160                -no-sql-sqlite \
161                -no-sql-sqlite2 \
162                -nomake examples \
163                -nomake demos \
164                -nomake docs \
165                -nomake translations \
166                -sdk "$SDK"
167
168    make -j 4
169    make install
170
171    # Register plugins.
172    cat <<-EOF > "$APP"/Contents/Resources/qt.conf
173        [Paths]
174        Plugins = Resources/Qt4/plugins
175EOF
176
177    # In case the Python executable is invokes directly we also want it to
178    # find the plugins.
179    cat <<-EOF > "$APP"/Contents/Frameworks/Python.framework/Resources/Python.app/Contents/Resources/qt.conf
180        [Paths]
181        Plugins = ../../../../../Resources/Qt4/plugins
182EOF
183
184}
185
186function install_sip {
187    download_and_extract "http://sourceforge.net/projects/pyqt/files/sip/sip-4.14.6/sip-4.14.6.tar.gz"
188    cd sip-4.14.6
189
190    $PYTHON configure.py  --arch i386 --arch x86_64 --sdk "$SDK"
191
192    make
193    make install
194
195    $PYTHON -c"import sip"
196
197}
198
199function install_pyqt4 {
200    download_and_extract "http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.10.1/PyQt-mac-gpl-4.10.1.tar.gz"
201    cd PyQt-mac-gpl-4.10.1
202
203    yes yes | $PYTHON configure.py --qmake "$APP"/Contents/Resources/Qt4/bin/qmake
204
205    make
206    make install
207
208    $PYTHON -c"import PyQt4.QtGui, PyQt4.QtGui"
209
210}
211
212function install_pyqwt5 {
213    download_and_extract "http://sourceforge.net/projects/pyqwt/files/pyqwt5/PyQwt-5.2.0/PyQwt-5.2.0.tar.gz"
214
215    # configure.py fails (with ld: library not found for -lcrt1.10.5.o) trying to
216    # build static libraries
217    export CPPFLAGS="--shared"
218
219    cd PyQwt-5.2.0/configure
220
221    $PYTHON configure.py -Q ../qwt-5.2 \
222                        --extra-cflags="-arch i386 -arch x86_64" \
223                        --extra-cxxflags="-arch i386 -arch x86_64" \
224                        --extra-lflags="-arch i386 -arch x86_64"
225    make
226    make install
227
228    unset CPPFLAGS
229
230    $PYTHON -c"import PyQt4.Qwt5"
231}
232
233function install_numpy {
234    $PIP install numpy
235
236    $PYTHON -c"import numpy"
237}
238
239function install_scipy {
240    # This is tricky (req gfortran)
241    $PIP install scipy
242
243    $PYTHON -c"import scipy"
244}
245
246function download_and_extract() {
247    # Usage: download_and_extract http://example/source.tar.gz
248    #
249    # Download the specified .tar source package and extract it in the current dir
250    # If the source package is already present only extract it
251
252    URL=$1
253    if [[ ! $URL ]]; then
254        echo "An url expected"
255        exit 1
256    fi
257
258    SOURCE_TAR=$(basename "$URL")
259
260    if [[ ! -e $SOURCE_TAR ]]; then
261        echo "Downloading $SOURCE_TAR"
262        curl --fail -L --max-redirs 3 $URL -o $SOURCE_TAR
263    fi
264    tar -xzf $SOURCE_TAR
265}
266
267
268function create_shell_start_script() {
269    # Usage: create_shell_start_script pip
270    #
271    # create a start script for the specified script in $APP/Contents/MacOS
272
273    SCRIPT=$1
274
275    cat <<-'EOF' > "$APP"/Contents/MacOS/"$SCRIPT"
276        #!/bin/bash
277
278        DIRNAME=$(dirname "$0")
279        NAME=$(basename "$0")
280
281        # Set the proper env variables
282        source "$DIRNAME"/ENV
283
284        exec -a "$0" "$DIRNAME"/python "$FRAMEWORKS_DIR"/Python.framework/Versions/Current/bin/"$NAME" "$@"
285EOF
286
287    chmod +x "$APP"/Contents/MacOS/"$SCRIPT"
288}
289
290function cleanup {
291    # Cleanup the application bundle by removing unnecesary files.
292    find "$APP"/Contents/ \( -name '*~' -or -name '*.bak' -or -name '*.pyc' -or -name '*.pyo' -or -name '*.pyd' \) -exec rm -rf {} ';'
293
294    find "$APP"/Contents/Frameworks/*Qt*.framework -name '*_debug*' -delete
295    find "$APP"/Contents/Frameworks/*Qt*.framework -name '*_debug*' -delete
296
297    find "$APP"/Contents/Frameworks/*Qt*.framework -name '*.la' -delete
298    find "$APP"/Contents/Frameworks/*Qt*.framework -name '*.a' -delete
299    find "$APP"/Contents/Frameworks/*Qt*.framework -name '*.prl' -delete
300
301}
302
303function make_standalone {
304    $PIP install macholib
305    $PYTHON -m macholib standalone $APP
306    yes y | $PIP uninstall altgraph
307    yes y | $PIP uninstall macholib
308}
309
310create_template
311
312install_python
313
314install_distribute
315
316install_pip
317
318install_numpy
319
320install_scipy
321
322install_qt4
323
324install_sip
325
326install_pyqt4
327
328install_pyqwt5
329
330install_ipython
331
332cleanup
333
334make_standalone
Note: See TracBrowser for help on using the repository browser.