dist: trusty
sudo: true
  #
language: c
  #
env:
  global:
    - IDE_VERSION=1.8.1
  matrix:
    - BOARD="multi4in1:STM32F1:multistm32f103c:upload_method=serialMethod"
    - BOARD="multi4in1:STM32F1:multistm32f103c:upload_method=TxFlashMethod"
    - BOARD="multi4in1:avr:multixmega32d4"
    - BOARD="multi4in1:avr:multiatmega328p:bootloader=none"
    - BOARD="multi4in1:avr:multiatmega328p:bootloader=optiboot"
  #
notifications:
  email: false
  #
before_install:
  #
  # Fetch the tag information for the current branch
  - git fetch origin --tags
  #
  # Publish the buildroot script folder
  - chmod +x ${TRAVIS_BUILD_DIR}/buildroot/bin/*
  - export PATH=${TRAVIS_BUILD_DIR}/buildroot/bin/:${PATH}
  #
  # Install Arduino IDE
  - wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz
  - tar xf arduino-$IDE_VERSION-linux64.tar.xz
  - mv arduino-$IDE_VERSION $HOME/arduino-ide
  - export PATH=$PATH:$HOME/arduino-ide
  # Set the Multi boards package URL
  - arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/pascallanger/DIY-Multiprotocol-TX-Module-Boards/master/package_multi_4in1_board_index.json" --save-prefs
  #
  - if [[ "$BOARD" =~ "multi4in1:STM32F1:" ]]; then
      arduino --install-boards multi4in1:STM32F1;
    fi
  #
  - if [[ "$BOARD" =~ "multi4in1:avr:" ]]; then
      arduino --install-boards multi4in1:avr;
    fi
  #
  - buildMulti() { arduino --verify --board $BOARD Multiprotocol/Multiprotocol.ino; }
  - buildProtocol() { opt_disable $ALL_PROTOCOLS; opt_enable $1; buildMulti; }
  - buildEachProtocol() { exitcode=0; for PROTOCOL in $ALL_PROTOCOLS ; do echo Building $PROTOCOL; buildProtocol $PROTOCOL; if [ $? -ne 0 ]; then exitcode=1; fi; echo; done; return $exitcode; }
  #
install: true
before_script:
  #
  # Change current working directory to the build dir
  - cd ${TRAVIS_BUILD_DIR}
  # Log the initial Multi config 
  - cat Multiprotocol/_Config.h
  # Derive the Multi protocols from the Multi source
  - A7105_PROTOCOLS=$(sed -n 's/[\/\/]*[[:blank:]]*#define[[:blank:]]*\([[:alnum:]_]*_A7105_INO\)\(.*\)/\1/p' Multiprotocol/_Config.h)
  - CC2500_PROTOCOLS=$(sed -n 's/[\/\/]*[[:blank:]]*#define[[:blank:]]*\([[:alnum:]_]*_CC2500_INO\)\(.*\)/\1/p' Multiprotocol/_Config.h)
  - CYRF6936_PROTOCOLS=$(sed -n 's/[\/\/]*[[:blank:]]*#define[[:blank:]]*\([[:alnum:]_]*_CYRF6936_INO\)\(.*\)/\1/p' Multiprotocol/_Config.h)
  - NRF24L01_PROTOCOLS=$(sed -n 's/[\/\/]*[[:blank:]]*#define[[:blank:]]*\([[:alnum:]_]*_NRF24L01_INO\)\(.*\)/\1/p' Multiprotocol/_Config.h)
  - if [[ "$BOARD" =~ "multi4in1:avr:multixmega32d4" ]]; then
      ALL_PROTOCOLS=$(echo $CYRF6936_PROTOCOLS);
    else
      ALL_PROTOCOLS=$(echo $A7105_PROTOCOLS $CC2500_PROTOCOLS $CYRF6936_PROTOCOLS $NRF24L01_PROTOCOLS);
    fi
  - echo $ALL_PROTOCOLS
  #
  # Enable CHECK_FOR_BOOTLOADER when needed
  - if [[ "$BOARD" =~ ":upload_method=TxFlashMethod" ]] || [[ "$BOARD" =~ ":bootloader=optiboot" ]]; then
      opt_enable CHECK_FOR_BOOTLOADER;
    fi
  #
  # Trim the build down for the Atmega328p board
  - if [[ "$BOARD" =~ "multi4in1:avr:multiatmega328p:" ]]; then
      opt_disable $ALL_PROTOCOLS;
      opt_enable FRSKYX_CC2500_INO AFHDS2A_A7105_INO MJXQ_NRF24L01_INO DSM_CYRF6936_INO;
    fi
  #
script:
  # Build with all protocols enabled for STM32; a subset of protocols for Atmega
  - buildMulti
  #
  # Serial only
  - opt_disable ENABLE_PPM
  - opt_enable ENABLE_SERIAL
  - buildMulti
  #
  # PPM only
  - opt_enable ENABLE_PPM
  - opt_disable ENABLE_SERIAL
  - buildMulti
  #
  # Re-enable PPM and serial
  - opt_enable ENABLE_SERIAL
  - opt_enable ENABLE_PPM
  #
  # Build each protocol individually
  - buildEachProtocol
