# -fstack-protector-strong offers good protection against stack smashing attacks.
# It is (currently) enabled only on Android because we know for sure that Andoroid compilers supports it
QMAKE_CFLAGS += -fstack-protector-strong -DANDROID

equals(ANDROID_TARGET_ARCH, armeabi-v7a): \
    QMAKE_CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -fno-builtin-memmove
else: equals(ANDROID_TARGET_ARCH, armeabi): \
    QMAKE_CFLAGS += -march=armv5te -mtune=xscale -msoft-float -fno-builtin-memmove
# -fno-builtin-memmove is used to workaround https://code.google.com/p/android/issues/detail?id=81692

QMAKE_CFLAGS += --sysroot=$$ANDROID_PLATFORM_ROOT_PATH
QMAKE_CFLAGS_WARN_ON    = -Wall -W
QMAKE_CFLAGS_WARN_OFF   =
equals(ANDROID_TARGET_ARCH, armeabi-v7a) | equals(ANDROID_TARGET_ARCH, armeabi) {
    QMAKE_CFLAGS_RELEASE                   = -Os
    QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO    = -g -Os
    QMAKE_CFLAGS_DEBUG                     = -g -marm -O0
    equals(ANDROID_TARGET_ARCH, armeabi):if(equals(NDK_TOOLCHAIN_VERSION, 4.8)|equals(NDK_TOOLCHAIN_VERSION, 4.9)) {
        DEFINES += QT_OS_ANDROID_GCC_48_WORKAROUND
    } else {
        QMAKE_CFLAGS_RELEASE += -mthumb
        QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -mthumb
    }

    # Don't override our options with -O3
    QMAKE_CFLAGS_OPTIMIZE_FULL =
} else {
    QMAKE_CFLAGS_RELEASE                   = -O2
    QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO    = -g -O2
    QMAKE_CFLAGS_DEBUG                     = -g
}

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_CXXFLAGS_CXX11    = -std=c++11
QMAKE_CXXFLAGS_CXX14    = -std=c++14
QMAKE_CXXFLAGS_CXX1Z    = -std=c++1z
QMAKE_CXXFLAGS_GNUCXX11 = -std=gnu++11
QMAKE_CXXFLAGS_GNUCXX14 = -std=gnu++14
QMAKE_CXXFLAGS_GNUCXX1Z = -std=gnu++1z

QMAKE_CXXFLAGS          = $$QMAKE_CFLAGS
QMAKE_CXXFLAGS_WARN_ON  = $$QMAKE_CFLAGS_WARN_ON
QMAKE_CXXFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF
QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_RELEASE
QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO += $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO
QMAKE_CXXFLAGS_DEBUG   += $$QMAKE_CFLAGS_DEBUG
QMAKE_CXXFLAGS_SHLIB    = $$QMAKE_CFLAGS_SHLIB
QMAKE_CXXFLAGS_YACC     = $$QMAKE_CFLAGS_YACC
QMAKE_CXXFLAGS_THREAD   = $$QMAKE_CFLAGS_THREAD
QMAKE_CXXFLAGS_HIDESYMS = $$QMAKE_CFLAGS_HIDESYMS -fvisibility-inlines-hidden

# modifications to linux.conf
QMAKE_AR                = $$NDK_TOOLCHAIN_PATH/bin/$$NDK_TOOLS_PREFIX-ar cqs
QMAKE_OBJCOPY           = $$NDK_TOOLCHAIN_PATH/bin/$$NDK_TOOLS_PREFIX-objcopy
QMAKE_NM                = $$NDK_TOOLCHAIN_PATH/bin/$$NDK_TOOLS_PREFIX-nm -P

QMAKE_STRIP             =
#$$NDK_TOOLCHAIN_PATH/bin/$$NDK_TOOLS_PREFIX-strip

QMAKE_RANLIB            = $$NDK_TOOLCHAIN_PATH/bin/$$NDK_TOOLS_PREFIX-ranlib

equals(ANDROID_TARGET_ARCH, armeabi)|equals(ANDROID_TARGET_ARCH, armeabi-v7a): \
    LIBGCC_PATH_FULL = $$system("$$QMAKE_GCC -mthumb-interwork -print-libgcc-file-name")
else: \
    LIBGCC_PATH_FULL = $$system("$$QMAKE_GCC -print-libgcc-file-name")

LIBGCC_PATH             = $$dirname(LIBGCC_PATH_FULL)

QMAKE_INCDIR            = $$ANDROID_SOURCES_CXX_STL_INCDIR $$QMAKE_ANDROID_PLATFORM_INCDIR
QMAKE_LIBDIR            = $$ANDROID_SOURCES_CXX_STL_LIBDIR $$QMAKE_ANDROID_PLATFORM_LIBDIR $$LIBGCC_PATH
QMAKE_INCDIR_X11        =
QMAKE_LIBDIR_X11        =
QMAKE_INCDIR_OPENGL     = $$QMAKE_ANDROID_PLATFORM_INCDIR
QMAKE_LIBDIR_OPENGL     = $$QMAKE_ANDROID_PLATFORM_LIBDIR

QMAKE_LINK_SHLIB        = $$QMAKE_LINK
QMAKE_LFLAGS            = --sysroot=$$ANDROID_PLATFORM_ROOT_PATH
QMAKE_RPATHLINK         = $$QMAKE_ANDROID_PLATFORM_LIBDIR
QMAKE_LFLAGS_APP        = -Wl,--no-undefined -Wl,-z,noexecstack -shared
QMAKE_LFLAGS_SHLIB      = -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=

QMAKE_LIBS_PRIVATE      = -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc
QMAKE_LIBS_X11          =
QMAKE_LIBS_THREAD       =
QMAKE_LIBS_EGL          = -lEGL
QMAKE_LIBS_OPENGL       =
QMAKE_LIBS_OPENGL_ES2   = -lGLESv2


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

load(qt_config)

QMAKE_DEFAULT_LIBDIRS = $$QMAKE_LIBDIR
QMAKE_DEFAULT_INCDIRS = $$QMAKE_INCDIR
