1declare_args() {
2  # The target archs LLVM should support. Defaults to the host arch.
3  # Set to a list, e.g. `llvm_targets_to_build = [ "X86", "ARM" ]`,
4  # or to the string "all" to get all known targets.
5  llvm_targets_to_build = "host"
6}
7
8# FIXME: Port the remaining targets.
9llvm_all_targets = [
10  "AArch64",
11  "AMDGPU",
12  "ARM",
13  "AVR",
14  "BPF",
15  "Hexagon",
16  "Lanai",
17  "Mips",
18  "NVPTX",
19  "PowerPC",
20  "RISCV",
21  "Sparc",
22  "SystemZ",
23  "WebAssembly",
24  "X86",
25]
26
27if (llvm_targets_to_build == "host") {
28  if (host_cpu == "arm64") {
29    llvm_targets_to_build = [ "AArch64" ]
30  } else if (host_cpu == "arm") {
31    llvm_targets_to_build = [ "ARM" ]
32  } else if (host_cpu == "ppc" || host_cpu == "ppc64") {
33    llvm_targets_to_build = [ "PowerPC" ]
34  } else if (host_cpu == "x86" || host_cpu == "x64") {
35    llvm_targets_to_build = [ "X86" ]
36  } else {
37    assert(false, "add your host_cpu above")
38  }
39} else if (llvm_targets_to_build == "all") {
40  llvm_targets_to_build = llvm_all_targets
41}
42
43# Validate that llvm_targets_to_build is set to a list of valid targets,
44# and remember which targets are built where needed (for conditionally-built
45# unittest targets).
46llvm_build_AArch64 = false
47llvm_build_ARM = false
48llvm_build_BPF = false
49llvm_build_Mips = false
50llvm_build_PowerPC = false
51llvm_build_WebAssembly = false
52llvm_build_X86 = false
53foreach(target, llvm_targets_to_build) {
54  if (target == "AArch64") {
55    llvm_build_AArch64 = true
56  } else if (target == "ARM") {
57    llvm_build_ARM = true
58  } else if (target == "BPF") {
59    llvm_build_BPF = true
60  } else if (target == "Mips") {
61    llvm_build_Mips = true
62  } else if (target == "PowerPC") {
63    llvm_build_PowerPC = true
64  } else if (target == "WebAssembly") {
65    llvm_build_WebAssembly = true
66  } else if (target == "X86") {
67    llvm_build_X86 = true
68  } else if (target == "AMDGPU" || target == "AVR" || target == "Hexagon" ||
69             target == "Lanai" || target == "NVPTX" || target == "RISCV" ||
70             target == "Sparc" || target == "SystemZ") {
71    # Nothing to do.
72  } else {
73    all_targets_string = ""
74    foreach(target, llvm_all_targets) {
75      all_targets_string += "$0x0a    " + target
76    }
77    assert(false, "Unknown target '$target' in llvm_targets_to_build. " +
78                      "Known targets:" + all_targets_string)
79  }
80}
81
82# FIXME: This should be based off target_cpu once cross compiles work.
83if (host_cpu == "arm64") {
84  native_target = "AArch64"
85} else if (host_cpu == "arm") {
86  native_target = "ARM"
87} else if (host_cpu == "ppc" || host_cpu == "ppc64") {
88  native_target = "PowerPC"
89} else if (host_cpu == "x86" || host_cpu == "x64") {
90  native_target = "X86"
91} else {
92  assert(false, "Unsuppored host_cpu '$host_cpu'.")
93}
94