name: CI - Linux Android Compilation

on:
  push:
    branches:
    - 'main'
    - 'development'
  pull_request:
    branches:
    - 'main'
    - 'development'
  workflow_dispatch:

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - name: Git checkout
      uses: actions/checkout@v4

    - name: Install auto tools
      run: |
        sudo apt-get install automake
    
    - name: Download Android NDK and unzip 
      run: |
        wget -q https://dl.google.com/android/repository/android-ndk-r27-linux.zip
        unzip -q android-ndk-r27-linux.zip

    - name: Set Up Build Environment, compile code for Android platform
      run: |
        echo "Set Up Build Environment"
        export ANDROID_NDK_HOME="$PWD/android-ndk-r27" 
        export PATH="$PATH:$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/"        
        export CC=aarch64-linux-android34-clang
        export CXX=aarch64-linux-android34-clang++
        export AS=llvm-as
        export LD=ld
        export RANLIB=llvm-ranlib
        export STRIP=llvm-strip

        echo "Compile the source code"
        make -v
        ./gitcompile --host=aarch64-linux-android

    - name: Verify the compiled binaries
      run: |
        echo "Verify the compiled binaries"
        Files=("src/.libs/libadsp_default_listener.so
          src/.libs/libadsprpc.so
          src/.libs/libcdsp_default_listener.so
          src/.libs/libcdsprpc.so
          src/.libs/libsdsp_default_listener.so
          src/.libs/libsdsprpc.so
          src/adsprpcd
          src/cdsprpcd
          src/sdsprpcd")
        for File in $Files
        do 
         if [ -f $File ] ; then echo $File " - Exists" ; else echo $File " - Not Exists" && exit -1 ; fi
        done

