# Copyright 2016 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("//remoting/build/config/remoting_build.gni")

source_set("constants") {
  defines = [ "HOST_BUNDLE_NAME=\"" + host_bundle_name + "\"" ]

  sources = [
    "constants_mac.cc",
    "constants_mac.h",
  ]

  deps = [
    "//remoting/host:remoting_version",
  ]
}

# remoting_me2me_host-InfoPlist.strings
foreach(locale, remoting_locales_with_underscores) {
  bundle_data("remoting_me2me_host_strings_${locale}_bundle_data") {
    sources = [
      "$root_gen_dir/remoting/host/remoting_me2me_host-InfoPlist.strings/$locale.lproj/InfoPlist.strings",
    ]
    outputs = [
      "{{bundle_resources_dir}}/$locale.lproj/{{source_file_part}}",
    ]
    deps = [
      "//remoting/host:remoting_infoplist_strings",
    ]
  }
}

mac_xib_bundle_data("remoting_host_xibs") {
  sources = [
    "disconnect_window.xib",
  ]
}

bundle_data("remoting_host_resources") {
  sources = [
    "$root_gen_dir/remoting/CREDITS.txt",
    "remoting_me2me_host.icns",
  ]

  outputs = [
    "{{bundle_resources_dir}}/{{source_file_part}}",
  ]

  public_deps = [
    "//remoting/host/installer:credits",
  ]

  if (icu_use_data_file) {
    sources += [ "$root_out_dir/icudtl.dat" ]
    public_deps += [ "//third_party/icu:icudata" ]
  }
}

target("mac_app_bundle", "remoting_me2me_host") {
  extra_configs = [ "//remoting/build/config:version" ]
  info_plist = "remoting_me2me_host-Info.plist"
  extra_substitutions = [
    "BUNDLE_ID=$host_bundle_id",
    "VERSION_FULL=$remoting_version_full",
    "VERSION_SHORT=$remoting_version_short",
    "MACOSX_DEPLOYMENT_TARGET=10.7",
  ]

  # TODO(joedow): Re-enable or replace with Crashpad: crbug.com/637884.
  # if (is_chrome_branded && is_official_build) {
  #   defines = [ "REMOTING_ENABLE_BREAKPAD" ]
  # }

  deps = [
    "//build/config:exe_and_shlib_deps",
    "//remoting/base:breakpad",
    "//remoting/host:main",
    "//remoting/host:remoting_me2me_host_static",
    "//remoting/host/installer:credits",
    "//remoting/resources",
  ]

  foreach(locale, remoting_locales_with_underscores) {
    deps += [
      ":remoting_host_locale_${locale}_bundle_data",
      ":remoting_me2me_host_strings_${locale}_bundle_data",
    ]
  }
  deps += [
    ":remoting_host_resources",
    ":remoting_host_xibs",
    "//remoting/host:remoting_infoplist_strings",
    "//remoting/resources:copy_locales",
  ]
}

foreach(locale, remoting_locales_with_underscores) {
  bundle_data("remoting_host_locale_${locale}_bundle_data") {
    sources = [
      "$root_build_dir/remoting/resources/$locale.lproj/locale.pak",
    ]
    outputs = [
      "{{bundle_resources_dir}}/$locale.lproj/{{source_file_part}}",
    ]
    deps = [
      "//remoting/resources:copy_locales",
    ]
  }
}

# native_messaging_host-InfoPlist.strings
foreach(locale, remoting_locales_with_underscores) {
  bundle_data("native_messaging_host_strings_${locale}_bundle_data") {
    sources = [
      "$root_gen_dir/remoting/host/native_messaging_host-InfoPlist.strings/$locale.lproj/InfoPlist.strings",
    ]
    outputs = [
      "{{bundle_resources_dir}}/$locale.lproj/{{source_file_part}}",
    ]
    deps = [
      "//remoting/host:remoting_infoplist_strings",
    ]
  }
}

bundle_data("remoting_native_messaging_host_resources") {
  sources = [
    # This image is used to badge the lock icon in the authentication dialogs,
    # used for elevating privileges to set up the host. The exact filename is
    # required by base::mac::GetAuthorizationRightsWithPrompt().
    # It needs to exist as a file on disk and not just something in a
    # resource bundle because that's the interface that Authorization Services
    # uses. Also, Authorization Services can't deal with .icns files.
    "//remoting/resources/product_logo_32.png",
  ]
  outputs = [
    "{{bundle_resources_dir}}/{{source_file_part}}",
  ]
}

target("mac_app_bundle", "remoting_native_messaging_host") {
  output_name = "native_messaging_host"
  info_plist = "../setup/native_messaging_host-Info.plist"
  extra_configs = [ "//build/config/compiler:wexit_time_destructors" ]
  extra_substitutions = [
    "BUNDLE_ID=$native_messaging_host_bundle_id",
    "VERSION_FULL=$remoting_version_full",
    "VERSION_SHORT=$remoting_version_short",
    "MACOSX_DEPLOYMENT_TARGET=10.7",
  ]

  sources = [
    "../setup/me2me_native_messaging_host_entry_point.cc",
    "../setup/me2me_native_messaging_host_main.cc",
    "../setup/me2me_native_messaging_host_main.h",
  ]

  deps = [
    ":remoting_native_messaging_host_resources",
    "//base",
    "//net",
    "//remoting/base:breakpad",
    "//remoting/host",
    "//remoting/host:remoting_infoplist_strings",
    "//remoting/host/native_messaging",
    "//remoting/host/setup",
  ]
  foreach(locale, remoting_locales_with_underscores) {
    deps += [
      ":native_messaging_host_strings_${locale}_bundle_data",
      "//remoting/host/mac:remoting_host_locale_${locale}_bundle_data",
    ]
  }
  deps += [ "//remoting/resources:copy_locales" ]

  # The |major|, |build| and |patch| versions are inherited from Chrome.
  # Since Chrome's |minor| version is always '0', we replace it with a
  # Chromoting-specific patch version.
  defines =
      [ "VERSION=" + "$chrome_version_major" + "." + "$remoting_version_patch" +
        "." + "$chrome_version_build" + "." + "$chrome_version_patch" ]
}