# C/C++ with GCC
# Build your C/C++ project with GCC using make.
# Add steps that publish test results, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/c-cpp/gcc


variables:
  PERL_CACHE: $(Pipeline.Workspace)/perl5
  CCACHE_DIR: $(Pipeline.Workspace)/ccache

trigger:
- master

pr:
  - master

pool:
  vmImage: 'ubuntu-20.04'

steps:
- checkout: self
  submodules: true
- task: Cache@1
  inputs:
    key: 'perl_cache | "$(Agent.OS)"'
    path: $(PERL_CACHE)
  displayName: perlcache
- task: Cache@2
  inputs:
    key: 'ccache | "$(Agent.OS)"'
    path: $(CCACHE_DIR)
  displayName: ccache
- bash: |
    sudo apt-get update
    sudo apt-get install -y ragel re2c dos2unix texinfo texi2html gdb curl cpanminus ccache libboost-all-dev libmodern-perl-perl libtemplate-perl libtemplate-plugin-yaml-perl libyaml-perl liblocal-lib-perl libcapture-tiny-perl libpath-tiny-perl libtest-differences-perl libtext-table-perl libdata-hexdump-perl libregexp-common-perl libclone-perl
    eval $(perl -I$PERL_CACHE -Mlocal::lib=$PERL_CACHE)
    cpanm  App::Prove Capture::Tiny::Extended File::Path  CPU::Z80::Assembler Test::Cmd::Common Test::HexDifferences Object::Tiny::RW List::Uniq
  displayName: "Install prerequisites"
- bash: |
    eval $(perl -I$PERL_CACHE -Mlocal::lib=$PERL_CACHE)
    ./build.sh -l
  displayName: 'Build binaries'
- bash: |
    eval $(perl -I$PERL_CACHE -Mlocal::lib=$PERL_CACHE)
    ./build.sh -b 
  displayName: 'Build libraries'
- bash: |
    eval $(perl -I$PERL_CACHE -Mlocal::lib=$PERL_CACHE)
    ./build.sh -b -l -e
  displayName: 'Build examples'
- bash: |
    eval $(perl -I$PERL_CACHE -Mlocal::lib=$PERL_CACHE)
    ./build.sh -b -l -t
  displayName: 'Build and run tests'
