2021-07-05 16:54:44 -04:00
|
|
|
Customizing the Makefiles
|
|
|
|
==========================
|
2021-07-05 13:35:04 -04:00
|
|
|
|
2021-07-05 18:37:40 -04:00
|
|
|
A powerful tool in creating your own designs is understanding how to generate your own Makefile to
|
2021-08-20 14:15:44 -04:00
|
|
|
compile projects. This tutorial walks you through how to do that.
|
2021-06-08 14:12:42 -04:00
|
|
|
|
2021-07-02 17:50:12 -04:00
|
|
|
If you would like to use methods other than a Makefile to build and compile your designs
|
2021-07-05 18:37:40 -04:00
|
|
|
(such as python or bash scripts) or if you would like to learn more about the various Symbiflow
|
2021-08-20 14:15:44 -04:00
|
|
|
commands used by the common Makefile to build and compile designs take a look at the
|
2021-07-02 17:50:12 -04:00
|
|
|
`Understanding Toolchain Commands <understanding-commands.html>`_ page.
|
|
|
|
|
2021-06-08 14:12:42 -04:00
|
|
|
Example
|
2021-06-08 22:45:35 -04:00
|
|
|
-------
|
2021-06-25 20:26:22 -04:00
|
|
|
|
2021-09-01 20:47:42 -04:00
|
|
|
By including Symbiflow's provided common Makefile in your designs, running the commands necessary for building
|
2021-08-20 14:15:44 -04:00
|
|
|
your personal projects is incredibly simple. All you have to do is run a few simple commands and set
|
|
|
|
a few variables.
|
2021-06-08 14:12:42 -04:00
|
|
|
|
2021-09-01 20:47:42 -04:00
|
|
|
Create a makefile for your project by running ``touch Makefile``, and add the following to the contents.
|
2021-06-08 14:12:42 -04:00
|
|
|
|
2021-08-20 14:15:44 -04:00
|
|
|
.. code-block:: bash
|
|
|
|
:name: makefile-example
|
|
|
|
:linenos:
|
2021-06-08 14:12:42 -04:00
|
|
|
|
2021-08-20 14:15:44 -04:00
|
|
|
current_dir := ${CURDIR}
|
2021-09-01 20:47:42 -04:00
|
|
|
TOP := <put the name of your top module here>
|
|
|
|
SOURCES := ${current_dir}/<put your HDL sources here>
|
|
|
|
|
|
|
|
# Include your constraint file path(s) below. Use either an XDC file
|
|
|
|
# or a PCF+SDC pair. Don't use all three file types.
|
|
|
|
XDC := ${current_dir}/<name of your pcf file if applicable>
|
|
|
|
PCF := ${current_dir}/<name of your xdc file if applicable>
|
|
|
|
SDC := ${current_dir}/<name of your sdc file if applicable>
|
2021-07-02 17:50:12 -04:00
|
|
|
|
2021-09-01 20:47:42 -04:00
|
|
|
include <path to symbiflow-examples root directory>/common/common.mk
|
2021-07-05 16:54:44 -04:00
|
|
|
|
2021-08-20 14:15:44 -04:00
|
|
|
Lets talk briefly about each of the commands in the above makefile
|
2021-07-05 16:54:44 -04:00
|
|
|
|
|
|
|
|
2021-08-20 14:15:44 -04:00
|
|
|
Adding HDL Sources and Specifying the Top Module
|
|
|
|
------------------------------------------------
|
2021-07-05 16:54:44 -04:00
|
|
|
|
2021-08-20 14:15:44 -04:00
|
|
|
:ref:`Line 2<makefile-example>` in the Makefile shows how to define the name for your top level module.
|
|
|
|
For example, if your top module was named ``module switches ( ...`` then you would simply uncomment
|
|
|
|
line 3 and change the text in ``<>`` to ``TOP := switches``.
|
2021-07-05 16:54:44 -04:00
|
|
|
|
2021-08-20 14:15:44 -04:00
|
|
|
:ref:`Line 3<makefile-example>` in the Makefile shows how to add HDL files to the design. The general
|
|
|
|
syntax is: ``SOURCES:=${current_dir}/<your HDL file path>``. You can also add multiple HDL files to a
|
2021-06-30 11:06:12 -04:00
|
|
|
design using the following syntax:
|
2021-06-08 22:45:35 -04:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
:name: multi-file-example
|
2021-06-08 14:12:42 -04:00
|
|
|
|
2021-08-20 14:15:44 -04:00
|
|
|
SOURCES := ${current_dir}/<HDL file 1> \
|
|
|
|
${current_dir}/<HDL file 2> \
|
|
|
|
${current_dir}/<HDL file 3> \
|
|
|
|
...
|
|
|
|
${current_dir}/<HDL file n> \
|
|
|
|
|
2021-06-08 22:45:35 -04:00
|
|
|
|
2021-06-30 11:06:12 -04:00
|
|
|
You could also use wildcards to collect all HDL file types of a specific extension and add them
|
|
|
|
to your design. For example, if you wanted to add all verilog files within the current directory
|
2021-08-20 14:15:44 -04:00
|
|
|
to your design, you could replace line 3 in the Makefile with:
|
2021-06-08 22:45:35 -04:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
:name: wildcard-example
|
|
|
|
|
2021-08-20 14:15:44 -04:00
|
|
|
SOURCES := ${current_dir}/*.v
|
2021-06-08 22:45:35 -04:00
|
|
|
|
2021-06-30 11:06:12 -04:00
|
|
|
To include SystemVerilog HDL in your designs simply change the ``.v`` extension in the examples
|
2021-08-20 14:15:44 -04:00
|
|
|
above to a ``.sv``.
|
2021-06-08 22:45:35 -04:00
|
|
|
|
2021-06-08 22:49:58 -04:00
|
|
|
.. note::
|
|
|
|
|
2021-07-02 17:50:12 -04:00
|
|
|
As of this writing, symbiflow only offers full support for Verilog by default.
|
|
|
|
SystemVerilog can also be run through the toolchain but more complicated
|
|
|
|
designs may not be fully supported.
|
2021-06-08 22:49:58 -04:00
|
|
|
|
2021-06-08 22:45:35 -04:00
|
|
|
|
|
|
|
Constraint files
|
|
|
|
----------------
|
|
|
|
|
2021-09-01 20:47:42 -04:00
|
|
|
:ref:`Lines 7-9 <makefile-example>` show how you can specify what constraint files are being used for
|
|
|
|
your design. The general syntax depends on whether you are using XDC files or a SDC+PCF pair:
|
2021-06-08 22:45:35 -04:00
|
|
|
|
|
|
|
.. tabs::
|
|
|
|
|
|
|
|
.. group-tab:: XDC
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
2021-07-05 13:52:12 -04:00
|
|
|
XDC := ${current_dir}/<name of XDC file>
|
2021-06-08 22:45:35 -04:00
|
|
|
|
|
|
|
.. group-tab:: SDC+PCF
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
PCF := ${current_dir}/<name of PCF file>
|
|
|
|
SDC := ${current_dir}/<name of SDC file>
|
|
|
|
|
2021-06-08 22:49:58 -04:00
|
|
|
|
2021-08-20 14:15:44 -04:00
|
|
|
.. note::
|
2021-06-08 22:49:58 -04:00
|
|
|
|
2021-08-20 14:15:44 -04:00
|
|
|
:ref:`Line 1 <makefile-example>` calls a make function ``CURDIR`` which returns the absolute
|
|
|
|
path for the current directory. :ref:`Line 9 <makefile-example>` simply includes the path to the
|
|
|
|
common makefile.
|
2021-06-08 22:49:58 -04:00
|
|
|
|
2021-06-25 20:26:22 -04:00
|
|
|
|
|
|
|
A Note on the example designs use of ifeq/else ifeq blocks
|
|
|
|
-------------------------------------------------------------
|
|
|
|
|
2021-07-05 18:37:40 -04:00
|
|
|
If you look at the Makefiles from the example designs within Symbiflow
|
2021-07-05 16:54:44 -04:00
|
|
|
(i.e. counter test, Picosoc, etc.), you will find an ifeq else ifeq block. The following snippet
|
|
|
|
is from lines 9-39 of `the Makefile from counter test <https://github.com/SymbiFlow/symbiflow-examples/blob/master/xc7/counter_test/Makefile>`_:
|
2021-06-25 20:26:22 -04:00
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
:name: counter-test Makefile snippet
|
2021-08-20 14:15:44 -04:00
|
|
|
:lineno-start: 5
|
2021-06-25 20:26:22 -04:00
|
|
|
|
|
|
|
ifeq ($(TARGET),arty_35)
|
2021-08-20 14:15:44 -04:00
|
|
|
XDC := ${current_dir}/arty.xdc
|
2021-06-25 20:26:22 -04:00
|
|
|
else ifeq ($(TARGET),arty_100)
|
2021-08-20 14:15:44 -04:00
|
|
|
XDC := ${current_dir}/arty.xdc
|
2021-06-25 20:26:22 -04:00
|
|
|
else ifeq ($(TARGET),nexys4ddr)
|
2021-08-20 14:15:44 -04:00
|
|
|
XDC := ${current_dir}/nexys4ddr.xdc
|
2021-06-25 20:26:22 -04:00
|
|
|
else ifeq ($(TARGET),zybo)
|
2021-08-20 14:15:44 -04:00
|
|
|
XDC := ${current_dir}/zybo.xdc
|
|
|
|
SOURCES:=${current_dir}/counter_zynq.v
|
2021-06-25 20:26:22 -04:00
|
|
|
else ifeq ($(TARGET),nexys_video)
|
2021-08-20 14:15:44 -04:00
|
|
|
XDC := ${current_dir}/nexys_video.xdc
|
2021-06-25 20:26:22 -04:00
|
|
|
else
|
2021-08-20 14:15:44 -04:00
|
|
|
XDC := ${current_dir}/basys3.xdc
|
2021-06-25 20:26:22 -04:00
|
|
|
endif
|
|
|
|
|
2021-08-20 14:15:44 -04:00
|
|
|
This snippet of code is an if else block used to set device specific constraints (i.e. ``basys3.xdc``,
|
2021-06-30 11:06:12 -04:00
|
|
|
``nexys_video.xdc``). The code block determines what type of hardware is being used based upon a
|
|
|
|
TARGET variable which is assumed to be defined before running make. For example, you may recall
|
2021-07-05 16:54:44 -04:00
|
|
|
running ``TARGET="<board type>" make -C counter_test`` before building the counter test example.
|
2021-06-30 11:06:12 -04:00
|
|
|
This command sets the TARGET variable to the type of hardware you are using.
|
2021-06-25 20:26:22 -04:00
|
|
|
|
2021-06-30 11:06:12 -04:00
|
|
|
The if else block is completely optional. If you are only using one type of hardware for your
|
2021-08-20 14:15:44 -04:00
|
|
|
designs you could just specify the TARGET variable within your makefile like so:
|
2021-06-25 20:26:22 -04:00
|
|
|
|
|
|
|
.. code-block:: bash
|
2021-08-20 14:15:44 -04:00
|
|
|
:emphasize-lines: 2
|
|
|
|
:linenos:
|
2021-06-25 20:26:22 -04:00
|
|
|
|
2021-08-20 14:15:44 -04:00
|
|
|
current_dir := ${CURDIR}
|
|
|
|
TARGET := basys3
|
|
|
|
TOP := ${current_dir}/# put the name of your top module here
|
|
|
|
SOURCES := ${current_dir}/# put your HDL sources here
|
|
|
|
...
|
2021-06-25 20:26:22 -04:00
|
|
|
|
2021-08-20 14:15:44 -04:00
|
|
|
By setting the ``TARGET`` variable within the Makefile itself, you don't even have to specify
|
|
|
|
the TARGET variable before calling make. You can just use ``make -C <path to directory containing
|
|
|
|
your design>``
|