language: c++
compiler: gcc
sudo: require
dist: xenial

before_install:
    - sudo add-apt-repository ppa:beineri/opt-qt-5.12.2-xenial -y
    - sudo apt-get update -qq
    
install: 
    - sudo apt-get -y install qt5-qmake qt5-default libqt5opengl5-dev qtbase5-dev libqwt-qt5-dev libsndfile1-dev librtlsdr-dev librtlsdr0 libfftw3-dev portaudio19-dev libfaad-dev zlib1g-dev rtl-sdr libusb-1.0-0-dev mesa-common-dev libgl1-mesa-dev libsamplerate-dev 
    - sudo apt-get -y install libiio-dev
    - # source /opt/qt5/bin/qt5-env.sh
    - # QWT for Qt 5, see https://github.com/arkottke/strata/blob/master/.travis.yml
    - # svn checkout svn://svn.code.sf.net/p/qwt/code/branches/qwt-6.1 qwt
    - # cd qwt
    - # qmake
    - # make -j4
    - # sudo make install
    - # find /usr/local/qwt-6.1.4-svn/
    - # cd ..
    
script:
  - # sed -i -e 's|CONFIG.*sdrplay||g' qt-dab.pro
  - # sed -i -e 's|CONFIG.*airspy||g' qt-dab.pro
  - # sed -i -e 's|CONFIG.*spectrum||g' qt-dab.pro

  - cd dab-maxi
  - cmake . -DTRY_EPG=ON -DRTLSDR=ON -DRTL_TCP=ON  -DAIRSPY=ON -DSDRPLAY=ON -DSDRPLAY_V3=ON -DLIMESDR=ON -DHACKRF=ON -DPLUTO=ON -DCMAKE_INSTALL_PREFIX=/usr
  - make -j4
  - # sudo make DESTIDR=appdir install ; sudo chown -R $USER appdir ; find appdir/
  - ls -lh .
  - rm -rf *_autogen
  - mkdir -p appdir/usr/bin
  - cp qt-dab-3.7  appdir/usr/bin/qt-dab
 
  - mkdir -p appdir/usr/share/applications ; cp qt-dab.desktop appdir/usr/share/applications
  - cp qt-dab.png appdir/qt-dab.png
  - touch appdir/qt-dab.png # Dear upstream developers, please provide an application icon
  - mkdir -p ./appdir/usr/share/icons/hicolor/256x256/apps/
  - cp qt-dab.png appdir/usr/share/icons/hicolor/256x256/apps/
  
after_success:
  - wget -c "https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage" 
  - chmod a+x linuxdeployqt*.AppImage
  - unset QTDIR; unset QT_PLUGIN_PATH ; unset LD_LIBRARY_PATH
  - ./linuxdeployqt*.AppImage ./appdir/usr/share/applications/* -bundle-non-qt-libs
  - # Workaround for https://github.com/probonopd/linuxdeployqt/issues/31#issuecomment-289267637
  - ./linuxdeployqt*.AppImage --appimage-extract
  - find appdir/usr/plugins/ -type f -exec squashfs-root/usr/bin/patchelf --set-rpath '$ORIGIN/../../lib' {} \;
  - ./linuxdeployqt*.AppImage ./appdir/usr/share/applications/* -bundle-non-qt-libs
  - # Workaround for https://github.com/JvanKatwijk/qt-dab/issues/34
  - # find /usr/ -type f -name librtlsdr.so* -exec cp {} appdir/usr/lib/librtlsdr.so \;
  - find /usr/lib/ -type f -name librtlsdr.so* -exec cp {} appdir/usr/lib/librtlsdr.so \;
  - chmod a+x appimage/* ; rm appdir/AppRun ; cp appimage/* appdir/
  - export PATH=squashfs-root/usr/bin/:$PATH # Make it pick up our private patched mksquashfs; https://github.com/plougher/squashfs-tools/pull/13/files
  - squashfs-root/usr/bin/appimagetool $(readlink -f ./appdir/)
  - find ./appdir -executable -type f -exec ldd {} \; | grep " => /usr" | cut -d " " -f 2-3 | sort | uniq
  - curl --upload-file ./Qt_DAB*.AppImage https://transfer.sh/Qt_DAB-git.$(git rev-parse --short HEAD)-x86_64.AppImage
  - wget -c https://github.com/probonopd/uploadtool/raw/master/upload.sh
  - bash ./upload.sh ./Qt_DAB*.AppImage

