language: cpp
compiler: gcc
sudo: require
dist: trusty

before_install:
  - sudo add-apt-repository ppa:beineri/opt-qt593-trusty -y
  - sudo apt-get update -qq

install:
  - sudo apt-get -y install qt59base qt59declarative qt59quickcontrols qt59quickcontrols2 qt59graphicaleffects
  - source /opt/qt*/bin/qt*-env.sh

script:
  - cd source/
  - qmake CONFIG+=release PREFIX=/usr
  - make -j$(nproc)
  - make INSTALL_ROOT=appdir -j$(nproc) install ; find appdir/
  - mkdir -p appdir/usr ; mv appdir/opt/hanoi_towers/bin appdir/usr/ ; rm -rf appdir/opt # Bug in .pro file?
  - mkdir -p appdir/usr/share/icons/hicolor/256x256/apps/ ; cp res/icon.png appdir/usr/share/icons/hicolor/256x256/apps/hanoi_towers.png
  - mkdir -p appdir/usr/share/applications ; cp ../snap/gui/HanoiTower.desktop appdir/usr/share/applications
  - sed -i -e 's|/snap/hanoi-towers/current/meta/gui/icon.png|hanoi-towers|g' appdir/usr/share/applications/*.desktop
  - sed -i -e 's|hanoi-towers|hanoi_towers|g' appdir/usr/share/applications/*.desktop # Bug in desktop file?
  - sed -i -e 's|Games;Application;|Game;|g' appdir/usr/share/applications/*.desktop # Bug in desktop file!
  - sed -i -e 's|^Version=.*||g' appdir/usr/share/applications/*.desktop # Bug in desktop file!
  - wget -c -nv "https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage"
  - chmod a+x linuxdeployqt-continuous-x86_64.AppImage
  - unset QTDIR; unset QT_PLUGIN_PATH ; unset LD_LIBRARY_PATH
  - export VERSION=$(git rev-parse --short HEAD) # linuxdeployqt uses this for naming the file
  - find /opt -iname '*Controls*'
  - ./linuxdeployqt-continuous-x86_64.AppImage appdir/usr/share/applications/*.desktop -bundle-non-qt-libs -qmldir=.
  - ./linuxdeployqt-continuous-x86_64.AppImage appdir/usr/share/applications/*.desktop -appimage -qmldir=.

after_success:
  - find appdir -executable -type f -exec ldd {} \; | grep " => /usr" | cut -d " " -f 2-3 | sort | uniq
  - # curl --upload-file Hanoi_Towers*.AppImage https://transfer.sh/APPNAME-git.$(git rev-parse --short HEAD)-x86_64.AppImage
  - wget -c https://github.com/probonopd/uploadtool/raw/master/upload.sh
  - bash upload.sh Hanoi_Towers*.AppImage*
  
branches:
  except:
    - # Do not build tags that we create when we upload to GitHub Releases
    - /^(?i:continuous)/
