Fixed quotes in `litex_setup.py`
[litex.git] / litex_setup.py
1 #!/usr/bin/env python3
2
3 import os
4 import sys
5 import subprocess
6 import shutil
7 from collections import OrderedDict
8
9 import urllib.request
10
11 current_path = os.path.dirname(os.path.realpath(__file__))
12
13 # Repositories -------------------------------------------------------------------------------------
14
15 # name, (url, recursive clone, develop)
16 repos = [
17 # HDL
18 ("migen", ("https://github.com/m-labs/", True, True)),
19
20 # LiteX SoC builder
21 ('litex-data-software-compiler_rt', ("https://github.com/litex-hub/", False, True))
22 ("litex", ("https://github.com/enjoy-digital/", False, True)),
23
24 # LiteX cores ecosystem
25 ("liteeth", ("https://github.com/enjoy-digital/", False, True)),
26 ("litedram", ("https://github.com/enjoy-digital/", False, True)),
27 ("litepcie", ("https://github.com/enjoy-digital/", False, True)),
28 ("litesata", ("https://github.com/enjoy-digital/", False, True)),
29 ("litesdcard", ("https://github.com/enjoy-digital/", False, True)),
30 ("liteiclink", ("https://github.com/enjoy-digital/", False, True)),
31 ("litevideo", ("https://github.com/enjoy-digital/", False, True)),
32 ("litescope", ("https://github.com/enjoy-digital/", False, True)),
33 ("litejesd204b", ("https://github.com/enjoy-digital/", False, True)),
34 ("litespi", ("https://github.com/litex-hub/", False, True)),
35
36 # LiteX boards support
37 ("litex-boards", ("https://github.com/litex-hub/", False, True)),
38
39 # Optional LiteX data
40 ("litex-data-cpu-blackparrot", ("https://github.com/litex-hub/", False, True))
41 ("litex-data-cpu-mor1kx", ("https://github.com/litex-hub/", False, True))
42 ("litex-data-cpu-lm32", ("https://github.com/litex-hub/", False, True))
43 ("litex-data-cpu-microwatt", ("https://github.com/litex-hub/", False, True))
44 ("litex-data-cpu-picorv32", ("https://github.com/litex-hub/", False, True))
45 ("litex-data-cpu-rocket", ("https://github.com/litex-hub/", False, True))
46 ("litex-data-misc-tapcfg", ("https://github.com/litex-hub/", False, True))
47 ]
48 repos = OrderedDict(repos)
49
50 # RISC-V toolchain download ------------------------------------------------------------------------
51
52 def sifive_riscv_download():
53 base_url = "https://static.dev.sifive.com/dev-tools/"
54 base_file = "riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-"
55
56 # Windows
57 if (sys.platform.startswith("win") or sys.platform.startswith("cygwin")):
58 end_file = "w64-mingw32.zip"
59 # Linux
60 elif sys.platform.startswith("linux"):
61 end_file = "linux-ubuntu14.tar.gz"
62 # Mac OS
63 elif sys.platform.startswith("darwin"):
64 end_file = "apple-darwin.tar.gz"
65 else:
66 raise NotImplementedError(sys.platform)
67 fn = base_file + end_file
68
69 if not os.path.exists(fn):
70 url = base_url + fn
71 print("Downloading", url, "to", fn)
72 urllib.request.urlretrieve(url, fn)
73 else:
74 print("Using existing file", fn)
75
76 print("Extracting", fn)
77 shutil.unpack_archive(fn)
78
79 # Setup --------------------------------------------------------------------------------------------
80
81 if os.environ.get("TRAVIS", "") == "true":
82 # Ignore `ssl.SSLCertVerificationError` on CI.
83 import ssl
84 ssl._create_default_https_context = ssl._create_unverified_context
85
86 if len(sys.argv) < 2:
87 print("Available commands:")
88 print("- init")
89 print("- install (add --user to install to user directory)")
90 print("- update")
91 print("- gcc")
92 exit()
93
94 # Repositories cloning
95 if "init" in sys.argv[1:]:
96 os.chdir(os.path.join(current_path))
97 for name in repos.keys():
98 url, need_recursive, need_develop = repos[name]
99 # clone repo (recursive if needed)
100 print("[cloning " + name + "]...")
101 full_url = url + name
102 opts = "--recursive" if need_recursive else ""
103 subprocess.check_call(
104 "git clone " + full_url + " " + opts,
105 shell=True)
106
107 # Repositories installation
108 if "install" in sys.argv[1:]:
109 for name in repos.keys():
110 url, need_recursive, need_develop = repos[name]
111 # develop if needed
112 print("[installing " + name + "]...")
113 if need_develop:
114 os.chdir(os.path.join(current_path, name))
115 if "--user" in sys.argv[1:]:
116 subprocess.check_call(
117 "python3 setup.py develop --user",
118 shell=True)
119 else:
120 subprocess.check_call(
121 "python3 setup.py develop",
122 shell=True)
123 os.chdir(os.path.join(current_path))
124
125 if "--user" in sys.argv[1:]:
126 if ".local/bin" not in os.environ.get("PATH", ""):
127 print("Make sure that ~/.local/bin is in your PATH")
128 print("export PATH=$PATH:~/.local/bin")
129
130 # Repositories update
131 if "update" in sys.argv[1:]:
132 for name in repos.keys():
133 # update
134 print("[updating " + name + "]...")
135 os.chdir(os.path.join(current_path, name))
136 subprocess.check_call(
137 "git pull",
138 shell=True)
139 os.chdir(os.path.join(current_path))
140
141 # RISC-V GCC installation
142 if "gcc" in sys.argv[1:]:
143 sifive_riscv_download()
144 if "riscv64" not in os.environ.get("PATH", ""):
145 print("Make sure that the downloaded RISC-V compiler is in your $PATH.")
146 print("export PATH=$PATH:$(echo $PWD/riscv64-*/bin/)")