Skip to content

Commit 301e75b

Browse files
committed
Merge pull request cvra#18 from antoinealb/issue-17-patch-makefile
Fix issue cvra#17 (Create a script to patch Altera's Makefile).
2 parents 6778ec9 + 4d7deb6 commit 301e75b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Diff for: tools/patch_makefile.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Patches a Makefile generated by Altera's NIOS-II SBT to comply with the
4+
CVRA build process.
5+
"""
6+
import argparse, os
7+
8+
def main():
9+
"""
10+
Program entry point. It is good practice to wrap all the code in a function
11+
to avoid exporting globals.
12+
"""
13+
parser = argparse.ArgumentParser(
14+
description="""Patch an Altera-generated Makefile to
15+
setup the CVRA dev environment. It will output the patched
16+
Makefile to stdout.""")
17+
parser.add_argument("makefile", action="store",
18+
help="Path to the original Makefile.")
19+
parser.add_argument("source_dir", action="store",
20+
help="Path to the modules checkout directory.")
21+
args = parser.parse_args()
22+
23+
modules_dir = os.path.join(args.source_dir, "modules")
24+
25+
dir_list = [os.path.join(args.source_dir, "include/")]
26+
for directory in os.listdir(modules_dir):
27+
dir_list.append(os.path.join(modules_dir, directory))
28+
29+
modules_dir = os.path.join(modules_dir, "math")
30+
for directory in os.listdir(modules_dir):
31+
dir_list.append(os.path.join(modules_dir, directory))
32+
33+
with open(args.makefile) as makefile:
34+
for line in makefile:
35+
print(line, end="")
36+
if "ALT_INCLUDE_DIRS :=" in line:
37+
for i in dir_list:
38+
print("ALT_INCLUDE_DIRS += {0}\r\n".format(i))
39+
if "ALT_CFLAGS :=" in line:
40+
print("ALT_CFLAGS += -DCOMPILE_ON_ROBOT")
41+
42+
43+
if __name__ == "__main__":
44+
main()

0 commit comments

Comments
 (0)