|
| 1 | +# Time-stamp: <2021-05-07 14:15:50 kmodi> |
| 2 | +# Author : Kaushal Modi |
| 3 | + |
| 4 | +UVM ?= 0 |
| 5 | + |
| 6 | +FILES ?= tb.sv |
| 7 | +DEFINES = DEFINE_PLACEHOLDER |
| 8 | +# DSEM2009, DSEMEL: Don't keep on bugging by telling that SV 2009 is |
| 9 | +# being used. I know it already. |
| 10 | +# SPDUSD: Don't warn about unused include dirs. |
| 11 | +NOWARNS = -nowarn DSEM2009 -nowarn DSEMEL -nowarn SPDUSD |
| 12 | +NC_SWITCHES ?= |
| 13 | +NC_CLEAN ?= 1 |
| 14 | + |
| 15 | +# Subdirs contains a list of all directories containing a "Makefile". |
| 16 | +SUBDIRS = $(shell find . -name "Makefile" | sed 's|/Makefile||') |
| 17 | + |
| 18 | +GDB ?= 0 # When set to 1, enable gdb support for both nim and xrun |
| 19 | +VALG ?= 0 # When set to 1, enable valgrind |
| 20 | + |
| 21 | +NIM ?= nim |
| 22 | + |
| 23 | +ARCH ?= 64 |
| 24 | +ifeq ($(ARCH), 64) |
| 25 | + NIM_ARCH_FLAGS := |
| 26 | + NIM_SO := libvpi_64.so |
| 27 | + NC_ARCH_FLAGS := -64bit |
| 28 | + GCC_ARCH_FLAG := -m64 |
| 29 | +else |
| 30 | + NIM_ARCH_FLAGS := --cpu:i386 --passC:-m32 --passL:-m32 |
| 31 | + NIM_SO := libvpi_32.so |
| 32 | + NC_ARCH_FLAGS := |
| 33 | + GCC_ARCH_FLAG := -m32 |
| 34 | +endif |
| 35 | + |
| 36 | +DEFAULT_VPI_LIB ?= libvpi.so |
| 37 | +# Possible values of NIM_COMPILES_TO: c, cpp |
| 38 | +NIM_COMPILES_TO ?= c |
| 39 | +# See ./gc_crash_debug/README.org on why --gc:none is the default. |
| 40 | +NIM_GC ?= none |
| 41 | +NIM_RELEASE ?= 1 |
| 42 | +NIM_DEFINES ?= |
| 43 | +NIM_SWITCHES ?= |
| 44 | +NIM_THREADS ?= 0 |
| 45 | +NIM_DBG_DLL ?= 0 |
| 46 | + |
| 47 | +.PHONY: clean nim nimcpp clibvpi nc $(SUBDIRS) all valg |
| 48 | + |
| 49 | +clean: |
| 50 | + rm -rf *~ core simv* urg* *.log *.history \#*.* *.dump .simvision/ waves.shm/ \ |
| 51 | + core.* simv* csrc* *.tmp *.vpd *.key log temp .vcs* DVE* *~ \ |
| 52 | + INCA_libs xcelium.d *.o ./.nimcache sigusrdump.out \ |
| 53 | + .bpad/ bpad*.err |
| 54 | + |
| 55 | +# libvpi.nim -> libvpi.c -> $(DEFAULT_VPI_LIB) |
| 56 | +# --gc:none is needed else Nim tries to free memory allocated for |
| 57 | +# arrays and stuff by the simulator on SV side. |
| 58 | +# https://irclogs.nim-lang.org/21-01-2019.html#17:16:39 |
| 59 | +# Thanks to https://stackoverflow.com/a/15561911/1219634 for the trick to |
| 60 | +# modify Makefile vars within target definitions. |
| 61 | +nim: |
| 62 | + @find . \( -name libvpi.o -o -name $(NIM_SO) \) -delete |
| 63 | +ifeq ($(GDB), 1) |
| 64 | + $(eval NIM_SWITCHES += --debugger:native) |
| 65 | + $(eval NIM_SWITCHES += --listCmd) |
| 66 | + $(eval NIM_SWITCHES += --gcc.options.debug="-O0 -g3 -ggdb3") |
| 67 | + $(eval NIM_SWITCHES += --gcc.cpp.options.debug="-O0 -g3 -ggdb3") |
| 68 | +endif |
| 69 | +ifeq ($(NIM_THREADS), 1) |
| 70 | + $(eval NIM_SWITCHES += --threads:on) |
| 71 | +endif |
| 72 | +ifeq ($(NIM_RELEASE), 1) |
| 73 | + $(eval NIM_DEFINES += -d:release) |
| 74 | +endif |
| 75 | +ifeq ($(NIM_DBG_DLL), 1) |
| 76 | + $(eval NIM_DEFINES += -d:nimDebugDlOpen) |
| 77 | +endif |
| 78 | +ifeq ($(VALG), 1) |
| 79 | + $(eval NIM_DEFINES += -d:useSysAssert -d:useGcAssert) |
| 80 | +endif |
| 81 | +ifneq ($(NIM_GC),) |
| 82 | + $(eval NIM_SWITCHES += --gc:$(NIM_GC)) |
| 83 | +endif |
| 84 | + $(NIM) $(NIM_COMPILES_TO) --out:$(NIM_SO) --app:lib \ |
| 85 | + --nimcache:./.nimcache \ |
| 86 | + $(NIM_ARCH_FLAGS) $(NIM_DEFINES) \ |
| 87 | + $(NIM_SWITCHES) \ |
| 88 | + --hint[Processing]:off \ |
| 89 | + libvpi.nim |
| 90 | + |
| 91 | +nimcpp: |
| 92 | + $(MAKE) nim NIM_COMPILES_TO=cpp |
| 93 | + |
| 94 | +nc: |
| 95 | + ln -sf $(NIM_SO) $(DEFAULT_VPI_LIB) |
| 96 | +ifeq ($(UVM), 1) |
| 97 | + $(eval NC_SWITCHES += -uvm -uvmhome CDNS-1.2) |
| 98 | +endif |
| 99 | +ifeq ($(GDB), 1) |
| 100 | + $(eval NC_SWITCHES += -g -gdb) |
| 101 | +endif |
| 102 | +ifeq ($(VALG), 1) |
| 103 | + $(eval NC_SWITCHES += -valgrind) |
| 104 | +endif |
| 105 | +ifeq ($(NC_CLEAN), 1) |
| 106 | + $(eval NC_SWITCHES += -clean) |
| 107 | +endif |
| 108 | + xrun -sv $(NC_ARCH_FLAGS) \ |
| 109 | + -timescale 1ns/10ps \ |
| 110 | + +define+SHM_DUMP -debug \ |
| 111 | + +define+$(DEFINES) \ |
| 112 | + $(FILES) \ |
| 113 | + +incdir+./ \ |
| 114 | + $(NOWARNS) \ |
| 115 | + $(NC_SWITCHES) |
| 116 | + |
| 117 | +# libvpi.c -> $(DEFAULT_SV_LIB) |
| 118 | +# -I$(XCELIUM_ROOT)/../include for "vpi_user.h" |
| 119 | +clibvpi: |
| 120 | + @find . \( -name libvpi.o -o -name $(NIM_SO) \) -delete |
| 121 | + gcc -c -fPIC -I$(XCELIUM_ROOT)/../include libvpi.c $(GCC_ARCH_FLAG) -o libvpi.o |
| 122 | + gcc -shared -Wl,-soname,$(DEFAULT_SV_LIB) $(GCC_ARCH_FLAG) -o $(NIM_SO) libvpi.o |
| 123 | + @rm -f libvpi.o |
| 124 | + |
| 125 | +$(SUBDIRS): |
| 126 | + $(MAKE) -C $@ |
| 127 | + |
| 128 | +all: $(SUBDIRS) |
| 129 | + |
| 130 | +# Run "make ARCH=32" to build 32-bit libvpi_32.so and run 32-bit xrun. |
| 131 | +# Run "make" to build 64-bit libvpi_64.so and run 64-bit xrun. |
0 commit comments