forked from wyvernSemi/CoSim
-
Notifications
You must be signed in to change notification settings - Fork 2
/
makefile.ghdl
203 lines (180 loc) · 7.03 KB
/
makefile.ghdl
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File Name: makefile
# Purpose: make file for compiling GHDL cosimulation with
# callable simulator
# Revision: OSVVM MODELS STANDARD VERSION
#
# Maintainer: Simon Southwell email: [email protected]
# Contributor(s):
# Simon Southwell email: [email protected]
#
# Description
# Tcl procedures supporting compiling of Co-cimuation C/C++ code
# using make
#
# Revision History:
# Date Version Description
# 10/2022 2023.01 Initial version
#
# This file is part of OSVVM.
#
# Copyright (c) 2022 by [OSVVM Authors](AUTHORS.md)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# --------------------------------------------------------------------------
#
# User overridable variables: make VAR=NEW_VALUE ...
#
# OSVVMDIR : Absolute path to the OsvvmLibraries directory
# GHDLROOT : Absolute path to the GHDL lib directory
# USRCDIR : Directory containing the test source code
# TEST : The directory containing the test source code, relative to ${USRCDIR}
# COSIMDIR : The path to OsvvmLibraries/CoSim, if different from ${USRCDIR}
# OPDIR : Directory for compilation output, if not the directory from which make was run
# USRFLAGS : Additional user defined compile and link flags
# VHDLLIB : The path, relative to the run directory, to the VHDL_LIBS/<version>/ directory
# TBLIBRARY : Name of library containing top level test component
# TESTBENCH : Name of top level test component
# ADALIBPATH : Path to ADA library. Only really needed for MINGW. Version specific.
#
# This makefile assumes all the relevant OsvvmLibraries and test files
# have already been analysed into libraries in ${VHDLLIB}
#
# --------------------------------------------------------------------------
# Get OS type
OSTYPE:=$(shell uname)
# Set OS specific variables between Linux and Windows (MinGW)
ifeq (${OSTYPE}, Linux)
OSVVMDIR = /git/OsvvmLibraries
GHDLROOT = /usr/lib/ghdl
SIMEXE = ${LCTB}
OSGHDLFLAGS =
ADALIBPATH = /usr/lib/gcc/x86_64-linux-gnu/9/adalib/
else
OSVVMDIR = /c/git/OsvvmLibraries
GHDLROOT = /mingw64/lib/ghdl
SIMEXE = ${LCTB}.exe
OSGHDLFLAGS = -ldbghelp -Wl,--stack=0x2000000
ADALIBPATH = /mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/adalib/
endif
#
# User overridable variables (see above)
#
USRCDIR = ${OSVVMDIR}/CoSim
TEST = tests/ghdl_main
CTESTDIR = ${USRCDIR}/${TEST}
COSIMDIR = ${USRCDIR}
OPDIR = ${CURDIR}
USRFLAGS =
VHDLLIB = VHDL_LIBS/GHDL-3.0.0-dev
TBLIBRARY = osvvm_tbaxi4
TESTBENCH = TbAb_CoSim
#
# Directory with test code to be compiled
#
MAINSRC = main.cpp
#
# gcc linker flags required by GHDL code
#
GHDLFLAGS = -L ${ADALIBPATH} \
-L. \
${GHDLROOT}/libgrt.a \
-l:VProc.so -l:VUser.so \
-ldl \
-lpthread \
-lz \
${OSGHDLFLAGS}
#
# Test bench name in lower case
#
LCTB = $(shell echo ${TESTBENCH} | tr A-Z a-z)
#
# Compilation outputs
#
COSIMCODE = VProc.so
USRCODE = VUser.so
TBLIB = libtb.a
LIBELAB = libelab.a
#
# Compilers
#
CC = g++
AR = ar
MAKE = make
GHDL = ghdl
#------------------------------------------------------
# BUILD RULES
#------------------------------------------------------
all: ${SIMEXE}
#
# Co-simulation code compiled in the same way as normal, but with
# DISABLE_VUSERMAIN_THREAD defined
#
${USRCODE} ${COSIMCODE}:
@${MAKE} -C ${COSIMDIR} \
--no-print-directory \
SIM=GHDL \
USRCDIR=${CTESTDIR} \
OPDIR=${OPDIR} \
EXCLFILE=${MAINSRC} \
USRFLAGS="-I./include -L./lib -DGHDL -DDISABLE_VUSERMAIN_THREAD ${USRFLAGS}"
#
# Collect all the user objects in VHDL_LIBS and all the relevant objects
# for the libraries into a new static library
#
${TBLIB}: obj/${MAINSRC:%.cpp=%.o}
@rm -f $@
@${AR} crs $@ $<
@for i in `ls ${VHDLLIB}` ; \
do \
${AR} q $@ `find ${VHDLLIB}/$${i}/ -name "*.o"` ; \
done
@${AR} q $@ `find ${GHDLROOT}/std/v08/ ${GHDLROOT}/ieee/v08/ -name "*.o"`
#
# Elaborate the test bench to generate the top level object file
#
e~${LCTB}.o: ${COSIMCODE}
@${GHDL} -e --std=08 \
-Wl,-lpthread \
--work=${TBLIBRARY} \
--workdir=${VHDLLIB}/${TBLIBRARY}/v08 \
-P${VHDLLIB} \
${TESTBENCH}
#
# Create library from the elabrorated code
#
${LIBELAB}: e~${LCTB}.o
@rm -f $@
@${AR} crs $@ $<
# Remove executable generated by GHDL elaboration as this won't work
@rm -f ${LCTB}.exe
#
# Generate a new executable with all user code and the GHDL required libraries
#
${SIMEXE}: ${LIBELAB} ${TBLIB} ${USRCODE}
@${CC} -Wl,-whole-archive \
$< \
-Wl,-no-whole-archive \
${TBLIB} \
${GHDLFLAGS} \
-o $@
#
# Build rule for main source code
#
obj/${MAINSRC:%.cpp=%.o}: ${CTESTDIR}/${MAINSRC}
@g++ -c -I${COSIMDIR}/code $< -o $@
#------------------------------------------------------
# CLEANING RULES
#------------------------------------------------------
clean:
@rm -rf obj lib*.a ${TBLIB} ${COSIMCODE} ${USRCODE} ${SIMEXE} e~${LCTB}.o