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