1# This Source Code Form is subject to the terms of the Mozilla Public
2# License, v. 2.0. If a copy of the MPL was not distributed with this
3# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5from __future__ import absolute_import, print_function, unicode_literals
6
7from mozbuild.util import EnumString
8from collections import OrderedDict
9
10
11CompilerType = EnumString.subclass(
12    'clang',
13    'clang-cl',
14    'gcc',
15    'msvc',
16)
17
18OS = EnumString.subclass(
19    'Android',
20    'DragonFly',
21    'FreeBSD',
22    'GNU',
23    'iOS',
24    'NetBSD',
25    'OpenBSD',
26    'OSX',
27    'SunOS',
28    'WINNT',
29)
30
31Kernel = EnumString.subclass(
32    'Darwin',
33    'DragonFly',
34    'FreeBSD',
35    'kFreeBSD',
36    'Linux',
37    'NetBSD',
38    'OpenBSD',
39    'SunOS',
40    'WINNT',
41)
42
43CPU_bitness = {
44    'aarch64': 64,
45    'Alpha': 64,
46    'arm': 32,
47    'hppa': 32,
48    'ia64': 64,
49    'mips32': 32,
50    'mips64': 64,
51    'ppc': 32,
52    'ppc64': 64,
53    's390': 32,
54    's390x': 64,
55    'sh4': 32,
56    'sparc': 32,
57    'sparc64': 64,
58    'x86': 32,
59    'x86_64': 64,
60}
61
62CPU = EnumString.subclass(*CPU_bitness.keys())
63
64Endianness = EnumString.subclass(
65    'big',
66    'little',
67)
68
69WindowsBinaryType = EnumString.subclass(
70    'win32',
71    'win64',
72)
73
74# The order of those checks matter
75CPU_preprocessor_checks = OrderedDict((
76    ('x86', '__i386__ || _M_IX86'),
77    ('x86_64', '__x86_64__ || _M_X64'),
78    ('arm', '__arm__ || _M_ARM'),
79    ('aarch64', '__aarch64__'),
80    ('ia64', '__ia64__'),
81    ('s390x', '__s390x__'),
82    ('s390', '__s390__'),
83    ('ppc64', '__powerpc64__'),
84    ('ppc', '__powerpc__'),
85    ('Alpha', '__alpha__'),
86    ('hppa', '__hppa__'),
87    ('sparc64', '__sparc__ && __arch64__'),
88    ('sparc', '__sparc__'),
89    ('mips64', '__mips64'),
90    ('mips32', '__mips__'),
91    ('sh4', '__sh__'),
92))
93
94assert sorted(CPU_preprocessor_checks.keys()) == sorted(CPU.POSSIBLE_VALUES)
95
96kernel_preprocessor_checks = {
97    'Darwin': '__APPLE__',
98    'DragonFly': '__DragonFly__',
99    'FreeBSD': '__FreeBSD__',
100    'kFreeBSD': '__FreeBSD_kernel__',
101    'Linux': '__linux__',
102    'NetBSD': '__NetBSD__',
103    'OpenBSD': '__OpenBSD__',
104    'SunOS': '__sun__',
105    'WINNT': '_WIN32 || __CYGWIN__',
106}
107
108assert sorted(kernel_preprocessor_checks.keys()) == sorted(Kernel.POSSIBLE_VALUES)
109