[third_party][openthread] Split build targets

Splitting build targets for legacy extensions which applies related
defines for all build targets. Also use openthread-confing-fuchsia.h as
default config file for fuchsia (instead of opentherad-config-android.h)

This is done by:
1) Creating two variants of config files:
   openthread-config-fuchsia.h and
   openthread-config-fuchsia-legacy-extensions.h

2) Split the top level "openthread_config" target into two by adding
"openthread_config_legacy_extensions"

3) Recursively split all the targets that depend on openthread_config
into two variants.

This is needed as previous change of applying defines at top level
doesn't have desired effect.

Bug: 73057
Tests: This is currently functionally a no-op on current fuchsia tree.
       Build goes through.
       Confirmed that defines are applied to all the files, and
       expected functionality is working with additional changes in
       fuchsia.git and vendor/google changes.

Change-Id: I4afdf63debef3244f89334ee9aed6cc798f8fa68
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/openthread/+/539461
Reviewed-by: Robert Quattlebaum <rquattle@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index 0224c22..dba75f2 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -41,6 +41,19 @@
   ]
 }
 
+# TODO(fxbug.dev/78118): Need to explore splitting with templates
+config("openthread_config_legacy_extensions") {
+  defines = []
+  defines += [ "OPENTHREAD_CONFIG_FILE=\"openthread-config-fuchsia-legacy-extensions.h\"" ]
+
+  include_dirs = openthread_project_include_dirs
+
+  include_dirs += [
+    "${root_gen_dir}/include",
+    "include",
+  ]
+}
+
 config("openthread_ftd_config") {
   defines = [
     "OPENTHREAD_FTD=1",
@@ -70,16 +83,32 @@
   deps = [ "src/core:libopenthread-ftd" ]
 }
 
+group("libopenthread-ftd-legacy-extensions") {
+  public_deps = [ "include/openthread:openthread_legacy_extensions" ]
+  deps = [ "src/core:libopenthread-ftd-legacy-extensions" ]
+}
+
+
 group("libopenthread-mtd") {
   public_deps = [ "include/openthread" ]
   deps = [ "src/core:libopenthread-mtd" ]
 }
 
+group("libopenthread-mtd-legacy-extensions") {
+  public_deps = [ "include/openthread:openthread_legacy_extensions" ]
+  deps = [ "src/core:libopenthread-mtd-legacy-extensions" ]
+}
+
 group("libopenthread-radio") {
   public_deps = [ "include/openthread" ]
   deps = [ "src/core:libopenthread-radio" ]
 }
 
+group("libopenthread-radio-legacy-extensions") {
+  public_deps = [ "include/openthread:openthread_legacy_extensions" ]
+  deps = [ "src/core:libopenthread-radio-legacy-extensions" ]
+}
+
 group("libopenthread-cli-ftd") {
   public_deps = [ "include/openthread" ]
   deps = [ "src/cli:libopenthread-cli-ftd" ]
@@ -90,16 +119,36 @@
   deps = [ "src/cli:libopenthread-cli-mtd" ]
 }
 
+group("libopenthread-cli-ftd-legacy-extensions") {
+  public_deps = [ "include/openthread:openthread_legacy_extensions" ]
+  deps = [ "src/cli:libopenthread-cli-ftd-legacy-extensions" ]
+}
+
+group("libopenthread-cli-mtd-legacy-extensions") {
+  public_deps = [ "include/openthread:openthread_legacy_extensions" ]
+  deps = [ "src/cli:libopenthread-cli-mtd-legacy-extensions" ]
+}
+
 group("libopenthread-spinel-ncp") {
   public_deps = [ "src/lib/spinel:spinel-api" ]
   deps = [ "src/lib/spinel:libopenthread-spinel-ncp" ]
 }
 
+group("libopenthread-spinel-ncp-legacy-extensions") {
+  public_deps = [ "src/lib/spinel:spinel-api" ]
+  deps = [ "src/lib/spinel:libopenthread-spinel-ncp-legacy-extensions" ]
+}
+
 group("libopenthread-spinel-rcp") {
   public_deps = [ "src/lib/spinel:spinel-api" ]
   deps = [ "src/lib/spinel:libopenthread-spinel-rcp" ]
 }
 
+group("libopenthread-spinel-rcp-legacy-extensions") {
+  public_deps = [ "src/lib/spinel:spinel-api" ]
+  deps = [ "src/lib/spinel:libopenthread-spinel-rcp-legacy-extensions" ]
+}
+
 if (current_os == "fuchsia") {
   group("lib-ot-core") {
     public_deps = [
@@ -111,18 +160,9 @@
 
   group("lib-ot-core-legacy-extensions") {
     public_deps = [
-      ":libopenthread-ftd",
-      "src/core:libopenthread-ftd",
-      "src/ncp:libopenthread-ncp-ftd",
-    ]
-
-    public_configs = [ ":openthread_legacy_enable" ]
-  }
-
-  config("openthread_legacy_enable") {
-    defines = [
-      "OPENTHREAD_ENABLE_VENDOR_EXTENSION=1",
-      "OPENTHREAD_CONFIG_LEGACY_ENABLE=1",
+      ":libopenthread-ftd-legacy-extensions",
+      "src/core:libopenthread-ftd-legacy-extensions",
+      "src/ncp:libopenthread-ncp-ftd-legacy-extensions",
     ]
   }
 }
diff --git a/etc/gn/openthread.gni b/etc/gn/openthread.gni
index 6774c3b..64a3be8 100644
--- a/etc/gn/openthread.gni
+++ b/etc/gn/openthread.gni
@@ -27,7 +27,7 @@
 
 _openthread_config_file = ""
 if (current_os == "fuchsia") {
-  _openthread_config_file = "<openthread-config-android.h>"
+  _openthread_config_file = "<openthread-config-fuchsia.h>"
 }
 
 declare_args() {
diff --git a/include/openthread-config-fuchsia-legacy-extensions.h b/include/openthread-config-fuchsia-legacy-extensions.h
new file mode 100644
index 0000000..270f5f7
--- /dev/null
+++ b/include/openthread-config-fuchsia-legacy-extensions.h
@@ -0,0 +1,56 @@
+/*
+ *  Copyright (c) 2018, The OpenThread Authors.
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *  1. Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *  2. Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *  3. Neither the name of the copyright holder nor the
+ *     names of its contributors may be used to endorse or promote products
+ *     derived from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *  POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef OPENTHREAD_INCLUDE_OPENTHREAD_CONFIG_FUCHSIA_LEGACY_EXTENSIONS_H_
+#define OPENTHREAD_INCLUDE_OPENTHREAD_CONFIG_FUCHSIA_LEGACY_EXTENSIONS_H_
+
+#include "openthread-config-fuchsia.h"
+
+/**
+ * @def OPENTHREAD_CONFIG_LEGACY_ENABLE
+ * Define to 1 if you want to use legacy network support
+ *
+ */
+#define OPENTHREAD_CONFIG_LEGACY_ENABLE 1
+
+/**
+ * @def OPENTHREAD_ENABLE_VENDOR_EXTENSION
+ * Define to 1 if you want to use any kind of extensions like legacy network support.
+ *
+ */
+#define OPENTHREAD_ENABLE_VENDOR_EXTENSION 1
+
+/**
+ * @def OPENTHREAD_CONFIG_MAC_JOIN_BEACON_VERSION
+ *
+ * The Beacon version to use when the beacon join flag is set.
+ *
+ */
+#define OPENTHREAD_CONFIG_MAC_JOIN_BEACON_VERSION 1
+
+#endif  // OPENTHREAD_INCLUDE_OPENTHREAD_CONFIG_FUCHSIA_LEGACY_EXTENSIONS_H_
diff --git a/include/openthread-config-fuchsia.h b/include/openthread-config-fuchsia.h
new file mode 100644
index 0000000..0c1d2c1
--- /dev/null
+++ b/include/openthread-config-fuchsia.h
@@ -0,0 +1,83 @@
+/*
+ *  Copyright (c) 2018, The OpenThread Authors.
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *  1. Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *  2. Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *  3. Neither the name of the copyright holder nor the
+ *     names of its contributors may be used to endorse or promote products
+ *     derived from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *  POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef OPENTHREAD_CONFIG_ANDROID_VERSION_HEADER_ENABLE
+#include <openthread-config-android-version.h>
+#endif
+
+/* Define to 1 to enable the border agent feature. */
+#define OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE 1
+
+/* Define to 1 if you want to enable Border Router */
+#define OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE 1
+
+/* Define to 1 if you want to enable channel manager feature */
+#define OPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE 0
+
+/* Define to 1 if you want to use channel monitor feature */
+#define OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE 0
+
+/* Define to 1 if you want to use child supervision feature */
+#define OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE 1
+
+/* Define to 1 to enable dtls support. */
+#define OPENTHREAD_CONFIG_DTLS_ENABLE 1
+
+/* Define to 1 if you want to use jam detection feature */
+#define OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE 1
+
+/* Define to 1 to enable the joiner role. */
+#define OPENTHREAD_CONFIG_JOINER_ENABLE 1
+
+
+/* Define to 1 to enable the NCP HDLC interface. */
+#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 0
+
+/* Define to 1 to enable posix platform. */
+#define OPENTHREAD_PLATFORM_POSIX 0
+
+/* Define to 1 if you want to enable Service */
+#define OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE 1
+
+/* Define to 1 if you want to enable mac filter */
+#define OPENTHREAD_CONFIG_MAC_FILTER_ENABLE 1
+
+/* OpenThread examples */
+#define OPENTHREAD_EXAMPLES none
+
+/* OpenThread diagnostic feature */
+#define OPENTHREAD_CONFIG_DIAG_ENABLE 1
+
+/* OpenThread mac filter settings */
+#define OPENTHREAD_CONFIG_MAC_FILTER_ENABLE 1
+
+/* Allow OOB steering data to be set */
+#define OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE 1
+
+/* The settings storage path on android. */
+#define OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH "/data/thread"
diff --git a/include/openthread/BUILD.gn b/include/openthread/BUILD.gn
index 767f670..34b58a2 100644
--- a/include/openthread/BUILD.gn
+++ b/include/openthread/BUILD.gn
@@ -54,6 +54,20 @@
   public_configs = [ "../..:openthread_config" ]
 }
 
+
+source_set("openthread_config_legacy_extensions") {
+  public = [ "config.h" ]
+
+  if (openthread_config_file == "") {
+    public_deps = [ ":openthread_config_generic" ]
+  } else {
+    public_deps = openthread_config_deps
+  }
+
+  public_configs = [ "../..:openthread_config_legacy_extensions" ]
+}
+
+
 source_set("openthread") {
   public = [
     "backbone_router.h",
@@ -127,3 +141,77 @@
 
   public_deps = [ ":openthread_config" ]
 }
+
+source_set("openthread_legacy_extensions") {
+  public = [
+    "backbone_router.h",
+    "backbone_router_ftd.h",
+    "border_agent.h",
+    "border_router.h",
+    "channel_manager.h",
+    "channel_monitor.h",
+    "child_supervision.h",
+    "cli.h",
+    "coap.h",
+    "coap_secure.h",
+    "commissioner.h",
+    "config.h",
+    "crypto.h",
+    "dataset.h",
+    "dataset_ftd.h",
+    "dataset_updater.h",
+    "diag.h",
+    "dns.h",
+    "dns_client.h",
+    "entropy.h",
+    "error.h",
+    "heap.h",
+    "icmp6.h",
+    "instance.h",
+    "ip6.h",
+    "jam_detection.h",
+    "joiner.h",
+    "link.h",
+    "link_metrics.h",
+    "link_raw.h",
+    "logging.h",
+    "message.h",
+    "multi_radio.h",
+    "ncp.h",
+    "netdata.h",
+    "netdiag.h",
+    "network_time.h",
+    "ping_sender.h",
+    "platform/alarm-micro.h",
+    "platform/alarm-milli.h",
+    "platform/debug_uart.h",
+    "platform/diag.h",
+    "platform/entropy.h",
+    "platform/flash.h",
+    "platform/infra_if.h",
+    "platform/logging.h",
+    "platform/memory.h",
+    "platform/messagepool.h",
+    "platform/misc.h",
+    "platform/otns.h",
+    "platform/radio.h",
+    "platform/settings.h",
+    "platform/spi-slave.h",
+    "platform/time.h",
+    "platform/toolchain.h",
+    "platform/trel-udp6.h",
+    "platform/udp.h",
+    "random_crypto.h",
+    "random_noncrypto.h",
+    "server.h",
+    "sntp.h",
+    "srp_client.h",
+    "srp_server.h",
+    "tasklet.h",
+    "thread.h",
+    "thread_ftd.h",
+    "udp.h",
+  ]
+
+  public_deps = [ ":openthread_config_legacy_extensions" ]
+}
diff --git a/src/cli/BUILD.gn b/src/cli/BUILD.gn
index cce5768..74ad6ec 100644
--- a/src/cli/BUILD.gn
+++ b/src/cli/BUILD.gn
@@ -69,3 +69,17 @@
   public_configs = [":cli_config"]
   visibility = [ "../../*" ]
 }
+
+static_library("libopenthread-cli-ftd-legacy-extensions") {
+  sources = openthread_cli_sources
+  public_deps = [ "../core:libopenthread-ftd-legacy-extensions" ]
+  public_configs = [":cli_config"]
+  visibility = [ "../../*" ]
+}
+
+static_library("libopenthread-cli-mtd-legacy-extensions") {
+  sources = openthread_cli_sources
+  public_deps = [ "../core:libopenthread-mtd-legacy-extensions" ]
+  public_configs = [":cli_config"]
+  visibility = [ "../../*" ]
+}
diff --git a/src/core/BUILD.gn b/src/core/BUILD.gn
index 42cf45f..bab84c5 100644
--- a/src/core/BUILD.gn
+++ b/src/core/BUILD.gn
@@ -714,6 +714,52 @@
   public_deps += openthread_core_config_deps
 }
 
+
+source_set("libopenthread_core_config_legacy_extensions") {
+  public = [
+    "config/announce_sender.h",
+    "config/backbone_router.h",
+    "config/border_router.h",
+    "config/channel_manager.h",
+    "config/channel_monitor.h",
+    "config/child_supervision.h",
+    "config/coap.h",
+    "config/commissioner.h",
+    "config/dataset_updater.h",
+    "config/dhcp6_client.h",
+    "config/dhcp6_server.h",
+    "config/diag.h",
+    "config/dns_client.h",
+    "config/dnssd_server.h",
+    "config/dtls.h",
+    "config/ip6.h",
+    "config/joiner.h",
+    "config/link_quality.h",
+    "config/link_raw.h",
+    "config/logging.h",
+    "config/mac.h",
+    "config/mle.h",
+    "config/openthread-core-config-check.h",
+    "config/openthread-core-default-config.h",
+    "config/parent_search.h",
+    "config/ping_sender.h",
+    "config/platform.h",
+    "config/radio_link.h",
+    "config/sntp_client.h",
+    "config/srp_client.h",
+    "config/srp_server.h",
+    "config/time_sync.h",
+    "config/tmf.h",
+    "openthread-core-config.h",
+  ]
+  public_configs = [
+    ":core_config",
+    "../..:openthread_config_legacy_extensions",
+  ]
+  public_deps = [ "../../include/openthread:openthread_config_legacy_extensions" ]
+  public_deps += openthread_core_config_deps
+}
+
 source_set("libopenthread_core_headers") {
   public = openthread_core_headers
   public_deps = [
@@ -723,6 +769,15 @@
   visibility += [ "*" ]
 }
 
+source_set("libopenthread_core_headers_legacy_extensions") {
+  public = openthread_core_headers
+  public_deps = [
+    ":libopenthread_core_config_legacy_extensions",
+    "../../include/openthread:openthread_legacy_extensions",
+  ]
+  visibility += [ "*" ]
+}
+
 group("libopenthread_platform") {
   public_deps = []
   if (openthread_external_platform != "") {
@@ -734,20 +789,49 @@
   ]
 }
 
+group("libopenthread_platform_legacy_extensions") {
+  public_deps = []
+  if (openthread_external_platform != "") {
+    public_deps += [ openthread_external_platform ]
+  }
+  public_deps += [
+    ":libopenthread_core_headers_legacy_extensions",
+    "${mbedtls_target}" + ":mbedtls_legacy_extensions",
+  ]
+}
+
 static_library("libopenthread-ftd") {
   sources = openthread_core_sources
   public_deps = [ ":libopenthread_platform" ]
   public_configs = [ "../..:openthread_ftd_config" ]
 }
 
+static_library("libopenthread-ftd-legacy-extensions") {
+  sources = openthread_core_sources
+  public_deps = [ ":libopenthread_platform_legacy_extensions" ]
+  public_configs = [ "../..:openthread_ftd_config" ]
+}
+
 static_library("libopenthread-mtd") {
   sources = openthread_core_sources
   public_deps = [ ":libopenthread_platform" ]
   public_configs = [ "../..:openthread_mtd_config" ]
 }
 
+static_library("libopenthread-mtd-legacy-extensions") {
+  sources = openthread_core_sources
+  public_deps = [ ":libopenthread_platform_legacy_extensions" ]
+  public_configs = [ "../..:openthread_mtd_config" ]
+}
+
 static_library("libopenthread-radio") {
   sources = openthread_radio_sources
   public_deps = [ ":libopenthread_platform" ]
   public_configs = [ "../..:openthread_radio_config" ]
 }
+
+static_library("libopenthread-radio-legacy-extensions") {
+  sources = openthread_radio_sources
+  public_deps = [ ":libopenthread_platform_legacy_extensions" ]
+  public_configs = [ "../..:openthread_radio_config" ]
+}
diff --git a/src/lib/spinel/BUILD.gn b/src/lib/spinel/BUILD.gn
index e4e8f03..b674cc2 100644
--- a/src/lib/spinel/BUILD.gn
+++ b/src/lib/spinel/BUILD.gn
@@ -83,3 +83,23 @@
   ]
   public_configs = [ ":spinel_config_openthread_message_disable" ]
 }
+
+static_library("libopenthread-spinel-ncp-legacy-extensions") {
+  sources = spinel_sources
+  public_deps = [
+    ":spinel-api",
+    "../../core:libopenthread_core_headers_legacy_extensions",
+    "../platform:libopenthread-platform",
+  ]
+  public_configs = [ ":spinel_config_openthread_message_enable" ]
+}
+
+static_library("libopenthread-spinel-rcp-legacy-extensions") {
+  sources = spinel_sources
+  public_deps = [
+    ":spinel-api",
+    "../../core:libopenthread_core_headers_legacy_extensions",
+    "../platform:libopenthread-platform",
+  ]
+  public_configs = [ ":spinel_config_openthread_message_disable" ]
+}
diff --git a/src/ncp/BUILD.gn b/src/ncp/BUILD.gn
index 2adfdec..0e3c8e3 100644
--- a/src/ncp/BUILD.gn
+++ b/src/ncp/BUILD.gn
@@ -58,6 +58,16 @@
   visibility = [ "../../*" ]
 }
 
+static_library("libopenthread-ncp-ftd-legacy-extensions") {
+  sources = openthread_ncp_sources
+  public_deps = [
+    "../core:libopenthread-ftd-legacy-extensions",
+    "../lib/spinel:libopenthread-spinel-ncp-legacy-extensions",
+  ]
+  public_configs = [ ":ncp_config" ]
+  visibility = [ "../../*" ]
+}
+
 static_library("libopenthread-ncp-mtd") {
   sources = openthread_ncp_sources
   public_deps = [
@@ -68,6 +78,16 @@
   visibility = [ "../../*" ]
 }
 
+static_library("libopenthread-ncp-mtd-legacy-extensions") {
+  sources = openthread_ncp_sources
+  public_deps = [
+    "../core:libopenthread-mtd-legacy-extensions",
+    "../lib/spinel:libopenthread-spinel-ncp-legacy-extensions",
+  ]
+  public_configs = [ ":ncp_config" ]
+  visibility = [ "../../*" ]
+}
+
 static_library("libopenthread-rcp") {
   sources = openthread_ncp_sources
   public_deps = [
@@ -77,3 +97,13 @@
   public_configs = [ ":ncp_config" ]
   visibility = [ "../../*" ]
 }
+
+static_library("libopenthread-rcp-legacy-extensions") {
+  sources = openthread_ncp_sources
+  public_deps = [
+    "../core:libopenthread-radio-legacy-extensions",
+    "../lib/spinel:libopenthread-spinel-rcp-legacy-extensions",
+  ]
+  public_configs = [ ":ncp_config" ]
+  visibility = [ "../../*" ]
+}
diff --git a/third_party/mbedtls/BUILD.gn b/third_party/mbedtls/BUILD.gn
index d93fc6a..82d0416 100644
--- a/third_party/mbedtls/BUILD.gn
+++ b/third_party/mbedtls/BUILD.gn
@@ -28,9 +28,6 @@
 declare_args() {
   # Configuration file for MbedTLS.
   mbedtls_config_file = "mbedtls-config.h"
-
-  # Extra dependencies for MbedTLS
-  mbedtls_deps = [ "../../src/core:libopenthread_core_config" ]
 }
 
 config("mbedtls_config") {
@@ -204,7 +201,174 @@
     "repo/library/xtea.c",
   ]
 
-  public_deps = mbedtls_deps
+  public_deps = [ "../../src/core:libopenthread_core_config" ]
+
+  public_configs = [ ":mbedtls_config" ]
+}
+
+
+static_library("mbedtls_legacy_extensions") {
+  sources = [
+    "repo/include/mbedtls/aes.h",
+    "repo/include/mbedtls/aesni.h",
+    "repo/include/mbedtls/arc4.h",
+    "repo/include/mbedtls/aria.h",
+    "repo/include/mbedtls/asn1.h",
+    "repo/include/mbedtls/asn1write.h",
+    "repo/include/mbedtls/base64.h",
+    "repo/include/mbedtls/bignum.h",
+    "repo/include/mbedtls/blowfish.h",
+    "repo/include/mbedtls/bn_mul.h",
+    "repo/include/mbedtls/camellia.h",
+    "repo/include/mbedtls/ccm.h",
+    "repo/include/mbedtls/certs.h",
+    "repo/include/mbedtls/chacha20.h",
+    "repo/include/mbedtls/chachapoly.h",
+    "repo/include/mbedtls/check_config.h",
+    "repo/include/mbedtls/cipher.h",
+    "repo/include/mbedtls/cipher_internal.h",
+    "repo/include/mbedtls/cmac.h",
+    "repo/include/mbedtls/compat-1.3.h",
+    "repo/include/mbedtls/config.h",
+    "repo/include/mbedtls/ctr_drbg.h",
+    "repo/include/mbedtls/debug.h",
+    "repo/include/mbedtls/des.h",
+    "repo/include/mbedtls/dhm.h",
+    "repo/include/mbedtls/ecdh.h",
+    "repo/include/mbedtls/ecdsa.h",
+    "repo/include/mbedtls/ecjpake.h",
+    "repo/include/mbedtls/ecp.h",
+    "repo/include/mbedtls/ecp_internal.h",
+    "repo/include/mbedtls/entropy.h",
+    "repo/include/mbedtls/entropy_poll.h",
+    "repo/include/mbedtls/error.h",
+    "repo/include/mbedtls/gcm.h",
+    "repo/include/mbedtls/havege.h",
+    "repo/include/mbedtls/hkdf.h",
+    "repo/include/mbedtls/hmac_drbg.h",
+    "repo/include/mbedtls/md.h",
+    "repo/include/mbedtls/md2.h",
+    "repo/include/mbedtls/md4.h",
+    "repo/include/mbedtls/md5.h",
+    "repo/include/mbedtls/md_internal.h",
+    "repo/include/mbedtls/memory_buffer_alloc.h",
+    "repo/include/mbedtls/net.h",
+    "repo/include/mbedtls/net_sockets.h",
+    "repo/include/mbedtls/nist_kw.h",
+    "repo/include/mbedtls/oid.h",
+    "repo/include/mbedtls/padlock.h",
+    "repo/include/mbedtls/pem.h",
+    "repo/include/mbedtls/pk.h",
+    "repo/include/mbedtls/pk_internal.h",
+    "repo/include/mbedtls/pkcs11.h",
+    "repo/include/mbedtls/pkcs12.h",
+    "repo/include/mbedtls/pkcs5.h",
+    "repo/include/mbedtls/platform.h",
+    "repo/include/mbedtls/platform_time.h",
+    "repo/include/mbedtls/platform_util.h",
+    "repo/include/mbedtls/poly1305.h",
+    "repo/include/mbedtls/ripemd160.h",
+    "repo/include/mbedtls/rsa.h",
+    "repo/include/mbedtls/rsa_internal.h",
+    "repo/include/mbedtls/sha1.h",
+    "repo/include/mbedtls/sha256.h",
+    "repo/include/mbedtls/sha512.h",
+    "repo/include/mbedtls/ssl.h",
+    "repo/include/mbedtls/ssl_cache.h",
+    "repo/include/mbedtls/ssl_ciphersuites.h",
+    "repo/include/mbedtls/ssl_cookie.h",
+    "repo/include/mbedtls/ssl_internal.h",
+    "repo/include/mbedtls/ssl_ticket.h",
+    "repo/include/mbedtls/threading.h",
+    "repo/include/mbedtls/timing.h",
+    "repo/include/mbedtls/version.h",
+    "repo/include/mbedtls/x509.h",
+    "repo/include/mbedtls/x509_crl.h",
+    "repo/include/mbedtls/x509_crt.h",
+    "repo/include/mbedtls/x509_csr.h",
+    "repo/include/mbedtls/xtea.h",
+    "repo/library/aes.c",
+    "repo/library/aesni.c",
+    "repo/library/arc4.c",
+    "repo/library/aria.c",
+    "repo/library/asn1parse.c",
+    "repo/library/asn1write.c",
+    "repo/library/base64.c",
+    "repo/library/bignum.c",
+    "repo/library/blowfish.c",
+    "repo/library/camellia.c",
+    "repo/library/ccm.c",
+    "repo/library/certs.c",
+    "repo/library/chacha20.c",
+    "repo/library/chachapoly.c",
+    "repo/library/cipher.c",
+    "repo/library/cipher_wrap.c",
+    "repo/library/cmac.c",
+    "repo/library/ctr_drbg.c",
+    "repo/library/debug.c",
+    "repo/library/des.c",
+    "repo/library/dhm.c",
+    "repo/library/ecdh.c",
+    "repo/library/ecdsa.c",
+    "repo/library/ecjpake.c",
+    "repo/library/ecp.c",
+    "repo/library/ecp_curves.c",
+    "repo/library/entropy.c",
+    "repo/library/entropy_poll.c",
+    "repo/library/error.c",
+    "repo/library/gcm.c",
+    "repo/library/havege.c",
+    "repo/library/hkdf.c",
+    "repo/library/hmac_drbg.c",
+    "repo/library/md.c",
+    "repo/library/md2.c",
+    "repo/library/md4.c",
+    "repo/library/md5.c",
+    "repo/library/md_wrap.c",
+    "repo/library/memory_buffer_alloc.c",
+    "repo/library/net_sockets.c",
+    "repo/library/nist_kw.c",
+    "repo/library/oid.c",
+    "repo/library/padlock.c",
+    "repo/library/pem.c",
+    "repo/library/pk.c",
+    "repo/library/pk_wrap.c",
+    "repo/library/pkcs11.c",
+    "repo/library/pkcs12.c",
+    "repo/library/pkcs5.c",
+    "repo/library/pkparse.c",
+    "repo/library/pkwrite.c",
+    "repo/library/platform.c",
+    "repo/library/platform_util.c",
+    "repo/library/poly1305.c",
+    "repo/library/ripemd160.c",
+    "repo/library/rsa.c",
+    "repo/library/rsa_internal.c",
+    "repo/library/sha1.c",
+    "repo/library/sha256.c",
+    "repo/library/sha512.c",
+    "repo/library/ssl_cache.c",
+    "repo/library/ssl_ciphersuites.c",
+    "repo/library/ssl_cli.c",
+    "repo/library/ssl_cookie.c",
+    "repo/library/ssl_srv.c",
+    "repo/library/ssl_ticket.c",
+    "repo/library/ssl_tls.c",
+    "repo/library/threading.c",
+    "repo/library/timing.c",
+    "repo/library/version.c",
+    "repo/library/version_features.c",
+    "repo/library/x509.c",
+    "repo/library/x509_create.c",
+    "repo/library/x509_crl.c",
+    "repo/library/x509_crt.c",
+    "repo/library/x509_csr.c",
+    "repo/library/x509write_crt.c",
+    "repo/library/x509write_csr.c",
+    "repo/library/xtea.c",
+  ]
+
+  public_deps = [ "../../src/core:libopenthread_core_config_legacy_extensions" ]
 
   public_configs = [ ":mbedtls_config" ]
 }