// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

filegroup {
    name: "LATIN_IME_CORE_SRC_FILES",
    srcs: [
        "src/dictionary/header/header_policy.cpp",
        "src/dictionary/header/header_read_write_utils.cpp",
        "src/dictionary/property/ngram_context.cpp",
        "src/dictionary/structure/dictionary_structure_with_buffer_policy_factory.cpp",
        "src/dictionary/structure/pt_common/bigram/bigram_list_read_write_utils.cpp",
        "src/dictionary/structure/pt_common/dynamic_pt_gc_event_listeners.cpp",
        "src/dictionary/structure/pt_common/dynamic_pt_reading_helper.cpp",
        "src/dictionary/structure/pt_common/dynamic_pt_reading_utils.cpp",
        "src/dictionary/structure/pt_common/dynamic_pt_updating_helper.cpp",
        "src/dictionary/structure/pt_common/dynamic_pt_writing_utils.cpp",
        "src/dictionary/structure/pt_common/patricia_trie_reading_utils.cpp",
        "src/dictionary/structure/pt_common/shortcut/shortcut_list_reading_utils.cpp",
        "src/dictionary/structure/v2/patricia_trie_policy.cpp",
        "src/dictionary/structure/v2/ver2_patricia_trie_node_reader.cpp",
        "src/dictionary/structure/v2/ver2_pt_node_array_reader.cpp",
        "src/dictionary/structure/v4/ver4_dict_buffers.cpp",
        "src/dictionary/structure/v4/ver4_dict_constants.cpp",
        "src/dictionary/structure/v4/ver4_patricia_trie_node_reader.cpp",
        "src/dictionary/structure/v4/ver4_patricia_trie_node_writer.cpp",
        "src/dictionary/structure/v4/ver4_patricia_trie_policy.cpp",
        "src/dictionary/structure/v4/ver4_patricia_trie_reading_utils.cpp",
        "src/dictionary/structure/v4/ver4_patricia_trie_writing_helper.cpp",
        "src/dictionary/structure/v4/ver4_pt_node_array_reader.cpp",
        "src/dictionary/structure/v4/content/dynamic_language_model_probability_utils.cpp",
        "src/dictionary/structure/v4/content/language_model_dict_content.cpp",
        "src/dictionary/structure/v4/content/language_model_dict_content_global_counters.cpp",
        "src/dictionary/structure/v4/content/shortcut_dict_content.cpp",
        "src/dictionary/structure/v4/content/sparse_table_dict_content.cpp",
        "src/dictionary/structure/v4/content/terminal_position_lookup_table.cpp",
        "src/dictionary/utils/buffer_with_extendable_buffer.cpp",
        "src/dictionary/utils/byte_array_utils.cpp",
        "src/dictionary/utils/dict_file_writing_utils.cpp",
        "src/dictionary/utils/file_utils.cpp",
        "src/dictionary/utils/forgetting_curve_utils.cpp",
        "src/dictionary/utils/format_utils.cpp",
        "src/dictionary/utils/mmapped_buffer.cpp",
        "src/dictionary/utils/multi_bigram_map.cpp",
        "src/dictionary/utils/probability_utils.cpp",
        "src/dictionary/utils/sparse_table.cpp",
        "src/dictionary/utils/trie_map.cpp",
        "src/suggest/core/suggest.cpp",
        "src/suggest/core/dicnode/dic_node.cpp",
        "src/suggest/core/dicnode/dic_node_utils.cpp",
        "src/suggest/core/dicnode/dic_nodes_cache.cpp",
        "src/suggest/core/dictionary/dictionary.cpp",
        "src/suggest/core/dictionary/dictionary_utils.cpp",
        "src/suggest/core/dictionary/digraph_utils.cpp",
        "src/suggest/core/dictionary/error_type_utils.cpp",
        "src/suggest/core/layout/additional_proximity_chars.cpp",
        "src/suggest/core/layout/proximity_info.cpp",
        "src/suggest/core/layout/proximity_info_params.cpp",
        "src/suggest/core/layout/proximity_info_state.cpp",
        "src/suggest/core/layout/proximity_info_state_utils.cpp",
        "src/suggest/core/policy/weighting.cpp",
        "src/suggest/core/session/dic_traverse_session.cpp",
        "src/suggest/core/result/suggestion_results.cpp",
        "src/suggest/core/result/suggestions_output_utils.cpp",
        "src/suggest/policyimpl/gesture/gesture_suggest_policy_factory.cpp",
        "src/suggest/policyimpl/typing/scoring_params.cpp",
        "src/suggest/policyimpl/typing/typing_scoring.cpp",
        "src/suggest/policyimpl/typing/typing_suggest_policy.cpp",
        "src/suggest/policyimpl/typing/typing_traversal.cpp",
        "src/suggest/policyimpl/typing/typing_weighting.cpp",
        "src/utils/autocorrection_threshold_utils.cpp",
        "src/utils/char_utils.cpp",
        "src/utils/jni_data_utils.cpp",
        "src/utils/log_utils.cpp",
        "src/utils/time_keeper.cpp",

        // BACKWARD_V402
        "src/dictionary/structure/backward/v402/ver4_dict_buffers.cpp",
        "src/dictionary/structure/backward/v402/ver4_dict_constants.cpp",
        "src/dictionary/structure/backward/v402/ver4_patricia_trie_node_reader.cpp",
        "src/dictionary/structure/backward/v402/ver4_patricia_trie_node_writer.cpp",
        "src/dictionary/structure/backward/v402/ver4_patricia_trie_policy.cpp",
        "src/dictionary/structure/backward/v402/ver4_patricia_trie_reading_utils.cpp",
        "src/dictionary/structure/backward/v402/ver4_patricia_trie_writing_helper.cpp",
        "src/dictionary/structure/backward/v402/ver4_pt_node_array_reader.cpp",
        "src/dictionary/structure/backward/v402/content/bigram_dict_content.cpp",
        "src/dictionary/structure/backward/v402/content/probability_dict_content.cpp",
        "src/dictionary/structure/backward/v402/content/shortcut_dict_content.cpp",
        "src/dictionary/structure/backward/v402/content/sparse_table_dict_content.cpp",
        "src/dictionary/structure/backward/v402/content/terminal_position_lookup_table.cpp",
        "src/dictionary/structure/backward/v402/bigram/ver4_bigram_list_policy.cpp",
    ],
}

cc_library {
    name: "libjni_latinime",
    host_supported: true,
    product_specific: true,

    sdk_version: "14",
    cflags: [
        "-Werror",
        "-Wall",
        "-Wextra",
        "-Weffc++",
        "-Wformat=2",
        "-Wcast-qual",
        "-Wcast-align",
        "-Wwrite-strings",
        "-Wfloat-equal",
        "-Wpointer-arith",
        "-Winit-self",
        "-Wredundant-decls",
        "-Woverloaded-virtual",
        "-Wsign-promo",
        "-Wno-system-headers",
        "-Wno-format-nonliteral",

        // To suppress compiler warnings for unused variables/functions used for debug features etc.
        "-Wno-unused-parameter",
        "-Wno-unused-function",
    ],
    local_include_dirs: ["src"],

    srcs: [
        "com_android_inputmethod_keyboard_ProximityInfo.cpp",
        "com_android_inputmethod_latin_BinaryDictionary.cpp",
        "com_android_inputmethod_latin_BinaryDictionaryUtils.cpp",
        "com_android_inputmethod_latin_DicTraverseSession.cpp",
        "jni_common.cpp",

        ":LATIN_IME_CORE_SRC_FILES",
    ],

    target: {
        android_x86: {
            // HACK: -mstackrealign is required for x86 builds running on pre-KitKat devices to avoid crashes
            // with SSE instructions.
            cflags: ["-mstackrealign"],
        },
        android: {
            stl: "libc++_static",
        },
        host: {
            cflags: ["-DHOST_TOOL"],
        },
    },
}

cc_library_static {
    name: "liblatinime_static_for_unittests",
    host_supported: true,

    cflags: [
        "-Wno-unused-parameter",
        "-Wno-unused-function",
        "-Wall",
        "-Werror",
    ],
    local_include_dirs: ["src"],
    sdk_version: "14",
    stl: "libc++_static",

    srcs: [":LATIN_IME_CORE_SRC_FILES"],
}

cc_test {
    name: "liblatinime_unittests",
    host_supported: true,

    cflags: [
        "-Wno-unused-parameter",
        "-Wno-unused-function",
        "-Wall",
        "-Werror",
    ],
    local_include_dirs: ["src"],
    sdk_version: "14",
    stl: "libc++_static",

    srcs: [
        "tests/defines_test.cpp",
        "tests/dictionary/header/header_read_write_utils_test.cpp",
        "tests/dictionary/structure/v4/content/language_model_dict_content_test.cpp",
        "tests/dictionary/structure/v4/content/language_model_dict_content_global_counters_test.cpp",
        "tests/dictionary/structure/v4/content/probability_entry_test.cpp",
        "tests/dictionary/structure/v4/content/terminal_position_lookup_table_test.cpp",
        "tests/dictionary/utils/bloom_filter_test.cpp",
        "tests/dictionary/utils/buffer_with_extendable_buffer_test.cpp",
        "tests/dictionary/utils/byte_array_utils_test.cpp",
        "tests/dictionary/utils/format_utils_test.cpp",
        "tests/dictionary/utils/probability_utils_test.cpp",
        "tests/dictionary/utils/sparse_table_test.cpp",
        "tests/dictionary/utils/trie_map_test.cpp",
        "tests/suggest/core/dicnode/dic_node_pool_test.cpp",
        "tests/suggest/core/layout/geometry_utils_test.cpp",
        "tests/suggest/core/layout/normal_distribution_2d_test.cpp",
        "tests/suggest/policyimpl/utils/damerau_levenshtein_edit_distance_policy_test.cpp",
        "tests/utils/autocorrection_threshold_utils_test.cpp",
        "tests/utils/char_utils_test.cpp",
        "tests/utils/int_array_view_test.cpp",
        "tests/utils/time_keeper_test.cpp",
    ],
    static_libs: ["liblatinime_static_for_unittests"],
}