language: c

matrix:
  include:
    - os: linux
      env: BUILD_OFFICIAL=1
      sudo: required
      services:
        - docker
    - os: osx
      env: BUILD_OFFICIAL=1
      osx_image: xcode7.2
    - os: linux
      dist: trusty
      compiler: clang
      env:
        CFLAGS="-O1 -g -fsanitize=address -fno-omit-frame-pointer"
        CONFIGURE_FLAGS="--disable-shared"
        ASAN_OPTIONS="detect_leaks=1 symbolize=1"
      addons:
        apt:
          packages:
            - nasm
    - os: linux
      compiler: gcc
      env: CONFIGURE_FLAGS="--with-12bit"
    - os: linux
      dist: trusty
      compiler: gcc
      env: CONFIGURE_FLAGS="--with-jpeg8"
      addons:
        apt:
          packages:
            - nasm
    - os: linux
      compiler: gcc
      env: CONFIGURE_FLAGS="--without-simd"

addons:
  ssh_known_hosts: shell.sourceforge.net

before_install:
  - if [ "${BUILD_OFFICIAL:-}" != "" ]; then
      if [ "$TRAVIS_OS_NAME" = "linux" ]; then
        docker pull dcommander/buildljt;
      fi &&
      git clone --depth=1 https://github.com/libjpeg-turbo/buildscripts.git ~/src/buildscripts &&
      openssl aes-256-cbc -K $encrypted_f92e8533f6f1_key -iv $encrypted_f92e8533f6f1_iv -in ci/deploy_ljt.enc -out ~/.ssh/id_rsa -d &&
      chmod 600 ~/.ssh/id_rsa;
    fi
  - if [ "$TRAVIS_OS_NAME" = "osx" ]; then
      brew install nasm homebrew/versions/gcc5 md5sha1sum Caskroom/versions/java6 &&
      git clone --depth=1 https://github.com/libjpeg-turbo/gas-preprocessor.git ~/src/gas-preprocessor &&
      ln -fs /Applications/Xcode.app /Applications/Xcode72.app;
    fi

script:
  - if [ "${BUILD_OFFICIAL:-}" != "" ]; then
      mkdir -p ~/src/ljt.nightly &&
      if [ "$TRAVIS_OS_NAME" = "linux" ]; then
        docker run -v $HOME/src/ljt.nightly:/root/src/ljt.nightly -v $HOME/src/buildscripts:/root/src/buildscripts -t dcommander/buildljt:latest bash -c "~/src/buildscripts/buildljt -r https://github.com/$TRAVIS_REPO_SLUG.git $TRAVIS_BRANCH -v" &&
        sudo chown -R travis:travis ~/src/ljt.nightly;
      else
        PATH=$PATH:~/src/gas-preprocessor ~/src/buildscripts/buildljt -r https://github.com/$TRAVIS_REPO_SLUG.git $TRAVIS_BRANCH -v;
      fi;
    fi
  - if [ "${BUILD_OFFICIAL:-}" == "" ]; then
      autoreconf -fiv &&
      mkdir build &&
      pushd build &&
      ../configure ${CONFIGURE_FLAGS} &&
      make -j &&
      if [[ "${CONFIGURE_FLAGS}" =~ "with-12bit" ||
            "${CONFIGURE_FLAGS}" =~ "without-simd" ]]; then
        make test FLOATTEST=32bit;
      else
        make test FLOATTEST=sse &&
        JSIMD_FORCESSE2=1 make test FLOATTEST=sse &&
        JSIMD_FORCENONE=1 make test FLOATTEST=32bit;
      fi &&
      popd;
    fi

after_failure:
  - if [ "${BUILD_OFFICIAL:-}" == "" ]; then
      if [ -f $TRAVIS_BUILD_DIR/build/config.log ]; then
        cat $TRAVIS_BUILD_DIR/build/config.log;
      fi
    fi

before_deploy:
  - if [ "${BUILD_OFFICIAL:-}" != "" ]; then
      eval "$(ssh-agent -s)" &&
      ssh-add;
    fi

deploy:
  provider: script
  on:
    branch: master
  on:
    branch: dev
  script:
    if [ "${BUILD_OFFICIAL:-}" != "" ]; then
      mv ~/src/ljt.nightly/latest/log-$TRAVIS_OS_NAME.txt ~/src/ljt.nightly/latest/files/ &&
      ~/src/buildscripts/uploadljt dcommander $TRAVIS_BRANCH.$TRAVIS_OS_NAME;
    fi
