branches:
    only:
        - master

git:
    quiet: true
    depth: 5

language: c

addons:
    apt:
      packages:
          - lcov

compiler:
    - clang
    - gcc

os:
    - linux
    - osx

env:
    global:
        - MAKEJOBS="-j$(getconf _NPROCESSORS_ONLN)"
        - TRAVIS_COMMIT_LOG=`git log --format=fuller -2`
        - COVERAGE=OFF # Currently works only with gcc on linux

before_script:
    - '[[ "${TRAVIS_OS_NAME}-${TRAVIS_COMPILER}" != "linux-gcc" ]] || export COVERAGE="ON"'

script:
    - |
      if [ $COVERAGE = "ON" ]; then
          export LDFLAGS=" -lgcov --coverage"
          export CFLAGS="-O0 -ggdb -fprofile-arcs -ftest-coverage"
      fi
    - make $MAKEJOBS || ( echo "Build failure. Verbose build follows." && make V=1 ; false )
    - make check -j1 VERBOSE=1

jobs:
  include:
    - stage: Benchmark
      os: linux
      compiler: gcc
      before_script:
          - export COVERAGE=OFF
      script:
          - make $MAKEJOBS
          - make $MAKEJOBS bench
    - stage: Benchmark
      os: linux
      compiler: gcc
      env:
          - CFLAGS="-march=native -mtune=native -O3"
      before_script:
          - export COVERAGE=OFF
      script:
          - make $MAKEJOBS
          - make $MAKEJOBS bench
    - stage: Benchmark
      os: osx
      compiler: clang
      env:
          - CFLAGS="-march=native -mtune=native -O3"
      before_script:
          - export COVERAGE=OFF
      script:
          - make $MAKEJOBS
          - make $MAKEJOBS bench
    - stage: Benchmark
      os: osx
      compiler: clang
      before_script:
          - export COVERAGE=OFF
      script:
          - make $MAKEJOBS
          - make $MAKEJOBS bench

after_success:
    - '[[ "$COVERAGE" != "ON" ]] || bash <(curl -s https://codecov.io/bash)'

after_script:
    - printf "$TRAVIS_COMMIT_RANGE\n"
    - printf "$TRAVIS_COMMIT_LOG\n"
