Add rule to build librclcore.bc as replacement for libruntime.bc.

Change-Id: Ief73c30f426e3f262a6c703fc42ac27d09fb1905
diff --git a/Android.mk b/Android.mk
index 3a66833..d194c53 100644
--- a/Android.mk
+++ b/Android.mk
@@ -54,16 +54,6 @@
 endif
 
 #
-# libruntime.bc
-# ========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := libruntime.bc
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := SHARED_LIBRARIES
-LOCAL_SRC_FILES := lib/runtime/$(LOCAL_MODULE)
-include $(BUILD_PREBUILT)
-
-#
 # Shared library for target
 # ========================================================
 include $(CLEAR_VARS)
@@ -145,8 +135,8 @@
   $(LOCAL_STATIC_LIBRARIES)
 endif
 
-# This makes libruntime.bc get installed if and only if the target libbcc.so is installed.
-LOCAL_REQUIRED_MODULES := libruntime.bc
+# This makes libclcore.bc get installed if and only if the target libbcc.so is installed.
+LOCAL_REQUIRED_MODULES := libclcore.bc
 
 # -Wl,--exclude-libs=ALL would hide most of the symbols in the shared library
 # and reduces the size of libbcc.so by about 800k.
@@ -217,7 +207,6 @@
 
 # Build children
 # ========================================================
-
 include $(call all-makefiles-under,$(LOCAL_PATH))
 
 endif # TARGET_SIMULATOR != true
diff --git a/lib/Android.mk b/lib/Android.mk
new file mode 100644
index 0000000..9073ac3
--- /dev/null
+++ b/lib/Android.mk
@@ -0,0 +1,19 @@
+#
+# Copyright (C) 2010 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/lib/runtime/Android.mk b/lib/runtime/Android.mk
new file mode 100644
index 0000000..f05fe22
--- /dev/null
+++ b/lib/runtime/Android.mk
@@ -0,0 +1,48 @@
+#
+# Copyright (C) 2011 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.
+#
+
+ifneq ($(TARGET_SIMULATOR),true)
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libclcore.bc
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+
+LOCAL_SRC_FILES := \
+    rs_cl.c \
+    rs_core.c
+
+
+include $(BUILD_SYSTEM)/base_rules.mk
+
+clcore_CLANG := $(HOST_OUT_EXECUTABLES)/clang$(HOST_EXECUTABLE_SUFFIX)
+clcore_LLVM_LINK := $(HOST_OUT_EXECUTABLES)/llvm-link$(HOST_EXECUTABLE_SUFFIX)
+
+clcore_bc_files := $(patsubst %.c,%.bc, \
+    $(addprefix $(intermediates)/, $(LOCAL_SRC_FILES)))
+
+$(clcore_bc_files): PRIVATE_INCLUDES := frameworks/base/libs/rs/scriptc
+$(clcore_bc_files): $(intermediates)/%.bc: $(LOCAL_PATH)/%.c  $(clcore_CLANG)
+	@mkdir -p $(dir $@)
+	$(hide) $(clcore_CLANG) $(addprefix -I, $(PRIVATE_INCLUDES)) -c -O3 $< -emit-llvm -o $@
+
+$(LOCAL_BUILT_MODULE): PRIVATE_BC_FILES := $(clcore_bc_files)
+$(LOCAL_BUILT_MODULE) : $(clcore_bc_files) $(clcore_LLVM_LINK)
+	@mkdir -p $(dir $@)
+	$(hide) $(clcore_LLVM_LINK) $(PRIVATE_BC_FILES) -o $@
+
+endif
diff --git a/lib/runtime/Android.mk.disabled b/lib/runtime/Android.mk.disabled
deleted file mode 100644
index 14f533a..0000000
--- a/lib/runtime/Android.mk.disabled
+++ /dev/null
@@ -1,11 +0,0 @@
-# build libclcore.bc
-# ========================================================
-include $(CLEAR_VARS)
-LOCAL_MODULE := libclcore.bc
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SRC_FILES := \
- lib/runtime/rs_cl.ll \
- lib/runtime/rs_core.ll 
-
-include build_clcore.mk
diff --git a/lib/runtime/build_clcore.mk b/lib/runtime/build_clcore.mk
deleted file mode 100644
index 4498b6a..0000000
--- a/lib/runtime/build_clcore.mk
+++ /dev/null
@@ -1,40 +0,0 @@
-LLVM_AS := $(HOST_OUT_EXECUTABLES)/llvm-as$(HOST_EXECUTABLE_SUFFIX)
-LLVM_RS_LINK  := $(HOST_OUT_EXECUTABLES)/llvm-rs-link$(HOST_EXECUTABLE_SUFFIX)
-
-stub_module   := $(LOCAL_PATH)/$(LOCAL_MODULE:%.bc=%.ll)
-linked_module := $(LOCAL_MODULE)
-linked_module_fullpath := $(LOCAL_PATH)/$(LOCAL_MODULE)
-
-llvm_ll_sources := $(filter %.ll,$(LOCAL_SRC_FILES))
-llvm_ll_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(llvm_ll_sources))
-PRIVATE_LL_SOURCE_FILES := $(llvm_ll_sources_fullpath)
-
-llvm_bc_sources := $(llvm_ll_sources:.ll=.bc)
-llvm_bc_sources_fullpath :=  $(addprefix $(LOCAL_PATH)/,$(llvm_bc_sources))
-PRIVATE_BC_SOURCE_FILES := $(llvm_bc_sources_fullpath)
-
-%.bc: %.ll
-       $(call transform-ll-to-bc)
-
-$(linked_module): $(PRIVATE_BC_SOURCE_FILES)
-       $(call transform-host-bc-to-libruntime)
-
-###########################################################
-## Commands to compile LLVM Assembly
-###########################################################
-define transform-ll-to-bc
-        $(hide) $(LLVM_AS) $< -o $@
-endef
-
-
-###########################################################
-## Commands for running llvm-rs-link
-###########################################################
-define transform-host-bc-to-libruntime
-touch $(stub_module)
-$(hide) $(LLVM_AS) $(stub_module) -o $(linked_module_fullpath)
-
-$(hide) $(LLVM_RS_LINK) -nostdlib \
-         $(foreach bc,$(PRIVATE_BC_SOURCE_FILES),$(addprefix -l , $(bc))) \
-         $(linked_module_fullpath)
-endef
diff --git a/lib/runtime/build_clcore.sh b/lib/runtime/build_clcore.sh
index faa27c9..d7892e0 100755
--- a/lib/runtime/build_clcore.sh
+++ b/lib/runtime/build_clcore.sh
@@ -6,12 +6,14 @@
 # Generate rs_cl.bc
 # =================
 
-clang -c -O3 rs_cl.c -emit-llvm -o rs_cl.bc
+scriptc_path=../../../../base/libs/rs/scriptc
+
+clang -I${scriptc_path} -c -O3 rs_cl.c -emit-llvm -o rs_cl.bc
 
 # Generate rs_core.bc
 # ===================
 
-clang -c -O3 rs_core.c -emit-llvm -o rs_core.bc
+clang -I${scriptc_path} -c -O3 rs_core.c -emit-llvm -o rs_core.bc
 
 # Link everything together
 # ========================
diff --git a/lib/runtime/libruntime.bc b/lib/runtime/libruntime.bc
deleted file mode 100644
index b0ae5db..0000000
--- a/lib/runtime/libruntime.bc
+++ /dev/null
Binary files differ
diff --git a/lib/runtime/libruntime.ll b/lib/runtime/libruntime.ll
deleted file mode 100644
index 00ddb24..0000000
--- a/lib/runtime/libruntime.ll
+++ /dev/null
@@ -1,49 +0,0 @@
-; ModuleID = 'rslib.bc'
-
-;define <3 x float> @_Z15convert1_float3Dv3_h(<3 x i8> %u3) nounwind readnone {
-;  %conv = uitofp <3 x i8> %u3 to <3 x float>
-;  ret <3 x float> %conv
-;}
-
-define <3 x i8> @_Z14convert2uchar3Dv3_f(<3 x float> %v) nounwind readnone {
-  %1 = extractelement <3 x float> %v, i32 0
-  %2 = fptoui float %1 to i8
-  %3 = insertelement <3 x i8> undef, i8 %2, i32 0
-  %4 = extractelement <3 x float> %v, i32 1
-  %5 = fptoui float %4 to i8
-  %6 = insertelement <3 x i8> %3, i8 %5, i32 1
-  %7 = extractelement <3 x float> %v, i32 2
-  %8 = fptoui float %7 to i8
-  %9 = insertelement <3 x i8> %6, i8 %8, i32 2
-  ret <3 x i8> %9
-}
-
-;declare float @llvm.powi.f32(float, i32) nounwind readonly
-;
-;define <3 x float> @_Z4powiDv3_fi(<3 x float> %f3, i32 %exp) nounwind readnone {
-;  %x = extractelement <3 x float> %f3, i32 0
-;  %y = extractelement <3 x float> %f3, i32 1
-;  %z = extractelement <3 x float> %f3, i32 2
-;  %retx = tail call float @llvm.powi.f32(float %x, i32 %exp)
-;  %rety = tail call float @llvm.powi.f32(float %y, i32 %exp)
-;  %retz = tail call float @llvm.powi.f32(float %z, i32 %exp)
-;  %tmp1 = insertelement <3 x float> %f3, float %retx, i32 0
-;  %tmp2 = insertelement <3 x float> %tmp1, float %rety, i32 1
-;  %ret = insertelement <3 x float> %tmp2, float %retz, i32 2
-;  ret <3 x float> %ret
-;}
-;
-;declare float @llvm.pow.f32(float, float) nounwind readonly
-;
-;define <3 x float> @_Z4pow3Dv3_ff(<3 x float> %f3, float %exp) nounwind readnone {
-;  %x = extractelement <3 x float> %f3, i32 0
-;  %y = extractelement <3 x float> %f3, i32 1
-;  %z = extractelement <3 x float> %f3, i32 2
-;  %retx = tail call float @llvm.pow.f32(float %x, float %exp)
-;  %rety = tail call float @llvm.pow.f32(float %y, float %exp)
-;  %retz = tail call float @llvm.pow.f32(float %z, float %exp)
-;  %tmp1 = insertelement <3 x float> %f3, float %retx, i32 0
-;  %tmp2 = insertelement <3 x float> %tmp1, float %rety, i32 1
-;  %ret = insertelement <3 x float> %tmp2, float %retz, i32 2
-;  ret <3 x float> %ret
-;}
diff --git a/lib/runtime/rs_cl.c b/lib/runtime/rs_cl.c
index 5d008b8..f9565c7 100644
--- a/lib/runtime/rs_cl.c
+++ b/lib/runtime/rs_cl.c
@@ -1,5 +1,4 @@
-#include "../../../../base/libs/rs/scriptc/rs_types.rsh"
+#include "rs_types.rsh"
 
 #define BCC_PREPARE_BC 1
-#include "../../../../base/libs/rs/scriptc/rs_cl.rsh"
-
+#include "rs_cl.rsh"
diff --git a/lib/runtime/rs_core.c b/lib/runtime/rs_core.c
index f352cda..c9a7c1d 100644
--- a/lib/runtime/rs_core.c
+++ b/lib/runtime/rs_core.c
@@ -1,4 +1,4 @@
-#include "../../../../base/libs/rs/scriptc/rs_types.rsh"
+#include "rs_types.rsh"
 
 #define bool  int
 #define true  1
@@ -8,4 +8,4 @@
 extern float4 __attribute__((overloadable)) convert_float4(uchar4 c);
 
 #define BCC_PREPARE_BC 1
-#include "../../../../base/libs/rs/scriptc/rs_core.rsh"
+#include "rs_core.rsh"