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
88 if os
.environ
.get('TRAVIS', '') == 'true':
89 # Ignore `ssl.SSLCertVerificationError` on CI.
91 ssl
._create
_default
_https
_context
= ssl
._create
_unverified
_context
94 print("Available commands:")
96 print("- install (add --user to install to user directory)")
101 if "init" in sys
.argv
[1:]:
102 os
.chdir(os
.path
.join(current_path
))
103 for name
in repos
.keys():
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
,
113 if "install" in sys
.argv
[1:]:
114 for name
in repos
.keys():
115 url
, need_recursive
, need_develop
= repos
[name
]
117 print("[installing " + name
+ "]...")
119 os
.chdir(os
.path
.join(current_path
, name
))
120 if "--user" in sys
.argv
[1:]:
121 subprocess
.check_call(
122 "python3 setup.py develop --user",
125 subprocess
.check_call(
126 "python3 setup.py develop",
128 os
.chdir(os
.path
.join(current_path
))
130 if "gcc" in sys
.argv
[1:]:
131 sifive_riscv_download()
133 if "update" in sys
.argv
[1:]:
134 for name
in repos
.keys():
136 print("[updating " + name
+ "]...")
137 os
.chdir(os
.path
.join(current_path
, name
))
138 subprocess
.check_call(
141 os
.chdir(os
.path
.join(current_path
))
143 if "--user" in sys
.argv
[1:]:
144 if ".local/bin" not in os
.environ
.get("PATH", ""):
145 print("Make sure that ~/.local/bin is in your PATH")
146 print("export PATH=$PATH:~/.local/bin")
147 elif "gcc" in sys
.argv
[1:]:
148 print("Make sure that the downloaded RISC-V compiler is in your $PATH.")
149 print("export PATH=$PATH:$(echo $PWD/riscv64-*/bin/)")