# Copyright 2018 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("//build/config/android/rules.gni")
import("//third_party/angle/gni/angle.gni")

template("angle_apk") {
  manifest_target_name = "${target_name}__manifest"
  manifest_path = "${target_gen_dir}/${target_name}/android/AndroidManifest.xml"

  jinja_template(manifest_target_name) {
    input = "//third_party/angle/android/AndroidManifest.xml.jinja2"
    output = manifest_path
    variables = [ "manifest_package=${invoker.package_name}" ]
  }

  android_resources("${invoker.package_name}_resources") {
    resource_dirs = [ "android/res" ]

    custom_package = "com.android.angle.common"
    deps = [
      "//third_party/android_deps:android_support_v14_preference_java",
      "//third_party/android_deps:android_support_v7_preference_java",
    ]
  }

  android_assets("${invoker.package_name}_assets") {
    disable_compression = true
    sources = [
      "src/feature_support_util/a4a_rules.json",
    ]
  }

  android_apk(target_name) {
    forward_variables_from(invoker, "*")
    android_manifest = manifest_path
    android_manifest_dep = ":$manifest_target_name"
    deps = [
      ":${invoker.package_name}_assets",
      ":${invoker.package_name}_resources",
      "//base:base_java",
      "//third_party/android_deps:android_support_v14_preference_java",
      "//third_party/android_deps:android_support_v7_preference_java",
    ]

    uncompress_shared_libraries = true

    if (build_apk_secondary_abi && android_64bit_target_cpu) {
      secondary_abi_shared_libraries = [
        "//third_party/angle:libEGL${angle_libs_suffix}($android_secondary_abi_toolchain)",
        "//third_party/angle:libGLESv1_CM${angle_libs_suffix}($android_secondary_abi_toolchain)",
        "//third_party/angle:libGLESv2${angle_libs_suffix}($android_secondary_abi_toolchain)",
        "//third_party/angle:libfeature_support${angle_libs_suffix}" +
            "($android_secondary_abi_toolchain)",
      ]
    }

    shared_libraries = [
      "//third_party/angle:libEGL${angle_libs_suffix}",
      "//third_party/angle:libGLESv1_CM${angle_libs_suffix}",
      "//third_party/angle:libGLESv2${angle_libs_suffix}",
      "//third_party/angle:libfeature_support${angle_libs_suffix}",
    ]

    # Common files required by all builds
    java_files = [
      "android/src/com/android/angle/common/GlobalSettings.java",
      "android/src/com/android/angle/common/MainFragment.java",
      "android/src/com/android/angle/common/Receiver.java",
    ]

    if (target_name == "aosp_apk") {
      java_files += [ "android/src/com/android/angle/MainActivity.java" ]
    } else if (target_name == "google_apk") {
      java_files += [ "android/src/com/google/android/angle/MainActivity.java" ]
    }
  }
}
