require 'fileutils' $curdir = pwd TARGETDIR = ENV['TARGET_TEMP_DIR'] raise "TARGET_TEMP_DIR is not set" if TARGETDIR.nil? OBJDIR = ENV['TEMP_FILES_DIR'] raise "TEMP_FILES_DIR is not set" if OBJDIR.nil? $rootdir = ENV['RHO_ROOT'] raise "RHO_ROOT is not set" if $rootdir.nil? $appincdir = ENV["RHO_INC"] raise "RHO_INC is not set" if $appincdir.nil? $androidndkpath = ENV['ANDROID_NDK'] raise 'ANDROID_NDK is not set' if $androidndkpath.nil? require File.join($rootdir, 'platform/android/build/androidcommon.rb') ARGS = ['-Iext', "-I\"#{$rootdir}/platform/shared\"", "-I\"#{$rootdir}/platform/shared/common\"", "-I\"#{$rootdir}/platform/shared/ruby/include\"", "-I\"#{$rootdir}/platform/shared/ruby/android\"", "-I\"#{$rootdir}/platform/shared/ruby/generated\"", "-I\"#{$curdir}/../../../openssl.so-edge/ext/openssl-1-1-0-stable/include\"" ] OBJDIR_ARM = File.join(OBJDIR,'arm') OBJDIR_x86 = File.join(OBJDIR,'x86') OBJDIR_MIPS = File.join(OBJDIR,'mips') SRC = get_sources File.join($curdir, 'ext_native.files') OBJ_ARM = FileList.new(get_objects(SRC, OBJDIR_ARM)) OBJ_x86 = FileList.new(get_objects(SRC, OBJDIR_x86)) OBJ_MIPS = FileList.new(get_objects(SRC, OBJDIR_MIPS)) TARGETDIR_ARM = File.join(TARGETDIR,'armeabi') TARGETDIR_x86 = File.join(TARGETDIR,'x86') TARGETDIR_MIPS = File.join(TARGETDIR,'mips') TARGETLIB_ARM = File.join(TARGETDIR_ARM,'libopenssl.a') TARGETLIB_x86 = File.join(TARGETDIR_x86,'libopenssl.a') TARGETLIB_MIPS = File.join(TARGETDIR_MIPS,'libopenssl.a') cd '../..' namespace 'config' do task :arm do setup_ndk(ENV['ANDROID_NDK'],ENV['ANDROID_API_LEVEL'],'arm') end task :x86 do setup_ndk(ENV['ANDROID_NDK'],ENV['ANDROID_API_LEVEL'],'x86') end task :mips do setup_ndk(ENV['ANDROID_NDK'],ENV['ANDROID_API_LEVEL'],'mips') end end directory TARGETDIR_ARM directory TARGETDIR_x86 directory TARGETDIR_MIPS directory OBJDIR_ARM directory OBJDIR_x86 directory OBJDIR_MIPS rule '.o' => lambda {|obj| find_source(obj) } do |t| abi = File.basename(File.dirname(t.name)) Rake::Task["config:#{abi}"].invoke cc_compile find_source(t.name), File.dirname(t.name), ARGS or raise "\e[31mCompilation failed: #{find_source(t.name)}\e[0m" end task OBJ_ARM => OBJDIR_ARM task OBJ_x86 => OBJDIR_x86 task OBJ_MIPS => OBJDIR_MIPS def find_source(objfile) base = File.basename(objfile, '.o') src = SRC.find { |s| File.basename(s) == base } src end file TARGETLIB_ARM => TARGETDIR_ARM do |t| Rake::Task["config:arm"].invoke cc_ar t.name, OBJ_ARM or raise "\e[31mCreating library failed: #{t.name}\e[0m" end multitask TARGETLIB_ARM => OBJ_ARM file TARGETLIB_x86 => TARGETDIR_x86 do |t| Rake::Task["config:x86"].invoke cc_ar t.name, OBJ_x86 or raise "\e[31mCreating library failed: #{t.name}\e[0m" end multitask TARGETLIB_x86 => OBJ_x86 file TARGETLIB_MIPS => TARGETDIR_MIPS do |t| Rake::Task["config:mips"].invoke cc_ar t.name, OBJ_MIPS or raise "\e[31mCreating library failed: #{t.name}\e[0m" end multitask TARGETLIB_MIPS => OBJ_MIPS namespace 'arch' do task :arm => [TARGETLIB_ARM] task :x86 => [TARGETLIB_x86] task :mips => [TARGETLIB_MIPS] end task :default => ["arch:arm", "arch:x86"]