-
Notifications
You must be signed in to change notification settings - Fork 4
/
core-rules.mk
69 lines (49 loc) · 1.93 KB
/
core-rules.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#
# Nitro FPGA build system: Core rules file
#
# Copyright (C) 2020 Sylvain Munaut
# SPDX-License-Identifier: BSD-3-Clause
#
# Save value
THIS_CORE := $(CORE)
# Default tools
IVERILOG ?= iverilog
ICE40_LIBS ?= $(shell yosys-config --datdir/ice40/cells_sim.v)
# Must be first rule and call it 'all' by convention
all: sim
# Base directories
ifeq ($(origin NO2BUILD_DIR), undefined)
NO2BUILD_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
endif
ifeq ($(origin NO2CORES_DIR), undefined)
NO2CORES_DIR := $(abspath $(NO2BUILD_DIR)/../cores)
endif
# Temporary build-directory
BUILD_TMP := $(abspath build-tmp)
$(BUILD_TMP):
@mkdir -p $(BUILD_TMP)
# Discover all cores
$(foreach core_def, $(wildcard $(NO2CORES_DIR)/*/no2core.mk), $(eval include $(core_def)))
# Resolve dependency tree for project and collect sources
$(BUILD_TMP)/core-deps.mk: Makefile $(BUILD_TMP) $(BUILD_TMP)/deps-core-$(THIS_CORE)
@echo "SELF_DIR := \$$(dir \$$(lastword \$$(MAKEFILE_LIST)))" > $@
@echo "include \$$(SELF_DIR)deps-core-*" >> $@
@echo "CORE_ALL_DEPS := \$$(DEPS_SOLVE_TMP)" >> $@
@echo "CORE_ALL_RTL_SRCS := \$$(RTL_SRCS_SOLVE_TMP)" >> $@
@echo "CORE_ALL_SIM_SRCS := \$$(SIM_SRCS_SOLVE_TMP)" >> $@
@echo "CORE_ALL_PREREQ := \$$(PREREQ_SOLVE_TMP)" >> $@
include $(BUILD_TMP)/core-deps.mk
# Include path
CORE_SYNTH_INCLUDES := $(addsuffix /rtl/, $(addprefix -I$(NO2CORES_DIR)/, $(CORE_ALL_DEPS)))
CORE_SIM_INCLUDES := $(addsuffix /sim/, $(addprefix -I$(NO2CORES_DIR)/, $(CORE_ALL_DEPS)))
# Simulation
$(BUILD_TMP)/%_tb: sim/%_tb.v $(ICE40_LIBS) $(CORE_ALL_PREREQ) $(CORE_ALL_RTL_SRCS) $(CORE_ALL_SIM_SRCS)
$(IVERILOG) -Wall -Wno-portbind -Wno-timescale -DSIM=1 -DNO_ICE40_DEFAULT_ASSIGNMENTS -o $@ \
$(CORE_SYNTH_INCLUDES) $(CORE_SIM_INCLUDES) \
$(addprefix -l, $(ICE40_LIBS) $(CORE_ALL_RTL_SRCS) $(CORE_ALL_SIM_SRCS)) \
$<
# Action targets
sim: $(addprefix $(BUILD_TMP)/, $(TESTBENCHES_$(THIS_CORE)))
clean:
@rm -Rf $(BUILD_TMP)
.PHONY: all sim clean