Drop this Makefile in the root directory of your VHDL project and always use
the .vhd
extension for your source files. From the root directory of your
VHDL project type make
to print the short help or make long-help
for the
complete help.
Usage:
make [GOAL] [VARIABLE=VALUE ...]
Examples:
make foo_sim DIR=/tmp/mysim SIM=vsim V=1
make foo_sim.sim DIR=/tmp/ghdl_sim SIM=ghdl GUI=yes
Variable valid values description (current value)
DIR - temporary build directory (/tmp/build/ghdl)
GHDLAFLAGS - GHDL analysis options (--std=08)
GHDLRFLAGS - GHDL simulation options (--std=08)
GHDLRUNOPTS - GHDL RUNOPTS options ()
GUI yes|no use Graphical User Interface (no)
MODE work|dirname default target library (work)
SIM ghdl|vsim|xsim simulation toolchain (ghdl)
SKIP - UNITs to ignore for compilation ()
V 0|1 verbosity level (0)
VCOMFLAGS - Modelsim analysis options (-2008)
VSIMFLAGS - Modelsim simulation options ()
XVHDLFLAGS - Vivado analysis options (-2008)
XELABFLAGS - Vivado elaboration options ()
XSIMFLAGS - Vivado simulation options ()
Goals:
help this help (default goal)
long-help print long help
libs print library names
UNIT compile UNIT.vhd
units print existing UNITs not in SKIP
all compile all source files not in SKIP
UNIT.sim simulate UNIT
clean delete temporary build directory
This Makefile is for GNU make only and relies on conventions; if your make is not GNU make or your project is not compatible with the conventions, please do not use this Makefile.
The vhdl
sub-directory contains some VHDL source files for testing.
-
The directory containing this Makefile is the
TOP
directory. All make commands must be launched fromTOP
:cd TOP; make ...
or:
make -C TOP ...
-
Source files are considered as indivisible units. They must be stored in the
TOP
directory or its sub-directories and namedUNIT.vhd
whereUNIT
is any combination of alphanumeric characters, plus underscores (no spaces or tabs, for instance). The "name" of a unit is the basename of its source file without the.vhd
extension. Example: the name of unitTOP/tests/cooley.vhd
iscooley
. -
Each unit has a default target library:
work
ifMODE=work
, or the name of the directory of the unit ifMODE=dirname
. Target libraries are automatically created if they don't exist. -
Unit names must be unique. It is not possible to have units
TOP/common/version.vhd
andTOP/tests/version.vhd
, even ifMODE=dirname
and their target libraries are different. -
If there is a file named
config
inTOP
, it is included before anything else. It can be used to set configuration variables to other values than the default. Example ofTOP/config
file:DIR := /tmp/build/vsim GUI := yes MODE := work SIM := vsim SKIP := bogus in_progress V := 1
Variable assignments on the command line overwrite assignments in
TOP/config
. Example to temporarily disable the GUI for a specific simulation:make cooley_sim.sim GUI=no
-
Simulations can be launched with
make UNIT.sim
to simulate entityUNIT
defined in fileUNIT.vhd
. Example: if unitTOP/tests/cooley_sim.vhd
defines entitycooley_sim
a simulation can be launched with:make cooley_sim.sim [VAR=VALUE...]
Note: the simulations are launched from the
DIR
temporary build directory. It can matter if, for instance, a simulation reads or writes data files.Note: GHDL has no GUI; instead, with GHDL and
GUI=yes
, aDIR/UNIT.ghw
waveform file is generated for post-simulation visualization with, e.g., GTKWave. -
Inter-unit dependencies must be declared in text files with the
.mk
extension stored inTOP
or its sub-directories. The dependency syntax is:UNIT [UNIT...]: UNIT [UNIT...]
where the left-hand side units depend on the right-hand side units. Example: if
cooley_sim.vhd
depends onrnd_pkg.vhd
andcooley.vhd
(that is, ifrnd_pkg.vhd
andcooley.vhd
must be compiled beforecooley_sim.vhd
), the following can be added to a.mk
file somewhere underTOP
:cooley_sim: rnd_pkg cooley
The sub-directory in which a
.mk
file is stored does not matter but the letter case matters in dependency rules: if a unit iscooley.vhd
, its name iscooley
and the dependency rules must usecooley
, notCooley
orCOOLEY
..mk
files can also specify per-unit target libraries other than the defaults usingUNIT-lib
variables. Example: ifMODE=dirname
andTOP/common/rnd_pkg.vhd
must be compiled in librarytests
instead of the defaultcommon
, the following can be added to a.mk
file somewhere underTOP
:rnd_pkg-lib := tests
Other GNU make statements can be added to .mk
files. Example if the GHDL
simulation of cooley_sim
depends on data file cooley.txt
generated by shell
script TOP/tests/cooley.sh
, and generic parameter n
must be set to
100000
, the following can be added to, e.g., TOP/tests/cooley.mk
:
cooley_sim.sim: GHDLRUNOPTS += -gn=100000
cooley_sim.sim: $(DIR)/cooley.txt
$(DIR)/cooley.txt: $(TOP)/tests/cooley.sh
$< > $@