Skip to content

Commit 727b5d5

Browse files
committedMay 7, 2021
Add makefiles
1 parent 1d7d73d commit 727b5d5

File tree

4 files changed

+166
-4
lines changed

4 files changed

+166
-4
lines changed
 

‎.gitignore

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# https://stackoverflow.com/a/25592735/1219634
2+
13
# Ignore all
24
*
35

@@ -7,9 +9,21 @@
79
# Unignore all dirs
810
!*/
911

10-
!LICENSE
12+
# Unignore make files
13+
!makefile
14+
!Makefile
1115

12-
.nimcache/
13-
*.so
1416
xcelium.d/
15-
xrun.*
17+
*.log
18+
*.so
19+
*.history
20+
.nimcache/
21+
sigusrdump.out
22+
work/
23+
xrun.key
24+
*.o
25+
*.a
26+
.bpad/
27+
.simvision/
28+
bpad*.err
29+
waves.shm/

‎makefile

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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.

‎tests/basic/Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Time-stamp: <2021-05-07 11:02:36 kmodi>
2+
3+
.DEFAULT_GOAL := default
4+
5+
GIT_ROOT = $(shell git rev-parse --show-toplevel)
6+
NIM_GC ?= arc
7+
8+
include $(GIT_ROOT)/makefile
9+
10+
default: nimcpp nc

‎tests/basic/orig/Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DEFAULT_GOAL := default
2+
3+
GIT_ROOT = $(shell git rev-parse --show-toplevel)
4+
5+
include $(GIT_ROOT)/makefile
6+
7+
default: clean clibvpi nc

0 commit comments

Comments
 (0)
Please sign in to comment.