Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- =begin
- droid-wrapper : Android toolchain wrapper script
- version 1.0.5
- Copyright 2009-2010, Takuya Murakami, Yoshiaki Okuyama.
- Author:
- Takuya Murakami <tmurakam at tmurakam.org>
- Yoshiaki Okuyama <okuyam2y at gmail.com>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- =end
- debug = false
- if (ENV["DROID_WRAPPER_DEBUG"])
- debug = true
- end
- droid_root = ENV["DROID_ROOT"]
- if (!droid_root)
- #STDERR.puts "You must specify DROID_ROOT"
- #exit 1
- droid_root = "/opt/android-ndk"
- end
- droid_target = ENV["DROID_TARGET"]
- if (!droid_target)
- #STDERR.puts "You must specify DROID_TARGET"
- #exit 1
- droid_target = "general"
- end
- droid_host = ENV["DROID_HOST"]
- if (!droid_host)
- droid_host = "linux-x86"
- end
- toolver = "4.4.3"
- #toolchain = "#{droid_root}/prebuilt/#{droid_host}/toolchain/arm-eabi-#{toolver}"
- toolchain = "#{droid_root}/toolchains/arm-linux-androideabi-#{toolver}/prebuilt/#{droid_host}"
- #alib = "#{droid_root}/out/target/product/#{droid_target}/obj/lib"
- alib = "#{droid_root}/platforms/android-8/arch-arm/usr/lib/"
- # many compiler/linker flags were extracted from
- # build/core/combo/linux-arm.mk file.
- cflags =
- [
- "-DANDROID",
- "-msoft-float",
- "-mandroid",
- "-fpic",
- "-ffunction-sections",
- "-funwind-tables",
- "-fstack-protector",
- "-fno-short-enums",
- "-fno-exceptions",
- "-fmessage-length=0",
- "-Wno-multichar",
- "--sysroot=#{droid_root}/platforms/android-8/arch-arm",
- #"-mthumb-interwork",
- "-I#{droid_root}/system/core/include",
- "-I#{droid_root}/hardware/libhardware/include",
- "-I#{droid_root}/hardware/libhardware_legacy/include",
- "-I#{droid_root}/hardware/ril/include",
- "-I#{droid_root}/dalvik/libnativehelper/include",
- "-I#{droid_root}/frameworks/base/include",
- "-I#{droid_root}/frameworks/base/opengl/include",
- "-I#{droid_root}/external/skia/include",
- "-I#{droid_root}/out/target/product/#{droid_target}/obj/include",
- "-I#{droid_root}/bionic/libc/arch-arm/include",
- "-I#{droid_root}/bionic/libc/include",
- "-I#{droid_root}/bionic/libstdc++/include",
- "-I#{droid_root}/bionic/libc/kernel/common",
- "-I#{droid_root}/bionic/libc/kernel/arch-arm",
- "-I#{droid_root}/bionic/libm/include",
- "-I#{droid_root}/bionic/libm/include/arch/arm",
- "-I#{droid_root}/bionic/libthread_db/include",
- "-I#{droid_root}/bionic/libm/arm",
- "-I#{droid_root}/bionic/libm",
- "-I#{droid_root}/out/target/product/#{droid_target}/obj/SHARED_LIBRARIES/libm_intermediates"
- ]
- link_args =
- [
- "-Bdynamic",
- "-mandroid",
- #"-Wl,-T,#{droid_root}/build/core/armelf.x",
- "-Wl,-dynamic-linker,/system/bin/linker",
- "-Wl,--gc-sections",
- "-Wl,-z,nocopyreloc",
- "-Wl,--no-undefined",
- "-Wl,-rpath-link=#{alib}",
- "-Wl,-rpath,/system/lib",
- "-L#{alib}",
- "-nostdlib",
- "#{alib}/crtbegin_dynamic.o",
- "#{toolchain}/lib/gcc/arm-linux-androideabi/#{toolver}/libgcc.a",
- "#{alib}/crtend_android.o",
- "-lc",
- "-lm"
- ]
- shlib_args =
- [
- "-nostdlib",
- "-Wl,-T,#{droid_root}/build/core/armelf.xsc",
- "-Wl,--gc-sections",
- "-Wl,-shared,-Bsymbolic",
- "-L#{alib}",
- "-Wl,--no-whole-archive",
- "-lc",
- "-lm",
- "-Wl,--no-undefined",
- "#{toolchain}/lib/gcc/arm-eabi/#{toolver}/interwork/libgcc.a",
- "-Wl,--whole-archive",
- "-Wl,--warn-unresolved-symbols"
- ]
- ### check myself
- prog = nil
- oprog = nil
- if ($0 =~ /^.*-([^-]+)$/)
- oprog = $1
- prog = "#{toolchain}/bin/arm-linux-androideabi-#{$1}"
- else
- STDERR.puts "internal error: invalid command name."
- exit 1
- end
- isLD = false
- if (oprog == "ld")
- isLD = true
- end
- ### parse command line options
- if (["ar", "nm", "objcopy", "objdump", "ranlib", "strip"].include?(oprog))
- mode = "passthrough"
- else
- mode = "link"
- ARGV.each do |arg|
- case arg
- when "-c", "-S", "-E", "-r"
- mode = "compile"
- when "-shared"
- mode = "shlib"
- end
- end
- end
- ### generate command line
- argv = ARGV
- case mode
- when "compile"
- argv = cflags + ARGV
- when "link"
- if (!isLD)
- argv = cflags + link_args + ARGV
- else
- argv = link_args + ARGV
- end
- when "shlib"
- if (!isLD)
- argv = cflags + shlib_args + ARGV
- else
- argv = shlib_args + ARGV
- end
- end
- # remove -Wl options for linker
- if (isLD)
- argv2 = Array.new
- argv.each do |arg|
- if (arg =~ /^-Wl,(.*)$/)
- argv2 += $1.split(/,/)
- else
- argv2.push(arg)
- end
- end
- argv = argv2
- end
- # Note: Behavior of this command line might differ from
- # following exec call, because each arguments are not quoted.
- puts "droid-debug(#{mode}): #{prog} #{argv.join(" ")}" if (debug)
- exec [prog, prog], *argv
Advertisement
Add Comment
Please, Sign In to add comment