//
// Copyright (C) 2011 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.
//

cc_defaults {
    name: "libartbase_defaults",
    defaults: ["art_defaults"],
    host_supported: true,
    srcs: [
        "arch/instruction_set.cc",
        "base/allocator.cc",
        "base/arena_allocator.cc",
        "base/arena_bit_vector.cc",
        "base/bit_vector.cc",
        "base/enums.cc",
        "base/file_magic.cc",
        "base/file_utils.cc",
        "base/hex_dump.cc",
        "base/hiddenapi_flags.cc",
        "base/logging.cc",
        "base/malloc_arena_pool.cc",
        "base/membarrier.cc",
        "base/memfd.cc",
        "base/memory_region.cc",
        "base/mem_map.cc",
        // "base/mem_map_fuchsia.cc", put in target when fuchsia supported by soong
        "base/os_linux.cc",
        "base/runtime_debug.cc",
        "base/safe_copy.cc",
        "base/scoped_arena_allocator.cc",
        "base/scoped_flock.cc",
        "base/socket_peer_is_trusted.cc",
        "base/time_utils.cc",
        "base/unix_file/fd_file.cc",
        "base/unix_file/random_access_file_utils.cc",
        "base/utils.cc",
        "base/zip_archive.cc",
    ],
    target: {
        android: {
            srcs: [
                "base/mem_map_unix.cc",
            ],
            static_libs: [
                // ZipArchive support, the order matters here to get all symbols.
                "libziparchive",
                "libz",
            ],
            shared_libs: [
                "liblog",
                // For ashmem.
                "libartpalette",
                // For common macros.
                "libbase",
            ],
            export_shared_lib_headers: ["libbase"],
            // Exclude the version script from Darwin host since it's not
            // supported by the linker there. That means ASan checks on Darwin
            // might trigger ODR violations.
            version_script: "libartbase.map",
        },
        not_windows: {
            srcs: [
                "base/mem_map_unix.cc",
            ],
            shared_libs: [
                "libziparchive",
                "libz",
                "liblog",
                // For ashmem.
                "libartpalette",
                // For common macros.
                "libbase",
            ],
            export_shared_lib_headers: ["libbase"],
        },
        linux_glibc: {
            version_script: "libartbase.map",
        },
        windows: {
            version_script: "libartbase.map",
            srcs: [
                "base/mem_map_windows.cc",
            ],
            static_libs: [
                "libziparchive",
                "libz",
                "liblog",
                // For ashmem.
                "libartpalette",
                // For common macros.
                "libbase",
            ],
            export_static_lib_headers: ["libbase"],
            cflags: ["-Wno-thread-safety"],
        },
        darwin: {
            enabled: true,  // for libdexfile.
        },
    },
    generated_sources: ["art_libartbase_operator_srcs"],
    cflags: ["-DBUILDING_LIBART=1"],

    // Utilities used by various ART libs and tools are linked in statically
    // here to avoid shared lib dependencies outside the ART APEX. No target
    // there should depend on these separately.
    whole_static_libs: [
        "liblz4",
        "liblzma",
    ],

    export_include_dirs: ["."],
    // ART's macros.h depends on libbase's macros.h.
    // Note: runtime_options.h depends on cmdline. But we don't really want to export this
    //       generically. dex2oat takes care of it itself.
}

cc_defaults {
    name: "libartbase_static_base_defaults",
    static_libs: [
        "libbase",
        "libartpalette",
        "liblog",
        "libz",
        "libziparchive",
    ],
}

cc_defaults {
    name: "libartbase_static_defaults",
    defaults: ["libartbase_static_base_defaults"],
    static_libs: ["libartbase"],
}

cc_defaults {
    name: "libartbased_static_defaults",
    defaults: ["libartbase_static_base_defaults"],
    static_libs: ["libartbased"],
}

gensrcs {
    name: "art_libartbase_operator_srcs",
    cmd: "$(location generate_operator_out) art/libartbase $(in) > $(out)",
    tools: ["generate_operator_out"],
    srcs: [
        "arch/instruction_set.h",
        "base/allocator.h",
        "base/unix_file/fd_file.h",
    ],
    output_extension: "operator_out.cc",
}

art_cc_library {
    name: "libartbase",
    defaults: ["libartbase_defaults"],
    // Leave the symbols in the shared library so that stack unwinders can
    // produce meaningful name resolution.
    strip: {
        keep_symbols: true,
    },
    shared_libs: [
        "libbase",
        "libziparchive",
    ],
    export_shared_lib_headers: ["libbase"],
    target: {
        windows: {
            enabled: true,
            shared: {
                enabled: false,
            },
        },
    },
}

art_cc_library {
    name: "libartbased",
    defaults: [
        "art_debug_defaults",
        "libartbase_defaults",
    ],
    shared_libs: [
        "libbase",
        "libziparchive",
    ],
    export_shared_lib_headers: ["libbase"],
    target: {
        windows: {
            enabled: true,
            shared: {
                enabled: false,
            },
        },
    },
}

art_cc_library {
    name: "libartbase-art-gtest",
    defaults: ["libart-gtest-defaults"],
    srcs: [
        "base/common_art_test.cc",
    ],
    shared_libs: [
        "libartbased",
        "libdexfiled",
        "libbase",
        "libbacktrace",
    ],
    header_libs: [
        "libnativehelper_header_only",
    ],
}

art_cc_test {
    name: "art_libartbase_tests",
    defaults: [
        "art_gtest_defaults",
    ],
    srcs: [
        "arch/instruction_set_test.cc",
        "base/arena_allocator_test.cc",
        "base/bit_field_test.cc",
        "base/bit_memory_region_test.cc",
        "base/bit_string_test.cc",
        "base/bit_struct_test.cc",
        "base/bit_table_test.cc",
        "base/bit_utils_test.cc",
        "base/bit_vector_test.cc",
        "base/file_utils_test.cc",
        "base/hash_set_test.cc",
        "base/hex_dump_test.cc",
        "base/histogram_test.cc",
        "base/indenter_test.cc",
        "base/leb128_test.cc",
        "base/logging_test.cc",
        "base/memfd_test.cc",
        "base/membarrier_test.cc",
        "base/memory_region_test.cc",
        "base/mem_map_test.cc",
        "base/memory_type_table_test.cc",
        "base/safe_copy_test.cc",
        "base/scoped_flock_test.cc",
        "base/time_utils_test.cc",
        "base/transform_array_ref_test.cc",
        "base/transform_iterator_test.cc",
        "base/unix_file/fd_file_test.cc",
        "base/utils_test.cc",
        "base/variant_map_test.cc",
        "base/zip_archive_test.cc",
    ],
    shared_libs: [
        "libbase",
    ],
}

cc_library_headers {
    name: "art_libartbase_headers",
    host_supported: true,
    export_include_dirs: ["."],
    shared_libs: ["libbase"],
    export_shared_lib_headers: ["libbase"],
}