Add flag for compiling into shared libraries.

We would like libicu to be compiled into shared libraries then can be
reused by chrome and other programs on ChromeOS. To achieve this, we
need to do two modifications on the BUILD.gn of icu,

1. Enable libicu to be compiled into a shared library.
2. Let chrome use system icu on ChromeOS.

This CL achieves the first modification. For more discussion, please
see

https://docs.google.com/document/d/1T0H6DaRD9116pfaQMpBwfJtxlHPVJrroVsT_-SrAr1A/edit?usp=sharing

BUG=chromium:1020393
TEST=on workstation, this mod can produce libicu*.so

Change-Id: Ia48b47bd0c87dff0da7e92dcadb03aa4e639aa45
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/deps/icu/+/2018302
Reviewed-by: Jungshik Shin <jshin@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index 4c21560..49e56eb 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -20,6 +20,9 @@
     ":icui18n",
     ":icuuc",
   ]
+  if (icu_compile_to_shared_library) {
+    public_deps += [ ":icudata" ]
+  }
 }
 
 # Shared config used by ICU and all dependents.
@@ -37,7 +40,7 @@
     "USE_CHROMIUM_ICU=1",
   ]
 
-  if (!is_component_build) {
+  if (!is_component_build && !icu_compile_to_shared_library) {
     defines += [ "U_STATIC_IMPLEMENTATION" ]
   }
 
@@ -59,6 +62,12 @@
   }
 }
 
+if (is_component_build || icu_compile_to_shared_library) {
+  icu_target_type = "shared_library"
+} else {
+  icu_target_type = "static_library"
+}
+
 # Config used only by ICU code.
 config("icu_code") {
   cflags = []
@@ -110,7 +119,7 @@
   }
 }
 
-component("icui18n") {
+target(icu_target_type, "icui18n") {
   # find  source/i18n -maxdepth 1  ! -type d  | egrep  '\.(c|cpp|h)$' |\
   # sort | sed 's/^\(.*\)$/    "\1",/'
   sources = [
@@ -637,7 +646,7 @@
   }
 }
 
-component("icuuc") {
+target(icu_target_type, "icuuc") {
   # find  source/common -maxdepth 1  ! -type d  | egrep  '\.(c|cpp|h)$' |\
   # sort | sed 's/^\(.*\)$/    "\1",/'
   sources = [
diff --git a/config.gni b/config.gni
index 8c03c52..b17532b 100644
--- a/config.gni
+++ b/config.gni
@@ -6,4 +6,7 @@
   # Tells icu to load an external data file rather than rely on the icudata
   # being linked directly into the binary.
   icu_use_data_file = true
+  # If true, compile icu into shared libraries. Currently this is only useful on
+  # ChromeOS.
+  icu_compile_to_shared_library = false
 }