2022-08-24 16:14:19 -05:00
|
|
|
#
|
|
|
|
# Top Makefile
|
|
|
|
# ------------
|
|
|
|
#
|
|
|
|
# Top-level makefile to compile the codebase
|
|
|
|
#
|
|
|
|
# Following options are available
|
|
|
|
#
|
|
|
|
# .. option:: BUILD_TYPE=<string>
|
|
|
|
#
|
|
|
|
# Pick the type of compilation. Can be either ``release`` or ``debug``. By default, release mode is selected (full optimization on runtime).
|
|
|
|
#
|
|
|
|
# .. option:: CMAKE_FLAGS=<string>
|
|
|
|
#
|
|
|
|
# Force compilation flags for CMake to generate Makefiles
|
2020-12-08 10:52:35 -06:00
|
|
|
|
2022-08-24 16:14:19 -05:00
|
|
|
BUILD_TYPE ?= release
|
|
|
|
# Convert to lower case for consistency
|
|
|
|
BUILD_TYPE := $(shell echo ${BUILD_TYPE} | tr '[:upper:]' '[lower]')
|
|
|
|
# Trim any _pgo or _strict in the build type name (since it would not match any of CMake's standard build types
|
|
|
|
CMAKE_BUILD_TYPE := $(shell echo ${BUILD_TYPE} | sed 's/_\?pgo//' | sed 's/_\?strict//')
|
|
|
|
|
|
|
|
# Allow users to pass parameters to cmake, without defining build types
|
|
|
|
# e.g. make CMAKE_FLAGS="-DCMAKE_CXX_COMPILER=g++-9'
|
|
|
|
override CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -G 'Unix Makefiles' ${CMAKE_FLAGS}
|
|
|
|
|
2022-08-24 16:39:21 -05:00
|
|
|
# -s : Suppresss makefile output (e.g. entering/leaving directories)
|
|
|
|
# --output-sync target : For parallel compilation ensure output for each target is synchronized (make version >= 4.0)
|
|
|
|
MAKEFLAGS := -s
|
|
|
|
|
2022-08-24 18:26:12 -05:00
|
|
|
# Directory to build the codes
|
|
|
|
SOURCE_DIR :=${PWD}
|
|
|
|
BUILD_DIR ?= build
|
2022-12-30 13:00:17 -06:00
|
|
|
CMAKE_GOALS = all
|
2022-08-24 18:26:12 -05:00
|
|
|
|
2022-08-24 16:14:19 -05:00
|
|
|
# Find CMake command from system variable, otherwise use a default one
|
2020-12-08 10:52:35 -06:00
|
|
|
ifeq ($(origin CMAKE_COMMAND),undefined)
|
|
|
|
CMAKE_COMMAND := cmake
|
|
|
|
else
|
|
|
|
CMAKE_COMMAND := ${CMAKE_COMMAND}
|
|
|
|
endif
|
|
|
|
|
2022-10-06 18:59:15 -05:00
|
|
|
# Define executables
|
2022-08-24 16:14:19 -05:00
|
|
|
PYTHON_EXEC ?= python3
|
2022-10-06 18:59:15 -05:00
|
|
|
CLANG_FORMAT_EXEC ?= clang-format-10
|
2022-10-07 12:16:00 -05:00
|
|
|
XML_FORMAT_EXEC ?= xmllint
|
2022-11-21 16:20:45 -06:00
|
|
|
PYTHON_FORMAT_EXEC ?= black
|
2022-08-24 16:14:19 -05:00
|
|
|
|
|
|
|
# Put it first so that "make" without argument is like "make help".
|
|
|
|
export COMMENT_EXTRACT
|
|
|
|
|
|
|
|
# Put it first so that "make" without argument is like "make help".
|
|
|
|
help:
|
|
|
|
@${PYTHON_EXEC} -c "$$COMMENT_EXTRACT"
|
|
|
|
|
2022-12-30 13:00:17 -06:00
|
|
|
.PHONY: help
|
2020-12-08 10:52:35 -06:00
|
|
|
|
2020-12-14 11:25:50 -06:00
|
|
|
checkout:
|
2022-08-24 16:14:19 -05:00
|
|
|
# Update all the submodules
|
2020-12-08 10:52:35 -06:00
|
|
|
git submodule init
|
2023-04-18 03:52:20 -05:00
|
|
|
git submodule update --init --depth 1
|
2020-12-14 11:25:50 -06:00
|
|
|
|
2022-12-30 13:00:17 -06:00
|
|
|
prebuild:
|
|
|
|
# Run cmake to generate Makefile under the build directory, before compilation
|
2023-01-31 13:59:01 -06:00
|
|
|
@mkdir -p ${BUILD_DIR} && \
|
|
|
|
echo "cd ${BUILD_DIR} && ${CMAKE_COMMAND} ${CMAKE_FLAGS} ${SOURCE_DIR}" && \
|
2022-08-24 18:26:12 -05:00
|
|
|
cd ${BUILD_DIR} && ${CMAKE_COMMAND} ${CMAKE_FLAGS} ${SOURCE_DIR}
|
2022-12-30 13:00:17 -06:00
|
|
|
|
2023-05-10 00:48:43 -05:00
|
|
|
compile: | prebuild
|
2022-12-30 13:00:17 -06:00
|
|
|
# Compile the code base. By default, all the targets will be compiled
|
|
|
|
# Following options are available
|
|
|
|
# .. option:: CMAKE_GOALS
|
|
|
|
#
|
|
|
|
# Define the target for cmake to compile. for example, ``cmake_goals=openfpga`` indicates that only openfpga binary will be compiled
|
|
|
|
echo "Building target(s): ${CMAKE_GOALS}"
|
|
|
|
@+${MAKE} -C ${BUILD_DIR} ${CMAKE_GOALS}
|
|
|
|
|
2023-05-10 00:48:43 -05:00
|
|
|
list_cmake_targets: | prebuild
|
2022-12-30 13:00:17 -06:00
|
|
|
# Show the targets available to be built, which can be specified through ``CMAKE_GOALS`` when compile
|
|
|
|
cd ${BUILD_DIR} && make help && cd -
|
2022-08-24 18:26:12 -05:00
|
|
|
|
2023-05-10 03:05:24 -05:00
|
|
|
all: checkout
|
2022-08-24 18:26:12 -05:00
|
|
|
# A shortcut command to run checkout and compile in serial
|
2023-05-10 03:05:24 -05:00
|
|
|
@+${MAKE} compile
|
2020-12-14 11:25:50 -06:00
|
|
|
|
2022-10-06 18:59:15 -05:00
|
|
|
format-cpp:
|
|
|
|
# Format all the C/C++ files under this project, excluding submodules
|
2022-10-06 19:07:57 -05:00
|
|
|
for f in `find libs openfpga -iname *.cpp -o -iname *.hpp -o -iname *.c -o -iname *.h`; \
|
2022-10-06 19:04:30 -05:00
|
|
|
do \
|
|
|
|
${CLANG_FORMAT_EXEC} --style=file -i $${f} || exit 1; \
|
|
|
|
done
|
2022-10-06 18:59:15 -05:00
|
|
|
|
2022-10-07 12:16:00 -05:00
|
|
|
format-xml:
|
|
|
|
# Format all the XML files under this project, excluding submodules
|
|
|
|
for f in `find openfpga_flow/vpr_arch openfpga_flow/openfpga_arch -iname *.xml`; \
|
|
|
|
do \
|
2022-10-07 12:33:59 -05:00
|
|
|
XMLLINT_INDENT=" " && ${XML_FORMAT_EXEC} --format $${f} --output $${f} || exit 1; \
|
2022-10-07 12:16:00 -05:00
|
|
|
done
|
|
|
|
|
2022-11-21 16:20:45 -06:00
|
|
|
format-py:
|
|
|
|
# Format all the python scripts under this project, excluding submodules
|
|
|
|
for f in `find openfpga_flow/scripts -iname *.py`; \
|
|
|
|
do \
|
|
|
|
${PYTHON_FORMAT_EXEC} $${f} --line-length 100 || exit 1; \
|
|
|
|
done
|
|
|
|
|
2022-11-21 16:44:27 -06:00
|
|
|
format-all: format-cpp format-xml format-py
|
|
|
|
# Format all the C/C++, XML and Python codes
|
|
|
|
|
2020-12-14 11:25:50 -06:00
|
|
|
clean:
|
2022-08-24 16:14:19 -05:00
|
|
|
# Remove current build results
|
2022-08-24 18:26:12 -05:00
|
|
|
rm -rf ${BUILD_DIR} yosys/install
|
2022-08-24 16:14:19 -05:00
|
|
|
|
|
|
|
# Functions to extract comments from Makefiles
|
|
|
|
define COMMENT_EXTRACT
|
|
|
|
import re
|
|
|
|
with open ('Makefile', 'r' ) as f:
|
|
|
|
matches = re.finditer('^([a-zA-Z-_]*):.*\n#(.*)', f.read(), flags=re.M)
|
|
|
|
for _, match in enumerate(matches, start=1):
|
|
|
|
header, content = match[1], match[2]
|
|
|
|
print(f" {header:10} {content}")
|
|
|
|
endef
|