language: cpp

matrix:
  include:
    - os: linux
      compiler: gcc
      cache: apt
      dist: xenial

env:
  global:
    - PROJECT_NAME=PortaPack-HAVOC
    - SHORT_COMMIT_HASH=`git rev-parse --short HEAD`
    - VERSION_STRING=nightly-$SHORT_COMMIT_HASH
    - BUILD_DATE="`date +%Y-%m-%d`"
    - BUILD_NAME="$PROJECT_NAME-$BUILD_DATE-$SHORT_COMMIT_HASH"
    - ARTEFACT_BASE=$TRAVIS_BUILD_DIR/artefacts/
    - ARTEFACT_PATH=$ARTEFACT_BASE/$BUILD_NAME

before_install:
  - sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa -y
  - sudo apt-get update -q
  - sudo apt-get install gcc-arm-embedded -y

script:
  # TODO: Introduce top-level Makefile, this is lame.
  - sed -e "s/\#set(VERSION.*/set(VERSION \"$VERSION_STRING\")/" -i".bak" CMakeLists.txt
  - mkdir build/
  - pushd build/
  - cmake ..
  - make firmware
  - popd

after_success:
  - mkdir -p $ARTEFACT_PATH
  # Copy firmware to firmware-bin directory
  - cd $TRAVIS_BUILD_DIR/build
  - cp firmware/portapack-h1-havoc.bin $ARTEFACT_PATH/
  - cp hackrf/firmware/hackrf_usb/hackrf_usb.dfu $ARTEFACT_PATH/
  - cd $TRAVIS_BUILD_DIR
  - cp LICENSE $ARTEFACT_PATH/
  # Build the archive
  - cd $ARTEFACT_BASE
  - tar -cJvf $ARTEFACT_BASE/$BUILD_NAME.tar.xz $BUILD_NAME
  - md5sum --binary $BUILD_NAME.tar.xz >MD5SUMS
  - sha256sum --binary $BUILD_NAME.tar.xz >SHA256SUMS

addons:
  apt:
    packages:
      - coreutils
      - tar
      - sed
      - cmake
      - dfu-util

