Merge "Set global default to use lld."
diff --git a/core/clear_vars.mk b/core/clear_vars.mk
index 3325752..292f842 100644
--- a/core/clear_vars.mk
+++ b/core/clear_vars.mk
@@ -57,6 +57,7 @@
 LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING:=
 LOCAL_DEX_PREOPT:= # '',true,false,nostripping
 LOCAL_DISABLE_AUTO_GENERATE_TEST_CONFIG:=
+LOCAL_DISABLE_RESOLVE_SUPPORT_LIBRARIES:=
 LOCAL_DONT_CHECK_MODULE:=
 # Don't delete the META_INF dir when merging static Java libraries.
 LOCAL_DONT_DELETE_JAR_META_INF:=
diff --git a/core/config.mk b/core/config.mk
index 39dbf55..713760f 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -110,6 +110,9 @@
 # Various mappings to avoid hard-coding paths all over the place
 include $(BUILD_SYSTEM)/pathmap.mk
 
+# Allow projects to define their own globally-available variables
+include $(BUILD_SYSTEM)/project_definitions.mk
+
 # ###############################################################
 # Build system internal files
 # ###############################################################
diff --git a/core/package_internal.mk b/core/package_internal.mk
index ac4b53c..f8e610b 100644
--- a/core/package_internal.mk
+++ b/core/package_internal.mk
@@ -314,6 +314,9 @@
 LOCAL_AAPT_FLAGS += --auto-add-overlay --extra-packages com.android.databinding.library
 endif  # LOCAL_DATA_BINDING
 
+# Process Support Library dependencies.
+include $(BUILD_SYSTEM)/support_libraries.mk
+
 # If the module is a compressed module, we don't pre-opt it because its final
 # installation location will be the data partition.
 ifdef LOCAL_COMPRESSED_MODULE
diff --git a/core/project_definitions.mk b/core/project_definitions.mk
new file mode 100644
index 0000000..5728b67
--- /dev/null
+++ b/core/project_definitions.mk
@@ -0,0 +1,24 @@
+#
+# Copyright (C) 2018 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
+# Allow projects to define their own globally-available variables.
+#
+
+#
+# Include definitions for prebuilt SDK, if present.
+#
+-include prebuilts/sdk/current/definitions.mk
diff --git a/core/static_java_library.mk b/core/static_java_library.mk
index a3f560c..8ef28b8 100644
--- a/core/static_java_library.mk
+++ b/core/static_java_library.mk
@@ -32,6 +32,9 @@
 LOCAL_USE_AAPT2 := true
 endif
 
+# Process Support Library dependencies.
+include $(BUILD_SYSTEM)/support_libraries.mk
+
 # Hack to build static Java library with Android resource
 # See bug 5714516
 all_resources :=
diff --git a/core/support_libraries.mk b/core/support_libraries.mk
new file mode 100644
index 0000000..7538ce0
--- /dev/null
+++ b/core/support_libraries.mk
@@ -0,0 +1,53 @@
+#
+# Copyright (C) 2018 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+###########################################################
+## Rules for resolving Support Library dependencies.
+##
+## The following variables may be modified:
+## - LOCAL_JAVA_LIBRARIES
+## - LOCAL_STATIC_JAVA_LIBRARIES
+## - LOCAL_SHARED_ANDROID_LIBRARIES
+## - LOCAL_STATIC_ANDROID_LIBRARIES
+###########################################################
+
+# Some projects don't work correctly yet. Allow them to skip resolution.
+ifndef LOCAL_DISABLE_RESOLVE_SUPPORT_LIBRARIES
+
+# Aggregate all requested Support Library modules.
+requested_support_libs := $(filter $(SUPPORT_LIBRARIES_JARS) $(SUPPORT_LIBRARIES_AARS), \
+    $(LOCAL_JAVA_LIBRARIES) $(LOCAL_STATIC_JAVA_LIBRARIES) \
+    $(LOCAL_SHARED_ANDROID_LIBRARIES) $(LOCAL_STATIC_ANDROID_LIBRARIES))
+
+# Filter the Support Library modules out of the library variables. We don't
+# trust developers to get these right, so they will be added back by the
+# build system based on the output of this file and the type of build.
+LOCAL_JAVA_LIBRARIES := $(filter-out $(requested_support_libs), \
+    $(LOCAL_JAVA_LIBRARIES))
+LOCAL_STATIC_JAVA_LIBRARIES := $(filter-out $(requested_support_libs), \
+    $(LOCAL_STATIC_JAVA_LIBRARIES))
+LOCAL_SHARED_ANDROID_LIBRARIES := $(filter-out $(requested_support_libs), \
+    $(LOCAL_SHARED_ANDROID_LIBRARIES))
+LOCAL_STATIC_ANDROID_LIBRARIES := $(filter-out $(requested_support_libs), \
+    $(LOCAL_STATIC_ANDROID_LIBRARIES))
+
+LOCAL_STATIC_ANDROID_LIBRARIES := $(strip $(LOCAL_STATIC_ANDROID_LIBRARIES) \
+    $(filter $(SUPPORT_LIBRARIES_AARS),$(requested_support_libs)))
+LOCAL_STATIC_JAVA_LIBRARIES := $(strip $(LOCAL_STATIC_JAVA_LIBRARIES) \
+    $(filter $(SUPPORT_LIBRARIES_JARS),$(requested_support_libs)))
+
+endif #LOCAL_DISABLE_RESOLVE_SUPPORT_LIBRARIES
+LOCAL_DISABLE_RESOLVE_SUPPORT_LIBRARIES :=