Search code examples
makefileyosys

How to output dependency files in Yosys (gcc -MMD equivalent)?


Is there a command for Yosys, which creates a dependency file equivalent to the gcc option -MMD? (This option outputs a small Makefile fragment, which lists all files included by the compilation unit. See Using g++ with -MMD in makefile to automatically generate dependencies)

Background: I try to build a Makefile, which synthesizes a verilog project using Yosys. The project uses a single top verilog file, from which other verilog dependencies are included. To do that I use the following make rule, which works very well:

$(HARDWARE_BLIF_FILES): $(SUITE_OBJ_DIR)/%.blif : $(SUITE_SUPPORT_HARDWARE_DIR)/%.v
    $(HARDWARE_YOSYS) -q -p 'read_verilog -I/path/to/hwlib $<' -p 'synth_ice40 -blif $@'

Since I don't want to mention the other verilog files in the Makefile explicitly, I would like to use a dependency file. This would allow to detect changes applied to any of the dependency files and trigger a recompilation.


Thanks to the new yosys -E option added by Clifford, I could change the Makefile rule above as follows:

-include $(HARDWARE_BLIF_DEP_FILES)

$(HARDWARE_BLIF_FILES): $(SUITE_OBJ_DIR)/%.blif : $(SUITE_SUPPORT_HARDWARE_DIR)/%.v
    $(HARDWARE_YOSYS) -q -E $(SUITE_OBJ_DIR)/$*.v.d -p 'read_verilog -I/path/to/hwlib $<' -p 'synth_ice40 -blif $@'

Now, the blif file is generated, whenever one of the implicitly referenced Verilog files changes.


Solution

  • A feature like this has now been added to Yosys git head (a96c775). Simply add -E <depsfile> to your yosys call to generate a dependencies file.