-
Notifications
You must be signed in to change notification settings - Fork 15
/
configure.sh
executable file
·193 lines (179 loc) · 4.61 KB
/
configure.sh
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
#!/bin/bash
set -eu
LLVM_VERSION=18
# Default values for all tunables.
TARGET="release"
ENABLE_ASSERTS="no"
LLVM_CONFIG_BIN="llvm-config-"${LLVM_VERSION}
ENABLE_COVERAGE="no"
ENABLE_HLS=
CIRCT_PATH="./usr"
CIRCT_LDFLAGS=
ENABLE_MLIR=
MLIR_PATH="./usr"
MLIR_LDFLAGS=
function usage()
{
echo "Usage: ./configure.sh [OPTION] [VAR=VALUE]"
echo ""
echo "The following options can be set, with defaults specified in brackets:"
echo " --target MODE Sets the build mode. Supported build modes are"
echo " 'debug' and 'release'. [${TARGET}]"
echo " --enable-asserts Enables asserts."
echo " --enable-hls[=PATH] Enable the HLS backend, and optionally sets a custom"
echo " path to the CIRCT installation. [${CIRCT_PATH}]"
echo " --llvm-config PATH The llvm-config script used to determine up llvm"
echo " build dependencies. [${LLVM_CONFIG_BIN}]"
echo " --enable-mlir[=PATH] Enables the MLIR Dialect, and optionally sets a custom"
echo " path to the MLIR dialect installation. [${MLIR_PATH}]"
echo " --enable-coverage Enable test coverage computation target."
echo " --help Prints this message and stops."
echo
echo "Influential variables that can be set:"
echo " CXX C++ compiler command"
echo " CXXFLAGS C++ compiler flags"
}
while [[ "$#" -ge 1 ]] ; do
case "$1" in
--target)
shift
TARGET="$1"
shift
;;
--enable-hls)
ENABLE_HLS="yes"
shift
;;
--enable-hls=*)
ENABLE_HLS="yes"
CIRCT_PATH="${1#*=}"
shift
;;
--enable-asserts)
ENABLE_ASSERTS="yes"
shift
;;
--llvm-config)
shift
LLVM_CONFIG_BIN="$1"
shift
;;
--enable-mlir)
ENABLE_MLIR="yes"
shift
;;
--enable-mlir=*)
ENABLE_MLIR="yes"
MLIR_PATH="${1#*=}"
shift
;;
--enable-coverage)
ENABLE_COVERAGE="yes"
shift
;;
-*) # Any unknown option triggers the usage text. This includes --help and -h
usage >&2
exit 1
;;
*=*)
VARNAME=${1%%=*}
VARVAL=${1#*=}
eval "${VARNAME}"="${VARVAL}"
shift
;;
*)
usage >&2
exit 1
;;
esac
done
CXXFLAGS_COMMON="--std=c++17 -Wall -Wpedantic -Wextra -Wno-unused-parameter -Werror -Wfatal-errors -gdwarf-4 -g"
CPPFLAGS_COMMON="-I. -Itests"
CPPFLAGS_LLVM=$(${LLVM_CONFIG_BIN} --cflags)
CXXFLAGS_TARGET=""
if [ "${TARGET}" == "release" ] ; then
CXXFLAGS_TARGET="-O3"
elif [ "${TARGET}" == "debug" ] ; then
CXXFLAGS_TARGET="-O0"
else
echo "No build type set. Please select either 'debug' or 'release'." >&2
exit 1
fi
CPPFLAGS_ASSERTS=""
if [ "${ENABLE_ASSERTS}" == "yes" ] ; then
CPPFLAGS_ASSERTS="-DJLM_ENABLE_ASSERTS"
fi
CPPFLAGS_CIRCT=""
CXXFLAGS_NO_COMMENT=""
if [ "${ENABLE_HLS}" == "yes" ] ; then
CPPFLAGS_CIRCT="-I${CIRCT_PATH}/include"
CXXFLAGS_NO_COMMENT="-Wno-error=comment"
CIRCT_LDFLAGS_ARRAY=(
"-L${CIRCT_PATH}/lib"
"-lCIRCTAnalysisTestPasses"
"-lCIRCTDependenceAnalysis"
"-lCIRCTExportFIRRTL"
"-lCIRCTScheduling"
"-lCIRCTSchedulingAnalysis"
"-lCIRCTFirtool"
"-lCIRCTFIRRTLReductions"
"-lCIRCTFIRRTLToHW"
"-lCIRCTExportVerilog"
"-lCIRCTImportFIRFile"
"-lCIRCTFIRRTLTransforms"
"-lCIRCTHWTransforms"
"-lCIRCTOMTransforms"
"-lCIRCTSim"
"-lCIRCTSVTransforms"
"-lCIRCTTransforms"
"-lCIRCTTargetDebugInfo"
"-lCIRCTSV"
"-lCIRCTComb"
"-lCIRCTSupport"
"-lCIRCTDebug"
"-lCIRCTLTL"
"-lCIRCTVerif"
"-lCIRCTFIRRTL"
"-lCIRCTSeq"
"-lCIRCTSeqToSV"
"-lCIRCTSeqTransforms"
"-lCIRCTHW"
"-lCIRCTVerifToSV"
"-lCIRCTSimToSV"
"-lCIRCTExportChiselInterface"
"-lCIRCTOM"
"-lMLIR"
)
fi
CPPFLAGS_MLIR=""
if [ "${ENABLE_MLIR}" == "yes" ] ; then
CPPFLAGS_MLIR="-I${MLIR_PATH}/include -DENABLE_MLIR"
CXXFLAGS_NO_COMMENT="-Wno-error=comment"
MLIR_LDFLAGS="-L${MLIR_PATH}/lib -lMLIRJLM -lMLIRRVSDG -lMLIR"
fi
if [ "${ENABLE_COVERAGE}" == "yes" ] ; then
if ! which gcovr >/dev/null ; then
echo "Warning: gcovr is required for code coverage computation but could not be found on search path."
fi
fi
mkdir -p build-"${TARGET}"
rm -rf build ; ln -sf build-"${TARGET}" build
(
cat <<EOF
CXXFLAGS=${CXXFLAGS-} ${CXXFLAGS_COMMON} ${CXXFLAGS_TARGET} ${CXXFLAGS_NO_COMMENT}
CPPFLAGS=${CPPFLAGS-} ${CPPFLAGS_COMMON} ${CPPFLAGS_LLVM} ${CPPFLAGS_ASSERTS} ${CPPFLAGS_CIRCT} ${CPPFLAGS_MLIR}
ENABLE_HLS=${ENABLE_HLS}
CIRCT_PATH=${CIRCT_PATH}
CIRCT_LDFLAGS=${CIRCT_LDFLAGS_ARRAY[*]}
ENABLE_MLIR=${ENABLE_MLIR}
MLIR_PATH=${MLIR_PATH}
MLIR_LDFLAGS=${MLIR_LDFLAGS}
LLVMCONFIG=${LLVM_CONFIG_BIN}
LLVM_VERSION=${LLVM_VERSION}
ENABLE_COVERAGE=${ENABLE_COVERAGE}
export LD_LIBRARY_PATH=$(${LLVM_CONFIG_BIN} --libdir)
EOF
if [ ! -z "${CXX-}" ] ; then
echo "CXX=${CXX}"
fi
) > Makefile.config