# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//testing/test.gni")
import("config.gni")

if (current_toolchain == host_toolchain) {
  source_set("android_lib_relocation_packer") {
    deps = [
      "//third_party/elfutils:libelf",
    ]
    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [ "//build/config/compiler:no_chromium_code" ]
    sources = [
      "bionic/tools/relocation_packer/src/debug.cc",
      "bionic/tools/relocation_packer/src/debug.h",
      "bionic/tools/relocation_packer/src/delta_encoder.cc",
      "bionic/tools/relocation_packer/src/delta_encoder.h",
      "bionic/tools/relocation_packer/src/elf_file.cc",
      "bionic/tools/relocation_packer/src/elf_file.h",
      "bionic/tools/relocation_packer/src/elf_traits.h",
      "bionic/tools/relocation_packer/src/packer.cc",
      "bionic/tools/relocation_packer/src/packer.h",
      "bionic/tools/relocation_packer/src/sleb128.cc",
      "bionic/tools/relocation_packer/src/sleb128.h",
    ]
  }

  executable("android_relocation_packer") {
    deps = [
      ":android_lib_relocation_packer",
      "//build/config/sanitizers:deps",
      "//third_party/elfutils:libelf",
    ]
    sources = [
      "bionic/tools/relocation_packer/src/main.cc",
      "bionic/tools/relocation_packer/src/nativehelper/ScopedFd.h",
    ]
  }

  copy("copy_android_relocation_packer_test_data") {
    sources = [
      "bionic/tools/relocation_packer/test_data/elf_file_unittest_relocs_arm32.so",
      "bionic/tools/relocation_packer/test_data/elf_file_unittest_relocs_arm32_packed.so",
      "bionic/tools/relocation_packer/test_data/elf_file_unittest_relocs_arm64.so",
      "bionic/tools/relocation_packer/test_data/elf_file_unittest_relocs_arm64_packed.so",
      "bionic/tools/relocation_packer/test_data/elf_file_unittest_relocs_ia32.so",
      "bionic/tools/relocation_packer/test_data/elf_file_unittest_relocs_ia32_packed.so",
      "bionic/tools/relocation_packer/test_data/elf_file_unittest_relocs_mips32.so",
      "bionic/tools/relocation_packer/test_data/elf_file_unittest_relocs_mips32_packed.so",
      "bionic/tools/relocation_packer/test_data/elf_file_unittest_relocs_x64.so",
      "bionic/tools/relocation_packer/test_data/elf_file_unittest_relocs_x64_packed.so",
    ]
    outputs = [
      "$root_out_dir/{{source_file_part}}",
    ]
  }

  test("android_relocation_packer_unittests") {
    deps = [
      ":android_lib_relocation_packer",
      ":copy_android_relocation_packer_test_data",
      "//testing/gtest",
    ]
    sources = [
      "bionic/tools/relocation_packer/src/debug_unittest.cc",
      "bionic/tools/relocation_packer/src/delta_encoder_unittest.cc",
      "bionic/tools/relocation_packer/src/elf_file_unittest.cc",
      "bionic/tools/relocation_packer/src/packer_unittest.cc",
      "bionic/tools/relocation_packer/src/run_all_unittests.cc",
      "bionic/tools/relocation_packer/src/sleb128_unittest.cc",
    ]
  }
}

if (is_android) {
  import("//build/config/android/rules.gni")

  wrapper_script("stack_wrapper") {
    target = "//third_party/android_platform/development/scripts/stack"
  }
}
