Colin Cross | 1e047d3 | 2018-03-12 18:23:15 -0700 | [diff] [blame] | 1 | ############################################################### |
| 2 | ## Renderscript support for java |
| 3 | ## Adds rules to convert .rs files to .java and .bc files |
| 4 | ############################################################### |
| 5 | |
| 6 | renderscript_sources := $(filter %.rs,$(LOCAL_SRC_FILES)) |
| 7 | LOCAL_SRC_FILES := $(filter-out %.rs,$(LOCAL_SRC_FILES)) |
| 8 | |
| 9 | rs_generated_res_zip := |
| 10 | rs_generated_src_jar := |
| 11 | rs_compatibility_jni_libs := |
| 12 | ifneq ($(renderscript_sources),) |
| 13 | renderscript_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(renderscript_sources)) |
| 14 | renderscript_intermediate.COMMON := $(intermediates.COMMON)/renderscript |
| 15 | rs_generated_res_zip := $(renderscript_intermediate.COMMON)/res.zip |
| 16 | rs_generated_src_jar := $(renderscript_intermediate.COMMON)/rs.srcjar |
| 17 | |
| 18 | LOCAL_SRCJARS += $(rs_generated_src_jar) |
| 19 | |
| 20 | # Defaulting to an empty string uses the latest available platform SDK. |
| 21 | renderscript_target_api := |
| 22 | |
| 23 | ifneq (,$(LOCAL_RENDERSCRIPT_TARGET_API)) |
| 24 | renderscript_target_api := $(LOCAL_RENDERSCRIPT_TARGET_API) |
| 25 | else |
| 26 | ifneq (,$(LOCAL_SDK_VERSION)) |
| 27 | # Set target-api for LOCAL_SDK_VERSIONs other than current. |
| 28 | ifneq (,$(filter-out current system_current test_current core_current, $(LOCAL_SDK_VERSION))) |
| 29 | renderscript_target_api := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION)) |
| 30 | endif |
| 31 | endif # LOCAL_SDK_VERSION is set |
| 32 | endif # LOCAL_RENDERSCRIPT_TARGET_API is set |
| 33 | |
| 34 | # For 64-bit, we always have to upgrade to at least 21 for compat build. |
| 35 | ifneq ($(LOCAL_RENDERSCRIPT_COMPATIBILITY),) |
| 36 | ifeq ($(TARGET_IS_64_BIT),true) |
| 37 | ifneq ($(filter $(RSCOMPAT_32BIT_ONLY_API_LEVELS),$(renderscript_target_api)),) |
| 38 | renderscript_target_api := 21 |
| 39 | endif |
| 40 | endif |
| 41 | endif |
| 42 | |
| 43 | ifeq ($(LOCAL_RENDERSCRIPT_CC),) |
| 44 | LOCAL_RENDERSCRIPT_CC := $(LLVM_RS_CC) |
| 45 | endif |
| 46 | |
| 47 | # Turn on all warnings and warnings as errors for RS compiles. |
| 48 | # This can be disabled with LOCAL_RENDERSCRIPT_FLAGS := -Wno-error |
| 49 | renderscript_flags := -Wall -Werror |
| 50 | renderscript_flags += $(LOCAL_RENDERSCRIPT_FLAGS) |
| 51 | |
| 52 | # prepend the RenderScript system include path |
| 53 | ifneq ($(filter-out current system_current test_current core_current,$(LOCAL_SDK_VERSION))$(if $(TARGET_BUILD_APPS),$(filter current system_current test_current,$(LOCAL_SDK_VERSION))),) |
| 54 | # if a numeric LOCAL_SDK_VERSION, or current LOCAL_SDK_VERSION with TARGET_BUILD_APPS |
| 55 | LOCAL_RENDERSCRIPT_INCLUDES := \ |
| 56 | $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/clang-include \ |
| 57 | $(HISTORICAL_SDK_VERSIONS_ROOT)/renderscript/include \ |
| 58 | $(LOCAL_RENDERSCRIPT_INCLUDES) |
| 59 | else |
| 60 | LOCAL_RENDERSCRIPT_INCLUDES := \ |
| 61 | $(TOPDIR)external/clang/lib/Headers \ |
| 62 | $(TOPDIR)frameworks/rs/script_api/include \ |
| 63 | $(LOCAL_RENDERSCRIPT_INCLUDES) |
| 64 | endif |
| 65 | |
| 66 | ifneq ($(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE),) |
| 67 | LOCAL_RENDERSCRIPT_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES_OVERRIDE) |
| 68 | endif |
| 69 | |
| 70 | bc_files := $(patsubst %.rs,%.bc, $(notdir $(renderscript_sources))) |
| 71 | bc_dep_files := $(addprefix $(renderscript_intermediate.COMMON)/,$(patsubst %.bc,%.d,$(bc_files))) |
| 72 | |
| 73 | $(rs_generated_src_jar): PRIVATE_RS_INCLUDES := $(LOCAL_RENDERSCRIPT_INCLUDES) |
| 74 | $(rs_generated_src_jar): PRIVATE_RS_CC := $(LOCAL_RENDERSCRIPT_CC) |
| 75 | $(rs_generated_src_jar): PRIVATE_RS_FLAGS := $(renderscript_flags) |
| 76 | $(rs_generated_src_jar): PRIVATE_RS_SOURCE_FILES := $(renderscript_sources_fullpath) |
| 77 | $(rs_generated_src_jar): PRIVATE_RS_OUTPUT_DIR := $(renderscript_intermediate.COMMON) |
| 78 | $(rs_generated_src_jar): PRIVATE_RS_TARGET_API := $(renderscript_target_api) |
| 79 | $(rs_generated_src_jar): PRIVATE_DEP_FILES := $(bc_dep_files) |
| 80 | $(rs_generated_src_jar): PRIVATE_RS_OUTPUT_RES_ZIP := $(rs_generated_res_zip) |
| 81 | $(rs_generated_src_jar): .KATI_IMPLICIT_OUTPUTS := $(rs_generated_res_zip) |
| 82 | $(rs_generated_src_jar): $(renderscript_sources_fullpath) $(LOCAL_RENDERSCRIPT_CC) $(SOONG_ZIP) |
| 83 | $(transform-renderscripts-to-java-and-bc) |
| 84 | |
| 85 | # include the dependency files (.d/.P) generated by llvm-rs-cc. |
| 86 | $(call include-depfile,$(rs_generated_src_jar).P,$(rs_generated_src_jar)) |
| 87 | |
| 88 | ifneq ($(LOCAL_RENDERSCRIPT_COMPATIBILITY),) |
| 89 | |
| 90 | |
| 91 | ifeq ($(filter $(RSCOMPAT_32BIT_ONLY_API_LEVELS),$(renderscript_target_api)),) |
| 92 | ifeq ($(TARGET_IS_64_BIT),true) |
| 93 | renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/bc64/ |
| 94 | else |
| 95 | renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/bc32/ |
| 96 | endif |
| 97 | else |
| 98 | renderscript_intermediate.bc_folder := $(renderscript_intermediate.COMMON)/res/raw/ |
| 99 | endif |
| 100 | |
| 101 | rs_generated_bc := $(addprefix \ |
| 102 | $(renderscript_intermediate.bc_folder), $(bc_files)) |
| 103 | |
| 104 | renderscript_intermediate := $(intermediates)/renderscript |
| 105 | |
| 106 | # We don't need the .so files in bundled branches |
| 107 | # Prevent these from showing up on the device |
| 108 | # One exception is librsjni.so, which is needed for |
| 109 | # both native path and compat path. |
| 110 | rs_jni_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/librsjni.so |
| 111 | LOCAL_JNI_SHARED_LIBRARIES += librsjni |
| 112 | |
| 113 | ifneq (,$(TARGET_BUILD_APPS)$(FORCE_BUILD_RS_COMPAT)) |
| 114 | |
| 115 | rs_compatibility_jni_libs := $(addprefix \ |
| 116 | $(renderscript_intermediate)/librs., \ |
| 117 | $(patsubst %.bc,%.so, $(bc_files))) |
| 118 | |
| 119 | $(rs_generated_src_jar): .KATI_IMPLICIT_OUTPUTS += $(rs_generated_bc) |
| 120 | |
| 121 | rs_support_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/libRSSupport.so |
| 122 | LOCAL_JNI_SHARED_LIBRARIES += libRSSupport |
| 123 | |
| 124 | rs_support_io_lib := |
| 125 | # check if the target api level support USAGE_IO |
| 126 | ifeq ($(filter $(RSCOMPAT_NO_USAGEIO_API_LEVELS),$(renderscript_target_api)),) |
| 127 | rs_support_io_lib := $(TARGET_OUT_INTERMEDIATE_LIBRARIES)/libRSSupportIO.so |
| 128 | LOCAL_JNI_SHARED_LIBRARIES += libRSSupportIO |
| 129 | endif |
| 130 | |
| 131 | my_arch := $(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH) |
| 132 | ifneq (,$(filter arm64 mips64 x86_64,$(my_arch))) |
| 133 | my_min_sdk_version := 21 |
| 134 | else |
| 135 | my_min_sdk_version := $(MIN_SUPPORTED_SDK_VERSION) |
| 136 | endif |
| 137 | |
| 138 | $(rs_compatibility_jni_libs): $(RS_PREBUILT_CLCORE) \ |
| 139 | $(rs_support_lib) $(rs_support_io_lib) $(rs_jni_lib) $(rs_compiler_rt) |
| 140 | $(rs_compatibility_jni_libs): $(BCC_COMPAT) |
| 141 | $(rs_compatibility_jni_libs): PRIVATE_CXX := $(CXX_WRAPPER) $(TARGET_CXX) |
| 142 | $(rs_compatibility_jni_libs): PRIVATE_SDK_VERSION := $(my_min_sdk_version) |
| 143 | $(rs_compatibility_jni_libs): $(renderscript_intermediate)/librs.%.so: \ |
| 144 | $(renderscript_intermediate.bc_folder)%.bc \ |
| 145 | $(SOONG_OUT_DIR)/ndk.timestamp |
| 146 | $(transform-bc-to-so) |
| 147 | |
| 148 | endif |
| 149 | |
| 150 | endif |
| 151 | |
| 152 | LOCAL_INTERMEDIATE_TARGETS += $(rs_generated_src_jar) |
| 153 | # Make sure the generated resource will be added to the apk. |
| 154 | LOCAL_RESOURCE_DIR := $(renderscript_intermediate.COMMON)/res $(LOCAL_RESOURCE_DIR) |
| 155 | endif |