################################################################### # Makefile for Virtual Processor VHDL testcode in NVC # # Copyright (c) 2005-2024 Simon Southwell. # # This file is part of VProc. # # VProc is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # VProc is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with VProc. If not, see . # ################################################################### # Define the maximum number of supported VProcs in the compile pli library MAX_NUM_VPROC = 64 SRCDIR = ../../code PYSRCDIR = ../src TESTDIR = . VOBJDIR = ${TESTDIR}/obj # Name of the Python executable PYEXENAME = python3 # If PYTHONHOME environment variable not set give an error ifeq ("${PYTHONHOME}", "") $(error "PYTHONHOME environment variable not set.") endif # Extract the python version number in the format python.. # which is the name of the python libray to link. SHELLCMD = ${PYEXENAME} -V | awk -F"[. ]" '{print "python" $$2 "." $$3}' PYVER = $(shell ${SHELLCMD}) # Get OS type OSTYPE:=$(shell uname) # VPROC C source code VPROC_C = VSched.c \ VUser.c # Python interface C code compiled into PyVProc.so PYTHON_C = PythonVProc.c # Memory model C code MEM_C = # Test user code USER_C = VUserMainPy.c USER_CPP_BASE = $(notdir $(filter %cpp, ${USER_C})) USER_C_BASE = $(notdir $(filter %c, ${USER_C})) MEM_CPP_BASE = $(notdir $(filter %cpp, ${MEM_C})) MEM_C_BASE = $(notdir $(filter %c, ${MEM_C})) VOBJS = ${addprefix ${VOBJDIR}/, ${USER_C_BASE:%.c=%.o} ${USER_CPP_BASE:%.cpp=%.o} \ ${VPROC_C:%.c=%.o} ${MEM_C_BASE:%.c=%.o} ${MEM_CPP_BASE:%.cpp=%.o}} USRFLAGS = # Generated PLI C library VPROC_PLI = ${TESTDIR}/VProc.so VLIB = ${TESTDIR}/libvproc.a # Python interface foreign module shared object PYVRPOC_PLI = ${TESTDIR}/PyVProc.so VPROC_TOP = test # Set OS specific variables between Linux and Windows (MinGW) ifeq (${OSTYPE}, Linux) CFLAGS_SO = -shared -lpthread -lrt -rdynamic CPPSTD = -std=c++11 else CFLAGS_SO = -shared -Wl,-export-all-symbols CPPSTD = endif CC = gcc C++ = g++ ARCHFLAG = -m64 CFLAGS = -fPIC \ ${ARCHFLAG} \ -g \ -D_GNU_SOURCE \ ${USRFLAGS} \ -I${SRCDIR} \ -I${PYSRCDIR} \ -I${PYTHONHOME}/include/${PYVER} \ -DVP_MAX_NODES=${MAX_NUM_VPROC} \ -DVPROC_VHDL \ -DNVC \ -D_REENTRANT # Rutime flags for nvc SIMFLAGS = --ieee-warnings=off \ --format=fst --wave=${WAVEFILE} \ --load=${VPROC_PLI} \ ${VPROC_TOP} WAVEFILE = waves.fst WAVESAVEFILE = ${WAVEFILE:%.fst=%.gtkw} #------------------------------------------------------ # BUILD RULES #------------------------------------------------------ all: ${VPROC_PLI} vhdl ${VOBJDIR}/%.o: ${SRCDIR}/%.c ${SRCDIR}/*.h @${CC} -c ${CFLAGS} $< -o $@ ${VOBJDIR}/%.o: ${SRCDIR}/%.cpp ${SRCDIR}/*.h @${C++}-c ${CFLAGS} $< -o $@ ${VOBJDIR}/%.o: ${PYSRCDIR}/%.c @${CC} -Wno-write-strings -c ${CFLAGS} $< -o $@ ${VOBJDIR}/%.o: ${PYSRCDIR}/%.cpp @${C++} ${CPPSTD} -Wno-write-strings -c ${CFLAGS} $< -o $@ ${VOBJDIR}/%.o: ${MEMMODELDIR}/%.c ${MEMMODELDIR}/*.h @${CC} -c ${CFLAGS} $< -o $@ ${VOBJDIR}/%.o: ${MEMMODELDIR}/%.cpp ${MEMMODELDIR}/*.h @${C++} -c ${CFLAGS} $< -o $@ ${VLIB} : ${VOBJS} ${VOBJDIR} @ar cr ${VLIB} ${VOBJS} ${VOBJS}: | ${VOBJDIR} ${VOBJDIR}: @mkdir ${VOBJDIR} ${VPROC_PLI}: ${PYVRPOC_PLI} ${VLIB} @${C++} ${CPPSTD} \ ${CFLAGS_SO} \ -Wl,-whole-archive \ ${CFLAGS} \ -lpthread \ -L${TESTDIR} -lvproc -l:PyVProc.so \ -Wl,-no-whole-archive \ -o $@ ${PYVRPOC_PLI}: ${PYSRCDIR}/${PYTHON_C} @${CC} -fPIC -shared -DNO_PLI_INCLUDE \ $^ \ -I../../code -L../../ \ ${ARCHFLAG} \ -I${PYTHONHOME}/include/${PYVER} \ -L${PYTHONHOME}/lib -l${PYVER} \ -ldl \ -o $@ # Analyse the VHDL files .PHONY: vhdl vhdl: ${VPROC_PLI} @nvc --std=08 -a -f files_nvc.tcl -e ${VPROC_TOP} #------------------------------------------------------ # EXECUTION RULES #------------------------------------------------------ run: vhdl @nvc -r ${SIMFLAGS} rungui: vhdl @nvc -r ${SIMFLAGS} @if [ -e ${WAVESAVEFILE} ]; then \ gtkwave -A ${WAVEFILE}; \ else \ gtkwave ${WAVEFILE}; \ fi gui: rungui .SILENT: help: @$(info make help Display this message) @$(info make Build C/C++ and HDL code without running simulation) @$(info make run Build and run batch simulation) @$(info make rungui/gui Build and run GUI simulation) @$(info make clean clean previous build artefacts) #------------------------------------------------------ # CLEANING RULES #------------------------------------------------------ clean: @rm -rf ${VPROC_PLI} ${PYVRPOC_PLI} ${VLIB} ${VOBJDIR} waves.fst work