language: c

cache:
  pip: true

matrix:
  include:
    - arch: amd64
      os: linux
      dist: bionic
      sudo: required
      compiler: clang
      env: TRAVIS_ARCH="amd64"
    - arch: amd64
      os: linux
      dist: bionic
      sudo: required
      compiler: gcc
      env: TRAVIS_ARCH="amd64" DEPLOY_BUILD=TRUE
    - arch: arm64
      os: linux
      dist: bionic
      sudo: required
      compiler: gcc
      env: TRAVIS_ARCH="arm64"
    - arch: amd64
      os: linux
      dist: bionic
      sudo: required
      compiler: gcc
      env: TRAVIS_ARCH="amd64" ENABLE_STATIC=ON
    - arch: amd64
      os: osx
      compiler: gcc
      env: TRAVIS_ARCH="amd64"
    - arch: ppc64le
      os: linux
      dist: bionic
      sudo: required
      compiler: gcc
      env: TRAVIS_ARCH="ppc64le"
    - arch: ppc64le
      os: linux
      dist: bionic
      sudo: required
      compiler: clang
      env: TRAVIS_ARCH="ppc64le"       
  allow_failures:
    - os: osx

branches:
  only:
    - master
    - devel

addons:
  apt:
    packages:
    - abi-dumper
    - abi-compliance-checker
    - pkg-config
    - w3m
    - curl
    - valgrind
    - libcmocka-dev
    - libpcre3-dev
    - python3-dev
    - python3-cffi
    - python3-setuptools
    - python3-pip
    - swig
    update: true
  homebrew:
    packages:
    - curl
    - cmocka
    update: true

before_install:
  - if [ "$DEPLOY_BUILD" = "TRUE" ]; then sudo snap install universal-ctags; fi
  - if [ "$DEPLOY_BUILD" = "TRUE" ]; then pip3 install --user codecov==2.0.22; export CFLAGS="-coverage"; fi

script:
  - mkdir build && cd build
  - if [ "$TRAVIS_OS_NAME" = "osx" ]; then cmake -DENABLE_VALGRIND_TESTS=OFF ..; fi
  - if [ "$TRAVIS_OS_NAME" = "linux" ] && [ "$TRAVIS_ARCH" = "amd64" ]; then cmake -DGEN_LANGUAGE_BINDINGS=ON -DENABLE_STATIC=${ENABLE_STATIC:-OFF} ..; fi
  - if [ "$TRAVIS_OS_NAME" = "linux" ] && [ "$TRAVIS_ARCH" = "arm64" ]; then cmake -DGEN_LANGUAGE_BINDINGS=ON -DENABLE_VALGRIND_TESTS=OFF ..; fi
  - if [ "$TRAVIS_OS_NAME" = "linux" ] && [ "$TRAVIS_ARCH" = "ppc64le" ]; then cmake -DGEN_LANGUAGE_BINDINGS=ON -DENABLE_VALGRIND_TESTS=OFF ..; fi
  - make -j2 && ctest --output-on-failure
  - cd -
  - if [ "$DEPLOY_BUILD" = "TRUE" ]; then ./tools/abi-check.sh; fi

deploy:
  - provider: script
    script: ./tools/codecov.sh
    skip_cleanup: true
    verbose: true
    on:
      branch: master
      condition: $DEPLOY_BUILD = TRUE
  - provider: script
    script: ./packages/create-package.sh
    skip_cleanup: true
    verbose: true
    on:
      branch: master
      condition: $DEPLOY_BUILD = TRUE
