Files
vhdl/make/ghdl.mk
T
2022-06-30 20:24:51 +02:00

124 lines
2.7 KiB
Makefile

# -------------------------------------------------
# User options
# -------------------------------------------------
# SRCS
# WITH_VCD
# WITH_GHW
TARGET ?= default
ENTITY ?= default
WORK_LIB ?= work
LANG_STD ?= 93c
IEEE_STD ?= standard
RUN_TIME ?= 1000ns
WAVE_FORMAT ?= fst
# Build path
BUILD_DIR ?= build/$(TARGET)
WORK_DIR ?= $(BUILD_DIR)/$(WORK_LIB)
# Can be pre-initialized by user
RUN_OPTS += --stop-time=$(RUN_TIME)
GHDL_OPTS += --work=$(WORK_LIB) --workdir=$(WORK_DIR) --std=$(LANG_STD) --ieee=$(IEEE_STD)
# -------------------------------------------------
# Make unique
# -------------------------------------------------
define uniq =
$(eval seen :=)
$(foreach _,$1,$(if $(filter $_,${seen}),,$(eval seen += $_)))
${seen}
endef
SRCS := $(abspath $(SRCS))
SRCS := $(call uniq,$(SRCS))
SRCS := $(filter-out ,$(SRCS))
#$(info ----------------------)
#$(info $(SRCS))
#$(info ----------------------)
# -------------------------------------------------
# GHDL binary
# -------------------------------------------------
GHDL := ghdl
GHDL_GCC := ghdl-gcc
# Wave format selection
SIM_FILE-vcd := $(BUILD_DIR)/$(TARGET).vcd
GTK_OPTS-vcd := --vcd=$(SIM_FILE-vcd)
SIM_FILE-fst := $(BUILD_DIR)/$(TARGET).fst
GTK_OPTS-fst := --fst=$(SIM_FILE-fst)
SIM_FILE-ghw := $(BUILD_DIR)/$(TARGET).ghw
GTK_OPTS-ghw := --wave=$(SIM_FILE-ghw)
SIM_FILE := $(SIM_FILE-$(WAVE_FORMAT))
GTK_OPTS := $(GTK_OPTS-$(WAVE_FORMAT))
# -------------------------------------------------
# Targets
# -------------------------------------------------
all: analyze
$(WORK_DIR):
mkdir -p $@
syntax:
$(GHDL) -s $(GHDL_OPTS) $(SRCS)
import:
$(GHDL) -i $(GHDL_OPTS) $(SRCS)
analyze: $(WORK_DIR) $(SRCS)
$(GHDL) -a $(GHDL_OPTS) $(SRCS)
html: $(WORK_DIR) $(SRCS)
$(GHDL) --pp-html $(GHDL_OPTS) $(SRCS) >$(BUILD_DIR)/$(TARGET).html
anaborate: $(WORK_DIR) $(SRCS)
$(GHDL) -c $(GHDL_OPTS) -o $(BUILD_DIR)/$(TARGET) $(SRCS) -e $(ENTITY)
makeunit: analyze
$(GHDL) -m $(GHDL_OPTS) $(ENTITY)
elaborate: analyze
$(GHDL) -e $(GHDL_OPTS) $(ENTITY)
run: analyze
$(GHDL) -r $(GHDL_OPTS) $(ENTITY) $(RUN_OPTS)
run_wave: analyze
$(GHDL) -r $(GHDL_OPTS) $(ENTITY) $(RUN_OPTS) $(GTK_OPTS) >$(BUILD_DIR)/$(TARGET).log
synth: analyze
$(GHDL) --synth $(GHDL_OPTS) $(ENTITY)
wave: run_wave
exec gtkwave -f $(SIM_FILE) -a $(TARGET).gtkw &
result:
exec gtkwave -f $(SIM_FILE) -a $(TARGET).gtkw &
tree: analyze
$(GHDL) -r $(GHDL_OPTS) $(ENTITY) $(RUN_OPTS) --no-run --disp-tree=inst
.PHONY: list
INSTR = $(foreach number,$(SRCS),echo $(number);)
list:
@$(INSTR)
clean:
rm -rf $(WORK_DIR)
rm -f $(BUILD_DIR)/$(TARGET)*.vcd
rm -f $(BUILD_DIR)/$(TARGET)*.fst
rm -f $(BUILD_DIR)/$(TARGET)*.ghw
rm -f $(BUILD_DIR)/$(TARGET)*.log
rm -f $(BUILD_DIR)/$(TARGET)*.o
mrproper:
rm -rf $(BUILD_DIR)