6 from collections
import OrderedDict
10 current_path
= os
.path
.dirname(os
.path
.realpath(__file__
))
12 # name, (url, recursive clone, develop)
15 ("migen", ("https://github.com/m-labs/", True, True)),
18 ("litex", ("https://github.com/enjoy-digital/", True, True)),
20 # LiteX cores ecosystem
21 ("liteeth", ("https://github.com/enjoy-digital/", False, True)),
22 ("litedram", ("https://github.com/enjoy-digital/", False, True)),
23 ("litepcie", ("https://github.com/enjoy-digital/", False, True)),
24 ("litesata", ("https://github.com/enjoy-digital/", False, True)),
25 ("litesdcard", ("https://github.com/enjoy-digital/", False, True)),
26 ("liteiclink", ("https://github.com/enjoy-digital/", False, True)),
27 ("litevideo", ("https://github.com/enjoy-digital/", False, True)),
28 ("litescope", ("https://github.com/enjoy-digital/", False, True)),
29 ("litejesd204b", ("https://github.com/enjoy-digital/", False, True)),
30 ("litespi", ("https://github.com/litex-hub/", False, True)),
32 # LiteX boards support
33 ("litex-boards", ("https://github.com/litex-hub/", False, True)),
35 repos
= OrderedDict(repos
)
38 def sifive_riscv_download():
39 base_url
= "https://static.dev.sifive.com/dev-tools/"
40 base_file
= "riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-"
43 sys
.platform
.startswith('win') or sys
.platform
.startswith('cygwin'))
45 end_file
= 'w64-mingw32.zip'
46 elif sys
.platform
.startswith('linux'):
47 end_file
= 'linux-ubuntu14.tar.gz'
48 elif sys
.platform
.startswith('darwin'):
49 end_file
= 'apple-darwin.tar.gz'
51 raise NotImplementedError(sys
.platform
)
52 fn
= base_file
+ end_file
54 if not os
.path
.exists(fn
):
56 print("Downloading", url
, "to", fn
)
57 urllib
.request
.urlretrieve(url
, fn
)
59 print("Using existing file", fn
)
61 print("Extracting", fn
)
62 if fn
.endswith(".tar.gz"):
64 with tarfile
.open(fn
) as t
:
66 elif fn
.endswith(".zip"):
68 with zipfile
.open(fn
) as z
:
71 if "--user" in sys
.argv
[1:] and not is_windows
:
72 print("Linking compiler into ~/.local/bin")
73 local_bin_dir
= os
.path
.join(
74 base_file
+ end_file
.split('.', 1)[0], "bin")
75 assert os
.path
.exists(local_bin_dir
), local_bin_dir
76 user_bin_dir
= os
.path
.abspath(os
.path
.expanduser("~/.local/bin"))
77 if not os
.path
.exists(user_bin_dir
):
78 os
.makedirs(user_bin_dir
)
79 for f
in os
.listdir(local_bin_dir
):
80 src
= os
.path
.abspath(os
.path
.join(local_bin_dir
, f
))
81 dst
= os
.path
.join(user_bin_dir
, f
)
82 assert os
.path
.exists(src
), src
83 if os
.path
.exists(dst
):
85 assert not os
.path
.exists(dst
), dst
90 print("Available commands:")
92 print("- install (add --user to install to user directory)")
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
,
109 if "install" in sys
.argv
[1:]:
110 for name
in repos
.keys():
111 url
, need_recursive
, need_develop
= repos
[name
]
113 print("[installing " + name
+ "]...")
115 os
.chdir(os
.path
.join(current_path
, name
))
116 if "--user" in sys
.argv
[1:]:
117 subprocess
.check_call(
118 "python3 setup.py develop --user",
121 subprocess
.check_call(
122 "python3 setup.py develop",
124 os
.chdir(os
.path
.join(current_path
))
126 if "gcc" in sys
.argv
[1:]:
127 sifive_riscv_download()
129 if "update" in sys
.argv
[1:]:
130 for name
in repos
.keys():
132 print("[updating " + name
+ "]...")
133 os
.chdir(os
.path
.join(current_path
, name
))
134 subprocess
.check_call(
137 os
.chdir(os
.path
.join(current_path
))
139 if "--user" in sys
.argv
[1:]:
140 if ".local/bin" not in os
.environ
.get("PATH", ""):
141 print("Make sure that ~/.local/bin is in your PATH")
142 elif "gcc" in sys
.argv
[1:]:
143 print("Make sure that the download RISC-V compiler is in your $PATH.")