apply plugin: 'com.android.application'

def getProcessesCountArg() {
    def procCount = Runtime.runtime.availableProcessors()

    Gradle gradle = getGradle()
    def isClean = gradle.getStartParameter().getTaskNames().find { it ==~ /.*clean.*/ }
    if (isClean) {
        procCount = 1
    }

    return "-j" + procCount
}

android {
    compileSdkVersion 33
    buildToolsVersion "33.0.0"
    defaultConfig {
        applicationId "com.ensoft.eepp"
        minSdk 27
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters 'arm64-v8a', 'x86_64'
        }
        externalNativeBuild {
            ndkBuild {
                arguments "APP_LDLIBS=-llog -lGLESv2 -lGLESv1_CM -lm -lz -lOpenSLES -lEGL -landroid"
                arguments "APP_PLATFORM=android-19"
                arguments getProcessesCountArg()
            }
        }
        signingConfig signingConfigs.debug
    }
    flavorDimensions "eepp"
    productFlavors {
        ecode {
            buildConfigField "String", "SO_NAME", "\"ecode\""
            applicationId "com.ensoft.ecode"
            dimension "eepp"
            resValue "string", "app_name", "ecode"
            externalNativeBuild {
                ndkBuild {
                    arguments "APP_MODULES=ecode"
                }
            }
        }
        eterm {
            buildConfigField "String", "SO_NAME", "\"eterm\""
            applicationId "com.ensoft.eterm"
            dimension "eepp"
            resValue "string", "app_name", "eterm"
            externalNativeBuild {
                ndkBuild {
                    arguments "APP_MODULES=eterm-app"
                }
            }
        }
        fulltest {
            buildConfigField "String", "SO_NAME", "\"main\""
            versionNameSuffix "-test"
            dimension "eepp"
            resValue "string", "app_name", "eepp"
            externalNativeBuild {
                ndkBuild {
                    arguments "APP_MODULES=main"
                }
            }
        }
    }
    buildTypes {
        debug {
            debuggable true
            externalNativeBuild {
                ndkBuild {
                    arguments "APP_CFLAGS=-g -DDEBUG -DEE_DEBUG"
                    arguments "APP_CPPFLAGS=-std=c++17 -frtti -fexceptions"
                    arguments "APP_OPTIM=debug"
                }
            }
        }
        release {
            externalNativeBuild {
                ndkBuild {
                    arguments "APP_CFLAGS=-fno-strict-aliasing -O3 -s -DNDEBUG -ffast-math"
                    arguments "APP_CPPFLAGS=-std=c++17 -frtti -fexceptions"
                }
            }
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets.main {
        jniLibs.srcDir 'libs'
    }
    externalNativeBuild {
        ndkBuild {
            path 'jni/Android.mk'
        }
    }
    lintOptions {
        abortOnError false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    ndkVersion '25.1.8937393'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
}
