Last active
June 29, 2024 14:05
-
-
Save etiennecollin/198f7520c4c58d545368a196e08f83ed to your computer and use it in GitHub Desktop.
Easily compile and simulate VHDL entities using GHDL and GTKWave. See instructions in the top comment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# By Etienne Collin | |
# https://gist.github.com/etiennecollin/198f7520c4c58d545368a196e08f83ed | |
# Dependencies (on macOS, install via Homebrew (https://brew.sh/)): | |
# ghdl: | |
# Source: https://github.com/ghdl/ghdl/ | |
# gtkwave: | |
# Source: https://gtkwave.sourceforge.net/ | |
#### INPUT REQUIRED #### | |
ENTITIES = entityName1 entityName2 | |
VHDL_EXTENSION = vhd | |
VHDL_MAIN_PATH = . | |
VHDL_DEPENDENCIES_PATH = . | |
VHDL_ARGS = -fexplicit -fsynopsys --std=08 | |
######################## | |
OUT_DIR = out | |
VHDL_MAIN := $(VHDL_MAIN_PATH)/*.$(VHDL_EXTENSION) | |
VHDL_DEPENDENCIES := $(VHDL_DEPENDENCIES_PATH)/*.$(VHDL_EXTENSION) | |
CF := $(OUT_DIR)/*.cf | |
GHW := $(OUT_DIR)/*.ghw | |
ENTITY = $(OUT_DIR)/$${entity}.ghw | |
VHDL_MOD_TIME = $(OUT_DIR)/vhdl_last_modification_time.txt | |
CF_MOD_TIME = $(OUT_DIR)/cf_last_modification_time.txt | |
.PHONY: all simulate clear purge | |
all: $(GHW) | |
# Make this the dependency of $(CF) if the files are always compiled even when not modified | |
# $(VHDL_MOD_TIME): $(VHDL_DEPENDENCIES) $(VHDL_MAIN) | |
# @$(MAKE) checkstructure | |
# @[ -f "$(VHDL_MOD_TIME)" ] || touch $(VHDL_MOD_TIME) | |
# @find $(VHDL_DEPENDENCIES) $(VHDL_MAIN) -type f -exec stat -f "%m %N" {} \; | sort -nr | head -1 > $(VHDL_MOD_TIME) | |
$(CF): $(VHDL_DEPENDENCIES) $(VHDL_MAIN) | |
@$(MAKE) checkstructure | |
@echo "Analyzing $(VHDL_EXTENSION) files..." | |
@ghdl -a $(VHDL_ARGS) --workdir=$(OUT_DIR) $(VHDL_DEPENDENCIES) | |
@ghdl -a $(VHDL_ARGS) --workdir=$(OUT_DIR) $(VHDL_MAIN) | |
@for entity in $(ENTITIES); do \ | |
echo "Compiling entity $${entity}..."; \ | |
ghdl -e $(VHDL_ARGS) --workdir=$(OUT_DIR) $${entity}; \ | |
done | |
# Make this the dependency of $(GHW) if the files are always compiled even when not modified | |
# $(CF_MOD_TIME): $(CF) | |
# @[ -f "$(CF_MOD_TIME)" ] || touch $(CF_MOD_TIME) | |
# @find $(CF) -type f -exec stat -f "%m %N" {} \; | sort -nr | head -1 > $(CF_MOD_TIME) | |
$(GHW): $(CF) | |
@for entity in $(ENTITIES); do \ | |
echo "Generating $${entity}.ghw file..."; \ | |
ghdl -r $(VHDL_ARGS) --workdir=$(OUT_DIR) $${entity} --wave=$(ENTITY); \ | |
done | |
simulate: $(GHW) | |
@for entity in $(ENTITIES); do \ | |
echo "Opening $${entity}.ghw in gtkwave..."; \ | |
open -a gtkwave $(ENTITY); \ | |
done | |
checkstructure: | |
@[ -d $(OUT_DIR) ] || ( echo "Creating output directory..."; mkdir -p $(OUT_DIR) ) | |
clear: | |
@echo "Cleaning auto-generated files from output directory..." | |
@rm -rf $(OUT_DIR)/* | |
purge: | |
@echo "Purging auto-generated file structure..." | |
@rm -rf $(OUT_DIR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Makefile VHDL
This makefile supports:
Installation
makefile_vhdl
tomakefile
.Dependencies
On macOS, install the dependencies via Homebrew with the following command:
Setup
Set the required variables in the makefile (these variables are at the top of the makefile and marked by
#### INPUT REQUIRED ####
):ENTITIES
: The name of the entities to simulate, separated by spaces.VHDL_EXTENSION
: The extension you are using for your VHDL files (usuallyvhd
orvhdl
)..
before the extension (such as.vhd
or.vhdl
); it is added automatically.VHDL_MAIN_PATH
: The relative path to the directory containing your main VHDL files.VHDL_DEPENDENCIES_PATH
: The relative path to the directory containing your VHDL dependencies (for example, components that are used in the main entity).VHDL_MAIN_PATH
.VHDL_ARGS
: The arguments to pass to the GHDL compiler.Run the makefile:
make
: Compile the files and run the tests.make simulate
: Compile the files, run the tests and open in GTKWave.make clear
: Delete auto-generated compilation files.make purge
: Delete auto-generated compilation files and directory.