build: aux: Fix link type checking for AUX builds

AUX build environent is volatile and is only instantiated in
a context of AUX-aware module.
link-type checking is happening outside such context, and
is not able to correctly determine AUX build dependencies.

1. Save enough of context in LINK_TYPE variable;
   Use AUX-<variant-name> instead of AUX
2. Load correct set of AUX meta build vars before
   building link_type rules

Bug: 62060489
Test: make auxiliary

build no longer tries to access "/STATIC_LIBRARIES" path

Change-Id: I9764d4a0740da1c55a6f8429398872fc4362942c
(cherry picked from commit 55ebe631b4a50f940850323354241baab9d9be24)
diff --git a/core/main.mk b/core/main.mk
index 0aab4f4..81ab0be 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -610,7 +610,7 @@
 #     - TARGET
 #     - HOST
 #     - HOST_CROSS
-#     - AUX
+#     - AUX-<variant-name>
 #   3: Whether to use the common intermediates directory or not
 #     - _
 #     - COMMON
@@ -637,9 +637,15 @@
 
 link_type_error :=
 
-define link-type-prefix
+define link-type-prefix-base
 $(word 2,$(subst :,$(space),$(1)))
 endef
+define link-type-prefix
+$(if $(filter AUX-%,$(link-type-prefix-base)),$(patsubst AUX-%,AUX,$(link-type-prefix-base)),$(link-type-prefix-base))
+endef
+define link-type-aux-variant
+$(if $(filter AUX-%,$(link-type-prefix-base)),$(patsubst AUX-%,%,$(link-type-prefix-base)))
+endef
 define link-type-common
 $(patsubst _,,$(word 3,$(subst :,$(space),$(1))))
 endef
@@ -729,7 +735,11 @@
 #  2. The jni_link_type rule for embedded native code
 #  3. The 2ND_jni_link_type for the second architecture native code
 define link-type-file
-$(call intermediates-dir-for,$(link-type-class),$(link-type-name),$(filter AUX HOST HOST_CROSS,$(link-type-prefix)),$(link-type-common),$(link-type-2ndarchprefix),$(filter HOST_CROSS,$(link-type-prefix)))/$(if $(filter APPS,$(link-type-class)),$(if $(link-type-common),,$(link-type-2ndarchprefix)jni_))link_type
+$(eval _ltf_aux_variant:=$(link-type-aux-variant))\
+$(if $(_ltf_aux_variant),$(call aux-variant-load-env,$(_ltf_aux_variant)))\
+$(call intermediates-dir-for,$(link-type-class),$(link-type-name),$(filter AUX HOST HOST_CROSS,$(link-type-prefix)),$(link-type-common),$(link-type-2ndarchprefix),$(filter HOST_CROSS,$(link-type-prefix)))/$(if $(filter APPS,$(link-type-class)),$(if $(link-type-common),,$(link-type-2ndarchprefix)jni_))link_type\
+$(if $(_ltf_aux_variant),$(call aux-variant-load-env,none))\
+$(eval _ltf_aux_variant:=)
 endef
 
 # Write out the file-based link_type rules for the ALLOW_MISSING_DEPENDENCIES