sudo: required
language: bash
services:
  - docker

# define the build matrix
env:
  global:
    - PROJECT_DIR: .
    - TOOLCHAIN: gcc-cxx11
    - BUILD_PACKAGES: cmake
    - RUN_TESTS: true

matrix:
  include:
    # Linux {

    #   Ubuntu 14.04
    - os: linux
      env: >
        BUILD_FLAVOR=ubuntu
        BUILD_RELEASE=trusty
        BUILD_ARCH=amd64
        BUILD_PACKAGES=cmake3
    - os: linux
      env: >
        BUILD_FLAVOR=ubuntu
        BUILD_RELEASE=trusty
        BUILD_ARCH=i386
        BUILD_PACKAGES=cmake3
    #   Ubuntu 16.04
    - os: linux
      env: >
        BUILD_FLAVOR=ubuntu
        BUILD_RELEASE=xenial
        BUILD_ARCH=amd64
    - os: linux
      env: >
        BUILD_FLAVOR=ubuntu
        BUILD_RELEASE=xenial
        BUILD_ARCH=i386
    #   Ubuntu 18.04
    - os: linux
      env: >
        BUILD_FLAVOR=ubuntu
        BUILD_RELEASE=bionic
        BUILD_ARCH=amd64
        TOOLCHAIN=gcc-cxx98
    - os: linux
      env: >
        BUILD_FLAVOR=ubuntu
        BUILD_RELEASE=bionic
        BUILD_ARCH=amd64
    - os: linux
      env: >
        BUILD_FLAVOR=ubuntu
        BUILD_RELEASE=bionic
        BUILD_ARCH=amd64
        TOOLCHAIN=gcc-gnuxx11
    - os: linux
      env: >
        BUILD_FLAVOR=ubuntu
        BUILD_RELEASE=bionic
        BUILD_ARCH=amd64
        TOOLCHAIN=gcc-cxx17
    - os: linux
      env: >
        BUILD_FLAVOR=ubuntu
        BUILD_RELEASE=bionic
        BUILD_ARCH=amd64
        TOOLCHAIN=clang-cxx17
        BUILD_PACKAGES="cmake clang"
    # } // end Linux

    # Windows build with mingw-w64 on Ubuntu 18.04
    - os: linux
      env: >
        BUILD_FLAVOR=ubuntu
        BUILD_RELEASE=bionic
        BUILD_ARCH=amd64
        TOOLCHAIN=linux-mingw-w64-cxx11
        BUILD_PACKAGES="cmake mingw-w64 wine-stable"
    - os: linux
      env: >
        BUILD_FLAVOR=ubuntu
        BUILD_RELEASE=bionic
        BUILD_ARCH=amd64
        TOOLCHAIN=linux-mingw-w64-gnuxx11
        BUILD_PACKAGES="cmake mingw-w64 wine-stable"
    - os: linux
      env: >
        BUILD_FLAVOR=ubuntu
        BUILD_RELEASE=bionic
        BUILD_ARCH=amd64
        TOOLCHAIN=linux-mingw-w64-cxx17
        BUILD_PACKAGES="cmake mingw-w64 wine-stable"

before_install:
  # use the Dockerfile.<distro>.template file for building the image with sed magic
  - |
    sed \
    -e "s/@BUILD_FLAVOR@/${BUILD_FLAVOR}/g" \
    -e "s/@BUILD_RELEASE@/${BUILD_RELEASE}/g" \
    -e "s/@BUILD_ARCH@/${BUILD_ARCH}/g" \
    -e "s/@BUILD_PACKAGES@/${BUILD_PACKAGES}/g" \
    Dockerfile.$BUILD_FLAVOR.template | tee Dockerfile.$BUILD_FLAVOR.$BUILD_RELEASE.$BUILD_ARCH
  - docker build -f Dockerfile.$BUILD_FLAVOR.$BUILD_RELEASE.$BUILD_ARCH -t glog-devel .

script: |
  # run the respective .travis.<distro>.sh script
  docker run \
  -e BUILD_FLAVOR="$BUILD_FLAVOR" \
  -e BUILD_RELEASE="$BUILD_RELEASE" \
  -e BUILD_ARCH="$BUILD_ARCH" \
  -e PROJECT_DIR="$PROJECT_DIR" \
  -e TOOLCHAIN="$TOOLCHAIN" \
  -e RUN_TESTS="$RUN_TESTS" \
  -it glog-devel ./.travis.$BUILD_FLAVOR.sh

