environment:
  global:
    CYG_MIRROR: http://cygwin.mirror.constant.com

  matrix:
    - CYG_ARCH: cygwin
      CYG_ROOT: C:\cygwin
      CYG_SETUP: C:\cygwin\setup-x86.exe
    - CYG_ARCH: cygwin64
      CYG_ROOT: C:\cygwin64
      CYG_SETUP: C:\cygwin64\setup-x86_64.exe

clone_depth: 1

init:
  # enable RDP access
  - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
  # do not convert new lines to CRLF
  - git config --global core.autocrlf input
  # print processor and OS architecture
  - wmic computersystem get systemtype
  - wmic OS get OSArchitecture

cache:
  - '%APPVEYOR_BUILD_FOLDER%\dependency\sources'
  - '%CYG_ROOT%\var\cache\setup'

install:
  - '%CYG_SETUP% --quiet-mode --no-shortcuts --packages patch,lua,lua-devel,lua-lpeg,libncurses-devel'
  - '%CYG_ROOT%\bin\cygcheck --check-setup --dump-only'

before_build:
  - ps: |
      $bash = $env:CYG_ROOT + "\bin\bash"
      $cmd = "cd `$APPVEYOR_BUILD_FOLDER && "
      $cmd +=
      @'
        for f in $(git ls-files -s | awk '$1 == 120000 {print $4}')
        do
          # echo $f is a symlink pointing to $dir/$target
          dir=$(dirname "${f}")
          pushd "$dir" 2>&1 > /dev/null
          file=$(basename "$f")
          target=`cat "$file"`
          rm "$file"
          ln -s "$target" "$file"
          popd 2>&1 > /dev/null
        done
      '@
      & $bash -lc $cmd

build_script:
  - '%CYG_ROOT%\bin\bash -lc "cd $APPVEYOR_BUILD_FOLDER && make local && file vis"'

test_script:
  - '%CYG_ROOT%\bin\bash -lc "cd $APPVEYOR_BUILD_FOLDER && make test"'

after_test:
  - 7z a -y vis-%CYG_ARCH%.zip *.exe lua

artifacts:
  - path: vis-%CYG_ARCH%.zip
