language: c
compiler: gcc
sudo: false
dist: precise
osx_image: xcode8

branches:
  only:
    - master
    - travis
    - coverity_scan
os:
  - linux
  - osx

addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
      - deadsnakes
    packages: [autoconf, automake, autotools-dev, bzip2, gcc-4.9, libtool,
      libjpeg-dev, libtiff4-dev, libpng12-dev, libfreetype6-dev, libgif-dev,
      libx11-dev, libxml2-dev, libpango1.0-dev, libcairo2-dev, python3.5-dev]
  coverity_scan:
    project:
      name: "fontforge/fontforge"
      description: "Free (libre) font editor for Windows, Mac OS X and GNU+Linux"
    build_command_prepend: cov-configure --comptype gcc --compiler $CC --template && ./bootstrap --force && ./configure $FFCONFIG
    build_command: make -j4
    branch_pattern: coverity_scan
    notification_email: jtanx_blackhole@outlook.com

cache:
  directories:
    - $TRAVIS_BUILD_DIR/travisdeps

#before_install:
#  - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update || brew update; fi

install:
  - |
    set -e
    export DEPSPREFIX=$TRAVIS_BUILD_DIR/travisdeps
    export PREFIX=$TRAVIS_BUILD_DIR/target
    export PATH=$PATH:$DEPSPREFIX/bin:$PREFIX/bin
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DEPSPREFIX/lib:$PREFIX/lib
    export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$DEPSPREFIX/lib/pkgconfig
    export FFCONFIG="--prefix=$PREFIX"

    if [ "$TRAVIS_OS_NAME" == "linux" ]; then
      export FTVER=`dpkg -s libfreetype6-dev | perl -ne 'print $1 if /^Version: (\d+(?:\.\d+)+)/'`
      export SFFTVER=`echo $FTVER | perl -ne 'print $1 if /^(\d+(?:\.\d+){1,2})/'`
      export FFCONFIG="$FFCONFIG --with-freetype-source=$DEPSPREFIX/freetype-$FTVER"
      export CC=gcc-4.9

      # This block only runs if the cache isn't present.
      if [ ! "$(ls -A $DEPSPREFIX)" ]; then
        mkdir -p work && pushd work
        wget 'https://github.com/zeromq/zeromq4-1/releases/download/v4.1.5/zeromq-4.1.5.tar.gz' -O - |tar -zxf -
        wget 'https://github.com/zeromq/czmq/releases/download/v3.0.2/czmq-3.0.2.tar.gz' -O - |tar -zxf -
        wget 'https://github.com/fontforge/libspiro/releases/download/0.5.20150702/libspiro-0.5.20150702.tar.gz' -O - | tar -zxf -
        wget 'https://github.com/fontforge/libuninameslist/releases/download/20160701/libuninameslist-20160701.tar.gz' -O - | tar -zxf -
        wget 'https://bitbucket.org/sortsmill/libunicodenames/downloads/libunicodenames-1.1.0_beta1.tar.xz' -O - | tar -Jxf -
        wget --tries 1 "http://download.savannah.gnu.org/releases/freetype/freetype-$FTVER.tar.gz" || \
          wget "https://sourceforge.net/projects/freetype/files/freetype2/$SFFTVER/freetype-$FTVER.tar.gz"

        pushd zeromq-4.1.5 && ./configure --prefix=$DEPSPREFIX && make -j4 && make install && popd
        pushd czmq-3.0.2 && ./configure --prefix=$DEPSPREFIX && make -j4 && make install && popd
        pushd libspiro-0.5.20150702 && ./configure --prefix=$DEPSPREFIX && make -j4 && make install && popd
        pushd libuninameslist-20160701 && ./configure --prefix=$DEPSPREFIX && make -j4 && make install && popd
        pushd libunicodenames-1.1.0_beta1 && ./configure --prefix=$DEPSPREFIX && make -j4 && make install && popd
        tar -zxf freetype-$FTVER.tar.gz -C $DEPSPREFIX
        popd
      fi

      # These are FF-specific mods (set here so it runs also in Coverity)
      export PYTHON=python3.5
      export PYTHONPATH=$PYTHONPATH:$PREFIX/lib/python$($PYTHON -c "import sys; print('{0}.{1}'.format(sys.version_info.major, sys.version_info.minor))")/site-packages
      export CFLAGS="-fdiagnostics-color=auto -Wall -Wno-switch"
    else
      export PATH=/opt/local/bin:$PATH
      export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig:/opt/X11/lib/pkgconfig:/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/pkgconfig:$PKG_CONFIG_PATH
      export PYTHONPATH=$PYTHONPATH:$PREFIX/lib/python2.7/site-packages
      export PYTHON=python
      wget https://github.com/macports/macports-base/releases/download/v2.4.1/MacPorts-2.4.1-10.11-ElCapitan.pkg
      sudo installer -pkg MacPorts-2.4.1-10.11-ElCapitan.pkg -target /
      sudo port selfupdate

      PORTDEFS=$(pushd osx >/dev/null && port deps | \
        grep '^Build\|^Library' | \
        sed -e 's/Build Dependencies://' -e 's/Library Dependencies://' | \
        tr , '\n' | \
        sed -e 's/^[[:space:]]*//' && \
        popd >/dev/null \
      )
      echo "Installing dependencies: $PORTDEFS"
      COLUMNS=80 sudo port install $PORTDEFS 2>&1 | tee /dev/null
      sudo port select --set python python27
      sudo port select --set python2 python27
    fi

    #Why.
    export LIBSPIRO_CFLAGS=`pkg-config --cflags libspiro` && export LIBSPIRO_LIBS=`pkg-config --libs libspiro`
    export LIBUNINAMESLIST_CFLAGS=`pkg-config --cflags libuninameslist` && export LIBUNINAMESLIST_LIBS=`pkg-config --libs libuninameslist`
    set +e

script:
  - ./bootstrap
  - ./configure $FFCONFIG
  - make -j4
  - make install
  - if [ "$TRAVIS_OS_NAME" == "linux" ]; then make distcheck -j4; fi
  - fontforge -version
  - $PYTHON -c "import fontforge; import psMat; print(fontforge.__version__, fontforge.version())"
  - if [ "$TRAVIS_OS_NAME" == "osx" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then travis-scripts/ffosxbuild.sh $PREFIX $TRAVIS_COMMIT; fi

deploy:
  provider: bintray
  file: "travis-scripts/bintray_descriptor.json"
  user: "fontforge-ci-bot"
  dry-run: false
  key:
    secure: "YBvK5QLZ4LNE3WQPXjDYalLsTgmiGyRGYY87ep5knQ0YGyt3Q9OiBCtQ3GvhHNKOa2L2QlctJi2VWcUu+ftrS72mi5j2tvse9wRF3V8EVFIPb3bxjnN6E11FjXtLIqU8WR7HlAHJpOL2bhO+RleIhSVZm0MsiSjekFOoA5tfll4="
  on:
    condition: $TRAVIS_OS_NAME = osx
    branch:
      - master
      - travis

env:
  global:
   # For Coverity
   - secure: "MeTS1Pqa5gzx1nn/peW/9a5kq84bba3XYUljOfkCUqzuyGiERk/nmok+RW7skrgzboBlKxnNG8+ykKqHMwK9s9M83ezFxvEWXBcKEpmEQKkqXPI5hpMs6jGLTgpeuheSIzqHA3danV8iircp1GOiTLWA0pt/AOsNLZiaYBh0OiE="
