summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile57
1 files changed, 41 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index fdfed63..4dbe558 100644
--- a/Makefile
+++ b/Makefile
@@ -2,43 +2,68 @@ MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
.SUFFIXES:
+## Variables
PROGRAM ?= led
+CST ?= tangnano9k.cst
FLASH_OPTS ?=
+YOSYS_OPTS ?= -Q -q -l $(PROGRAM).yosys.log
+DEPS := $(wildcard *.dep)
+# yosys deps-file doesn't work, it writes ": infile depfiles"
+#-E $(PROGRAM).deps
+
+## default target
all: $(PROGRAM).fs
+## dependencies
+
tangnano9k.cst:
wget https://github.com/YosysHQ/apicula/raw/refs/heads/master/examples/tangnano9k.cst || \
curl -LO https://github.com/YosysHQ/apicula/raw/refs/heads/master/examples/tangnano9k.cst
-%.json: %.v
- yosys -p "read_verilog $<; synth_gowin -top $* -json $@"
-
+## helper targets
+.PHONY: clean flash show synth deps
show: $(PROGRAM).v
yosys -p "read_verilog $<; show $(PROGRAM)"
-%.pnr.json: %.json tangnano9k.cst
+flash: $(PROGRAM).fs
+ openFPGALoader -b tangnano9k $(FLASH_OPTS) $(PROGRAM).fs
+
+clean:
+ rm -rf *.json *.fs *.svg *.log *.deps
+
+synth: $(PROGRAM).json
+
+deps: $(PROGRAM).deps
+
+## Patterns
+
+# synthesize
+%.json: %.v
+ yosys -p "read_verilog $<; synth_gowin -top $* -json $@" $(YOSYS_OPTS)
+
+%.deps: %.v
+ gawk 'match($$0, /`include "(.*)"/, ary) {print FILENAME, ":", ary[1]}' $< > $@
+
+# place and route?
+%.pnr.json: %.json $(CST)
nextpnr-himbaechel --json $< --write $@ \
--device GW1NR-LV9QN88PC6/I5 --vopt family=GW1N-9C \
- --vopt cst=tangnano9k.cst \
+ --vopt cst=$(CST) \
--placed-svg $*.plc.svg \
--routed-svg $*.rt.svg \
+ -q -l $(PROGRAM).pnr.log \
|| \
nextpnr-gowin --json $< --write $@ \
--device GW1NR-LV9QN88PC6/I5 --family GW1N-9C \
- --cst tangnano9k.cst \
+ --cst $(CST) \
--placed-svg $*.plc.svg \
- --routed-svg $*.rt.svg
+ --routed-svg $*.rt.svg \
+ -q -l $(PROGRAM).pnr.log
+# pack bitstream
%.fs: %.pnr.json
gowin_pack -d GW1N-9C -o $@ $<
-# flash: -f
-flash: $(PROGRAM).fs
- openFPGALoader -b tangnano9k $(FLASH_OPTS) $(PROGRAM).fs
-
-clean:
- rm -rf *.json *.fs *.svg *.log
-
-led.fs: clkdiv.v
-
+## inter-file dependencies
+-include $(DEPS)