# qmake configuration for building with android-clang
MAKEFILE_GENERATOR      = UNIX
QMAKE_PLATFORM          = android
QMAKE_COMPILER          = gcc clang llvm

CONFIG                 += android_install unversioned_soname unversioned_libname plugin_with_soname android_deployment_settings

include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/clang.conf)

load(device_config)

# In early configure setup; nothing useful to be done here.
isEmpty(DEFAULT_ANDROID_NDK_ROOT): return()

NDK_ROOT = $$(ANDROID_NDK_ROOT)
isEmpty(NDK_ROOT): NDK_ROOT = $$DEFAULT_ANDROID_NDK_ROOT

!exists($$NDK_ROOT): error("You need to set the ANDROID_NDK_ROOT environment variable to point to your Android NDK.")

NDK_HOST = $$(ANDROID_NDK_HOST)
isEmpty(NDK_HOST): NDK_HOST = $$DEFAULT_ANDROID_NDK_HOST

ANDROID_PLATFORM = $$(ANDROID_NDK_PLATFORM)
isEmpty(ANDROID_PLATFORM): ANDROID_PLATFORM = $$DEFAULT_ANDROID_PLATFORM

ANDROID_SDK_ROOT = $$(ANDROID_SDK_ROOT)
isEmpty(ANDROID_SDK_ROOT): ANDROID_SDK_ROOT = $$DEFAULT_ANDROID_SDK_ROOT

ANDROID_SDK_BUILD_TOOLS_REVISION = $$(ANDROID_BUILD_TOOLS_REVISION)
isEmpty(ANDROID_SDK_BUILD_TOOLS_REVISION) {
    SDK_BUILD_TOOLS_REVISIONS = $$files($$ANDROID_SDK_ROOT/build-tools/*)
    for (REVISION, SDK_BUILD_TOOLS_REVISIONS) {
        BASENAME = $$basename(REVISION)
        greaterThan(BASENAME, $$ANDROID_SDK_BUILD_TOOLS_REVISION): ANDROID_SDK_BUILD_TOOLS_REVISION = $$BASENAME
    }
}

ALL_ANDROID_ABIS = $$(ALL_ANDROID_ABIS)
isEmpty(ALL_ANDROID_ABIS): ALL_ANDROID_ABIS = $$DEFAULT_ANDROID_ABIS
isEmpty(ALL_ANDROID_ABIS): ALL_ANDROID_ABIS = arm64-v8a armeabi-v7a x86_64 x86

CONFIG += $$ANDROID_PLATFORM

ANDROID_MIN_SDK_VERSION = $$replace(ANDROID_PLATFORM, "android-", "")
ANDROID_TARGET_SDK_VERSION = 29

NDK_LLVM_PATH    = $$NDK_ROOT/toolchains/llvm/prebuilt/$$NDK_HOST
QMAKE_CC         = $$NDK_LLVM_PATH/bin/clang
QMAKE_CXX        = $$NDK_LLVM_PATH/bin/clang++
QMAKE_LINK       = $$QMAKE_CXX
QMAKE_OBJCOPY    = $$NDK_LLVM_PATH/bin/llvm-objcopy
QMAKE_AR         = $$NDK_LLVM_PATH/bin/llvm-ar cqs
QMAKE_OBJCOPY    = $$NDK_LLVM_PATH/bin/llvm-objcopy
QMAKE_NM         = $$NDK_LLVM_PATH/bin/llvm-nm -P

QMAKE_CFLAGS_OPTIMIZE      = -Oz
QMAKE_CFLAGS_OPTIMIZE_FULL = -Oz

QMAKE_CFLAGS_WARN_ON    = -Wall -W
QMAKE_CFLAGS_WARN_OFF   =
QMAKE_CFLAGS_SHLIB      = -fPIC
QMAKE_CFLAGS_YACC       = -Wno-unused -Wno-parentheses
QMAKE_CFLAGS_THREAD     = -D_REENTRANT
QMAKE_CFLAGS_HIDESYMS   = -fvisibility=hidden
QMAKE_CFLAGS_NEON       = -mfpu=neon

QMAKE_LFLAGS_APP        = -Wl,--build-id=sha1 -Wl,--no-undefined -Wl,-z,noexecstack -shared
QMAKE_LFLAGS_SHLIB      = -Wl,--build-id=sha1 -Wl,--no-undefined -Wl,-z,noexecstack -shared
QMAKE_LFLAGS_PLUGIN     = $$QMAKE_LFLAGS_SHLIB
QMAKE_LFLAGS_NOUNDEF    = -Wl,--no-undefined
QMAKE_LFLAGS_RPATH      = -Wl,-rpath=
QMAKE_LFLAGS_RPATHLINK  = -Wl,-rpath-link=

equals(QMAKE_HOST.os, Windows) {
    QMAKE_LINK_OBJECT_MAX = 10
    QMAKE_LINK_OBJECT_SCRIPT = object_script
}

QMAKE_LIBS_X11          =
QMAKE_LIBS_THREAD       =
QMAKE_LIBS_OPENGL       =
QMAKE_INCDIR_POST       =
QMAKE_INCDIR_X11        =
QMAKE_LIBDIR_X11        =
QMAKE_INCDIR_OPENGL     =
QMAKE_LIBDIR_OPENGL     =

ANDROID_USE_LLVM = true

armeabi-v7a.sdk = armeabi-v7a
armeabi-v7a.target = armeabi-v7a
armeabi-v7a.dir_affix = armeabi-v7a
armeabi-v7a.CONFIG = armeabi-v7a
armeabi-v7a.deployment_identifier = armeabi-v7a

arm64-v8a.sdk = arm64-v8a
arm64-v8a.target = arm64-v8a
arm64-v8a.dir_affix = arm64-v8a
arm64-v8a.CONFIG = arm64-v8a
arm64-v8a.deployment_identifier = arm64-v8a

x86.sdk = x86
x86.target = x86
x86.dir_affix = x86
x86.CONFIG = x86
x86.deployment_identifier = x86

x86_64.sdk = x86_64
x86_64.target = x86_64
x86_64.dir_affix = x86_64
x86_64.CONFIG = x86_64
x86_64.deployment_identifier = x86_64

load(qt_config)
