summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile12
-rw-r--r--resolvedeps.sh23
2 files changed, 31 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index de8af58..20b58af 100644
--- a/Makefile
+++ b/Makefile
@@ -6,15 +6,19 @@ MAKEFLAGS += --no-builtin-variables
PROGRAM ?= led
CST ?= tangnano9k.cst
FLASH_OPTS ?=
+# Can't use this for deps:
+# -E $(PROGRAM).deps
+# as yosys needs to have -o specified for this to work
+# but I specify the command manually
+# also, yosys inserts /tmp/ files which makes this useless.
YOSYS_OPTS ?= -Q -q -l $(PROGRAM).yosys.log
DEPS := $(wildcard *.dep)
+
# this is "bad", as it runs the deps target every time
# probably because of the include below
# SOURCES := $(wildcard *.v)
# DEPS := $(SOURCES:.v=.dep)
-# yosys deps-file doesn't work, it writes ": infile depfiles"
-#-E $(PROGRAM).deps
## default target
all: $(PROGRAM).fs
@@ -40,13 +44,13 @@ clean:
# synthesize
%.json: %.v
- gawk 'match($$0, /`include "(.*)"/, ary) {print "$*.json:", ary[1]}' $< > $*.dep
+ sh resolvedeps.sh $<
yosys -p "read_verilog $<; synth_gowin -top $* -json $@" $(YOSYS_OPTS)
# because yosys -E is buggy, or behaves differently than expected,
# use gawk to force-create deps.
%.dep: %.v
- gawk 'match($$0, /`include "(.*)"/, ary) {print "$*.json:", ary[1]}' $< > $@
+ sh resolvedeps.sh $<
# place and route?
%.pnr.json: %.json $(CST)
diff --git a/resolvedeps.sh b/resolvedeps.sh
new file mode 100644
index 0000000..e6363b3
--- /dev/null
+++ b/resolvedeps.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+## recursively resolve verilog dependencies
+
+if [ "$#" -ne 1 ]; then
+ echo "Illegal number of parameters"
+ echo "Usage $0 <in>"
+ exit 1
+fi
+
+filename="$1"
+filename="${filename%.*}"
+
+if test -f "$1"; then
+ echo " Resolve deps for $1"
+ gawk 'match($0, /`include "(.*)\.v"/, ary) {print "'"${filename}"'.json:", ary[1] ".v", ary[1] ".dep"}' "$1" > "${filename}.dep"
+ gawk 'match($0, /`include "(.*)"/, ary) {print ary[1];}' "$1" | while read fi; do
+ sh "$0" "$fi"
+ done
+else
+ echo " File $1 not found"
+ exit 1
+fi