cielavenir

droid-ndk-gcc for NDK r7

Dec 14th, 2011
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.63 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_args1 =
  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.     ]
  115. link_args2 = [
  116.      "#{alib}/crtbegin_dynamic.o",
  117.      "#{toolchain}/lib/gcc/arm-linux-androideabi/#{toolver}/libgcc.a",
  118.      "#{alib}/crtend_android.o",
  119.      "-lc",
  120.      "-lm",
  121.     ]
  122.  
  123. shlib_args =
  124.     [
  125.      "-nostdlib",
  126.      "-Wl,-T,#{droid_root}/build/core/armelf.xsc",
  127.      "-Wl,--gc-sections",
  128.      "-Wl,-shared,-Bsymbolic",
  129.      "-L#{alib}",
  130.      "-Wl,--no-whole-archive",
  131.      "-lc",
  132.      "-lm",
  133.      "-Wl,--no-undefined",
  134.      "#{toolchain}/lib/gcc/arm-eabi/#{toolver}/interwork/libgcc.a",
  135.      "-Wl,--whole-archive",
  136.      "-Wl,--warn-unresolved-symbols"
  137.     ]
  138.  
  139. ### check myself
  140. prog = nil
  141. oprog = nil
  142. if ($0 =~ /^.*-([^-]+)$/)
  143.     oprog = $1
  144.     prog = "#{toolchain}/bin/arm-linux-androideabi-#{$1}"
  145. else
  146.     STDERR.puts "internal error: invalid command name."
  147.     exit 1
  148. end
  149.  
  150. isLD = false
  151. if (oprog == "ld")
  152.     isLD = true
  153. end
  154.  
  155. ### parse command line options
  156. if (["ar", "nm", "objcopy", "objdump", "ranlib", "strip"].include?(oprog))
  157.     mode = "passthrough"
  158. else
  159.     mode = "link"
  160.  
  161.     ARGV.each do |arg|
  162.         case arg
  163.         when "-c", "-S", "-E", "-r"
  164.             mode = "compile"
  165.  
  166.         when "-shared"
  167.             mode = "shlib"
  168.         end
  169.     end
  170. end
  171.  
  172. ### generate command line
  173. argv = ARGV
  174.  
  175. case mode
  176. when "compile"
  177.     argv = cflags + ARGV
  178.    
  179. when "link"
  180.     if (!isLD)
  181.         argv = cflags + link_args1 + ARGV + link_args2
  182.     else
  183.         argv = link_args1 + ARGV + link_args2
  184.     end
  185.  
  186. when "shlib"
  187.     if (!isLD)
  188.         argv = cflags + shlib_args + ARGV
  189.     else
  190.         argv = shlib_args + ARGV
  191.     end
  192. end
  193.  
  194. # remove -Wl options for linker
  195. if (isLD)
  196.     argv2 = Array.new
  197.  
  198.     argv.each do |arg|
  199.         if (arg =~ /^-Wl,(.*)$/)
  200.             argv2 += $1.split(/,/)
  201.         else
  202.             argv2.push(arg)
  203.         end
  204.     end
  205.     argv = argv2
  206. end
  207.  
  208. # Note: Behavior of this command line might differ from
  209. # following exec call, because each arguments are not quoted.
  210. puts "droid-debug(#{mode}): #{prog} #{argv.join(" ")}" if (debug)
  211.  
  212. exec [prog, prog], *argv
Advertisement
Add Comment
Please, Sign In to add comment