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