# Standalone testbench build for the ZEMI3/DPI vhost demo.
#
# The testbench is a standalone executable (same pattern as the site
# B2B bench, ~/PCIe/C++/Makefile): it opens the board itself through
# ZEMI3Manager::open, so no zRci / tb.so is involved. It links against:
#   - the generated transactor glue $(ZEBU_WORK)/pcie_vhost_xtor.so
#     (built by compile.csh via dpixtor.mk; its header pcie_vhost_xtor.h
#     also lives in $(ZEBU_WORK) and is included by pcie_vhost_zebu.cpp)
#   - ZeBu runtime libs (libZebu, libZebuZEMI3, libZebuXtor)
# -rdynamic is required so the transactor glue can resolve the UDPI
# import functions implemented by pcie_vhost_zebu.cpp in the executable.
# ABI: ZeBu Q-2020.03 libraries are built with the pre-C++11 string ABI,
# so -D_GLIBCXX_USE_CXX11_ABI=0 is required (same as the site B2B bench).
#
# ZEBU_WORK must point at the inner zebu.work runtime database directory
# (absolute path).

ZEBU_ROOT ?= /eda_tools/synopsys/zebu/Q-2020.03-SP1
ZEBU_IP_ROOT ?= /eda_tools/synopsys/zebu_ip
ZEBU_WORK ?= ../../zebu.work/zebu.work

CXX      ?= g++
CXXFLAGS ?= -O2 -g -std=gnu++11 -fPIC -fexceptions -Wall \
            -Wno-write-strings -D_GLIBCXX_USE_CXX11_ABI=0

TARGET := pcie_vhost_tb
SRCS   := main.cpp pcie_vhost_zebu.cpp

all: $(TARGET)

$(TARGET): $(SRCS) pcie_vhost_api.h
	$(CXX) $(CXXFLAGS) -I$(ZEBU_ROOT)/include -I$(ZEBU_IP_ROOT)/include \
	    -I$(ZEBU_IP_ROOT)/XTOR/CAN_FD.Q-2021.03/include -I$(ZEBU_WORK) \
	    -rdynamic -o $@ $(SRCS) \
	    $(ZEBU_WORK)/pcie_vhost_xtor.so \
	    -L$(ZEBU_ROOT)/lib -lZebu -lZebuZEMI3 \
	    -L$(ZEBU_IP_ROOT)/lib -lZebuVpi -lZebuXtor \
	    -lpthread -ldl -lrt -lz

clean:
	rm -f $(TARGET) tb.so

.PHONY: all clean
