MAKEFLAGS += --no-builtin-rules MAKEFLAGS += --no-builtin-variables .SUFFIXES: ## 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) ## 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 ## helper targets .PHONY: clean flash show show: $(PROGRAM).v yosys -p "read_verilog $<; show $(PROGRAM)" flash: $(PROGRAM).fs openFPGALoader -b tangnano9k $(FLASH_OPTS) $(PROGRAM).fs clean: rm -rf *.json *.fs *.svg *.log *.dep ## Patterns # synthesize %.json: %.v 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 sh resolvedeps.sh $< # place and route? %.pnr.json: %.json $(CST) nextpnr-himbaechel --json $< --write $@ \ --device GW1NR-LV9QN88PC6/I5 --vopt family=GW1N-9C \ --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 $(CST) \ --placed-svg $*.plc.svg \ --routed-svg $*.rt.svg \ -q -l $(PROGRAM).pnr.log # pack bitstream %.fs: %.pnr.json gowin_pack -d GW1N-9C -o $@ $< ## inter-file dependencies -include $(DEPS) -include $($(wildcard *.fs:.fs=.dep)