# Copyright (c) 2013 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("//crypto/ssl/flags.gni")
import("//tools/grit/grit_rule.gni")

executable("chrome") {
  sources = [
    "app/breakpad_field_trial_win.cc",
    "app/breakpad_field_trial_win.h",
    "app/breakpad_win.cc",
    "app/breakpad_win.h",
    "app/chrome_dll_resource.h",
    "app/chrome_exe_main_aura.cc",
    "app/chrome_exe_main_gtk.cc",
    "app/chrome_exe_main_mac.cc",
    "app/chrome_exe_main_win.cc",
    "app/chrome_exe_resource.h",
    "app/chrome_main.cc",
    "app/chrome_main_delegate.cc",
    "app/chrome_main_delegate.h",
    "app/client_util.cc",
    "app/client_util.h",
    "app/hard_error_handler_win.cc",
    "app/hard_error_handler_win.h",
    "app/metro_driver_win.cc",
    "app/metro_driver_win.h",
    "../content/app/startup_helper_win.cc",
  ]

  if (is_linux) {
    configs += [
      # TODO(brettw) this is wrong, it should be picked up from deps.
      "//build/config/linux:gtk",
      "//build/config/linux:x11",
    ]
  }

  deps = [
    # TODO(brettw) this is right on linux? Everything is linked into the
    # exe, but wrong on Windows, where chrome_exe and chrome_dll are separate.
    ":browser",
    ":common",
    ":debugger",
    ":plugin",
    ":renderer",
    ":utility",
    "//base",
  ]

  # TODO(brettw) this isn't right for all platforms.
  if (!use_aura) {
    sources -= "app/chrome_exe_main_aura.cc"
  }

  if (!is_win) {
    sources -= [
      "app/client_util.cc",
      "app/client_util.h",
    ]
  }
}

static_library("browser") {
  external = true

  if (is_linux) {
    libs = [ "dl" ]
    if (toolkit_uses_gtk) {
      libs += "gconf-2"
    }
  }
  if (is_linux) {
    configs += [
      "//build/config/linux:x11",
    ]
  }

  deps = [
    "//third_party/expat",
  ]
}

static_library("common") {
  external = true

  if (use_nss && is_linux) {
    # common/net uses NSS.
    # TODO(brettw) have a better way to express this without having to do
    # "if (use_nss)" everywhere.
    configs += "//third_party/nss:nss_linux_config"
  }
  deps = [
  ]
}

# TODO(brettw) move to browser/devtools/BUILD.gn
source_set("debugger") {
  sources = [
    "browser/devtools/adb/android_rsa.cc",
    "browser/devtools/adb/android_rsa.h",
    "browser/devtools/adb/android_usb_device.cc",
    "browser/devtools/adb/android_usb_device.h",
    "browser/devtools/adb/android_usb_socket.cc",
    "browser/devtools/adb/android_usb_socket.h",
    "browser/devtools/adb_client_socket.cc",
    "browser/devtools/adb_client_socket.h",
    "browser/devtools/adb_web_socket.cc",
    "browser/devtools/adb_web_socket.h",
    "browser/devtools/browser_list_tabcontents_provider.cc",
    "browser/devtools/browser_list_tabcontents_provider.h",
    "browser/devtools/devtools_adb_bridge.cc",
    "browser/devtools/devtools_adb_bridge.h",
    "browser/devtools/devtools_embedder_message_dispatcher.cc",
    "browser/devtools/devtools_embedder_message_dispatcher.h",
    "browser/devtools/devtools_file_helper.cc",
    "browser/devtools/devtools_file_helper.h",
    "browser/devtools/devtools_file_system_indexer.cc",
    "browser/devtools/devtools_file_system_indexer.h",
    "browser/devtools/devtools_protocol.cc",
    "browser/devtools/devtools_protocol.h",
    "browser/devtools/devtools_toggle_action.h",
    "browser/devtools/devtools_window.cc",
    "browser/devtools/devtools_window.h",
    "browser/devtools/port_forwarding_controller.cc",
    "browser/devtools/port_forwarding_controller.h",
    "browser/devtools/remote_debugging_server.cc",
    "browser/devtools/remote_debugging_server.h",
  ]

  deps = [
#    ":chrome_extra_resources",
#    ":chrome_resources",
#    ":chrome_strings",
#    ":theme_resources",
    "//base",
    "//net",
    "//net:http_server",
    "//skia",
    "//third_party/icu:icui18n",
    "//third_party/icu:icuuc",
    "//third_party/leveldatabase",
    "//third_party/libusb",
  ]

  if (is_android) {
    sources -= [
      "browser/devtools/adb/android_rsa.cc",
      "browser/devtools/browser_list_tabcontents_provider.cc",
      "browser/devtools/devtools_file_system_indexer.cc",
      "browser/devtools/devtools_window.cc",
      "browser/devtools/remote_debugging_server.cc",
    ]
    deps -= "//third_party/libusb"
  }

  # TODO implement debug_devtools
  # if (debug_devtools) {
  #   defines = [ "DEBUG_DEVTOOLS=1" ]
  # }
  # TODO(brettw) this may be required on Windows:
  # if (is_win) {
  #   TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
  #   'msvs_disabled_warnings': [ 4267, ]
  # }

}

source_set("plugin") {
  external = true
}

source_set("renderer") {
  external = true
}

source_set("utility") {
  external = true
}


# Credits ----------------------------------------------------------------------

about_credits_file = "$root_gen_dir/about_credits.html"
build_relative_about_credits_file =
  rebase_path(about_credits_file, ".", root_build_dir)

custom("about_credits") {
  script = "//tools/licenses.py"
  outputs = [ about_credits_file ]

  # This script is impossible to write proper input dependencies for because it
  # basically greps the source tree for third_party directories. If a directory
  # is added or removed, it will change the result, but there is no way to
  # express this as a build dependency. We approximate this by depending on
  # the last change file to force an update whenever the code is updated.
  source_prereqs = [ "//build/util/LASTCHANGE" ]

  hard_dep = true

  args = [ "credits", build_relative_about_credits_file ]
}

# Resources --------------------------------------------------------------------

#group("chrome_resources") {
#  deps = [
#    ":browser_resources",
#    ":common_resources",
#    ":renderer_resources",
#  ]
#}
#grit("browser_resources") {
#  source = "browser/browser_resources.grd"
#  grit_flags = [ "-E", "about_credits_file=$build_relative_about_credits_file" ]
#  deps = [ ":about_credits" ]
#}
#grit("common_resources") {
#  source = "common/common_resources.grd"
#}
#grit("renderer_resources") {
#  source = "renderer/resources/renderer_resources.grd"
#}
#
#group("chrome_strings") {
#  deps = [
#    ":locale_settings",
#    ":chromium_strings",
#    ":generated_resources",
#    ":google_chrome_strings",
#  ]
#}
#grit("locale_settings") {
#  source = "app/resources/locale_settings.grd"
#}
#grit("chromium_strings") {
#  source = "app/chromium_strings.grd"
#}
#grit("generated_resources") {
#  source = "app/generated_resources.grd"
#}
#grit("google_chrome_strings") {
#  source = "app/google_chrome_strings.grd"
#}
#
#group("chrome_extra_resources") {
#  deps = [
#    ":memory_internals_resources",
#    ":net_internals_resources",
#    ":signin_internals_resources",
#    ":sync_internals_resources",
#    ":translate_internals_resources",
#  ]
#
#  if (!is_ios) {
#    deps += [
#      ":component_extension_resources",
#      ":devtools_discovery_page_resources",
#      ":options_resources",
#      ":quota_internals_resources",
#      ":sync_file_system_internals_resources",
#    ]
#  }
#}
#grit("component_extension_resources") {
#  source = "browser/resources/component_extension_resources.grd"
#}
#grit("devtools_discovery_page_resources") {
#  source = "browser/devtools/frontend/devtools_discovery_page_resources.grd"
#}
#grit("memory_internals_resources") {
#  source = "browser/resources/memory_internals_resources.grd"
#}
#grit("quota_internals_resources") {
#  source = "browser/resources/quota_internals_resources.grd"
#}
#grit("net_internals_resources") {
#  source = "browser/resources/net_internals_resources.grd"
#}
#grit("options_resources") {
#  source = "browser/resources/options_resources.grd"
#}
#grit("signin_internals_resources") {
#  source = "browser/resources/signin_internals_resources.grd"
#}
#grit("sync_file_system_internals_resources") {
#  source = "browser/resources/sync_file_system_internals_resources.grd"
#}
#grit("sync_internals_resources") {
#  source = "browser/resources/sync_internals_resources.grd"
#}
#grit("translate_internals_resources") {
#  source = "browser/resources/translate_internals_resources.grd"
#}
#
#group("theme_resources") {
#  deps = [
#    ":theme_resources_gen",
#    #"//ui:ui_resources",
#  ]
#}
#
## TODO(brettw) rename "app_theme_resources" or something when we don't support
## GYP any more. This name is required to match the GYP build.
#grit("theme_resources_gen") {
#  source = "app/theme/theme_resources.grd"
#}