apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

android {
    namespace = 'com.termux.nativeentrypoint'

    compileSdkVersion project.properties.compileSdkVersion.toInteger()
    ndkVersion = System.getenv("JITPACK_NDK_VERSION") ?: project.properties.ndkVersion

    defaultConfig {
        minSdkVersion project.properties.minSdkVersion.toInteger()
        targetSdkVersion project.properties.targetSdkVersion.toInteger()

        externalNativeBuild {
            ndkBuild {
                cFlags "-Wall", "-Wextra", "-Werror", "-Os", "-fno-stack-protector", "-Wl,--gc-sections"
            }
        }

        ndk {
            abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            jniDebuggable false
        }
        debug {
            jniDebuggable false
            minifyEnabled false
        }
    }

    externalNativeBuild {
        ndkBuild {
            path "src/main/jni/Android.mk"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    buildFeatures {
        viewBinding = false
    }
}

tasks.withType(JavaCompile).configureEach {
    options.compilerArgs << "-Xlint:deprecation"
}

dependencies {
    implementation 'androidx.annotation:annotation:1.9.1'
}

tasks.register('sourceJar', Jar) {
    from android.sourceSets.main.java.srcDirs
    archiveClassifier = "sources"
}

afterEvaluate {
    publishing {
        publications {
            // Creates a Maven publication called "release".
            release(MavenPublication) {
                from components.findByName('release')
                groupId = 'com.termux'
                artifactId = 'native-entrypoint'
                version = '1.0'
                artifact(sourceJar)
            }
        }
    }
}
