parameters:
  name: 'BuildLinux'
  vmImage: 'ubuntu-16.04'

jobs:
  - job: ${{ parameters.name }}
    pool:
      vmImage: ${{ parameters.vmImage }}
    variables:
      OPAMYES: 1
      ADD_REVISION: 1
    steps:
      - checkout: self
        submodules: recursive
      - script: |
          set -ex
          sudo add-apt-repository ppa:avsm/ppa -y # provides newer version of OCaml and OPAM
          sudo apt-get update -qqy
          sudo apt-get install -qqy ocaml-nox camlp4-extra opam libpcre3-dev zlib1g-dev libgtk2.0-dev ninja-build
        displayName: Install dependencies
      - template: install-neko-snapshot.yaml
        parameters:
          platform: linux64
      - script: |
          set -ex
          opam init
          opam update
          opam pin add haxe . --no-action
          opam install haxe --deps-only
          opam list
          ocamlopt -v
        displayName: Install OCaml libraries
      - script: |
          set -ex
          opam config exec -- make -s STATICLINK=1 libs
          opam config exec -- make -s STATICLINK=1 prebuild
          opam config exec -- make -s -j`nproc` STATICLINK=1 haxe
          opam config exec -- make -s haxelib
          make -s package_bin
          ls -l out
          ldd -v ./haxe
          ldd -v ./haxelib
        displayName: Build Haxe
      - task: PublishPipelineArtifact@0
        inputs:
          artifactName: 'linuxBinaries'
          targetPath: out
      - script: |
          set -ex
          make -s xmldoc
          cat >extra/doc/info.json <<EOL
            {
              "commit": "$(Build.SourceVersion)",
              "branch": "$(Build.SourceBranchName)"
            }
          EOL
        displayName: Build xmldoc
      - task: PublishPipelineArtifact@0
        inputs:
          artifactName: 'xmldoc'
          targetPath: extra/doc