core-rules.mk 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #
  2. # core-rules.mk
  3. #
  4. # Save value
  5. THIS_CORE := $(CORE)
  6. # Default tools
  7. IVERILOG ?= iverilog
  8. ICE40_LIBS ?= $(shell yosys-config --datdir/ice40/cells_sim.v)
  9. # Must be first rule and call it 'all' by convention
  10. all: sim
  11. # Root directory
  12. ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..)
  13. # Temporary build-directory
  14. BUILD_TMP := $(abspath build-tmp)
  15. $(BUILD_TMP):
  16. mkdir -p $(BUILD_TMP)
  17. # Discover all cores
  18. $(foreach core_dir, $(wildcard $(ROOT)/cores/*), $(eval include $(core_dir)/core.mk))
  19. # Resolve dependency tree for project and collect sources
  20. $(BUILD_TMP)/proj-deps.mk: Makefile $(BUILD_TMP) deps-core-$(THIS_CORE)
  21. @echo "CORE_ALL_DEPS := $(DEPS_SOLVE_TMP)" > $@
  22. @echo "CORE_ALL_SRCS := $(SRCS_SOLVE_TMP)" >> $@
  23. @echo "CORE_ALL_PREREQ := $(PREREQ_SOLVE_TMP)" >> $@
  24. include $(BUILD_TMP)/proj-deps.mk
  25. # Simulation
  26. $(BUILD_TMP)/%_tb: sim/%_tb.v $(ICE40_LIBS) $(CORE_ALL_PREREQ) $(CORE_ALL_SRCS)
  27. iverilog -Wall -DSIM=1 -o $@ $(ICE40_LIBS) $(CORE_ALL_SRCS) $<
  28. # Action targets
  29. sim: $(addprefix $(BUILD_TMP)/, $(TESTBENCHES_$(THIS_CORE)))
  30. clean:
  31. @rm -Rf $(BUILD_TMP)
  32. .PHONY: all sim clean