OpenCores
URL https://opencores.org/ocsvn/forth-cpu/forth-cpu/trunk

Subversion Repositories forth-cpu

[/] [forth-cpu/] [trunk/] [makefile] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 howe.r.j.8
#
2
# Makefile to simulate and synthesize VHDL designs
3
#
4
# @Author      Marc Eberhard/Richard Howe
5
# @Copyright   Copyright 2013 Marc Eberhard, 2016 Richard Howe
6
# @License     LGPL
7
#
8
# This makefile can build the toolchain, simulators, and the bit
9
# file for the FPGA. Type "make help" at the command line for a
10
# list of options
11
#
12
 
13
NETLIST=top
14
#TIME=time -p
15
TIME=
16
 
17
OS_FLAGS =
18
# From: https://stackoverflow.com/questions/714100/os-detecting-makefile
19
ifeq ($(OS),Windows_NT)
20
GUI_LDFLAGS = -lfreeglut -lopengl32 -lm
21
DF=
22
EXE=.exe
23
 
24
.PHONY: h2 gui text block
25
 
26
h2:     h2.exe
27
gui:    gui.exe
28
text:   text.exe
29
block:  block.exe
30
 
31
else # assume unixen
32
GUI_LDFLAGS = -lglut -lGL -lm
33
DF=./
34
EXE=
35
endif
36
 
37
.PHONY: simulation viewer synthesis bitfile upload clean run gui-run
38
 
39
## Remember to update the synthesis section as well
40
SOURCES = \
41
        util.vhd \
42
        timer.vhd \
43
        uart.vhd \
44
        kbd.vhd \
45
        vga.vhd \
46
        h2.vhd \
47
        ram.vhd \
48
        core.vhd \
49
        led.vhd
50
 
51
OBJECTS = ${SOURCES:.vhd=.o}
52
 
53
all:
54
        @echo ""
55
        @echo "Simulation:"
56
        @echo ""
57
        @echo "make simulation     - simulate VHDL design"
58
        @echo "make viewer         - start waveform viewer for simulation results"
59
        @echo "make documentation  - build the PDF and HTML documentation"
60
        @echo "make h2${EXE}             - build C based CLI emulator for the VHDL SoC"
61
        @echo "make gui${EXE}            - build C based GUI emulator for the Nexys3 board"
62
        @echo "make run            - run the C CLI emulator on h2.fth"
63
        @echo "make gui-run        - run the GUI emulator on h2.hex"
64
        @echo ""
65
        @echo "Synthesis:"
66
        @echo ""
67
        @echo "make synthesis      - synthesize design"
68
        @echo "make implementation - implement design"
69
        @echo "make bitfile        - generate bitfile"
70
        @echo ""
71
        @echo "Upload:"
72
        @echo ""
73
        @echo "make upload         - upload design to FPGA"
74
        @echo ""
75
        @echo "Cleanup:"
76
        @echo ""
77
        @echo "make clean          - delete temporary files and cleanup directory"
78
        @echo ""
79
 
80
## Documentation ===========================================================
81
 
82
documentation: readme.pdf readme.htm
83
 
84
%.pdf: %.md
85
        pandoc -V geometry:margin=0.5in --toc $< -o $@
86
 
87
%.htm: %.md
88
        pandoc --toc --self-contained $^ -o $@
89
 
90
## Assembler ===============================================================
91
 
92
%.hex: %.fth h2${EXE}
93
        ${DF}h2 -S h2.sym -a $< > $@
94
 
95
## Virtual Machine and UART communications =================================
96
 
97
CFLAGS=-Wall -Wextra -O2 -g
98
 
99
h2${EXE}: h2.c h2.h
100
        ${CC} ${CFLAGS} -std=c99 $< -o $@
101
 
102
disassemble: h2${EXE} h2.fth
103
        ${DF}h2 -S h2.sym -a h2.fth > h2.hex
104
        ${DF}h2 -L h2.sym h2.hex | awk '{printf "%04x %s\n", NR-1, $$0;}' | less -
105
 
106
block${EXE}: block.c
107
        ${CC} ${CFLAGS} -std=c99 $< -o $@
108
 
109
h2.sym: h2.hex
110
 
111
nvram.blk: nvram.txt h2.sym block${EXE}
112
        ${DF}block${EXE} < nvram.txt >  $@
113
        ${DF}block${EXE} < h2.sym    >> $@
114
 
115
# %.blk: %.txt block${EXE}
116
#       ${DF}block${EXE} < $< > $@
117
 
118
run: h2${EXE} h2.fth nvram.blk
119
        ${DF}h2 -H -R h2.fth
120
 
121
h2nomain.o: h2.c h2.h
122
        ${CC} ${CFLAGS} -std=c99 -DNO_MAIN  $< -c -o $@
123
 
124
gui.o: gui.c h2.h
125
        ${CC} ${CFLAGS} -std=gnu99  $< -c -o $@
126
 
127
gui${EXE}: h2nomain.o gui.o
128
        ${CC} ${CFLAGS} $^ ${GUI_LDFLAGS} -o $@
129
 
130
gui-run: gui${EXE} h2.hex nvram.blk text.hex
131
        ${DF}$< h2.hex
132
 
133
text${EXE}: text.c
134
        ${CC} ${CFLAGS} -std=c99 $< -o $@
135
 
136
text.hex: text${EXE}
137
        ${DF}$< -g > $@
138
 
139
## Simulation ==============================================================
140
 
141
%.o: %.vhd
142
        ghdl -a $<
143
 
144
ram.o: util.o
145
led.o: util.o led.vhd
146
kbd.o: util.o kbd.vhd
147
vga.o: util.o vga.vhd text.hex font.bin
148
core.o: util.o h2.o core.vhd h2.hex
149
uart.o: util.o uart.vhd
150
top.o: util.o timer.o core.o uart.o vga.o kbd.o led.o ram.o top.vhd
151
tb.o: top.o util.o tb.vhd
152
 
153
tb: ${OBJECTS} tb.o
154
        ghdl -e tb
155
 
156
%.ghw: % %.cfg
157
        ghdl -r $< --wave=$<.ghw
158
 
159
simulation: tb.ghw h2${EXE}
160
 
161
## Simulation ==============================================================
162
 
163
 
164
# gtkwave -S signals -f tb.ghw &> /dev/null&
165
 
166
ifeq ($(OS),Windows_NT)
167
viewer: simulation
168
        gtkwave -S signals -f tb.ghw
169
else
170
viewer: simulation
171
        gtkwave -S signals -f tb.ghw &> /dev/null&
172
endif
173
 
174
USB?=/dev/ttyUSB0
175
 
176
talk:
177
        picocom --omap delbs -e b -b 115200 ${USB}
178
 
179
bitfile: design.bit
180
 
181
reports:
182
        @[ -d reports    ]    || mkdir reports
183
tmp:
184
        @[ -d tmp        ]    || mkdir tmp
185
tmp/_xmsgs:
186
        @[ -d tmp/_xmsgs ]    || mkdir tmp/_xmsgs
187
 
188
tmp/top.prj: tmp
189
        @rm -f tmp/top.prj
190
        @( \
191
            for f in $(SOURCES); do \
192
                echo "vhdl work \"$$f\""; \
193
            done; \
194
            echo "vhdl work \"top.vhd\"" \
195
        ) > tmp/top.prj
196
 
197
tmp/top.lso: tmp
198
        @echo "work" > tmp/top.lso
199
 
200
tmp/top.xst: tmp tmp/_xmsgs tmp/top.lso tmp/top.lso
201
        @( \
202
            echo "set -tmpdir \"tmp\""; \
203
            echo "set -xsthdpdir \"tmp\""; \
204
            echo "run"; \
205
            echo "-lso tmp/top.lso"; \
206
            echo "-ifn tmp/top.prj"; \
207
            echo "-ofn top"; \
208
            echo "-p xc6slx16-csg324-3"; \
209
            echo "-top top"; \
210
            echo "-opt_mode speed"; \
211
            echo "-opt_level 2" \
212
        ) > tmp/top.xst
213
 
214
synthesis: h2.hex text.hex reports tmp tmp/_xmsgs tmp/top.prj tmp/top.xst
215
        @echo "Synthesis running..."
216
        @${TIME} xst -intstyle silent -ifn tmp/top.xst -ofn reports/xst.log
217
        @mv _xmsgs/* tmp/_xmsgs
218
        @rmdir _xmsgs
219
        @mv top_xst.xrpt tmp
220
        @grep "ERROR\|WARNING" reports/xst.log | \
221
         grep -v "WARNING.*has a constant value.*This FF/Latch will be trimmed during the optimization process." | \
222
         cat
223
 
224
implementation: reports tmp
225
        @echo "Implementation running..."
226
 
227
        @[ -d tmp/xlnx_auto_0_xdb ] || mkdir tmp/xlnx_auto_0_xdb
228
 
229
        @${TIME} ngdbuild -intstyle silent -quiet -dd tmp -uc top.ucf -p xc6slx16-csg324-3 top.ngc top.ngd
230
        @mv top.bld reports/ngdbuild.log
231
        @mv _xmsgs/* tmp/_xmsgs
232
        @rmdir _xmsgs
233
        @mv xlnx_auto_0_xdb/* tmp
234
        @rmdir xlnx_auto_0_xdb
235
        @mv top_ngdbuild.xrpt tmp
236
 
237
        @${TIME} map -intstyle silent -detail -p xc6slx16-csg324-3 -pr b -c 100 -w -o top_map.ncd top.ngd top.pcf
238
        @mv top_map.mrp reports/map.log
239
        @mv _xmsgs/* tmp/_xmsgs
240
        @rmdir _xmsgs
241
        @mv top_usage.xml top_summary.xml top_map.map top_map.xrpt tmp
242
 
243
        @${TIME} par -intstyle silent -w -ol std top_map.ncd top.ncd top.pcf
244
        @mv top.par reports/par.log
245
        @mv top_pad.txt reports/par_pad.txt
246
        @mv _xmsgs/* tmp/_xmsgs
247
        @rmdir _xmsgs
248
        @mv par_usage_statistics.html top.ptwx top.pad top_pad.csv top.unroutes top.xpi top_par.xrpt tmp
249
 
250
        @#trce -intstyle silent -v 3 -s 3 -n 3 -fastpaths -xml top.twx top.ncd -o top.twr top.pcf -ucf top.ucf
251
        @#mv top.twr reports/trce.log
252
        @#mv _xmsgs/* tmp/_xmsgs
253
        @#rmdir _xmsgs
254
        @#mv top.twx tmp
255
 
256
        @#netgen -intstyle silent -ofmt vhdl -sim -w top.ngc top_xsim.vhd
257
        @#netgen -intstyle silent -ofmt vhdl -sim -w -pcf top.pcf top.ncd top_tsim.vhd
258
        @#mv _xmsgs/* tmp/_xmsgs
259
        @#rmdir _xmsgs
260
        @#mv top_xsim.nlf top_tsim.nlf tmp
261
 
262
 
263
design.bit: reports tmp/_xmsgs
264
        @echo "Generate bitfile running..."
265
        @touch webtalk.log
266
        @${TIME} bitgen -intstyle silent -w top.ncd
267
        @mv top.bit design.bit
268
        @mv top.bgn reports/bitgen.log
269
        @mv _xmsgs/* tmp/_xmsgs
270
        @rmdir _xmsgs
271
        @sleep 5
272
        @mv top.drc top_bitgen.xwbt top_usage.xml top_summary.xml webtalk.log tmp
273
        @grep -i '\(warning\|clock period\)' reports/xst.log
274
 
275
upload:
276
        djtgcfg prog -d Nexys3 -i 0 -f design.bit
277
 
278
design: clean simulation synthesis implementation bitfile
279
 
280
postsyn:
281
        @netgen -w -ofmt vhdl -sim ${NETLIST}.ngc post_synthesis.vhd
282
        @netgen -w -ofmt vhdl -sim ${NETLIST}.ngd post_translate.vhd
283
        @netgen  -pcf ${NETLIST}.pcf -w -ofmt vhdl -sim ${NETLIST}.ncd post_map.vhd
284
 
285
 
286
clean:
287
        @echo "Deleting temporary files and cleaning up directory..."
288
        @rm -vf *~ *.o trace.dat tb tb.ghw work-obj93.cf top.ngc top.ngd top_map.ngm \
289
              top.pcf top_map.ncd top.ncd top_xsim.vhd top_tsim.vhd top_tsim.sdf \
290
              top_tsim.nlf top_xst.xrpt top_ngdbuild.xrpt top_usage.xml top_summary.xml \
291
              top_map.map top_map.xrpt par_usage_statistics.html top.ptwx top.pad top_pad.csv \
292
              top.unroutes top.xpi top_par.xrpt top.twx top.nlf design.bit top_map.mrp
293
        @rm -vrf _xmsgs reports tmp xlnx_auto_0_xdb
294
        @rm -vrf _xmsgs reports tmp xlnx_auto_0_xdb
295
        @rm -vrf h2${EXE} gui${EXE} block${EXE} text${EXE}
296
        @rm -vrf text.bin h2.hex text.hex
297
        @rm -vrf *.pdf *.htm
298
        @rm -vrf *.blk *.sym
299
        @rm -vrf xst/
300
        @rm -vf usage_statistics_webtalk.html
301
        @rm -vf mem_h2.binary mem_h2.hexadecimal
302
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.