language: r
sudo: false
r: devel
cache: packages

latex: true


env:
  matrix: 
    - CXX_OLEVEL=2 CXX=clang++

matrix:
  include:
    - os: linux
      compiler: clang
      addons:
        apt:
          sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-precise-5.0' ]        
          packages:
            - llvm-5.0-dev
      env:
        - CXX_OLEVEL=2 CXX=clang++


before_install:
  - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
  - sudo apt-get update -q
  - mkdir -p ~/.R/
  - echo "CXX = `R CMD config CXX`" >> ~/.R/Makevars
  - echo "CXXFLAGS = `R CMD config CXXFLAGS` -pedantic -g0 -flto -stdlib=libc++" >> ~/.R/Makevars
  - echo "LDFLAGS += -flto -stdlib=libc++" >> ~/.R/Makevars
  - export CLANG_EXTRA_ARG=""
  - if [[ $CXX = "clang++" ]] ;  then export CLANG_EXTRA_ARG=" -Qunused-arguments -fcolor-diagnostics " ; fi
  - sed -i.bak "s/ g++/ ${CXX}${CLANG_EXTRA_ARG}/" ~/.R/Makevars
  - sed -i.bak "s/O[0-3]/O$CXX_OLEVEL/" ~/.R/Makevars

script: 
  - |
    travis_wait 42 R CMD build .
    travis_wait 59 R CMD check RSTAN_PACKAGE_NAME*tar.gz

after_script:
  - tar -ztvf RSTAN_PACKAGE_NAME_*.tar.gz
  - echo ${NOT_CRAN}

after_success:
  - travis_wait 40 tar -C .. -xf $PKG_TARBALL

after_failure:
- cat RSTAN_PACKAGE_NAME.Rcheck/00*
