Revert "Revert "Add __ANDROID_APEX_<NAME>__ for apex variants""

This reverts commit 12f629b26d13012049fe4778669c4e4a822d8940.

Bug: 142582178
Test: m (soong test added)
diff --git a/cc/compiler.go b/cc/compiler.go
index ffb6ad2..438dee7 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -320,7 +320,9 @@
 	}
 
 	if ctx.apexName() != "" {
+		// TODO(b/142582178): remove the value for __ANDROID_APEX__
 		flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_APEX__="+ctx.apexName())
+		flags.GlobalFlags = append(flags.GlobalFlags, "-D__ANDROID_APEX_"+makeDefineString(ctx.apexName())+"__")
 	}
 
 	instructionSet := String(compiler.Properties.Instruction_set)
@@ -528,6 +530,12 @@
 	return false
 }
 
+// makeDefineString transforms a name of an APEX module into a value to be used as value for C define
+// For example, com.android.foo => COM_ANDROID_FOO
+func makeDefineString(name string) string {
+	return strings.ReplaceAll(strings.ToUpper(name), ".", "_")
+}
+
 var gnuToCReplacer = strings.NewReplacer("gnu", "c")
 
 func ndkPathDeps(ctx ModuleContext) android.Paths {