Ignore:
Timestamp:
07/17/13 16:15:38 (9 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Children:
11638:1e3311779a3b, 11639:ad4d94a25e19
Message:

Changes to osx application template build script.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • install-scripts/mac/build-osx-app-template.sh

    • Property exe set to *
    r11634 r11637  
    77#   $ build-osx-app-template.sh $HOME/Orange.app 
    88# 
    9  
    10  
    11 SCRIPT_DIR_NAME=$(dirname "$0") 
    12  
    13 BUNDLE_LITE=$SCRIPT_DIR_NAME/bundle-lite/Orange.app 
     9# Prerequisites: 
     10#     a working gcc compiler toolchain 
     11#     a working gfortran compiler on PATH 
     12 
     13 
     14function print_usage () { 
     15echo 'build-osx-app-template.sh [-t] [-k] some_path/Orange.app 
     16 
     17Build an Orange application template from scratch. 
     18This will download and build all requirements (Python, Qt4, ...) for a 
     19standalone .app distribution. 
     20 
     21Warning: This will take a lot of time. 
     22 
     23Options: 
     24    -t --build-temp DIR   A temporary build directory. 
     25    -k --keep-temp        Do not delete the temp directory after build. 
     26    -h --help             Print this help. 
     27' 
     28} 
     29 
     30while [[ ${1:0:1} = "-" ]]; do 
     31    case $1 in 
     32        -t|--build-temp) 
     33            BUILD_TEMP=$2 
     34            shift 2 
     35            ;; 
     36        -k|--keep-temp) 
     37            KEEP_TEMP=1 
     38            shift 1 
     39            ;; 
     40        -h|--help) 
     41            print_usage 
     42            exit 0 
     43            ;; 
     44        -*) 
     45            echo "Unknown option $1" >&2 
     46            print_usage 
     47            exit 1 
     48            ;; 
     49    esac 
     50done 
     51 
     52 
     53if [[ $BUILD_TEMP ]]; then 
     54    mkdir -p "$BUILD_TEMP" 
     55else 
     56    BUILD_TEMP=$(mktemp -d -t build-template) 
     57fi 
    1458 
    1559APP=$1 
    1660 
    1761if [[ ! $APP ]]; then 
    18     echo "Applicatition path must be specified" 
    19     echo "Usage: ./build-osx-app-template.sh ApplicationTemplate" 
     62    echo "Target application path must be specified" >&2 
     63    print_usage 
    2064    exit 1 
    2165fi 
    2266 
     67mkdir -p "$APP" 
     68 
     69# Convert to absolute path 
     70APP=$(cd "$APP"; pwd) 
     71 
     72# Get absolute path to the bundle-lite template 
     73SCRIPT_DIR_NAME=$(dirname "$0") 
     74# Convert to absolute path 
     75SCRIPT_DIR_NAME=$(cd "$SCRIPT_DIR_NAME"; pwd) 
     76BUNDLE_LITE=$SCRIPT_DIR_NAME/bundle-lite/Orange.app 
     77 
     78 
     79# Versions of included 3rd party software 
     80 
     81PYTHON_VER=2.7.5 
     82PIP_VER=1.3.1 
     83DISTRIBUTE_VER=0.6.49 
     84NUMPY_VER=1.7.1 
     85SCIPY_VER=0.12.0 
     86QT_VER=4.7.4 
     87SIP_VER=4.14.6 
     88PYQT_VER=4.10.1 
     89PYQWT_VER=5.2.0 
     90 
     91# Number of make jobs 
     92MAKE_JOBS=${MAKE_JOBS:-$(sysctl -n hw.physicalcpu)} 
    2393 
    2494PYTHON=$APP/Contents/MacOS/python 
     
    30100SDK=/Developer/SDKs/MacOSX$MACOSX_DEPLOYMENT_TARGET.sdk 
    31101 
     102 
    32103function create_template { 
    33104    # Create a minimal .app template with the expected dir structure 
     
    42113    cp "$BUNDLE_LITE"/Contents/Info.plist "$APP"/Contents/Info.plist 
    43114 
    44     #cp $BUNDLE_LITE/Contents/PkgInfo $APP/Contents/PkgInfo 
     115    cp "$BUNDLE_LITE"/Contents/PkgInfo $APP/Contents/PkgInfo 
    45116 
    46117    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} 
     118        # Create an environment for running python from the bundle 
     119        # Should be run as "source ENV" 
     120 
     121        BUNDLE_DIR=`dirname "$0"`/../ 
     122        BUNDLE_DIR=`perl -MCwd=realpath -e 'print realpath($ARGV[0])' "$BUNDLE_DIR"`/ 
     123        FRAMEWORKS_DIR="$BUNDLE_DIR"Frameworks/ 
     124        RESOURCES_DIR="$BUNDLE_DIR"Resources/ 
     125 
     126        PYVERSION="2.7" 
     127 
     128        PYTHONEXECUTABLE="$FRAMEWORKS_DIR"Python.framework/Resources/Python.app/Contents/MacOS/Python 
     129        PYTHONHOME="$FRAMEWORKS_DIR"Python.framework/Versions/"$PYVERSION"/ 
     130 
     131        DYLD_FRAMEWORK_PATH="$FRAMEWORKS_DIR"${DYLD_FRAMEWORK_PATH:+:$DYLD_FRAMEWORK_PATH} 
     132 
     133        export PYTHONEXECUTABLE 
     134        export PYTHONHOME 
     135 
     136        export DYLD_FRAMEWORK_PATH 
     137 
     138        # Some non framework libraries are put in $FRAMEWORKS_DIR by machlib standalone 
     139        export DYLD_LIBRARY_PATH="$FRAMEWORKS_DIR"${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH} 
    69140EOF 
    70141 
     
    72143 
    73144function 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 
     145    download_and_extract "http://www.python.org/ftp/python/$PYTHON_VER/Python-$PYTHON_VER.tgz" 
     146 
     147    pushd Python-$PYTHON_VER 
    77148 
    78149    # _hashlib import fails with  Symbol not found: _EVP_MD_CTX_md 
     
    90161                --enable-universalsdk="$SDK" 
    91162 
    92     make 
    93     make install 
    94     cd .. 
     163    make -j $MAKE_JOBS 
     164 
     165    # We don't want to install IDLE.app, Python Launcher.app, in /Applications 
     166    # on the build system. 
     167    make install PYTHONAPPSDIR=$(pwd) 
     168 
     169    popd 
    95170 
    96171    # PythonAppStart will be used for starting the application GUI. 
    97     # This needs to be symlinked here for Desktop services used the app's 
     172    # This needs to be symlinked here for Desktop services to read the app's 
    98173    # Info.plist and not the contained Python.app's 
    99174    ln -fs ../Frameworks/Python.framework/Resources/Python.app/Contents/MacOS/Python "$APP"/Contents/MacOS/PythonAppStart 
     
    113188    chmod +x "$APP"/Contents/MacOS/python 
    114189 
    115     $PYTHON -c"import sys" 
     190    "$PYTHON" -c"import sys, hashlib" 
    116191 
    117192} 
    118193 
    119194function 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 
     195    download_and_extract "https://pypi.python.org/packages/source/p/pip/pip-$PIP_VER.tar.gz" 
     196 
     197    pushd pip-$PIP_VER 
     198 
     199    "$PYTHON" setup.py install 
    124200    create_shell_start_script pip 
    125201 
    126     $PIP --version 
     202    "$PIP" --version 
     203 
     204    popd 
    127205} 
    128206 
    129207function 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 
     208    download_and_extract "https://pypi.python.org/packages/source/d/distribute/distribute-$DISTRIBUTE_VER.tar.gz" 
     209 
     210    pushd distribute-$DISTRIBUTE_VER 
     211 
     212    "$PYTHON" setup.py install 
    134213    create_shell_start_script easy_install 
    135214 
    136     $EASY_INSTALL --version 
     215    "$EASY_INSTALL" --version 
     216 
     217    popd 
    137218} 
    138219 
    139220function install_ipython { 
    140221    # install with easy_install (does not work with pip) 
    141     $EASY_INSTALL ipython 
     222    "$EASY_INSTALL" ipython 
    142223    create_shell_start_script ipython 
    143224} 
    144225 
    145226function 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 
     227    QT_VER_SHORT=${QT_VER%%\.[0-9]} 
     228 
     229    # 4.8.* (4.8 does not compile for x86_64 using 10.5 SDK) 
     230    #download_and_extract "http://download.qt-project.org/official_releases/qt/$QT_VER_SHORT/$QT_VER/qt-everywhere-opensource-src-$QT_VER.tar.gz" 
     231 
     232    # 4.7 or older 
     233    download_and_extract "http://download.qt-project.org/archive/qt/$QT_VER_SHORT/qt-everywhere-opensource-src-$QT_VER.tar.gz" 
     234 
     235    pushd qt-everywhere-opensource-src-$QT_VER 
    148236 
    149237    yes yes | ./configure -prefix "$APP"/Contents/Resources/Qt4 \ 
     
    166254                -sdk "$SDK" 
    167255 
    168     make -j 4 
     256    make -j $MAKE_JOBS 
    169257    make install 
    170258 
    171     # Register plugins. 
     259    # Register plugins with Qt. 
    172260    cat <<-EOF > "$APP"/Contents/Resources/qt.conf 
    173261        [Paths] 
     
    175263EOF 
    176264 
    177     # In case the Python executable is invokes directly we also want it to 
    178     # find the plugins. 
     265    # In case the Python executable is invoked directly (not through 
     266    # Contents/MacOS/python) we also want it to find the plugins. 
    179267    cat <<-EOF > "$APP"/Contents/Frameworks/Python.framework/Resources/Python.app/Contents/Resources/qt.conf 
    180268        [Paths] 
     
    182270EOF 
    183271 
     272    popd 
    184273} 
    185274 
    186275function 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 
     276    download_and_extract "http://sourceforge.net/projects/pyqt/files/sip/sip-$SIP_VER/sip-$SIP_VER.tar.gz" 
     277    pushd sip-$SIP_VER 
     278 
     279    "$PYTHON" configure.py  --arch i386 --arch x86_64 --sdk "$SDK" 
     280 
     281    make -j $MAKE_JOBS 
    193282    make install 
    194283 
    195     $PYTHON -c"import sip" 
     284    "$PYTHON" -c"import sip" 
     285 
     286    popd 
    196287 
    197288} 
    198289 
    199290function 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 
     291    download_and_extract "http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-$PYQT_VER/PyQt-mac-gpl-$PYQT_VER.tar.gz" 
     292    pushd PyQt-mac-gpl-$PYQT_VER 
     293 
     294    yes yes | "$PYTHON" configure.py --qmake "$APP"/Contents/Resources/Qt4/bin/qmake 
     295 
     296    make -j $MAKE_JOBS 
    206297    make install 
    207298 
    208     $PYTHON -c"import PyQt4.QtGui, PyQt4.QtGui" 
    209  
     299    "$PYTHON" -c"from PyQt4 import QtGui, QtWebKit, QtSvg, QtNetwork" 
     300 
     301    popd 
    210302} 
    211303 
    212304function install_pyqwt5 { 
    213     download_and_extract "http://sourceforge.net/projects/pyqwt/files/pyqwt5/PyQwt-5.2.0/PyQwt-5.2.0.tar.gz" 
     305    download_and_extract "http://sourceforge.net/projects/pyqwt/files/pyqwt5/PyQwt-$PYQWT_VER/PyQwt-$PYQWT_VER.tar.gz" 
     306 
     307    pushd PyQwt-$PYQWT_VER/configure 
    214308 
    215309    # configure.py fails (with ld: library not found for -lcrt1.10.5.o) trying to 
     
    217311    export CPPFLAGS="--shared" 
    218312 
    219     cd PyQwt-5.2.0/configure 
    220  
    221     $PYTHON configure.py -Q ../qwt-5.2 \ 
     313    PYQWT_VER_SHORT=${PYQWT_VER%%\.[0-9]} 
     314 
     315    "$PYTHON" configure.py -Q ../qwt-$PYQWT_VER_SHORT \ 
    222316                        --extra-cflags="-arch i386 -arch x86_64" \ 
    223317                        --extra-cxxflags="-arch i386 -arch x86_64" \ 
    224318                        --extra-lflags="-arch i386 -arch x86_64" 
    225     make 
     319    make -j $MAKE_JOBS 
    226320    make install 
    227321 
    228322    unset CPPFLAGS 
    229323 
    230     $PYTHON -c"import PyQt4.Qwt5" 
     324    "$PYTHON" -c"import PyQt4.Qwt5" 
     325 
     326    popd 
    231327} 
    232328 
    233329function install_numpy { 
    234     $PIP install numpy 
    235  
    236     $PYTHON -c"import numpy" 
     330    "$PIP" install numpy==$NUMPY_VER 
     331 
     332    "$PYTHON" -c"import numpy" 
    237333} 
    238334 
    239335function install_scipy { 
    240336    # This is tricky (req gfortran) 
    241     $PIP install scipy 
    242  
    243     $PYTHON -c"import scipy" 
     337    "$PIP" install scipy==$SCIPY_VER 
     338 
     339    "$PYTHON" -c"import scipy" 
    244340} 
    245341 
     
    260356    if [[ ! -e $SOURCE_TAR ]]; then 
    261357        echo "Downloading $SOURCE_TAR" 
    262         curl --fail -L --max-redirs 3 $URL -o $SOURCE_TAR 
     358        curl --fail -L --max-redirs 3 "$URL" -o "$SOURCE_TAR".part 
     359        mv "$SOURCE_TAR".part "$SOURCE_TAR" 
    263360    fi 
    264     tar -xzf $SOURCE_TAR 
     361    tar -xzf "$SOURCE_TAR" 
    265362} 
    266363 
     
    290387function cleanup { 
    291388    # 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  
     389    find "$APP"/Contents/ \( -name '*~' -or -name '*.bak' -or -name '*.pyc' -or -name '*.pyo' \) -delete 
     390 
     391    find "$APP"/Contents/Frameworks -name '*_debug*' -delete 
     392 
     393    find "$APP"/Contents/Frameworks -name '*.la' -delete 
     394    find "$APP"/Contents/Frameworks -name '*.a' -delete 
     395    find "$APP"/Contents/Frameworks -name '*.prl' -delete 
    301396} 
    302397 
    303398function 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 } 
     399    "$PIP" install macholib 
     400    "$PYTHON" -m macholib standalone $APP 
     401    yes y | "$PIP" uninstall altgraph 
     402    yes y | "$PIP" uninstall macholib 
     403} 
     404 
     405pushd $BUILD_TEMP 
     406 
     407echo "Building template in $BUILD_TEMP" 
     408echo 
    309409 
    310410create_template 
     
    330430install_ipython 
    331431 
     432make_standalone 
     433 
    332434cleanup 
    333435 
    334 make_standalone 
     436popd 
     437 
     438if [[ ! $KEEP_TEMP ]]; then 
     439    rm -rf $BUILD_TEMP 
     440fi 
Note: See TracChangeset for help on using the changeset viewer.