3.5.1.31 HLS Makefile

All SmartHLS projects have a Makefile that can contain variables that affect the SmartHLScompilation flow.

Makefile Supported Syntax

SmartHLS only supports a subset of Makefile syntax described in the table below. Otherwise, SmartHLS will fail with a "HLS Makefile parsing error" with the details of the unsupported Makefile syntax.
Variable assignment operators
=, ?=, +=
Variable interpolation
$(VAR)
Supported Code blocks
ifdef VAR
...
#endif
#ifndef VAR
...
#endif
Nested ifdef blocks and else are not supported.
Include statements
include Makefile.user
Comments
# put your comments here
Multi-line statements
Multi-line statements with lines ending in \

MakeFile Variables

There are several Makefile variables that the user can assign to change the SmartHLS compilation. The description of each variable is listed below:

Table 3-4. Makefile Variables
VariableDescription
SRCSThe SRCS variable in Makefile should list all the source files (.cpp or .c).Header files should not be added to SRCS, but should be properly included by the source files.shls init will automatically add the file names for the existing source files in the current directory. If source files are created after shls init, please update SRCS (e.g., SRCS = foo.cpp bar.cpp).
NAMEThe NAME variable stands for the project name, e.g., NAME = MY_PROJECT.The default project name is the current directory name when NAME is not specified in Makefile.
BOARD_PATHSpecify the path where the test will be run on board. The default is /home/root/.BOARD_PATH is always prefixed by /home/root/ as programs are run as root on the board.
PROGRAM_ARGUMENTSPROGRAM_ARGUMENTS can be used to specify the arguments of the software testbench (i.e., int main(int argc, char *argv[])).Here is an example: PROGRAM_ARGUMENTS = input_file.bmp golden_output_file.bmp. More details can be found in 3.5.1.7 Simulate HLS Hardware (SW/HW Co-Simulation).
NUM_LIBERO_PnR_PASSESDefines the maximum number of Place and Route passes to go through in order to meet the timing requirement.
INPUT_FILES_RISCVSpecifies the input files to the program to be copied to the development board, separated by a space. The path used for the files should be based on the path on the development local machine. For example:INPUT_FILES_RISCV = lane3.avi lane3_golden.txt`This will copy lane3.avi and lane3_golden.txt from the project folder to the Icicle board before running the program on board.
OUTPUT_FILES_RISCVSpecifies the output files of the program ran on the development board, separated by a space. The path used for the files should be based on the path on the development board. Example:OUTPUT_FILES_RISCV = output.avi output.txt will copy output.avi and output.txtThis will copy output.avi and output.txt from the the Icicle board to the project folder after running the program on board.
USER_CXX_FLAGAdditional flags used for compilation such as -I.Example:USER_CXX_FLAG = -I$(OPENCV_PATH)/include/opencv4The above compiler option will be added to all the compile command to include the OpenCV include directory.
USER_CXX_FLAG_RISCVAdditional flags used for compilation such as -I.USER_CXX_FLAG_RISCV is defaulted to USER_CXX_FLAG. Defining USER_CXX_FLAG_RISCV will override the default, including when it is defined but empty. User can define this flag for adding specific flags for compiling the binary running on the on-board RISCV processor. Example:USER_CXX_FLAG_RISCV = -I$(OPENCV_PATH)/include/opencv4The above compiler option will added to all the compile command to include the OpenCV include directory.
USER_LINK_FLAGFlags for linking dynamic libraries such as -L and -l.Example:USER_LINK_FLAG = -L$(FFMPEG_PATH)/lib -lavcodecThe above compiler option will link FFMPEG’s avcodec library.
USER_LINK_FLAG_RISCVFlags for linking dynamic libraries such as -L and -l.USER_LINK_FLAG_RISCV is defaulted to USER_LINK_FLAG. Defining USER_LINK_FLAG_RISCV will override the default, including when it is defined but empty. User can define this flag for adding specific flags for linking the binary running on the on-board RISCV processor. Example:USER_LINK_FLAG_RISCV = -L$(FFMPEG_PATH)/lib -lavcodecThe above compiler option will link FFMPEG’s avcodec library for the RISCV processor.
USER_ENV_VARSSet the environment variable used for running the program on development host. Example:USER_ENV_VARS = LD_LIBRARY_PATH=$(OPENCV_PATH)/libThe above compiler option will set LD_LIBRARY_PATH to $(OPENCV_PATH)/lib when running the program. Windows users should specify PATH instead of LD_LIBRARY_PATH for linking libraries, like so:USER_ENV_VARS = PATH=$(OPENCV_PATH)/bin
USER_ENV_VARS_RISCVSet the environment variable used for running the program on RISCV on the development board. USER_ENV_VARS_RISCV is defaulted to USER_ENV_VARS. Defining USER_ENV_VARS_RISCV will override the default, including when it is defined but empty. Example:USER_ENV_VARS_RISCV = LD_LIBRARY_PATH=$(OPENCV_PATH)/libThe above compiler option will set LD_LIBRARY_PATH to $(OPENCV_PATH)/lib when running the program.
HLS_PATH_SEPAutomatically set to : when running on Linux or ; when running on Windows.
HLS_OSAutomatically set to linux when running on Linux or win when running on Windows.

Makefile Example

The example below shows how to define some of the above Makefile variables.

For IDE projects, you should create a new Makefile.user file and put your custom Makefile settings there (any changes in the makefile of an IDE project will be overwritten).

# Path to place files on the Icicle kit, relative to root home dir.
BOARD_PATH=tests/lane-detection-shls

# To pass timing for this project, we require more PnR passes
NUM_LIBERO_PnR_PASSES = 10

# Extra defines to include shared opencv/ffmpeg libraries below:
OPENCV_PATH_RISCV = $(SHLS_ROOT_DIR)/smarthls-library/external/vision/precompiled_sw_libraries/opencv4.5.4-riscv_64
FFMPEG_PATH_RISCV = $(SHLS_ROOT_DIR)/smarthls-library/external/vision/precompiled_sw_libraries/ffmpeg4.4-riscv_64
OPENCV_PATH = $(SHLS_ROOT_DIR)/smarthls-library/external/vision/precompiled_sw_libraries/opencv4.5.4-x86_64
FFMPEG_PATH = $(SHLS_ROOT_DIR)/smarthls-library/external/vision/precompiled_sw_libraries/ffmpeg4.4-x86_64

###########################################################################################
# User Define variables

# Specify input and optput files to copy to and from the board.
# INPUT_FILES_RISCV should use host paths.
# OUTPUT_FILES should use on-board paths.
INPUT_FILES_RISCV = lane3.avi lane3_golden.txt
OUTPUT_FILES_RISCV = outputlane3.avi lane3_lane_distances.txt

# Secify input arguments
PROGRAM_ARGUMENTS = lane3.avi lane3_golden.txt

# Additional flags used for compilation, such as -I
USER_CXX_FLAG += -I$(OPENCV_PATH)/include/opencv4 -fexceptions \
                 -Wno-sign-compare -Wno-unused-function        \
                 -Wno-unused-variable

# Flags for additional link libraries such as -L and -l
# This variable is for running on local host machine (i.e., x86 target).
# -B/usr/lib/x86_64-linux-gnu specifies which library to reference
# when your platform has cross platform compilation capability
# Specify opencv and ffmpeg libs.
USER_LINK_FLAG += -B/usr/lib/x86_64-linux-gnu \
                  -L$(OPENCV_PATH)/lib \
                  -lopencv_videoio -lopencv_core -lopencv_imgcodecs -lopencv_imgproc \
                  -L$(FFMPEG_PATH)/lib \
                  -lavcodec -lavformat -lavutil -lswscale -lswresample \
                  -Wl,-rpath,$(FFMPEG_PATH)/lib

# Flags for additional link libraries such as -L and -l for
# This variable is for running on the SOC.
# Include opencv and ffmpeg libs in the cross compiler linker.
USER_LINK_FLAG_RISCV = -L$(OPENCV_PATH_RISCV)/lib \
                       -lopencv_videoio -lopencv_core -lopencv_imgcodecs -lopencv_imgproc -latomic \
                       -L$(FFMPEG_PATH_RISCV)/lib \
                       -lavcodec -lavformat -lavutil -lswscale -lswresample \
                       -Wl,-rpath-link,$(FFMPEG_PATH_RISCV)/lib

# Additional user-defined environment variables that user might need to run their program

# This variable is for running on local host machine
# Windows needs libraries on PATH
USER_ENV_VARS = PATH=$(OPENCV_PATH)/lib$(HLS_PATH_SEP)$(FFMPEG_PATH)/bin$(HLS_PATH_SEP)/usr/x86_64-w64-mingw32/sys-root/mingw/bin$(HLS_PATH_SEP)$$PATH
# Linux needs libraries on LD_LIBRARY_PATH
USER_ENV_VARS += LD_LIBRARY_PATH=$(OPENCV_PATH)/lib$(HLS_PATH_SEP)$(FFMPEG_PATH)/lib

# Additional user-defined environment variables that user might need to run their program
# This variable is for running on the SOC
# LD_LIBRARY_PATH is needed for dynamically linking OpenCV
USER_ENV_VARS_RISCV = LD_LIBRARY_PATH=/home/root/shls_sw_dependencies/opencv4.5.4-riscv_64/lib:/home/root/shls_sw_dependencies/ffmpeg4.4-riscv_64/lib

# The IP adddress of the ethernet-cable-connected Icicle kit.
BOARD_IP ?= 192.168.X.X

# The programmer ID for programming the Icicle kit.
PROGRAMMER_ID ?= 445F3438