language: cpp

sudo: required
dist: xenial

branches:
  only:
    - master

matrix:
  include:
  # Linux desktop builds
  - compiler: gcc
    env: BUILD=native SMW_USE_SDL2=false

  - compiler: gcc
    env: BUILD=native SMW_USE_SDL2=true

  - compiler: clang
    env: BUILD=native SMW_USE_SDL2=false

  - compiler: clang
    env: BUILD=native SMW_USE_SDL2=true

  # OSX SDL1.2 build
  - os: osx
    env: BUILD=native SMW_USE_SDL2=false
    compiler: clang
    before_script:
    - brew update
    - brew install sdl sdl_image sdl_mixer

  # OSX SDL2 build
  - os: osx
    env: BUILD=native SMW_USE_SDL2=true
    compiler: clang
    before_script:
    - brew update
    - brew install sdl2 sdl2_image sdl2_mixer

  # Emscripten
  - env: BUILD=emscripten

  # Android builds
  - language: android
    env: BUILD=android ABILIST='armeabi armeabi-v7a arm64-v8a'

  - language: android
    env: BUILD=android ABILIST='x86 x86_64'

  - language: android
    env: BUILD=android ABILIST='mips mips64'


before_script:
  # Native (Linux, OSX)
  - if [[ "$BUILD" == "native" && "$TRAVIS_OS_NAME" == "linux" ]]; then
      sudo apt-get -qq update &&
      sudo apt-get install -y
        cmake
        clang
        default-jre
        g++
        libsdl1.2-dev
        libsdl-image1.2-dev
        libsdl-mixer1.2-dev
        libsdl2-dev
        libsdl2-image-dev
        libsdl2-mixer-dev
        libegl1-mesa-dev
        libgles2-mesa-dev
    ; fi
  - if [[ "$BUILD" == "native" ]]; then $CXX --version; fi
  - if [[ "$BUILD" == "native" ]]; then cmake --version; fi
  - if [[ "$BUILD" == "native" && "$SMW_USE_SDL2" == "false" ]]; then sdl-config --version; fi
  - if [[ "$BUILD" == "native" && "$SMW_USE_SDL2" == "true" ]];  then sdl2-config --version; fi

  # Emscripten
  - if [[ "$BUILD" == "emscripten" && "$TRAVIS_OS_NAME" == "linux" ]]; then
      git clone https://github.com/emscripten-core/emsdk.git --depth=1;
      cd emsdk;
      ./emsdk install 1.39.5;
      ./emsdk activate 1.39.5;
      source ./emsdk_env.sh;
      cd ..;
    fi
  - if [[ "$BUILD" == "emscripten" && "$TRAVIS_OS_NAME" == "linux" ]]; then emcc -v; fi

  # Android SDK + NDK
  - if [[ "$BUILD" == "android" ]]; then
      sudo apt-get -qq update &&
      sudo apt-get install -y
        ant
        expect
        lib32bz2-1.0
        lib32gcc1
        lib32ncurses5
        lib32stdc++6
        lib32z1
        openjdk-7-jdk
    ; fi
  - if [[ "$BUILD" == "android" ]]; then
      cd ..;
      wget http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin;
      chmod +x ./android-ndk-r10e-linux-x86_64.bin;
      ./android-ndk-r10e-linux-x86_64.bin > /dev/null;
      export PATH=$PATH:$(pwd)/android-ndk-r10e;
    fi

script:
  - if [[ "$BUILD" == "native" ]]; then mkdir build && cd build; fi
  - if [[ "$BUILD" == "native" && "$SMW_USE_SDL2" == "false" ]]; then
      cmake -D USE_SDL2_LIBS:BOOL=OFF ..;
      make;
    fi
  - if [[ "$BUILD" == "native" && "$SMW_USE_SDL2" == "true" ]]; then
      cmake -D USE_SDL2_LIBS:BOOL=ON ..;
      make;
    fi

  # Android
  - if [[ "$BUILD" == "android" ]]; then
      git clone --depth=1 https://github.com/mmatyas/supermariowar-android.git;
      mv supermariowar supermariowar-android/;
      cd supermariowar-android;
      ./build.sh --abi=$ABILIST;
    fi

  # Emscripten
  - if [[ "$BUILD" == "emscripten" ]]; then
      cd dependencies;
      curl -L https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.4.tar.gz | tar xzf -;
      cd ..;
      sed -i 's|if (BUILD_STATIC_LIBS)|if (BUILD_STATIC_LIBS)\ninclude_directories(dependencies/SDL2_mixer-2.0.4)|' CMakeLists.txt;
      unzip data.zip > /dev/null;
      mkdir build_js && cd build_js;
      emconfigure cmake .. -DNO_NETWORK=1 -DDISABLE_SYSLIB_CHECKS=1 -DUSE_SDL2_LIBS=1;
      emmake make smw;
    fi

android:
  components:
    - build-tools-23.0.1
    - android-15
