OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2012 The Dart Authors. All rights reserved. | 3 # Copyright (c) 2012 The Dart Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """ | 7 """ |
8 This script performs the final link step for Android NDK executables. | 8 This script performs the final link step for Android NDK executables. |
9 Usage: | 9 Usage: |
10 ./android_link {arm,arm64,ia32} {executable,library,shared_library} | 10 ./android_link {arm,arm64,ia32} {executable,library,shared_library} |
(...skipping 30 matching lines...) Expand all Loading... |
41 if sys.argv[1] == '-shared': | 41 if sys.argv[1] == '-shared': |
42 sys.argv.remove('-shared') | 42 sys.argv.remove('-shared') |
43 | 43 |
44 # Grab the command line arguments. | 44 # Grab the command line arguments. |
45 target_arch = sys.argv[1] | 45 target_arch = sys.argv[1] |
46 link_type = sys.argv[2] | 46 link_type = sys.argv[2] |
47 link_target = sys.argv[3] | 47 link_target = sys.argv[3] |
48 link_args = sys.argv[4:] | 48 link_args = sys.argv[4:] |
49 | 49 |
50 # Check arguments. | 50 # Check arguments. |
51 if target_arch not in ['arm', 'arm64', 'ia32']: | 51 if target_arch not in ['arm', 'arm64', 'ia32', 'x64']: |
52 raise Exception(sys.argv[0] + | 52 raise Exception(sys.argv[0] + |
53 " first argument must be 'arm', 'arm64', or 'ia32'") | 53 " first argument must be 'arm', 'arm64', 'ia32', or 'x64'") |
54 if link_type not in ['executable', 'library', 'shared_library']: | 54 if link_type not in ['executable', 'library', 'shared_library']: |
55 raise Exception(sys.argv[0] + | 55 raise Exception(sys.argv[0] + |
56 " second argument must be 'executable' or 'library'") | 56 " second argument must be 'executable' or 'library'") |
57 if link_target not in ['host', 'target']: | 57 if link_target not in ['host', 'target']: |
58 raise Exception(sys.argv[0] + " third argument must be 'host' or 'target'") | 58 raise Exception(sys.argv[0] + " third argument must be 'host' or 'target'") |
59 | 59 |
60 # TODO(zra): Figure out how to link a shared library with the NDK | 60 # TODO(zra): Figure out how to link a shared library with the NDK |
61 # cross-compilers. For now, we disable it by generating empty files | 61 # cross-compilers. For now, we disable it by generating empty files |
62 # for the results. We disable it here to avoid inspecting the OS type in | 62 # for the results. We disable it here to avoid inspecting the OS type in |
63 # the gyp files. | 63 # the gyp files. |
(...skipping 10 matching lines...) Expand all Loading... |
74 CheckDirExists(android_tools, 'Android tools') | 74 CheckDirExists(android_tools, 'Android tools') |
75 android_ndk_root = os.path.join(android_tools, 'ndk') | 75 android_ndk_root = os.path.join(android_tools, 'ndk') |
76 CheckDirExists(android_ndk_root, 'Android NDK') | 76 CheckDirExists(android_ndk_root, 'Android NDK') |
77 | 77 |
78 # Set up the directory of the Android NDK cross-compiler toolchain. | 78 # Set up the directory of the Android NDK cross-compiler toolchain. |
79 toolchain_arch = 'arm-linux-androideabi-4.9' | 79 toolchain_arch = 'arm-linux-androideabi-4.9' |
80 if target_arch == 'arm64': | 80 if target_arch == 'arm64': |
81 toolchain_arch = 'aarch64-linux-android-4.9' | 81 toolchain_arch = 'aarch64-linux-android-4.9' |
82 if target_arch == 'ia32': | 82 if target_arch == 'ia32': |
83 toolchain_arch = 'x86-4.9' | 83 toolchain_arch = 'x86-4.9' |
| 84 if target_arch == 'x64': |
| 85 toolchain_arch = 'x86_64-4.9' |
84 toolchain_dir = 'linux-x86_64' | 86 toolchain_dir = 'linux-x86_64' |
85 android_toolchain = os.path.join(android_ndk_root, | 87 android_toolchain = os.path.join(android_ndk_root, |
86 'toolchains', toolchain_arch, | 88 'toolchains', toolchain_arch, |
87 'prebuilt', toolchain_dir, 'bin') | 89 'prebuilt', toolchain_dir, 'bin') |
88 CheckDirExists(android_toolchain, 'Android toolchain') | 90 CheckDirExists(android_toolchain, 'Android toolchain') |
89 | 91 |
90 # Set up the path to the linker executable. | 92 # Set up the path to the linker executable. |
91 android_linker = os.path.join(android_toolchain, 'arm-linux-androideabi-g++') | 93 android_linker = os.path.join(android_toolchain, 'arm-linux-androideabi-g++') |
92 if target_arch == 'arm64': | 94 if target_arch == 'arm64': |
93 android_linker = os.path.join( | 95 android_linker = os.path.join( |
94 android_toolchain, 'aarch64-linux-android-c++') | 96 android_toolchain, 'aarch64-linux-android-c++') |
95 if target_arch == 'ia32': | 97 if target_arch == 'ia32': |
96 android_linker = os.path.join(android_toolchain, 'i686-linux-android-g++') | 98 android_linker = os.path.join(android_toolchain, 'i686-linux-android-g++') |
| 99 if target_arch == 'x64': |
| 100 android_linker = os.path.join(android_toolchain, 'x86_64-linux-android-g++') |
97 | 101 |
98 # Grab the path to libgcc.a, which we must explicitly add to the link, | 102 # Grab the path to libgcc.a, which we must explicitly add to the link, |
99 # by invoking the cross-compiler with the -print-libgcc-file-name flag. | 103 # by invoking the cross-compiler with the -print-libgcc-file-name flag. |
100 android_gcc = os.path.join(android_toolchain, 'arm-linux-androideabi-gcc') | 104 android_gcc = os.path.join(android_toolchain, 'arm-linux-androideabi-gcc') |
101 if target_arch == 'arm64': | 105 if target_arch == 'arm64': |
102 android_gcc = os.path.join(android_toolchain, 'aarch64-linux-android-gcc') | 106 android_gcc = os.path.join(android_toolchain, 'aarch64-linux-android-gcc') |
103 if target_arch == 'ia32': | 107 if target_arch == 'ia32': |
104 android_gcc = os.path.join(android_toolchain, 'i686-linux-android-gcc') | 108 android_gcc = os.path.join(android_toolchain, 'i686-linux-android-gcc') |
| 109 if target_arch == 'x64': |
| 110 android_gcc = os.path.join(android_toolchain, 'x86_64-linux-android-gcc') |
105 android_libgcc = subprocess.check_output( | 111 android_libgcc = subprocess.check_output( |
106 [android_gcc, '-print-libgcc-file-name']).strip() | 112 [android_gcc, '-print-libgcc-file-name']).strip() |
107 | 113 |
108 # Set up the path to the system root directory, which is where we'll find the | 114 # Set up the path to the system root directory, which is where we'll find the |
109 # Android specific system includes and libraries. | 115 # Android specific system includes and libraries. |
110 android_ndk_sysroot = os.path.join(android_ndk_root, | 116 android_ndk_sysroot = os.path.join(android_ndk_root, |
111 'platforms', 'android-14', 'arch-arm') | 117 'platforms', 'android-14', 'arch-arm') |
| 118 libdir = 'lib' |
112 if target_arch == 'arm64': | 119 if target_arch == 'arm64': |
113 android_ndk_sysroot = os.path.join(android_ndk_root, | 120 android_ndk_sysroot = os.path.join(android_ndk_root, |
114 'platforms', 'android-21', 'arch-arm64') | 121 'platforms', 'android-21', 'arch-arm64') |
115 if target_arch == 'ia32': | 122 if target_arch == 'ia32': |
116 android_ndk_sysroot = os.path.join(android_ndk_root, | 123 android_ndk_sysroot = os.path.join(android_ndk_root, |
117 'platforms', 'android-14', 'arch-x86') | 124 'platforms', 'android-14', 'arch-x86') |
| 125 if target_arch == 'x64': |
| 126 android_ndk_sysroot = os.path.join(android_ndk_root, |
| 127 'platforms', 'android-21', 'arch-x86_64') |
| 128 libdir = 'lib64' |
118 CheckDirExists(android_ndk_sysroot, 'Android sysroot') | 129 CheckDirExists(android_ndk_sysroot, 'Android sysroot') |
119 android_ndk_lib = os.path.join(android_ndk_sysroot,'usr','lib') | 130 android_ndk_lib = os.path.join(android_ndk_sysroot, 'usr', libdir) |
120 crtend_android = os.path.join(android_ndk_lib, 'crtend_android.o') | 131 crtend_android = os.path.join(android_ndk_lib, 'crtend_android.o') |
121 | 132 |
122 if link_target == 'target': | 133 if link_target == 'target': |
123 # Add and remove libraries as listed in configurations_android.gypi | 134 # Add and remove libraries as listed in configurations_android.gypi |
124 libs_to_rm = ['-lrt', '-lpthread', '-lnss3', '-lnssutil3', '-lsmime3', | 135 libs_to_rm = ['-lrt', '-lpthread', '-lnss3', '-lnssutil3', '-lsmime3', |
125 '-lplds4', '-lplc4', '-lnspr4',] | 136 '-lplds4', '-lplc4', '-lnspr4',] |
126 libs_to_add = ['-lstlport_static', android_libgcc, '-lc', '-ldl', | 137 libs_to_add = ['-lstlport_static', android_libgcc, '-lc', '-ldl', |
127 '-lstdc++', '-lm',] | 138 '-lstdc++', '-lm',] |
128 | 139 |
129 # Add crtend_android to end if we are linking an executable. | 140 # Add crtend_android to end if we are linking an executable. |
130 if link_type == 'executable': | 141 if link_type == 'executable': |
131 libs_to_add.extend(['-llog', '-lz', crtend_android]) | 142 libs_to_add.extend(['-llog', '-lz', crtend_android]) |
132 | 143 |
133 link_args = [i for i in link_args if i not in libs_to_rm] | 144 link_args = [i for i in link_args if i not in libs_to_rm] |
134 link_args.extend(libs_to_add) | 145 link_args.extend(libs_to_add) |
135 | 146 |
136 link_args.insert(0, android_linker) | 147 link_args.insert(0, android_linker) |
137 else: | 148 else: |
138 link_args.extend(['-ldl', '-lrt']) | 149 link_args.extend(['-ldl', '-lrt']) |
139 link_args.insert(0, 'g++') | 150 link_args.insert(0, 'g++') |
140 | 151 |
141 sys.exit(execute(link_args)) | 152 sys.exit(execute(link_args)) |
142 | 153 |
143 if __name__ == '__main__': | 154 if __name__ == '__main__': |
144 main() | 155 main() |
OLD | NEW |