Remove symlinking step.
[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.dirname(os.path.realpath(__file__))
12
13 # name, (url, recursive clone, develop)
14 repos = [
15 # HDL
16 ("migen", ("https://github.com/m-labs/", True, True)),
17
18 # LiteX SoC builder
19 ("litex", ("https://github.com/enjoy-digital/", True, True)),
20
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)),
32
33 # LiteX boards support
34 ("litex-boards", ("https://github.com/litex-hub/", False, True)),
35 ]
36 repos = OrderedDict(repos)
37
38
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-"
42
43 is_windows = (
44 sys.platform.startswith('win') or sys.platform.startswith('cygwin'))
45 if is_windows:
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'
51 else:
52 raise NotImplementedError(sys.platform)
53 fn = base_file + end_file
54
55 if not os.path.exists(fn):
56 url = base_url+fn
57 print("Downloading", url, "to", fn)
58 urllib.request.urlretrieve(url, fn)
59 else:
60 print("Using existing file", fn)
61
62 print("Extracting", fn)
63 shutil.unpack_archive(fn)
64
65 if os.environ.get('TRAVIS', '') == 'true':
66 # Ignore `ssl.SSLCertVerificationError` on CI.
67 import ssl
68 ssl._create_default_https_context = ssl._create_unverified_context
69
70 if len(sys.argv) < 2:
71 print("Available commands:")
72 print("- init")
73 print("- install (add --user to install to user directory)")
74 print("- update")
75 print("- gcc")
76 exit()
77
78 if "init" in sys.argv[1:]:
79 os.chdir(os.path.join(current_path))
80 for name in repos.keys():
81 url, need_recursive, need_develop = repos[name]
82 # clone repo (recursive if needed)
83 print("[cloning " + name + "]...")
84 full_url = url + name
85 opts = "--recursive" if need_recursive else ""
86 subprocess.check_call(
87 "git clone " + full_url + " " + opts,
88 shell=True)
89
90 if "install" in sys.argv[1:]:
91 for name in repos.keys():
92 url, need_recursive, need_develop = repos[name]
93 # develop if needed
94 print("[installing " + name + "]...")
95 if need_develop:
96 os.chdir(os.path.join(current_path, name))
97 if "--user" in sys.argv[1:]:
98 subprocess.check_call(
99 "python3 setup.py develop --user",
100 shell=True)
101 else:
102 subprocess.check_call(
103 "python3 setup.py develop",
104 shell=True)
105 os.chdir(os.path.join(current_path))
106
107 if "gcc" in sys.argv[1:]:
108 sifive_riscv_download()
109
110 if "update" in sys.argv[1:]:
111 for name in repos.keys():
112 # update
113 print("[updating " + name + "]...")
114 os.chdir(os.path.join(current_path, name))
115 subprocess.check_call(
116 "git pull",
117 shell=True)
118 os.chdir(os.path.join(current_path))
119
120 if "--user" in sys.argv[1:]:
121 if ".local/bin" not in os.environ.get("PATH", ""):
122 print("Make sure that ~/.local/bin is in your PATH")
123 print("export PATH=$PATH:~/.local/bin")
124 if "gcc" in sys.argv[1:] and 'riscv64' not in os.environ.get("PATH", ""):
125 print("Make sure that the downloaded RISC-V compiler is in your $PATH.")
126 print("export PATH=$PATH:$(echo $PWD/riscv64-*/bin/)")