cielavenir

droid-ndk-gcc

Aug 7th, 2011
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.58 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. =begin
  4.  
  5.   droid-wrapper : Android toolchain wrapper script
  6.   version 1.0.5
  7.  
  8.   Copyright 2009-2010, Takuya Murakami, Yoshiaki Okuyama.
  9.  
  10.   Author:
  11.     Takuya Murakami <tmurakam at tmurakam.org>
  12.     Yoshiaki Okuyama <okuyam2y at gmail.com>
  13.  
  14.   This program is free software; you can redistribute it and/or modify
  15.   it under the terms of the GNU General Public License as published by
  16.   the Free Software Foundation; either version 2 of the License, or
  17.   (at your option) any later version.
  18.  
  19.   This program is distributed in the hope that it will be useful,
  20.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22.   GNU General Public License for more details.
  23.  
  24.   You should have received a copy of the GNU General Public License
  25.   along with this program; if not, write to the Free Software
  26.   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  27.  
  28. =end
  29.  
  30. debug = false
  31. if (ENV["DROID_WRAPPER_DEBUG"])
  32.     debug = true
  33. end
  34.  
  35. droid_root = ENV["DROID_ROOT"]
  36. if (!droid_root)
  37.     #STDERR.puts "You must specify DROID_ROOT"
  38.     #exit 1
  39.     droid_root = "/opt/android-ndk"
  40. end
  41. droid_target = ENV["DROID_TARGET"]
  42. if (!droid_target)
  43.     #STDERR.puts "You must specify DROID_TARGET"
  44.     #exit 1
  45.     droid_target = "general"
  46. end
  47.  
  48. droid_host = ENV["DROID_HOST"]
  49. if (!droid_host)
  50.     droid_host = "linux-x86"
  51. end
  52.  
  53. toolver = "4.4.3"
  54.  
  55. #toolchain = "#{droid_root}/prebuilt/#{droid_host}/toolchain/arm-eabi-#{toolver}"
  56. toolchain = "#{droid_root}/toolchains/arm-linux-androideabi-#{toolver}/prebuilt/#{droid_host}"
  57. #alib = "#{droid_root}/out/target/product/#{droid_target}/obj/lib"
  58. alib = "#{droid_root}/platforms/android-8/arch-arm/usr/lib/"
  59.  
  60. # many compiler/linker flags were extracted from
  61. # build/core/combo/linux-arm.mk file.
  62.  
  63. cflags =
  64.     [
  65.      "-DANDROID",
  66.      "-msoft-float",
  67.      "-mandroid",
  68.      "-fpic",
  69.      "-ffunction-sections",
  70.      "-funwind-tables",
  71.      "-fstack-protector",
  72.      "-fno-short-enums",
  73.      "-fno-exceptions",
  74.      "-fmessage-length=0",
  75.      "-Wno-multichar",
  76.      "--sysroot=#{droid_root}/platforms/android-8/arch-arm",
  77.      #"-mthumb-interwork",
  78.  
  79.      "-I#{droid_root}/system/core/include",
  80.      "-I#{droid_root}/hardware/libhardware/include",
  81.      "-I#{droid_root}/hardware/libhardware_legacy/include",
  82.      "-I#{droid_root}/hardware/ril/include",
  83.      "-I#{droid_root}/dalvik/libnativehelper/include",
  84.      "-I#{droid_root}/frameworks/base/include",
  85.      "-I#{droid_root}/frameworks/base/opengl/include",
  86.      "-I#{droid_root}/external/skia/include",
  87.      "-I#{droid_root}/out/target/product/#{droid_target}/obj/include",
  88.      "-I#{droid_root}/bionic/libc/arch-arm/include",
  89.      "-I#{droid_root}/bionic/libc/include",
  90.      "-I#{droid_root}/bionic/libstdc++/include",
  91.      "-I#{droid_root}/bionic/libc/kernel/common",
  92.      "-I#{droid_root}/bionic/libc/kernel/arch-arm",
  93.      "-I#{droid_root}/bionic/libm/include",
  94.      "-I#{droid_root}/bionic/libm/include/arch/arm",
  95.      "-I#{droid_root}/bionic/libthread_db/include",
  96.      "-I#{droid_root}/bionic/libm/arm",
  97.      "-I#{droid_root}/bionic/libm",
  98.      "-I#{droid_root}/out/target/product/#{droid_target}/obj/SHARED_LIBRARIES/libm_intermediates"
  99.     ]
  100.  
  101. link_args =
  102.     [
  103.      "-Bdynamic",
  104.      "-mandroid",
  105.      #"-Wl,-T,#{droid_root}/build/core/armelf.x",
  106.      "-Wl,-dynamic-linker,/system/bin/linker",
  107.      "-Wl,--gc-sections",
  108.      "-Wl,-z,nocopyreloc",
  109.      "-Wl,--no-undefined",
  110.      "-Wl,-rpath-link=#{alib}",
  111.      "-Wl,-rpath,/system/lib",
  112.      "-L#{alib}",
  113.      "-nostdlib",
  114.      "#{alib}/crtbegin_dynamic.o",
  115.      "#{toolchain}/lib/gcc/arm-linux-androideabi/#{toolver}/libgcc.a",
  116.      "#{alib}/crtend_android.o",
  117.      "-lc",
  118.      "-lm"
  119.     ]
  120.  
  121. shlib_args =
  122.     [
  123.      "-nostdlib",
  124.      "-Wl,-T,#{droid_root}/build/core/armelf.xsc",
  125.      "-Wl,--gc-sections",
  126.      "-Wl,-shared,-Bsymbolic",
  127.      "-L#{alib}",
  128.      "-Wl,--no-whole-archive",
  129.      "-lc",
  130.      "-lm",
  131.      "-Wl,--no-undefined",
  132.      "#{toolchain}/lib/gcc/arm-eabi/#{toolver}/interwork/libgcc.a",
  133.      "-Wl,--whole-archive",
  134.      "-Wl,--warn-unresolved-symbols"
  135.     ]
  136.  
  137. ### check myself
  138. prog = nil
  139. oprog = nil
  140. if ($0 =~ /^.*-([^-]+)$/)
  141.     oprog = $1
  142.     prog = "#{toolchain}/bin/arm-linux-androideabi-#{$1}"
  143. else
  144.     STDERR.puts "internal error: invalid command name."
  145.     exit 1
  146. end
  147.  
  148. isLD = false
  149. if (oprog == "ld")
  150.     isLD = true
  151. end
  152.  
  153. ### parse command line options
  154. if (["ar", "nm", "objcopy", "objdump", "ranlib", "strip"].include?(oprog))
  155.     mode = "passthrough"
  156. else
  157.     mode = "link"
  158.  
  159.     ARGV.each do |arg|
  160.         case arg
  161.         when "-c", "-S", "-E", "-r"
  162.             mode = "compile"
  163.  
  164.         when "-shared"
  165.             mode = "shlib"
  166.         end
  167.     end
  168. end
  169.  
  170. ### generate command line
  171. argv = ARGV
  172.  
  173. case mode
  174. when "compile"
  175.     argv = cflags + ARGV
  176.    
  177. when "link"
  178.     if (!isLD)
  179.         argv = cflags + link_args + ARGV
  180.     else
  181.         argv = link_args + ARGV
  182.     end
  183.  
  184. when "shlib"
  185.     if (!isLD)
  186.         argv = cflags + shlib_args + ARGV
  187.     else
  188.         argv = shlib_args + ARGV
  189.     end
  190. end
  191.  
  192. # remove -Wl options for linker
  193. if (isLD)
  194.     argv2 = Array.new
  195.  
  196.     argv.each do |arg|
  197.         if (arg =~ /^-Wl,(.*)$/)
  198.             argv2 += $1.split(/,/)
  199.         else
  200.             argv2.push(arg)
  201.         end
  202.     end
  203.     argv = argv2
  204. end
  205.  
  206. # Note: Behavior of this command line might differ from
  207. # following exec call, because each arguments are not quoted.
  208. puts "droid-debug(#{mode}): #{prog} #{argv.join(" ")}" if (debug)
  209.  
  210. exec [prog, prog], *argv
Advertisement
Add Comment
Please, Sign In to add comment