core-rules.mk 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. # Base directories
  12. ifeq ($(origin NO2BUILD_DIR), undefined)
  13. NO2BUILD_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
  14. endif
  15. ifeq ($(origin NO2CORES_DIR), undefined)
  16. NO2CORES_DIR := $(abspath $(NO2BUILD_DIR)/../cores)
  17. endif
  18. # Temporary build-directory
  19. BUILD_TMP := $(abspath build-tmp)
  20. $(BUILD_TMP):
  21. mkdir -p $(BUILD_TMP)
  22. # Discover all cores
  23. $(foreach core_def, $(wildcard $(NO2CORES_DIR)/*/no2core.mk), $(eval include $(core_def)))
  24. # Resolve dependency tree for project and collect sources
  25. $(BUILD_TMP)/core-deps.mk: Makefile $(BUILD_TMP) $(BUILD_TMP)/deps-core-$(THIS_CORE)
  26. @echo "SELF_DIR := \$$(dir \$$(lastword \$$(MAKEFILE_LIST)))" > $@
  27. @echo "include \$$(SELF_DIR)deps-core-*" >> $@
  28. @echo "CORE_ALL_DEPS := \$$(DEPS_SOLVE_TMP)" >> $@
  29. @echo "CORE_ALL_RTL_SRCS := \$$(RTL_SRCS_SOLVE_TMP)" >> $@
  30. @echo "CORE_ALL_SIM_SRCS := \$$(SIM_SRCS_SOLVE_TMP)" >> $@
  31. @echo "CORE_ALL_PREREQ := \$$(PREREQ_SOLVE_TMP)" >> $@
  32. include $(BUILD_TMP)/core-deps.mk
  33. # Include path
  34. CORE_SYNTH_INCLUDES := $(addsuffix /rtl/, $(addprefix -I$(NO2CORES_DIR)/, $(CORE_ALL_DEPS)))
  35. CORE_SIM_INCLUDES := $(addsuffix /sim/, $(addprefix -I$(NO2CORES_DIR)/, $(CORE_ALL_DEPS)))
  36. # Simulation
  37. $(BUILD_TMP)/%_tb: sim/%_tb.v $(ICE40_LIBS) $(CORE_ALL_PREREQ) $(CORE_ALL_RTL_SRCS) $(CORE_ALL_SIM_SRCS)
  38. iverilog -Wall -Wno-portbind -Wno-timescale -DSIM=1 -o $@ \
  39. $(CORE_SYNTH_INCLUDES) $(CORE_SIM_INCLUDES) \
  40. $(addprefix -l, $(ICE40_LIBS) $(CORE_ALL_RTL_SRCS) $(CORE_ALL_SIM_SRCS)) \
  41. $<
  42. # Action targets
  43. sim: $(addprefix $(BUILD_TMP)/, $(TESTBENCHES_$(THIS_CORE)))
  44. clean:
  45. @rm -Rf $(BUILD_TMP)
  46. .PHONY: all sim clean