-
Notifications
You must be signed in to change notification settings - Fork 83
/
Makefile
95 lines (73 loc) · 2.56 KB
/
Makefile
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
YOSYS ?= yosys
INKSCAPE ?= inkscape
VIEWER ?= eog
YOSYS_FLAGS ?= -q
# YOSYS_FLAGS ?= -Q -T
# Node JS is sometimes installed as node and sometimes as nodejs
ifneq ($(shell which node),)
NODE ?= node
else
ifneq ($(shell which nodejs),)
NODE ?= nodejs
else
$(error "Can not find node(js), please set $$NODE to the node binary")
endif
endif
NETLISTSVG = ../bin/netlistsvg
NETLISTSVG_SKIN ?= ../lib/default.svg
NETLISTSVG_DPI ?= 300
# Simple files are the same flattened as not
SIMPLE_FILES=dff.v muxcy.v xorcy.v
# Complex files are different when flattened
COMPLEX_FILES=carry4bits.v carry4whole.v
ALL_TARGETS= \
$(foreach v,$(SIMPLE_FILES) ,$(basename $(v)).simple.all) \
$(foreach v,$(COMPLEX_FILES),$(basename $(v)).complex.all)
GET_TOP ?= export TOP=$$(echo $(basename $<) | tr a-z A-Z);
# Top level diagram
%.json: %.v Makefile
$(GET_TOP) $(YOSYS) $(YOSYS_FLAGS) -p "prep -top $$TOP; write_json $@" $<
# Split wires, can make it easier for the diagram if nets are split up
%.split.json: %.v Makefile
$(GET_TOP) $(YOSYS) $(YOSYS_FLAGS) -p "prep -top $$TOP; splitnets; write_json $@" $<
# Flatten the diagram into logic + black boxes
%.flat.json: %.v Makefile
$(GET_TOP) $(YOSYS) $(YOSYS_FLAGS) -p "prep -top $$TOP -flatten; write_json $@" $<
# Convert logic into AND and NOT logic
%.aig.json: %.v Makefile
$(GET_TOP) $(YOSYS) $(YOSYS_FLAGS) -p "prep -top $$TOP -flatten; cd $$TOP; aigmap; write_json $@" $<
# Convert logic into NAND, AND and NOT logic
%.naig.json: %.v Makefile
$(GET_TOP) $(YOSYS) $(YOSYS_FLAGS) -p "prep -top $$TOP -flatten; cd $$TOP; aigmap -nand; write_json $@" $<
# Convert logic into "simple logic" - NOT, AND, XOR, etc
%.simplemap.json: %.v Makefile
$(GET_TOP) $(YOSYS) $(YOSYS_FLAGS) -p "prep -top $$TOP -flatten; cd $$TOP; simplemap; write_json $@" $<
# Use netlistsvg to generate SVG files
%.svg: %.json $(NETLISTSVG_SKIN)
$(NODE) $(NETLISTSVG) $< -o $@ --skin $(NETLISTSVG_SKIN)
# Use inkscape to render the SVG files into PNG files.
%.png: %.svg
$(INKSCAPE) --export-png $@ --export-dpi $(NETLISTSVG_DPI) $< 2>&1 | grep -v "WARNING: unknown type: s:alias"
# Open the rendered PNG in a file viewer
%.view: %.png
eog $< &
# Generate all PNGs for simple files
%.simple.all: %.png %.aig.png
@true
# Generate all PNGS for complex files
%.complex.all: %.png %.split.png %.flat.png %.aig.png %.simplemap.png
@true
# Build everything!
build.all: $(ALL_TARGETS)
@true
# View everything!
view.all: build.all
eog *.png &
clean:
rm -f *.json *.svg *.png
all:
make clean
make view.all
.DEFAULT_GOAL := all
.PRECIOUS: %.png
.PHONY: view clean all