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