1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 @depends(target.os, '--help')
8 def arm_option_defaults(os, _):
15 arch = thumb = fpu = float_abi = 'toolchain-default'
24 # Note: '{...|}' in the help of all options with a non-constant default to
25 # make the lint happy. The first arm is always going to be used, because a
26 # default is always returned. The lint is fooled by this file being
27 # conditional. If it weren't conditional, the lint wouldn't ask for '{|}' to
29 js_option('--with-arch', nargs=1,
30 default=arm_option_defaults.arch,
31 help='{Use specific CPU features (-march=type). Resets thumb, fpu, '
32 'float-abi, etc. defaults when set|}')
35 @depends('--with-arch')
36 def arch_option(value):
38 if value[0] != 'toolchain-default':
39 return ['-march={}'.format(value[0])]
43 js_option('--with-thumb', choices=('yes', 'no', 'toolchain-default'),
44 default=arm_option_defaults.thumb,
45 nargs='?', help='{Use Thumb instruction set (-mthumb)|}')
48 def normalize_arm_option(value):
53 elif value[0] == 'no':
60 @depends('--with-thumb')
61 def thumb_option(value):
62 value = normalize_arm_option(value)
70 js_option('--with-thumb-interwork', choices=('yes', 'no', 'toolchain-default'),
71 default='toolchain-default',
72 nargs='?', help='Use Thumb/ARM instuctions interwork (-mthumb-interwork)')
75 @depends('--with-thumb-interwork')
76 def thumb_interwork_option(value):
77 value = normalize_arm_option(value)
79 return ['-mthumb-interwork']
81 return ['-mno-thumb-interwork']
85 js_option('--with-fpu', nargs=1,
86 default=arm_option_defaults.fpu,
87 help='{Use specific FPU type (-mfpu=type)|}')
90 @depends('--with-fpu')
91 def fpu_option(value):
93 if value[0] != 'toolchain-default':
94 return ['-mfpu={}'.format(value[0])]
98 js_option('--with-float-abi', nargs=1,
99 default=arm_option_defaults.float_abi,
100 help='{Use specific arm float ABI (-mfloat-abi=type)|}')
103 @depends('--with-float-abi')
104 def float_abi_option(value):
106 if value[0] != 'toolchain-default':
107 return ['-mfloat-abi={}'.format(value[0])]
111 js_option('--with-soft-float', choices=('yes', 'no', 'toolchain-default'),
112 default='toolchain-default',
113 nargs='?', help='Use soft float library (-msoft-float)')
116 @depends('--with-soft-float')
117 def soft_float_option(value):
118 value = normalize_arm_option(value)
120 return ['-msoft-float']
122 return ['-mno-soft-float']
126 check_and_add_gcc_flag('-mno-unaligned-access',
127 when=depends(target.os)(lambda os: os == 'Android'))
130 @depends(arch_option, thumb_option, thumb_interwork_option, fpu_option,
131 float_abi_option, soft_float_option)
132 def all_flags(arch, thumb, interwork, fpu, float_abi, soft_float):
133 return arch + thumb + interwork + fpu + float_abi + soft_float
136 add_old_configure_assignment('_ARM_FLAGS', all_flags)
137 add_old_configure_assignment('_THUMB_FLAGS', thumb_option)
140 @depends(c_compiler, all_flags)
141 @checking('ARM version support in compiler', lambda x: x.arm_arch)
142 @imports(_from='textwrap', _import='dedent')
143 def arm_target(compiler, all_flags):
144 # We're going to preprocess the following source to figure out some details
145 # about the arm target options we have enabled.
153 // Confusingly, the __SOFTFP__ preprocessor variable indicates the
154 // "softfloat" ABI, not the "softfp" ABI.
162 // There is more subtlety to it than this preprocessor test, but MOZ_FPU doesn't
163 // need to be too fine-grained.
166 #elif __ARM_VFPV2__ || __ARM_FP == 12
170 #elif __ARM_VFPV4__ || __ARM_FP == 14
176 result = try_invoke_compiler(
177 compiler.wrapper + [compiler.compiler] + compiler.flags,
182 # Metadata emitted by preprocessors such as GCC with LANG=ja_JP.utf-8 may
183 # have non-ASCII characters. Treat the output as bytearray.
184 data = {'fpu': None} # fpu may not get a value from the preprocessor.
185 for line in result.splitlines():
186 if line.startswith(b'%'):
187 k, _, v = line.partition(' ')
188 k = k.lstrip('%').lower()
196 log.debug('%s = %s', k, data[k])
198 return namespace(**data)
201 @depends(arm_target.arm_arch, when=depends(target.os)(lambda os: os == 'Android'))
204 die('Android/armv6 and earlier are not supported')
207 set_config('MOZ_THUMB2', True, when=arm_target.thumb2)
208 set_define('MOZ_THUMB2', True, when=arm_target.thumb2)
209 add_old_configure_assignment('MOZ_THUMB2', True, when=arm_target.thumb2)
212 have_arm_simd = c_compiler.try_compile(body='asm("uqadd8 r1, r1, r2");',
213 check_msg='for ARM SIMD support in compiler')
215 set_config('HAVE_ARM_SIMD', have_arm_simd)
216 set_define('HAVE_ARM_SIMD', have_arm_simd)
218 have_arm_neon = c_compiler.try_compile(body='asm(".fpu neon\\n vadd.i8 d0, d0, d0");',
219 check_msg='for ARM NEON support in compiler')
221 set_config('HAVE_ARM_NEON', have_arm_neon)
222 set_define('HAVE_ARM_NEON', have_arm_neon)
225 # We don't need to build NEON support if we're targetting a non-NEON device.
226 # This matches media/webrtc/trunk/webrtc/build/common.gypi.
227 @depends(arm_target.arm_arch, when=have_arm_neon)
228 def build_arm_neon(arm_arch):
232 set_config('BUILD_ARM_NEON', build_arm_neon)
233 set_define('BUILD_ARM_NEON', build_arm_neon)
236 set_config('ARM_ARCH', depends(arm_target.arm_arch)(lambda x: str(x)))
237 add_old_configure_assignment('ARM_ARCH', depends(arm_target.arm_arch)(lambda x: str(x)))
238 set_config('MOZ_FPU', arm_target.fpu)
241 @depends(arm_target.float_abi)
242 def neon_flags(float_abi):
243 # Building with -mfpu=neon requires either the "softfp" or the
244 # "hardfp" ABI. Depending on the compiler's default target, and the
245 # CFLAGS, the default ABI might be neither, in which case it is the
247 # The "softfloat" ABI is binary-compatible with the "softfp" ABI, so
248 # we can safely mix code built with both ABIs. So, if we detect
249 # that compiling uses the "softfloat" ABI, force the use of the
250 # "softfp" ABI instead.
251 flags = ['-mfpu=neon']
252 if float_abi == 'soft':
253 flags.append('-mfloat-abi=softfp')
257 set_config('NEON_FLAGS', neon_flags)