-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_vscode.py
115 lines (109 loc) · 3.68 KB
/
make_vscode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
################################################################################
# make_vscode.py
# A part of make-fpga - see https://github.com/amb5l/make-fpga
# This script generates makefiles for use with GNU make to
# edit FPGA designs or simulations with Visual Studio Code and V4P.
################################################################################
import sys,os,argparse
from make_fpga import *
# parse arguments
parser = argparse.ArgumentParser(
prog='make_fpga.py',
description='Create makefiles for editing FPGA designs with Visual Studio Code and V4P',
)
parser.add_argument(
'--work',
help='work library (defaults to "work")',
default='work'
)
parser.add_argument(
'--src',
required=True,
nargs='+',
action='append',
help='source(s) (append =LIB to specify library name)'
)
parser.add_argument(
'--top',
action='append',
help='top level design unit(s)'
)
parser.add_argument(
'--aux',
nargs='+',
action='append',
help='auxiliary text file(s)'
)
args=parser.parse_args()
_,d=process_src(args.src,args.work)
args.aux=flatten(args.aux)
# output
print('# makefile generated by make_vscode.py (see https://github.com/amb5l/make-fpga)')
LIB=list(d)
print('# for editing FPGA source code with Visual Studio Code and V4P.')
print('')
print('################################################################################')
print('')
print('# libraries')
print('LIB:='+' '.join(d))
print('')
print('# path(s) to source(s) for each library')
for l in d:
print('SRC.%s:=%s' % (l,var_vals(d[l])))
print('')
print('# top level design unit(s)')
print('TOP:='+' '.join(args.top))
print('')
print('# auxiliary text file(s)')
print('AUX:=%s' % var_vals(args.aux))
print('')
print('################################################################################')
print('')
print('# useful definitions')
print('space:=$(subst x, ,x)')
print('comma:=,')
print('')
print('# generate rules and recipes to create symbolic links to sources')
print('ifeq ($(OS),Windows_NT)')
print('define rr_srclink')
print('$1/$(notdir $2): $2')
print('\tbash -c "mkdir -p $$(dir $$@)"')
print('\tbash -c "cmd.exe //C \\\"mklink $$(shell cygpath -w $$@) $$(shell cygpath -w -a $$<)\\\""')
print('endef')
print('else')
print('define rr_srclink')
print('$1/$(notdir $2): $2')
print('\tmkdir -p $$(dir $$@)')
print('\tln $$< $$@')
print('endef')
print('endif')
print('$(foreach l,$(LIB),$(foreach s,$(SRC.$l),$(eval $(call rr_srclink,$l,$s))))')
print('')
print('# library directory(s) containing symbolic link(s) to source(s)')
print('$(foreach l,$(LIB),$(eval $l: $(addprefix $l/,$(notdir $(SRC.$l)))))')
print('')
print('# generate rules and recipes to create symbolic links to auxiliary text files')
print('ifeq ($(OS),Windows_NT)')
print('define rr_auxlink')
print('$(notdir $1): $1')
print('\tbash -c "cmd.exe //C \\\"mklink $$(shell cygpath -w $$@) $$(shell cygpath -w -a $$<)\\\""')
print('endef')
print('else')
print('define rr_srclink')
print('$(notdir $1): $1')
print('\tln $$< $$@')
print('endef')
print('endif')
print('$(foreach a,$(AUX),$(eval $(call rr_auxlink,$a)))')
print('')
print('# editing session')
print('.PHONY: vscode')
print('vscode: config.v4p $(LIB) $(notdir $(AUX))')
print('\tcode .')
print('')
print('# V4P configuration file')
print('config.v4p: $(LIB)')
print('\techo "[libraries]" > config.v4p')
print('\t$(foreach l,$(LIB),$(foreach s,$(SRC.$l),echo "$l/$(notdir $s)=$l" >> config.v4p;))')
print('\techo "[settings]" >> config.v4p')
print('\techo "V4p.Settings.Basics.TopLevelEntities=$(subst $(space),$(comma),$(TOP))" >> config.v4p')