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