]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/configure
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / configure
CommitLineData
7c673cae
FG
1#!/usr/bin/env bash
2
3set -e
4
11fdf7f2
TL
5trap 'echo -e "\n\nConfiguration failed\n\n" >&2' ERR
6
7c673cae
FG
7function usage()
8{
9 echo "'configure' configures SPDK to compile on supported platforms."
10 echo ""
11 echo "Usage: ./configure [OPTION]..."
12 echo ""
13 echo "Defaults for the options are specified in brackets."
14 echo ""
15 echo "General:"
16 echo " -h, --help Display this help and exit"
11fdf7f2
TL
17 echo ""
18 echo " --prefix=path Configure installation prefix (default: /usr/local)"
19 echo ""
7c673cae 20 echo " --enable-debug Configure for debug builds"
11fdf7f2 21 echo " --enable-log-bt Enable support of backtrace printing in SPDK logs (requires libunwind)."
7c673cae
FG
22 echo " --enable-werror Treat compiler warnings as errors"
23 echo " --enable-asan Enable address sanitizer"
24 echo " --enable-ubsan Enable undefined behavior sanitizer"
25 echo " --enable-coverage Enable code coverage tracking"
11fdf7f2 26 echo " --enable-lto Enable link-time optimization"
9f95a23c
TL
27 echo " --enable-pgo-capture Enable generation of profile guided optimization data"
28 echo " --enable-pgo-use Use previously captured profile guided optimization data"
11fdf7f2 29 echo " --disable-tests Disable building of tests"
7c673cae
FG
30 echo ""
31 echo "Specifying Dependencies:"
32 echo "--with-DEPENDENCY[=path] Use the given dependency. Optionally, provide the"
33 echo " path."
34 echo "--without-DEPENDENCY Do not link to the given dependency. This may"
35 echo " disable features and components."
36 echo ""
37 echo "Valid dependencies are listed below."
11fdf7f2 38 echo " dpdk Optional. Uses dpdk submodule in spdk tree if not specified."
7c673cae 39 echo " example: /usr/share/dpdk/x86_64-default-linuxapp-gcc"
9f95a23c
TL
40 echo " env Use an alternate environment implementation instead of DPDK."
41 echo " Implies --without-dpdk."
42 echo " igb-uio-driver Build and use DPDK's igb-uio driver instead of uio_pci_generic"
43 echo " or vfio-pci. Required on some systems to use qat devices"
44 echo " No path required"
45 echo " crypto Required to build vbdev crypto module."
46 echo " No path required."
7c673cae
FG
47 echo " fio Required to build fio_plugin."
48 echo " example: /usr/src/fio"
11fdf7f2
TL
49 echo " vhost Required to build vhost target."
50 echo " No path required."
9f95a23c
TL
51 echo " internal-vhost-lib Use the internal copy of rte_vhost."
52 echo " No path required."
11fdf7f2
TL
53 echo " virtio Required to build vhost initiator (Virtio) bdev module."
54 echo " No path required."
55 echo " pmdk Required to build persistent memory bdev."
56 echo " example: /usr/share/pmdk"
9f95a23c
TL
57 echo " reduce Required to build vbdev compression module."
58 echo " No path required."
11fdf7f2 59 echo " vpp Required to build VPP net module."
9f95a23c 60 echo " example: /vpp_repo/build-root/rpmbuild/vpp-18.01.1.0/build-root/install-vpp-native/vpp"
7c673cae
FG
61 echo " rbd [disabled]"
62 echo " No path required."
63 echo " rdma [disabled]"
64 echo " No path required."
11fdf7f2
TL
65 echo " shared Required to build spdk shared libraries."
66 echo " No path required."
67 echo " iscsi-initiator [disabled]"
68 echo " No path required."
69 echo " vtune Required to profile I/O under Intel VTune Amplifier XE."
70 echo " example: /opt/intel/vtune_amplifier_xe_version"
9f95a23c
TL
71 echo " ocf Required to build OCF module."
72 echo " If argument is directory, interpret it as root of OCF repo"
73 echo " If argument is file, interpret it as compiled OCF lib"
74 echo " If no argument is specified, OCF git submodule is used by default"
75 echo " example: /usr/src/ocf/"
76 echo " isal Enabled by default on x86 architecture. Can be built without though."
77 echo " No path required."
78 echo " uring Required to support I/O uring on Linux. If no argument, searches"
79 echo " the standard installation directory. If an argument is provided, it is"
80 echo " considered a directory containing liburing.a and io_uring.h."
11fdf7f2
TL
81 echo ""
82 echo "Environment variables:"
83 echo ""
84 echo "CFLAGS C compiler flags"
85 echo "CXXFLAGS C++ compiler flags"
86 echo "LDFLAGS Linker flags"
87 echo "DESTDIR Destination for 'make install'"
7c673cae
FG
88 echo ""
89}
90
11fdf7f2
TL
91# Load default values
92# Convert config to sourcable configuration file
93sed -r 's/CONFIG_([[:alnum:]_]+)=(.*)/CONFIG[\1]=\2/g' CONFIG > CONFIG.sh
94declare -A CONFIG
95source CONFIG.sh
96rm CONFIG.sh
97
9f95a23c 98BUILD_CMD="${CC:-cc} -o /dev/null -x c $CPPFLAGS $CFLAGS $LDFLAGS"
11fdf7f2
TL
99
100function check_dir() {
101 arg="$1"
102 dir="${arg#*=}"
103 if [ ! -d "$dir" ]; then
104 echo "$arg: directory not found"
105 exit 1
106 fi
107}
108
7c673cae
FG
109for i in "$@"; do
110 case "$i" in
111 -h|--help)
112 usage
113 exit 0
114 ;;
11fdf7f2
TL
115 --prefix=*)
116 CONFIG[PREFIX]="${i#*=}"
117 ;;
7c673cae 118 --enable-debug)
11fdf7f2 119 CONFIG[DEBUG]=y
7c673cae
FG
120 ;;
121 --disable-debug)
11fdf7f2
TL
122 CONFIG[DEBUG]=n
123 ;;
124 --enable-log-bt)
125 CONFIG[LOG_BACKTRACE]=y
126 ;;
127 --disable-log-bt)
128 CONFIG[LOG_BACKTRACE]=n
7c673cae
FG
129 ;;
130 --enable-asan)
11fdf7f2 131 CONFIG[ASAN]=y
7c673cae
FG
132 ;;
133 --disable-asan)
11fdf7f2 134 CONFIG[ASAN]=n
7c673cae
FG
135 ;;
136 --enable-ubsan)
11fdf7f2 137 CONFIG[UBSAN]=y
7c673cae
FG
138 ;;
139 --disable-ubsan)
11fdf7f2
TL
140 CONFIG[UBSAN]=n
141 ;;
142 --enable-tsan)
143 CONFIG[TSAN]=y
144 ;;
145 --disable-tsan)
146 CONFIG[TSAN]=n
7c673cae
FG
147 ;;
148 --enable-coverage)
11fdf7f2 149 CONFIG[COVERAGE]=y
7c673cae
FG
150 ;;
151 --disable-coverage)
11fdf7f2
TL
152 CONFIG[COVERAGE]=n
153 ;;
154 --enable-lto)
155 CONFIG[LTO]=y
156 ;;
157 --disable-lto)
158 CONFIG[LTO]=n
159 ;;
9f95a23c
TL
160 --enable-pgo-capture)
161 CONFIG[PGO_CAPTURE]=y
162 ;;
163 --disable-pgo-capture)
164 CONFIG[PGO_CAPTURE]=n
165 ;;
166 --enable-pgo-use)
167 CONFIG[PGO_USE]=y
168 ;;
169 --disable-pgo-use)
170 CONFIG[PGO_USE]=n
171 ;;
11fdf7f2
TL
172 --enable-tests)
173 CONFIG[TESTS]=y
174 ;;
175 --disable-tests)
176 CONFIG[TESTS]=n
7c673cae
FG
177 ;;
178 --enable-werror)
11fdf7f2 179 CONFIG[WERROR]=y
7c673cae
FG
180 ;;
181 --disable-werror)
11fdf7f2 182 CONFIG[WERROR]=n
7c673cae 183 ;;
9f95a23c
TL
184 --with-dpdk=*)
185 check_dir "$i"
186 CONFIG[DPDK_DIR]=$(readlink -f ${i#*=})
187 ;;
188 --without-dpdk)
189 CONFIG[DPDK_DIR]=
190 ;;
7c673cae 191 --with-env=*)
11fdf7f2 192 CONFIG[ENV]="${i#*=}"
7c673cae
FG
193 ;;
194 --with-rbd)
11fdf7f2 195 CONFIG[RBD]=y
7c673cae
FG
196 ;;
197 --without-rbd)
11fdf7f2
TL
198 CONFIG[RBD]=n
199 ;;
7c673cae 200 --with-rdma)
11fdf7f2 201 CONFIG[RDMA]=y
7c673cae
FG
202 ;;
203 --without-rdma)
11fdf7f2
TL
204 CONFIG[RDMA]=n
205 ;;
206 --with-shared)
207 CONFIG[SHARED]=y
208 ;;
209 --without-shared)
210 CONFIG[SHARED]=n
211 ;;
212 --with-iscsi-initiator)
213 CONFIG[ISCSI_INITIATOR]=y
214 ;;
215 --without-iscsi-initiator)
216 CONFIG[ISCSI_INITIATOR]=n
7c673cae 217 ;;
11fdf7f2
TL
218 --with-crypto)
219 CONFIG[CRYPTO]=y
220 ;;
221 --without-crypto)
222 CONFIG[CRYPTO]=n
223 ;;
224 --with-vhost)
225 CONFIG[VHOST]=y
226 ;;
227 --without-vhost)
228 CONFIG[VHOST]=n
229 ;;
9f95a23c
TL
230 --with-internal-vhost-lib)
231 CONFIG[VHOST_INTERNAL_LIB]=y
232 ;;
233 --without-internal-vhost-lib)
234 CONFIG[VHOST_INTERNAL_LIB]=n
235 ;;
11fdf7f2
TL
236 --with-virtio)
237 CONFIG[VIRTIO]=y
238 ;;
239 --without-virtio)
240 CONFIG[VIRTIO]=n
241 ;;
242 --with-pmdk)
243 CONFIG[PMDK]=y
244 CONFIG[PMDK_DIR]=""
245 ;;
246 --with-pmdk=*)
247 CONFIG[PMDK]=y
248 check_dir "$i"
249 CONFIG[PMDK_DIR]=$(readlink -f ${i#*=})
250 ;;
251 --without-pmdk)
252 CONFIG[PMDK]=n
253 ;;
9f95a23c
TL
254 --with-reduce)
255 CONFIG[REDUCE]=y
256 ;;
257 --without-reduce)
258 CONFIG[REDUCE]=n
259 ;;
11fdf7f2
TL
260 --with-vpp)
261 CONFIG[VPP]=y
262 ;;
263 --with-vpp=*)
264 CONFIG[VPP]=y
265 check_dir "$i"
266 CONFIG[VPP_DIR]=$(readlink -f ${i#*=})
267 ;;
268 --without-vpp)
269 CONFIG[VPP]=n
7c673cae
FG
270 ;;
271 --with-fio=*)
11fdf7f2
TL
272 check_dir "$i"
273 CONFIG[FIO_SOURCE_DIR]="${i#*=}"
274 CONFIG[FIO_PLUGIN]=y
7c673cae
FG
275 ;;
276 --without-fio)
11fdf7f2
TL
277 CONFIG[FIO_SOURCE_DIR]=
278 CONFIG[FIO_PLUGIN]=n
279 ;;
280 --with-vtune=*)
281 check_dir "$i"
282 CONFIG[VTUNE_DIR]="${i#*=}"
283 CONFIG[VTUNE]=y
284 ;;
285 --without-vtune)
286 CONFIG[VTUNE_DIR]=
287 CONFIG[VTUNE]=n
288 ;;
289 --with-igb-uio-driver)
290 CONFIG[IGB_UIO_DRIVER]=y
291 ;;
292 --without-igb-uio-driver)
293 CONFIG[IGB_UIO_DRIVER]=n
7c673cae 294 ;;
9f95a23c
TL
295 --with-ocf)
296 CONFIG[OCF]=y
297 CONFIG[OCF_PATH]=$(readlink -f "./ocf")
298 ;;
299 --with-ocf=*)
300 CONFIG[OCF]=y
301 CONFIG[OCF_PATH]=$(readlink -f ${i#*=})
302 ;;
303 --without-ocf)
304 CONFIG[OCF]=n
305 CONFIG[OCF_PATH]=
306 ;;
307 --with-isal)
308 CONFIG[ISAL]=y
309 ;;
310 --without-isal)
311 CONFIG[ISAL]=n
312 ;;
313 --with-uring=*)
314 CONFIG[URING]=y
315 CONFIG[URING_PATH]=$(readlink -f ${i#*=})
316 ;;
317 --with-uring)
318 CONFIG[URING]=y
319 CONFIG[URING_PATH]=
320 ;;
321 --without-uring)
322 CONFIG[URING]=n
323 CONFIG[URING_PATH]=
324 ;;
7c673cae
FG
325 --)
326 break
327 ;;
328 *)
329 echo "Unrecognized option $i"
330 usage
331 exit 1
332 esac
333done
334
9f95a23c
TL
335# Detect architecture and force no isal if non x86 archtecture
336arch=$(uname -m)
337if [[ $arch != x86_64* ]]; then
338 echo "Notice: ISAL auto-disabled due to CPU incompatiblity."
339 CONFIG[ISAL]=n
340fi
341
342if [[ "${CONFIG[ISAL]}" = "n" ]] && [[ "${CONFIG[REDUCE]}" = "y" ]]; then
343 echo "ERROR Conflicting options: --with-reduce is not compatible with --without-isal."
344 exit 1
345fi
346
11fdf7f2
TL
347if [ -z "${CONFIG[ENV]}" ]; then
348 rootdir=$(readlink -f $(dirname $0))
349 CONFIG[ENV]=$rootdir/lib/env_dpdk
350 echo "Using default SPDK env in ${CONFIG[ENV]}"
351 if [ -z "${CONFIG[DPDK_DIR]}" ]; then
352 if [ ! -f "$rootdir"/dpdk/config/common_base ]; then
353 echo "DPDK not found; please specify --with-dpdk=<path> or run:"
354 echo
355 echo " git submodule update --init"
356 exit 1
357 else
358 CONFIG[DPDK_DIR]="${rootdir}/dpdk/build"
359 echo "Using default DPDK in ${CONFIG[DPDK_DIR]}"
360 fi
9f95a23c
TL
361
362 if [[ "${CONFIG[VHOST]}" = "y" ]] && [[ "${CONFIG[VHOST_INTERNAL_LIB]}" = "n" ]]; then
363 # We lookup "common_linux" file to check if DPDK version is >= 19.05.
364 # "common_linux" is available since exactly DPDK 19.05 - it was renamed
365 # from "common_linuxapp".
366 if [ ! -f "$rootdir"/dpdk/config/common_linux ]; then
367 echo "Notice: Using internal, legacy rte_vhost library due to DPDK" \
368 "version < 19.05"
369 CONFIG[VHOST_INTERNAL_LIB]=y
370 fi
371 fi
372 else
373 if [[ "${CONFIG[VHOST]}" = "y" ]] && [[ "${CONFIG[VHOST_INTERNAL_LIB]}" = "n" ]]; then
374 # DPDK must be already built, so we can simply try to use the new rte_vhost.
375 # It has a number of internal dependencies though, so don't try to link the
376 # program, just compile it
377 if ! echo -e '#include <rte_vhost.h>\n' \
378 'int main(void) { return rte_vhost_extern_callback_register(0, NULL, NULL); }\n' \
379 | $BUILD_CMD -c -Wno-deprecated-declarations -I"${CONFIG[DPDK_DIR]}/include" -; then
380 echo "Notice: DPDK's rte_vhost not found or version < 19.05, using internal," \
381 "legacy rte_vhost library."
382 CONFIG[VHOST_INTERNAL_LIB]=y
383 fi
384 fi
7c673cae 385 fi
11fdf7f2 386else
9f95a23c
TL
387 if [ -n "${CONFIG[DPDK_DIR]}" ]; then
388 echo "--with-env and --with-dpdk are mutually exclusive."
389 exit 1
390 fi
391
11fdf7f2
TL
392 if [ "${CONFIG[VHOST]}" = "y" ]; then
393 echo "Vhost is only supported when using the default DPDK environment. Disabling it."
394 fi
395 # Always disable vhost, but only print the error message if the user explicitly turned it on.
396 CONFIG[VHOST]="n"
397 if [ "${CONFIG[VIRTIO]}" = "y" ]; then
398 echo "Virtio is only supported when using the default DPDK environment. Disabling it."
399 fi
400 # Always disable virtio, but only print the error message if the user explicitly turned it on.
401 CONFIG[VIRTIO]="n"
7c673cae
FG
402fi
403
11fdf7f2
TL
404if [ "${CONFIG[FIO_PLUGIN]}" = "y" ]; then
405 if [ -z "${CONFIG[FIO_SOURCE_DIR]}" ]; then
7c673cae
FG
406 echo "When fio is enabled, you must specify the fio directory using --with-fio=path"
407 exit 1
408 fi
11fdf7f2
TL
409else
410 CONFIG[FIO_SOURCE_DIR]=
7c673cae
FG
411fi
412
11fdf7f2
TL
413if [ "${CONFIG[VTUNE]}" = "y" ]; then
414 if [ -z "${CONFIG[VTUNE_DIR]}" ]; then
415 echo "When VTune is enabled, you must specify the VTune directory using --with-vtune=path"
416 exit 1
417 fi
7c673cae 418fi
11fdf7f2
TL
419
420if [ "${CONFIG[ASAN]}" = "y" -a "${CONFIG[TSAN]}" = "y" ]; then
421 echo "ERROR: ASAN and TSAN cannot be enabled at the same time."
422 exit 1
7c673cae 423fi
11fdf7f2
TL
424
425if [[ "$OSTYPE" == "freebsd"* ]]; then
426 # FreeBSD doesn't support all configurations
427 if [[ "${CONFIG[COVERAGE]}" == "y" ]]; then
428 echo "ERROR: CONFIG_COVERAGE not available on FreeBSD"
429 exit 1
430 fi
7c673cae 431fi
11fdf7f2
TL
432
433if [ "${CONFIG[RDMA]}" = "y" ]; then
9f95a23c
TL
434 if ! echo -e '#include <infiniband/verbs.h>\n#include <rdma/rdma_verbs.h>\n' \
435 'int main(void) { return 0; }\n' \
436 | $BUILD_CMD -libverbs -lrdmacm - 2>/dev/null; then
437 echo --with-rdma requires libverbs and librdmacm.
438 echo Please install then re-run this script.
439 exit 1
440 fi
441
442 if echo -e '#include <infiniband/verbs.h>\n' \
443 'int main(void) { return !!IBV_WR_SEND_WITH_INV; }\n' \
444 | $BUILD_CMD -c - 2>/dev/null; then
445 CONFIG[RDMA_SEND_WITH_INVAL]="y"
446 else
447 CONFIG[RDMA_SEND_WITH_INVAL]="n"
448 echo "
11fdf7f2
TL
449*******************************************************************************
450WARNING: The Infiniband Verbs opcode Send With Invalidate is either not
451supported or is not functional with the current version of libibverbs installed
452on this system. Please upgrade to at least version 1.1.
453
454Beginning with Linux kernel 4.14, the kernel NVMe-oF initiator leverages Send
455With Invalidate RDMA operations to improve performance. Failing to use the
456Send With Invalidate operation on the NVMe-oF target side results in full
457functionality, but greatly reduced performance. The SPDK NVMe-oF target will
458be unable to leverage that operation using the currently installed version
459of libibverbs, so Linux kernel NVMe-oF initiators based on kernels greater
460than or equal to 4.14 will see significantly reduced performance.
461*******************************************************************************"
9f95a23c
TL
462 fi
463fi
464
465if [[ "${CONFIG[ISAL]}" = "y" ]] || [[ "${CONFIG[CRYPTO]}" = "y" ]]; then
466 ver=$(nasm -v | awk '{print $3}' | sed 's/[^0-9]*//g')
467 if [[ "${ver:0:1}" -le "2" ]] && [[ "${ver:0:3}" -le "213" ]] && [[ "${ver:0:5}" -lt "21303" ]]; then
468 echo "Notice: ISA-L, compression & crypto auto-disabled due to nasm dependency."
469 echo "These features require NASM version 2.13.03 or newer. Please install"
470 echo "or upgrade then re-run this script."
471 CONFIG[ISAL]=n
472 CONFIG[CRYPTO]=n
473 CONFIG[IPSEC_MB]=n
474 CONFIG[REDUCE]=n
475 else
476 if [[ "${CONFIG[CRYPTO]}" = "y" ]]; then
477 CONFIG[IPSEC_MB]=y
11fdf7f2
TL
478 fi
479 fi
7c673cae 480fi
11fdf7f2 481
9f95a23c
TL
482if [[ "${CONFIG[ISAL]}" = "y" ]]; then
483 if [ ! -f "$rootdir"/isa-l/autogen.sh ]; then
484 echo "ISA-L was not found; To install ISA-L run:"
485 echo " git submodule update --init"
11fdf7f2 486 exit 1
9f95a23c
TL
487 fi
488
489 if [[ "${CONFIG[RBD]}" = "y" ]]; then
490 echo "ISAL and RBD cannot co-exist currently so disabling ISAL and compression."
491 CONFIG[ISAL]=n
492 CONFIG[REDUCE]=n
493 else
494 cd $rootdir/isa-l
495 ISAL_LOG=/tmp/spdk-isal.log
496 echo -n "Configuring ISA-L (logfile: $ISAL_LOG)..."
497 ./autogen.sh &> $ISAL_LOG
498 ./configure CFLAGS="-fPIC -g -O2" --enable-shared=no >> $ISAL_LOG 2>&1
499 echo "done."
500 cd $rootdir
501 fi
502fi
503
504if [[ "${CONFIG[PMDK]}" = "y" ]]; then
505 if ! echo -e '#include <libpmemblk.h>\nint main(void) { return 0; }\n' \
506 | $BUILD_CMD -lpmemblk - 2>/dev/null; then
507 echo --with-pmdk requires libpmemblk.
508 echo Please install then re-run this script.
509 exit 1
510 fi
511fi
512
513if [[ "${CONFIG[REDUCE]}" = "y" ]]; then
514 if ! echo -e '#include <libpmem.h>\nint main(void) { return 0; }\n' \
515 | $BUILD_CMD -lpmem - 2>/dev/null; then
516 echo --with-reduce requires libpmem.
517 echo Please install then re-run this script.
518 exit 1
519 fi
520fi
521
522if [[ "${CONFIG[RBD]}" = "y" ]]; then
523 if ! echo -e '#include <rbd/librbd.h>\n#include <rados/librados.h>\n' \
524 'int main(void) { return 0; }\n' \
525 | $BUILD_CMD -lrados -lrbd - 2>/dev/null; then
526 echo --with-rbd requires librados and librbd.
527 echo Please install then re-run this script.
528 exit 1
529 fi
530fi
531
532if [[ "${CONFIG[ISCSI_INITIATOR]}" = "y" ]]; then
533 # Fedora installs libiscsi to /usr/lib64/iscsi for some reason.
534 if ! echo -e '#include <iscsi/iscsi.h>\n#include <iscsi/scsi-lowlevel.h>\n' \
535 '#if LIBISCSI_API_VERSION < 20150621\n' \
536 '#error\n' \
537 '#endif\n' \
538 'int main(void) { return 0; }\n' \
539 | $BUILD_CMD -L/usr/lib64/iscsi -liscsi - 2>/dev/null; then
540 echo --with-iscsi-initiator requires libiscsi with
541 echo 'LIBISCSI_API_VERSION >= 20150621.'
542 echo Please install then re-run this script.
543 exit 1
544 fi
545fi
546
547if [[ "${CONFIG[LOG_BACKTRACE]}" = "y" ]]; then
548 if ! echo -e '#include <libunwind.h>\nint main(void) { return 0; }\n' \
549 | $BUILD_CMD -lunwind - 2>/dev/null; then
550 echo --enable-log-bt requires libunwind.
551 echo Please install then re-run this script.
552 exit 1
553 fi
554fi
555
556if [[ "${CONFIG[ASAN]}" = "y" ]]; then
557 if ! echo -e 'int main(void) { return 0; }\n' \
558 | $BUILD_CMD -fsanitize=address - 2>/dev/null; then
559 echo --enable-asan requires libasan.
560 echo Please install then re-run this script.
561 exit 1
562 fi
563fi
564
565if [[ "${CONFIG[UBSAN]}" = "y" ]]; then
566 if ! echo -e 'int main(void) { return 0; }\n' \
567 | $BUILD_CMD -fsanitize=undefined - 2>/dev/null; then
568 echo --enable-ubsan requires libubsan.
569 echo Please install then re-run this script.
570 exit 1
571 fi
572fi
573
574if [[ "${CONFIG[TSAN]}" = "y" ]]; then
575 if ! echo -e 'int main(void) { return 0; }\n' \
576 | $BUILD_CMD -fsanitize=thread - 2>/dev/null; then
577 echo --enable-tsan requires libtsan.
578 echo Please install then re-run this script.
579 exit 1
580 fi
581fi
582
583if [[ "${CONFIG[OCF]}" = "y" ]]; then
584 # If OCF_PATH is a file, assume it is a library and use it to compile with
585 if [ -f ${CONFIG[OCF_PATH]} ]; then
586 CONFIG[CUSTOMOCF]=y
587 else
588 CONFIG[CUSTOMOCF]=n
589 fi
590fi
591
592if [[ "${CONFIG[PGO_CAPTURE]}" = "y" && "${CONFIG[PGO_USE]}" = "y" ]]; then
593 echo "ERROR: --enable-pgo-capture and --enable-pgo-use are mutually exclusive."
594 exit 1
595elif [[ "${CONFIG[PGO_USE]}" = "y" ]]; then
596 CC_TYPE=$($rootdir/scripts/detect_cc.sh --cc=$CC --cxx=$CXX --lto=$CONFIG[LTO] --ld=$LD | grep "CC_TYPE" | cut -d "=" -f 2)
597 if [[ "$CC_TYPE" = "clang" ]]; then
598 # For clang we need to run an extra step on gathered profiling data.
599 echo "Generating suitable profile data"
600 llvm-profdata merge -output=build/pgo/default.profdata build/pgo
601 fi
602fi
603
604if [[ "${CONFIG[URING]}" = "y" ]]; then
605 if [[ -n "${CONFIG[URING_PATH]}" ]]; then
606 if [ ! -d "${CONFIG[URING_PATH]}" ]; then
607 echo "${CONFIG[URING_PATH]}: directory not found"
11fdf7f2
TL
608 exit 1
609 fi
610 fi
7c673cae 611fi
11fdf7f2
TL
612
613# We are now ready to generate final configuration. But first do sanity
614# check to see if all keys in CONFIG array have its reflection in CONFIG file.
615if [ $(egrep -c "^\s*CONFIG_[[:alnum:]_]+=" CONFIG) -ne ${#CONFIG[@]} ]; then
616 echo ""
617 echo "BUG: Some configuration options are not present in CONFIG file. Please update this file."
618 echo "Missing options in CONFIG (+) file and in current config (-): "
619 diff -u --label "CONFIG file" --label "CONFIG[@]" \
620 <(sed -r -e '/^\s*$/d; /^\s*#.*/d; s/(CONFIG_[[:alnum:]_]+)=.*/\1/g' CONFIG | sort) \
621 <(printf "CONFIG_%s\n" ${!CONFIG[@]} | sort)
622 exit 1
7c673cae
FG
623fi
624
11fdf7f2
TL
625echo -n "Creating mk/config.mk..."
626cp -f CONFIG mk/config.mk
627for key in ${!CONFIG[@]}; do
628 sed -i.bak -r "s#^\s*CONFIG_${key}=.*#CONFIG_${key}\?=${CONFIG[$key]}#g" mk/config.mk
629done
630# On FreeBSD sed -i 'SUFFIX' - SUFFIX is mandatory. So no way but to delete the backed file.
631rm -f mk/config.mk.bak
9f95a23c 632echo "done."
11fdf7f2
TL
633
634# Environment variables
9f95a23c
TL
635echo -n "Creating mk/cc.flags.mk..."
636rm -f mk/cc.flags.mk
637[ -n "$CFLAGS" ] && echo "CFLAGS?=$CFLAGS" > mk/cc.flags.mk
638[ -n "$CXXFLAGS" ] && echo "CXXFLAGS?=$CXXFLAGS" >> mk/cc.flags.mk
639[ -n "$LDFLAGS" ] && echo "LDFLAGS?=$LDFLAGS" >> mk/cc.flags.mk
640[ -n "$DESTDIR" ] && echo "DESTDIR?=$DESTDIR" >> mk/cc.flags.mk
7c673cae 641echo "done."
11fdf7f2
TL
642
643if [[ "$OSTYPE" == "freebsd"* ]]; then
644 echo "Type 'gmake' to build."
645else
646 echo "Type 'make' to build."
647fi
7c673cae
FG
648
649exit 0