# Copyright 2014 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.

widevine_arch = cpu_arch
if (widevine_arch == "x86") {
  widevine_arch = "ia32"
}

if (is_android) {
  # Always available on Android regardless of branding.
  widevine_cdm_version_h_file = "android/widevine_cdm_version.h"
  widevine_cdm_binary_files = []
} else if (is_chrome_branded) {
  if (is_chromeos) {
    widevine_cdm_version_h_file =
      "chromeos/$widevine_arch/widevine_cdm_version.h"
    widevine_cdm_binary_files = [
      "chromeos/$widevine_arch/libwidevinecdm.so",
    ]
  } else if (is_linux) {
    widevine_cdm_version_h_file =
      "linux/$widevine_arch/widevine_cdm_version.h"
    widevine_cdm_binary_files = [
      "linux/$widevine_arch/libwidevinecdm.so",
    ]
  } else if (is_win) {
    widevine_cdm_version_h_file =
      "win/$widevine_arch/widevine_cdm_version.h"
    widevine_cdm_binary_files = [
      "win/$widevine_arch/widevinecdm.dll",
      "win/$widevine_arch/widevinecdm.dll.lib",
    ]
  } else if (is_mac) {
    widevine_cdm_version_h_file =
      "mac/$widevine_arch/widevine_cdm_version.h"
    widevine_cdm_binary_files = [
      "mac/$widevine_arch/libwidevinecdm.dylib",
    ]
  } else {
    # Other platforms, use the default one.
    widevine_cdm_version_h_file = "widevine_cdm_version.h"
    widevine_cdm_binary_files = []
  }
} else {
  # No branding, use the default one.
  widevine_cdm_version_h_file = "widevine_cdm_version.h"
  widevine_cdm_binary_files = []
}

# GYP version: third_party/widevine/cdm/widevine_cdm.gyp:widevine_cdm_version_h
copy("version_h") {
  sources = [ widevine_cdm_version_h_file ]
  # TODO(brettw) this should go into target_out_dir and callers should include
  # it from there. This requires, however, renaming the default
  # widevine_cdm_version.h in this directory to avoid conflicts.
  outputs = [ "$root_gen_dir/widevine_cdm_version.h" ]
}

# GYP version: third_party/widevine/cdm/widevine_cdm.gyp:widevine_cdm_binaries
if (widevine_cdm_binary_files == []) {
  group("binaries") {
    # NOP
  }
} else {
  copy("binaries") {
    sources = widevine_cdm_binary_files
    outputs = [ "$root_out_dir/{{source_file_part}}" ]
    # TODO(GYP)
    # 'COPY_PHASE_STRIP': 'NO',
  }
}

source_set("adapter") {
  if (is_chrome_branded) {
    deps = [
      ":widevine_cdm_version_h",
      ":widevine_cdm_binaries",
      "//ppapi:ppapi_cpp",
      #'<(DEPTH)/media/media_cdm_adapter.gyp:cdmadapter',  TODO(GYP)
    ]
  }

  if (is_linux) {
    libs = [ "$root_out_dir/libwidevinecdm.sp" ]
  } else if (is_win) {
    libs = [ "$root_out_dir/widevinecdm.dll.lib" ]
  } else if (is_mac) {
    libs = [ "$root_out_dir/libwidevinecdm.dylib" ]
  }
}

# This target exists for tests to depend on that pulls in a runtime dependency
# on the license server.
source_set("widevine_test_license_server") {
  if (is_chrome_branded && is_linux) {
    deps = [
      # TODO(GYP)
      #"//third_party/widevine/test/license_server/license_server.gyp:test_license_server"
    ]
  }
}