7 from collections
import OrderedDict
11 current_path
= os
.path
.dirname(os
.path
.realpath(__file__
))
13 # name, (url, recursive clone, develop)
16 ("migen", ("https://github.com/m-labs/", True, True)),
19 ("litex", ("https://github.com/enjoy-digital/", True, True)),
21 # LiteX cores ecosystem
22 ("liteeth", ("https://github.com/enjoy-digital/", False, True)),
23 ("litedram", ("https://github.com/enjoy-digital/", False, True)),
24 ("litepcie", ("https://github.com/enjoy-digital/", False, True)),
25 ("litesata", ("https://github.com/enjoy-digital/", False, True)),
26 ("litesdcard", ("https://github.com/enjoy-digital/", False, True)),
27 ("liteiclink", ("https://github.com/enjoy-digital/", False, True)),
28 ("litevideo", ("https://github.com/enjoy-digital/", False, True)),
29 ("litescope", ("https://github.com/enjoy-digital/", False, True)),
30 ("litejesd204b", ("https://github.com/enjoy-digital/", False, True)),
31 ("litespi", ("https://github.com/litex-hub/", False, True)),
33 # LiteX boards support
34 ("litex-boards", ("https://github.com/litex-hub/", False, True)),
36 repos
= OrderedDict(repos
)
39 def sifive_riscv_download():
40 base_url
= "https://static.dev.sifive.com/dev-tools/"
41 base_file
= "riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-"
44 sys
.platform
.startswith('win') or sys
.platform
.startswith('cygwin'))
46 end_file
= 'w64-mingw32.zip'
47 elif sys
.platform
.startswith('linux'):
48 end_file
= 'linux-ubuntu14.tar.gz'
49 elif sys
.platform
.startswith('darwin'):
50 end_file
= 'apple-darwin.tar.gz'
52 raise NotImplementedError(sys
.platform
)
53 fn
= base_file
+ end_file
55 if not os
.path
.exists(fn
):
57 print("Downloading", url
, "to", fn
)
58 urllib
.request
.urlretrieve(url
, fn
)
60 print("Using existing file", fn
)
62 print("Extracting", fn
)
63 shutil
.unpack_archive(fn
)
65 if "--user" in sys
.argv
[1:] and not is_windows
:
66 print("Linking compiler into ~/.local/bin")
67 local_bin_dir
= os
.path
.join(
68 base_file
+ end_file
.split('.', 1)[0], "bin")
69 assert os
.path
.exists(local_bin_dir
), local_bin_dir
70 user_bin_dir
= os
.path
.abspath(os
.path
.expanduser("~/.local/bin"))
71 if not os
.path
.exists(user_bin_dir
):
72 os
.makedirs(user_bin_dir
)
73 for f
in os
.listdir(local_bin_dir
):
74 src
= os
.path
.abspath(os
.path
.join(local_bin_dir
, f
))
75 dst
= os
.path
.join(user_bin_dir
, f
)
76 assert os
.path
.exists(src
), src
77 if os
.path
.exists(dst
):
79 assert not os
.path
.exists(dst
), dst
82 if os
.environ
.get('TRAVIS', '') == 'true':
83 # Ignore `ssl.SSLCertVerificationError` on CI.
85 ssl
._create
_default
_https
_context
= ssl
._create
_unverified
_context
88 print("Available commands:")
90 print("- install (add --user to install to user directory)")
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
,
107 if "install" in sys
.argv
[1:]:
108 for name
in repos
.keys():
109 url
, need_recursive
, need_develop
= repos
[name
]
111 print("[installing " + name
+ "]...")
113 os
.chdir(os
.path
.join(current_path
, name
))
114 if "--user" in sys
.argv
[1:]:
115 subprocess
.check_call(
116 "python3 setup.py develop --user",
119 subprocess
.check_call(
120 "python3 setup.py develop",
122 os
.chdir(os
.path
.join(current_path
))
124 if "gcc" in sys
.argv
[1:]:
125 sifive_riscv_download()
127 if "update" in sys
.argv
[1:]:
128 for name
in repos
.keys():
130 print("[updating " + name
+ "]...")
131 os
.chdir(os
.path
.join(current_path
, name
))
132 subprocess
.check_call(
135 os
.chdir(os
.path
.join(current_path
))
137 if "--user" in sys
.argv
[1:]:
138 if ".local/bin" not in os
.environ
.get("PATH", ""):
139 print("Make sure that ~/.local/bin is in your PATH")
140 print("export PATH=$PATH:~/.local/bin")
141 elif "gcc" in sys
.argv
[1:]:
142 print("Make sure that the downloaded RISC-V compiler is in your $PATH.")
143 print("export PATH=$PATH:$(echo $PWD/riscv64-*/bin/)")