Build system support for RenderScript

With this change, you can add your .rs files to LOCAL_SRC_FILES.
The .rs files will be compiled by slang and the output .java files
will be compiled into the jar, while the generated .bc files will
be put into the final apk as raw resources.

Change-Id: Icde3d6139951d6d039b4b37376e72e1fc5c8b0d4
diff --git a/core/definitions.mk b/core/definitions.mk
index 87e9013..5e1df45 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -236,6 +236,19 @@
 endef
 
 ###########################################################
+## Find all of the RenderScript files under the named directories.
+##  Meant to be used like:
+##    SRC_FILES := $(call all-renderscript-files-under,src)
+###########################################################
+
+define all-renderscript-files-under
+$(patsubst ./%,%, \
+  $(shell cd $(LOCAL_PATH) ; \
+          find $(1) -name "*.rs" -and -not -name ".*") \
+  )
+endef
+
+###########################################################
 ## Find all of the html files under the named directories.
 ## Meant to be used like:
 ##    SRC_FILES := $(call all-html-files-under,src tests)
@@ -732,6 +745,29 @@
 rm -f $(@:$1=$(YACC_HEADER_SUFFIX))
 endef
 
+###########################################################
+## Commands to compile RenderScript
+###########################################################
+# $(1) the .rs file
+define _compile-one-rs-file
+$(hide) $(SLANG) \
+  --allow-rs-prefix \
+  -o $(PRIVATE_RS_OUTPUT_DIR)/res/raw/$(patsubst %.rs,%.bc,$(notdir $(1))) \
+  -p $(PRIVATE_RS_OUTPUT_DIR)/src \
+  $(1)
+
+endef
+
+define transform-renderscripts-to-java-and-bc
+@echo "RenderScript: $(PRIVATE_MODULE) <= $(PRIVATE_RS_SOURCE_FILES)"
+$(hide) rm -rf $(PRIVATE_RS_OUTPUT_DIR)
+$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/res/raw
+$(hide) mkdir -p $(PRIVATE_RS_OUTPUT_DIR)/src
+$(foreach rs,$(PRIVATE_RS_SOURCE_FILES),$(call _compile-one-rs-file,$(rs)))
+$(hide) mkdir -p $(dir $@)
+$(hide) touch $@
+endef
+
 
 ###########################################################
 ## Commands for running aidl