//
// Copyright (C) 2016 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: "header-checker-defaults",

    defaults: [
        "llvm-build-host-tools-defaults",
    ],

    cflags: [
        "-Wall",
        "-Werror",
        "-Wno-unused-parameter",
        "-DGOOGLE_PROTOBUF_NO_RTTI",
        "-UNDEBUG",
    ],

    cppflags: [
        "-fno-exceptions",
        "-fno-rtti",
        "-std=c++17",
    ],

    target: {
        windows: {
            enabled: false,
        },
    },

    local_include_dirs: [
        "src",
    ],

    compile_multilib: "64",
    stl: "none",
}

cc_binary_host {
    name: "header-abi-dumper",

    defaults: [
        "header-checker-defaults",
    ],

    srcs: [
        "src/dumper/abi_wrappers.cpp",
        "src/dumper/ast_processing.cpp",
        "src/dumper/diagnostic_consumer.cpp",
        "src/dumper/fake_decl_source.cpp",
        "src/dumper/fixed_argv.cpp",
        "src/dumper/frontend_action.cpp",
        "src/dumper/frontend_action_factory.cpp",
        "src/dumper/header_checker.cpp",
    ],

    static_libs: [
        "libheader-checker",
        "libheader-checker-proto",
        "libjsoncpp",
    ],

    shared_libs: [
        "libprotobuf-cpp-full",
        "libLLVM_host",
        "libclang_cxx_host",
        "libc++_host",
    ],
}

cc_defaults {
    name: "header-abi-linker-defaults",

    defaults: ["header-checker-defaults"],

    static_libs: [
        "libheader-checker",
        "libheader-checker-proto",
        "libjsoncpp",
    ],

    shared_libs: [
        "libprotobuf-cpp-full",
        "libLLVM_host",
        "libclang_cxx_host",
        "libc++_host",
    ],
}

cc_binary_host {
    name: "header-abi-linker",

    defaults: [
        "header-checker-defaults",
        "header-abi-linker-defaults",
    ],

    srcs: [
        "src/linker/header_abi_linker.cpp",
    ],
}

cc_binary_host {
    name: "header-abi-diff",

    defaults: [
        "header-checker-defaults",
        "header-abi-linker-defaults",
    ],

    srcs: [
        "src/diff/abi_diff.cpp",
        "src/diff/abi_diff_wrappers.cpp",
        "src/diff/header_abi_diff.cpp",
    ],
}

cc_binary_host {
    name: "merge-abi-diff",

    defaults: [
        "header-checker-defaults",
        "header-abi-linker-defaults",
    ],

    srcs: [
        "src/diff_merge/merge_abi_diff.cpp",
    ],
}

cc_library_host_static {
    name: "libheader-checker",

    defaults: [
        "header-checker-defaults",
    ],

    srcs: [
        "src/repr/abi_diff_helpers.cpp",
        "src/repr/ir_diff_dumper.cpp",
        "src/repr/ir_dumper.cpp",
        "src/repr/ir_reader.cpp",
        "src/repr/ir_representation.cpp",
        "src/repr/json/converter.cpp",
        "src/repr/json/ir_dumper.cpp",
        "src/repr/json/ir_reader.cpp",
        "src/repr/protobuf/converter.cpp",
        "src/repr/protobuf/ir_diff_dumper.cpp",
        "src/repr/protobuf/ir_dumper.cpp",
        "src/repr/protobuf/ir_reader.cpp",
        "src/repr/symbol/exported_symbol_set.cpp",
        "src/repr/symbol/so_file_parser.cpp",
        "src/repr/symbol/version_script_parser.cpp",
        "src/utils/api_level.cpp",
        "src/utils/config_file.cpp",
        "src/utils/collect_exported_headers.cpp",
        "src/utils/string_utils.cpp",
    ],

    static_libs: [
        "libheader-checker-proto",
        "libjsoncpp",
    ],

    shared_libs: [
        "libLLVM_host",
        "libc++_host",
        "libprotobuf-cpp-full",
    ],

    cflags: [
        "-Wcast-qual",
        "-Wno-long-long",
        "-Wno-unused-parameter",
    ],
}

cc_test_host {
    name: "header-checker-unittests",

    defaults: [
        "header-checker-defaults",
    ],

    srcs: [
        "src/repr/symbol/exported_symbol_set_test.cpp",
        "src/repr/symbol/version_script_parser_test.cpp",
        "src/utils/api_level_test.cpp",
        "src/utils/config_file_test.cpp",
        "src/utils/string_utils_test.cpp",
    ],

    static_libs: [
        "libgtest",
        "libgtest_main",
        "libheader-checker",
    ],

    shared_libs: [
        "libc++_host",
    ],

    test_suites: ["general-tests"],
}
