configure: attempt to link against tcmalloc by default if available
[fio.git] / configure
1 #!/bin/sh
2 #
3 # Fio configure script. Heavily influenced by the manual qemu configure
4 # script. Sad this is easier than autoconf and enemies.
5 #
6
7 # set temporary file name
8 if test ! -z "$TMPDIR" ; then
9     TMPDIR1="${TMPDIR}"
10 elif test ! -z "$TEMPDIR" ; then
11     TMPDIR1="${TEMPDIR}"
12 else
13     TMPDIR1="/tmp"
14 fi
15
16 TMPC="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.c"
17 TMPC2="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}-2.c"
18 TMPO="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.o"
19 TMPE="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.exe"
20
21 # NB: do not call "exit" in the trap handler; this is buggy with some shells;
22 # see <1285349658-3122-1-git-send-email-loic.minier@linaro.org>
23 trap "rm -f $TMPC $TMPC2 $TMPO $TMPE" EXIT INT QUIT TERM
24
25 rm -rf config.log
26
27 config_host_mak="config-host.mak"
28 config_host_h="config-host.h"
29
30 rm -rf $config_host_mak
31 rm -rf $config_host_h
32
33 fatal() {
34   echo $@
35   echo "Configure failed, check config.log and/or the above output"
36   rm -rf $config_host_mak
37   rm -rf $config_host_h
38   exit 1
39 }
40
41 # Print result for each configuration test
42 print_config() {
43   printf "%-30s%s\n" "$1" "$2"
44 }
45
46 # Default CFLAGS
47 CFLAGS="-D_GNU_SOURCE -include config-host.h"
48 BUILD_CFLAGS=""
49
50 # Print a helpful header at the top of config.log
51 echo "# FIO configure log $(date)" >> config.log
52 printf "# Configured with:" >> config.log
53 printf " '%s'" "$0" "$@" >> config.log
54 echo >> config.log
55 echo "#" >> config.log
56
57 # Print configure header at the top of $config_host_h
58 echo "/*" > $config_host_h
59 echo " * Automatically generated by configure - do not modify" >> $config_host_h
60 printf " * Configured with:" >> $config_host_h
61 printf " * '%s'" "$0" "$@" >> $config_host_h
62 echo "" >> $config_host_h
63 echo " */" >> $config_host_h
64
65 do_cc() {
66     # Run the compiler, capturing its output to the log.
67     echo $cc "$@" >> config.log
68     $cc "$@" >> config.log 2>&1 || return $?
69     # Test passed. If this is an --enable-werror build, rerun
70     # the test with -Werror and bail out if it fails. This
71     # makes warning-generating-errors in configure test code
72     # obvious to developers.
73     if test "$werror" != "yes"; then
74         return 0
75     fi
76     # Don't bother rerunning the compile if we were already using -Werror
77     case "$*" in
78         *-Werror*)
79            return 0
80         ;;
81     esac
82     echo $cc -Werror "$@" >> config.log
83     $cc -Werror "$@" >> config.log 2>&1 && return $?
84     echo "ERROR: configure test passed without -Werror but failed with -Werror."
85     echo "This is probably a bug in the configure script. The failing command"
86     echo "will be at the bottom of config.log."
87     fatal "You can run configure with --disable-werror to bypass this check."
88 }
89
90 compile_object() {
91   do_cc $CFLAGS -c -o $TMPO $TMPC
92 }
93
94 compile_prog() {
95   local_cflags="$1"
96   local_ldflags="$2 $LIBS"
97   echo "Compiling test case $3" >> config.log
98   do_cc $CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
99 }
100
101 feature_not_found() {
102   feature=$1
103   packages=$2
104
105   echo "ERROR"
106   echo "ERROR: User requested feature $feature"
107   if test ! -z "$packages" ; then
108     echo "ERROR: That feature needs $packages installed"
109   fi
110   echo "ERROR: configure was not able to find it"
111   fatal "ERROR"
112 }
113
114 has() {
115   type "$1" >/dev/null 2>&1
116 }
117
118 check_define() {
119   cat > $TMPC <<EOF
120 #if !defined($1)
121 #error $1 not defined
122 #endif
123 int main(void)
124 {
125   return 0;
126 }
127 EOF
128   compile_object
129 }
130
131 output_sym() {
132   echo "$1=y" >> $config_host_mak
133   echo "#define $1" >> $config_host_h
134 }
135
136 targetos=""
137 cpu=""
138
139 # default options
140 show_help="no"
141 exit_val=0
142 gfio_check="no"
143 libhdfs="no"
144 pmemblk="no"
145 devdax="no"
146 pmem="no"
147 disable_lex=""
148 disable_pmem="no"
149 disable_native="no"
150 march_set="no"
151 libiscsi="no"
152 prefix=/usr/local
153
154 # parse options
155 for opt do
156   optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
157   case "$opt" in
158   --prefix=*) prefix="$optarg"
159   ;;
160   --cpu=*) cpu="$optarg"
161   ;;
162   #  esx is cross compiled and cannot be detect through simple uname calls
163   --esx)
164   esx="yes"
165   ;;
166   --cc=*) CC="$optarg"
167   ;;
168   --extra-cflags=*) CFLAGS="$CFLAGS $optarg"
169   ;;
170   --build-32bit-win) build_32bit_win="yes"
171   ;;
172   --target-win-ver=*) target_win_ver="$optarg"
173   ;;
174   --build-static) build_static="yes"
175   ;;
176   --enable-gfio) gfio_check="yes"
177   ;;
178   --disable-numa) disable_numa="yes"
179   ;;
180   --disable-rdma) disable_rdma="yes"
181   ;;
182   --disable-rados) disable_rados="yes"
183   ;;
184   --disable-rbd) disable_rbd="yes"
185   ;;
186   --disable-http) disable_http="yes"
187   ;;
188   --disable-gfapi) disable_gfapi="yes"
189   ;;
190   --enable-libhdfs) libhdfs="yes"
191   ;;
192   --disable-lex) disable_lex="yes"
193   ;;
194   --enable-lex) disable_lex="no"
195   ;;
196   --disable-shm) no_shm="yes"
197   ;;
198   --disable-optimizations) disable_opt="yes"
199   ;;
200   --disable-pmem) disable_pmem="yes"
201   ;;
202   --enable-cuda) enable_cuda="yes"
203   ;;
204   --disable-native) disable_native="yes"
205   ;;
206   --with-ime=*) ime_path="$optarg"
207   ;;
208   --enable-libiscsi) libiscsi="yes"
209   ;;
210   --disable-tcmalloc) disable_tcmalloc="yes"
211   ;;
212   --help)
213     show_help="yes"
214     ;;
215   *)
216   echo "Bad option $opt"
217   show_help="yes"
218   exit_val=1
219   esac
220 done
221
222 if test "$show_help" = "yes" ; then
223   echo "--prefix=               Use this directory as installation prefix"
224   echo "--cpu=                  Specify target CPU if auto-detect fails"
225   echo "--cc=                   Specify compiler to use"
226   echo "--extra-cflags=         Specify extra CFLAGS to pass to compiler"
227   echo "--build-32bit-win       Enable 32-bit build on Windows"
228   echo "--target-win-ver=       Minimum version of Windows to target (XP or 7)"
229   echo "--build-static          Build a static fio"
230   echo "--esx                   Configure build options for esx"
231   echo "--enable-gfio           Enable building of gtk gfio"
232   echo "--disable-numa          Disable libnuma even if found"
233   echo "--disable-rdma          Disable RDMA support even if found"
234   echo "--disable-rados         Disable Rados support even if found"
235   echo "--disable-rbd           Disable Rados Block Device even if found"
236   echo "--disable-http          Disable HTTP support even if found"
237   echo "--disable-gfapi         Disable gfapi"
238   echo "--enable-libhdfs        Enable hdfs support"
239   echo "--disable-lex           Disable use of lex/yacc for math"
240   echo "--disable-pmem          Disable pmem based engines even if found"
241   echo "--enable-lex            Enable use of lex/yacc for math"
242   echo "--disable-shm           Disable SHM support"
243   echo "--disable-optimizations Don't enable compiler optimizations"
244   echo "--enable-cuda           Enable GPUDirect RDMA support"
245   echo "--disable-native        Don't build for native host"
246   echo "--with-ime=             Install path for DDN's Infinite Memory Engine"
247   echo "--enable-libiscsi       Enable iscsi support"
248   echo "--disable-tcmalloc      Disable tcmalloc support"
249   exit $exit_val
250 fi
251
252 cross_prefix=${cross_prefix-${CROSS_COMPILE}}
253 # Preferred compiler (can be overriden later after we know the platform):
254 #  ${CC} (if set)
255 #  ${cross_prefix}gcc (if cross-prefix specified)
256 #  gcc if available
257 #  clang if available
258 if test -z "${CC}${cross_prefix}"; then
259   if has gcc; then
260     cc=gcc
261   elif has clang; then
262     cc=clang
263   fi
264 else
265   cc="${CC-${cross_prefix}gcc}"
266 fi
267
268 if check_define __ANDROID__ ; then
269   targetos="Android"
270 elif check_define __linux__ ; then
271   targetos="Linux"
272 elif check_define __OpenBSD__ ; then
273   targetos='OpenBSD'
274 elif check_define __NetBSD__ ; then
275   targetos='NetBSD'
276 elif check_define __sun__ ; then
277   targetos='SunOS'
278   CFLAGS="$CFLAGS -D_REENTRANT"
279 elif check_define _WIN32 ; then
280   targetos='CYGWIN'
281 else
282   targetos=`uname -s`
283 fi
284
285 echo "# Automatically generated by configure - do not modify" > $config_host_mak
286 printf "# Configured with:" >> $config_host_mak
287 printf " '%s'" "$0" "$@" >> $config_host_mak
288 echo >> $config_host_mak
289 echo "CONFIG_TARGET_OS=$targetos" >> $config_host_mak
290
291 if test "$no_shm" = "yes" ; then
292   output_sym "CONFIG_NO_SHM"
293 fi
294
295 if test "$disable_opt" = "yes" ; then
296   output_sym "CONFIG_FIO_NO_OPT"
297 fi
298
299 # Some host OSes need non-standard checks for which CPU to use.
300 # Note that these checks are broken for cross-compilation: if you're
301 # cross-compiling to one of these OSes then you'll need to specify
302 # the correct CPU with the --cpu option.
303 case $targetos in
304 AIX|OpenBSD|NetBSD)
305   # Unless explicitly enabled, turn off lex.
306   # OpenBSD will hit syntax error when enabled.
307   if test -z "$disable_lex" ; then
308     disable_lex="yes"
309   else
310     force_no_lex_o="yes"
311   fi
312   ;;
313 FreeBSD)
314   CFLAGS="$CFLAGS -I/usr/local/include"
315   LDFLAGS="$LDFLAGS -L/usr/local/lib"
316   ;;
317 Darwin)
318   # on Leopard most of the system is 32-bit, so we have to ask the kernel if
319   # we can run 64-bit userspace code.
320   # If the user didn't specify a CPU explicitly and the kernel says this is
321   # 64 bit hw, then assume x86_64. Otherwise fall through to the usual
322   # detection code.
323   if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then
324     cpu="x86_64"
325   fi
326   # Error at compile time linking of weak/partial symbols if possible...
327 cat > $TMPC <<EOF
328 int main(void)
329 {
330   return 0;
331 }
332 EOF
333   if compile_prog "" "-Wl,-no_weak_imports" "disable weak symbols"; then
334     echo "Disabling weak symbols"
335     LDFLAGS="$LDFLAGS -Wl,-no_weak_imports"
336   fi
337   ;;
338 SunOS)
339   # `uname -m` returns i86pc even on an x86_64 box, so default based on isainfo
340   if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
341     cpu="x86_64"
342   fi
343   LIBS="-lnsl -lsocket"
344   ;;
345 CYGWIN*)
346   # We still force some options, so keep this message here.
347   echo "Forcing some known good options on Windows"
348   if test -z "${CC}${cross_prefix}"; then
349     if test ! -z "$build_32bit_win" && test "$build_32bit_win" = "yes"; then
350       cc="i686-w64-mingw32-gcc"
351     else
352       cc="x86_64-w64-mingw32-gcc"
353     fi
354   fi
355
356   target_win_ver=$(echo "$target_win_ver" | tr '[:lower:]' '[:upper:]')
357   if test -z "$target_win_ver"; then
358     # Default Windows API target
359     target_win_ver="7"
360   fi
361   if test "$target_win_ver" = "XP"; then
362     output_sym "CONFIG_WINDOWS_XP"
363   elif test "$target_win_ver" = "7"; then
364     output_sym "CONFIG_WINDOWS_7"
365     CFLAGS="$CFLAGS -D_WIN32_WINNT=0x0601"
366   else
367     fatal "Unknown target Windows version"
368   fi
369
370   # We need this to be output_sym'd here because this is Windows specific.
371   # The regular configure path never sets this config.
372   output_sym "CONFIG_WINDOWSAIO"
373   # We now take the regular configuration path without having exit 0 here.
374   # Flags below are still necessary mostly for MinGW.
375   build_static="yes"
376   socklen_t="yes"
377   rusage_thread="yes"
378   fdatasync="yes"
379   clock_gettime="yes" # clock_monotonic probe has dependency on this
380   clock_monotonic="yes"
381   gettimeofday="yes"
382   sched_idle="yes"
383   tcp_nodelay="yes"
384   ipv6="yes"
385   ;;
386 esac
387
388 # Now we know the target platform we can have another guess at the preferred
389 # compiler when it wasn't explictly set
390 if test -z "${CC}${cross_prefix}"; then
391   if test "$targetos" = "FreeBSD" || test "$targetos" = "Darwin"; then
392     if has clang; then
393       cc=clang
394     fi
395   fi
396 fi
397 if test -z "$cc"; then
398     echo "configure: failed to find compiler"
399     exit 1
400 fi
401
402 if test ! -z "$cpu" ; then
403   # command line argument
404   :
405 elif check_define __i386__ ; then
406   cpu="i386"
407 elif check_define __x86_64__ ; then
408   cpu="x86_64"
409 elif check_define __sparc__ ; then
410   if check_define __arch64__ ; then
411     cpu="sparc64"
412   else
413     cpu="sparc"
414   fi
415 elif check_define _ARCH_PPC ; then
416   if check_define _ARCH_PPC64 ; then
417     cpu="ppc64"
418   else
419     cpu="ppc"
420   fi
421 elif check_define __mips__ ; then
422   cpu="mips"
423 elif check_define __ia64__ ; then
424   cpu="ia64"
425 elif check_define __s390__ ; then
426   if check_define __s390x__ ; then
427     cpu="s390x"
428   else
429     cpu="s390"
430   fi
431 elif check_define __arm__ ; then
432   cpu="arm"
433 elif check_define __aarch64__ ; then
434   cpu="aarch64"
435 elif check_define __hppa__ ; then
436   cpu="hppa"
437 else
438   cpu=`uname -m`
439 fi
440
441 # Normalise host CPU name and set ARCH.
442 case "$cpu" in
443   ia64|ppc|ppc64|s390|s390x|sparc64)
444     cpu="$cpu"
445   ;;
446   i386|i486|i586|i686|i86pc|BePC)
447     cpu="x86"
448   ;;
449   x86_64|amd64)
450     cpu="x86_64"
451   ;;
452   armv*b|armv*l|arm)
453     cpu="arm"
454   ;;
455   aarch64)
456     cpu="arm64"
457   ;;
458   hppa|parisc|parisc64)
459     cpu="hppa"
460   ;;
461   mips*)
462     cpu="mips"
463   ;;
464   sparc|sun4[cdmuv])
465     cpu="sparc"
466   ;;
467   *)
468   echo "Unknown CPU"
469   ;;
470 esac
471
472 ##########################################
473 # check cross compile
474
475 if test "$cross_compile" != "yes" ; then
476   cross_compile="no"
477 fi
478 cat > $TMPC <<EOF
479 int main(void)
480 {
481   return 0;
482 }
483 EOF
484 if compile_prog "" "" "cross"; then
485   $TMPE 2>/dev/null || cross_compile="yes"
486 else
487   fatal "compile test failed"
488 fi
489
490 ##########################################
491 # check endianness
492 if test "$bigendian" != "yes" ; then
493   bigendian="no"
494 fi
495 if test "$cross_compile" = "no" ; then
496   cat > $TMPC <<EOF
497 #include <inttypes.h>
498 int main(void)
499 {
500   volatile uint32_t i=0x01234567;
501   return (*((uint8_t*)(&i))) == 0x67;
502 }
503 EOF
504   if compile_prog "" "" "endian"; then
505     $TMPE && bigendian="yes"
506   fi
507 else
508   # If we're cross compiling, try our best to work it out and rely on the
509   # run-time check to fail if we get it wrong.
510   cat > $TMPC <<EOF
511 #include <endian.h>
512 int main(void)
513 {
514 #if __BYTE_ORDER != __BIG_ENDIAN
515 # error "Unknown endianness"
516 #endif
517 }
518 EOF
519   compile_prog "" "" "endian" && bigendian="yes"
520   check_define "__ARMEB__" && bigendian="yes"
521   check_define "__MIPSEB__" && bigendian="yes"
522 fi
523
524
525 print_config "Operating system" "$targetos"
526 print_config "CPU" "$cpu"
527 print_config "Big endian" "$bigendian"
528 if test ! -z "$target_win_ver"; then
529   print_config "Target Windows version" "$target_win_ver"
530 fi
531 print_config "Compiler" "$cc"
532 print_config "Cross compile" "$cross_compile"
533 echo
534
535 ##########################################
536 # See if we need to build a static build
537 if test "$build_static" = "yes" ; then
538   CFLAGS="$CFLAGS -ffunction-sections -fdata-sections"
539   LDFLAGS="$LDFLAGS -static -Wl,--gc-sections"
540 else
541   build_static="no"
542 fi
543 print_config "Static build" "$build_static"
544
545 ##########################################
546 # check for wordsize
547 wordsize="0"
548 cat > $TMPC <<EOF
549 #include <limits.h>
550 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
551 int main(void)
552 {
553   BUILD_BUG_ON(sizeof(long)*CHAR_BIT != WORDSIZE);
554   return 0;
555 }
556 EOF
557 if compile_prog "-DWORDSIZE=32" "" "wordsize"; then
558   wordsize="32"
559 elif compile_prog "-DWORDSIZE=64" "" "wordsize"; then
560   wordsize="64"
561 else
562   fatal "Unknown wordsize"
563 fi
564 print_config "Wordsize" "$wordsize"
565
566 ##########################################
567 # zlib probe
568 if test "$zlib" != "yes" ; then
569   zlib="no"
570 fi
571 cat > $TMPC <<EOF
572 #include <zlib.h>
573 int main(void)
574 {
575   z_stream stream;
576   if (inflateInit(&stream) != Z_OK)
577     return 1;
578   return 0;
579 }
580 EOF
581 if compile_prog "" "-lz" "zlib" ; then
582   zlib=yes
583   LIBS="-lz $LIBS"
584 fi
585 print_config "zlib" "$zlib"
586
587 ##########################################
588 # linux-aio probe
589 if test "$libaio" != "yes" ; then
590   libaio="no"
591 fi
592 if test "$esx" != "yes" ; then
593   cat > $TMPC <<EOF
594 #include <libaio.h>
595 #include <stddef.h>
596 int main(void)
597 {
598   io_setup(0, NULL);
599   return 0;
600 }
601 EOF
602   if compile_prog "" "-laio" "libaio" ; then
603     libaio=yes
604     LIBS="-laio $LIBS"
605   else
606     if test "$libaio" = "yes" ; then
607       feature_not_found "linux AIO" "libaio-dev or libaio-devel"
608     fi
609     libaio=no
610   fi
611 fi
612 print_config "Linux AIO support" "$libaio"
613
614 ##########################################
615 # posix aio probe
616 if test "$posix_aio" != "yes" ; then
617   posix_aio="no"
618 fi
619 if test "$posix_aio_lrt" != "yes" ; then
620   posix_aio_lrt="no"
621 fi
622 cat > $TMPC <<EOF
623 #include <aio.h>
624 int main(void)
625 {
626   struct aiocb cb;
627   aio_read(&cb);
628   return 0;
629 }
630 EOF
631 if compile_prog "" "" "posixaio" ; then
632   posix_aio="yes"
633 elif compile_prog "" "-lrt" "posixaio -lrt"; then
634   posix_aio="yes"
635   posix_aio_lrt="yes"
636   LIBS="-lrt $LIBS"
637 fi
638 print_config "POSIX AIO support" "$posix_aio"
639 print_config "POSIX AIO support needs -lrt" "$posix_aio_lrt"
640
641 ##########################################
642 # posix aio fsync probe
643 if test "$posix_aio_fsync" != "yes" ; then
644   posix_aio_fsync="no"
645 fi
646 if test "$posix_aio" = "yes" ; then
647   cat > $TMPC <<EOF
648 #include <fcntl.h>
649 #include <aio.h>
650 int main(void)
651 {
652   struct aiocb cb;
653   return aio_fsync(O_SYNC, &cb);
654   return 0;
655 }
656 EOF
657   if compile_prog "" "$LIBS" "posix_aio_fsync" ; then
658     posix_aio_fsync=yes
659   fi
660 fi
661 print_config "POSIX AIO fsync" "$posix_aio_fsync"
662
663 ##########################################
664 # POSIX pshared attribute probe
665 if test "$posix_pshared" != "yes" ; then
666   posix_pshared="no"
667 fi
668 cat > $TMPC <<EOF
669 #include <unistd.h>
670 int main(void)
671 {
672 #if defined(_POSIX_THREAD_PROCESS_SHARED) && ((_POSIX_THREAD_PROCESS_SHARED + 0) > 0)
673 # if defined(__CYGWIN__)
674 #  error "_POSIX_THREAD_PROCESS_SHARED is buggy on Cygwin"
675 # elif defined(__APPLE__)
676 #  include <AvailabilityMacros.h>
677 #  include <TargetConditionals.h>
678 #  if TARGET_OS_MAC && MAC_OS_X_VERSION_MIN_REQUIRED < 1070
679 #   error "_POSIX_THREAD_PROCESS_SHARED is buggy/unsupported prior to OSX 10.7"
680 #  endif
681 # endif
682 #else
683 # error "_POSIX_THREAD_PROCESS_SHARED is unsupported"
684 #endif
685   return 0;
686 }
687 EOF
688 if compile_prog "" "$LIBS" "posix_pshared" ; then
689   posix_pshared=yes
690 fi
691 print_config "POSIX pshared support" "$posix_pshared"
692
693 ##########################################
694 # solaris aio probe
695 if test "$solaris_aio" != "yes" ; then
696   solaris_aio="no"
697 fi
698 cat > $TMPC <<EOF
699 #include <sys/types.h>
700 #include <sys/asynch.h>
701 #include <unistd.h>
702 int main(void)
703 {
704   aio_result_t res;
705   return aioread(0, NULL, 0, 0, SEEK_SET, &res);
706   return 0;
707 }
708 EOF
709 if compile_prog "" "-laio" "solarisaio" ; then
710   solaris_aio=yes
711   LIBS="-laio $LIBS"
712 fi
713 print_config "Solaris AIO support" "$solaris_aio"
714
715 ##########################################
716 # __sync_fetch_and_add test
717 if test "$sfaa" != "yes" ; then
718   sfaa="no"
719 fi
720 cat > $TMPC << EOF
721 #include <inttypes.h>
722 static int sfaa(uint64_t *ptr)
723 {
724   return __sync_fetch_and_add(ptr, 0);
725 }
726
727 int main(int argc, char **argv)
728 {
729   uint64_t val = 42;
730   sfaa(&val);
731   return val;
732 }
733 EOF
734 if compile_prog "" "" "__sync_fetch_and_add()" ; then
735     sfaa="yes"
736 fi
737 print_config "__sync_fetch_and_add" "$sfaa"
738
739 ##########################################
740 # __sync_synchronize() test
741 if test "$sync_sync" != "yes" ; then
742   sync_sync="no"
743 fi
744 cat > $TMPC << EOF
745 #include <inttypes.h>
746
747 int main(int argc, char **argv)
748 {
749   __sync_synchronize();
750   return 0;
751 }
752 EOF
753 if compile_prog "" "" "__sync_synchronize()" ; then
754     sync_sync="yes"
755 fi
756 print_config "__sync_synchronize" "$sync_sync"
757
758 ##########################################
759 # __sync_val_compare_and_swap() test
760 if test "$cmp_swap" != "yes" ; then
761   cmp_swap="no"
762 fi
763 cat > $TMPC << EOF
764 #include <inttypes.h>
765
766 int main(int argc, char **argv)
767 {
768   int x = 0;
769   return __sync_val_compare_and_swap(&x, 1, 2);
770 }
771 EOF
772 if compile_prog "" "" "__sync_val_compare_and_swap()" ; then
773     cmp_swap="yes"
774 fi
775 print_config "__sync_val_compare_and_swap" "$cmp_swap"
776
777 ##########################################
778 # libverbs probe
779 if test "$libverbs" != "yes" ; then
780   libverbs="no"
781 fi
782 cat > $TMPC << EOF
783 #include <infiniband/verbs.h>
784 int main(int argc, char **argv)
785 {
786   struct ibv_pd *pd = ibv_alloc_pd(NULL);
787   return 0;
788 }
789 EOF
790 if test "$disable_rdma" != "yes" && compile_prog "" "-libverbs" "libverbs" ; then
791     libverbs="yes"
792     LIBS="-libverbs $LIBS"
793 fi
794 print_config "libverbs" "$libverbs"
795
796 ##########################################
797 # rdmacm probe
798 if test "$rdmacm" != "yes" ; then
799   rdmacm="no"
800 fi
801 cat > $TMPC << EOF
802 #include <stdio.h>
803 #include <rdma/rdma_cma.h>
804 int main(int argc, char **argv)
805 {
806   rdma_destroy_qp(NULL);
807   return 0;
808 }
809 EOF
810 if test "$disable_rdma" != "yes" && compile_prog "" "-lrdmacm" "rdma"; then
811     rdmacm="yes"
812     LIBS="-lrdmacm $LIBS"
813 fi
814 print_config "rdmacm" "$rdmacm"
815
816 ##########################################
817 # asprintf() and vasprintf() probes
818 if test "$have_asprintf" != "yes" ; then
819   have_asprintf="no"
820 fi
821 cat > $TMPC << EOF
822 #include <stdio.h>
823
824 int main(int argc, char **argv)
825 {
826   return asprintf(NULL, "%s", "str") == 0;
827 }
828 EOF
829 if compile_prog "" "" "have_asprintf"; then
830     have_asprintf="yes"
831 fi
832 print_config "asprintf()" "$have_asprintf"
833
834 if test "$have_vasprintf" != "yes" ; then
835   have_vasprintf="no"
836 fi
837 cat > $TMPC << EOF
838 #include <stdio.h>
839
840 int main(int argc, char **argv)
841 {
842   return vasprintf(NULL, "%s", NULL) == 0;
843 }
844 EOF
845 if compile_prog "" "" "have_vasprintf"; then
846     have_vasprintf="yes"
847 fi
848 print_config "vasprintf()" "$have_vasprintf"
849
850 ##########################################
851 # Linux fallocate probe
852 if test "$linux_fallocate" != "yes" ; then
853   linux_fallocate="no"
854 fi
855 cat > $TMPC << EOF
856 #include <stdio.h>
857 #include <fcntl.h>
858 #include <linux/falloc.h>
859 int main(int argc, char **argv)
860 {
861   int r = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 1024);
862   return r;
863 }
864 EOF
865 if compile_prog "" "" "linux_fallocate"; then
866     linux_fallocate="yes"
867 fi
868 print_config "Linux fallocate" "$linux_fallocate"
869
870 ##########################################
871 # POSIX fadvise probe
872 if test "$posix_fadvise" != "yes" ; then
873   posix_fadvise="no"
874 fi
875 cat > $TMPC << EOF
876 #include <stdio.h>
877 #include <fcntl.h>
878 int main(int argc, char **argv)
879 {
880   int r = posix_fadvise(0, 0, 0, POSIX_FADV_NORMAL);
881   return r;
882 }
883 EOF
884 if compile_prog "" "" "posix_fadvise"; then
885     posix_fadvise="yes"
886 fi
887 print_config "POSIX fadvise" "$posix_fadvise"
888
889 ##########################################
890 # POSIX fallocate probe
891 if test "$posix_fallocate" != "yes" ; then
892   posix_fallocate="no"
893 fi
894 cat > $TMPC << EOF
895 #include <stdio.h>
896 #include <fcntl.h>
897 int main(int argc, char **argv)
898 {
899   int r = posix_fallocate(0, 0, 1024);
900   return r;
901 }
902 EOF
903 if compile_prog "" "" "posix_fallocate"; then
904     posix_fallocate="yes"
905 fi
906 print_config "POSIX fallocate" "$posix_fallocate"
907
908 ##########################################
909 # sched_set/getaffinity 2 or 3 argument test
910 if test "$linux_2arg_affinity" != "yes" ; then
911   linux_2arg_affinity="no"
912 fi
913 if test "$linux_3arg_affinity" != "yes" ; then
914   linux_3arg_affinity="no"
915 fi
916 cat > $TMPC << EOF
917 #include <sched.h>
918 int main(int argc, char **argv)
919 {
920   cpu_set_t mask;
921   return sched_setaffinity(0, sizeof(mask), &mask);
922 }
923 EOF
924 if compile_prog "" "" "sched_setaffinity(,,)"; then
925   linux_3arg_affinity="yes"
926 else
927   cat > $TMPC << EOF
928 #include <sched.h>
929 int main(int argc, char **argv)
930 {
931   cpu_set_t mask;
932   return sched_setaffinity(0, &mask);
933 }
934 EOF
935   if compile_prog "" "" "sched_setaffinity(,)"; then
936     linux_2arg_affinity="yes"
937   fi
938 fi
939 print_config "sched_setaffinity(3 arg)" "$linux_3arg_affinity"
940 print_config "sched_setaffinity(2 arg)" "$linux_2arg_affinity"
941
942 ##########################################
943 # clock_gettime probe
944 if test "$clock_gettime" != "yes" ; then
945   clock_gettime="no"
946 fi
947 cat > $TMPC << EOF
948 #include <stdio.h>
949 #include <time.h>
950 int main(int argc, char **argv)
951 {
952   return clock_gettime(0, NULL);
953 }
954 EOF
955 if compile_prog "" "" "clock_gettime"; then
956     clock_gettime="yes"
957 elif compile_prog "" "-lrt" "clock_gettime"; then
958     clock_gettime="yes"
959     LIBS="-lrt $LIBS"
960 fi
961 print_config "clock_gettime" "$clock_gettime"
962
963 ##########################################
964 # CLOCK_MONOTONIC probe
965 if test "$clock_monotonic" != "yes" ; then
966   clock_monotonic="no"
967 fi
968 if test "$clock_gettime" = "yes" ; then
969   cat > $TMPC << EOF
970 #include <stdio.h>
971 #include <time.h>
972 int main(int argc, char **argv)
973 {
974   return clock_gettime(CLOCK_MONOTONIC, NULL);
975 }
976 EOF
977   if compile_prog "" "$LIBS" "clock monotonic"; then
978       clock_monotonic="yes"
979   fi
980 fi
981 print_config "CLOCK_MONOTONIC" "$clock_monotonic"
982
983 ##########################################
984 # CLOCK_MONOTONIC_RAW probe
985 if test "$clock_monotonic_raw" != "yes" ; then
986   clock_monotonic_raw="no"
987 fi
988 if test "$clock_gettime" = "yes" ; then
989   cat > $TMPC << EOF
990 #include <stdio.h>
991 #include <time.h>
992 int main(int argc, char **argv)
993 {
994   return clock_gettime(CLOCK_MONOTONIC_RAW, NULL);
995 }
996 EOF
997   if compile_prog "" "$LIBS" "clock monotonic"; then
998       clock_monotonic_raw="yes"
999   fi
1000 fi
1001 print_config "CLOCK_MONOTONIC_RAW" "$clock_monotonic_raw"
1002
1003 ##########################################
1004 # CLOCK_MONOTONIC_PRECISE probe
1005 if test "$clock_monotonic_precise" != "yes" ; then
1006   clock_monotonic_precise="no"
1007 fi
1008 if test "$clock_gettime" = "yes" ; then
1009   cat > $TMPC << EOF
1010 #include <stdio.h>
1011 #include <time.h>
1012 int main(int argc, char **argv)
1013 {
1014   return clock_gettime(CLOCK_MONOTONIC_PRECISE, NULL);
1015 }
1016 EOF
1017   if compile_prog "" "$LIBS" "clock monotonic precise"; then
1018       clock_monotonic_precise="yes"
1019   fi
1020 fi
1021 print_config "CLOCK_MONOTONIC_PRECISE" "$clock_monotonic_precise"
1022
1023 ##########################################
1024 # clockid_t probe
1025 if test "$clockid_t" != "yes" ; then
1026   clockid_t="no"
1027 fi
1028 cat > $TMPC << EOF
1029 #include <time.h>
1030 #include <string.h>
1031 int main(int argc, char **argv)
1032 {
1033   volatile clockid_t cid;
1034   memset((void*)&cid, 0, sizeof(cid));
1035   return 0;
1036 }
1037 EOF
1038 if compile_prog "" "$LIBS" "clockid_t"; then
1039   clockid_t="yes"
1040 fi
1041 print_config "clockid_t" "$clockid_t"
1042
1043 ##########################################
1044 # gettimeofday() probe
1045 if test "$gettimeofday" != "yes" ; then
1046   gettimeofday="no"
1047 fi
1048 cat > $TMPC << EOF
1049 #include <sys/time.h>
1050 #include <stdio.h>
1051 int main(int argc, char **argv)
1052 {
1053   struct timeval tv;
1054   return gettimeofday(&tv, NULL);
1055 }
1056 EOF
1057 if compile_prog "" "" "gettimeofday"; then
1058     gettimeofday="yes"
1059 fi
1060 print_config "gettimeofday" "$gettimeofday"
1061
1062 ##########################################
1063 # fdatasync() probe
1064 if test "$fdatasync" != "yes" ; then
1065   fdatasync="no"
1066 fi
1067 cat > $TMPC << EOF
1068 #include <stdio.h>
1069 #include <unistd.h>
1070 int main(int argc, char **argv)
1071 {
1072   return fdatasync(0);
1073 }
1074 EOF
1075 if compile_prog "" "" "fdatasync"; then
1076   fdatasync="yes"
1077 fi
1078 print_config "fdatasync" "$fdatasync"
1079
1080 ##########################################
1081 # sync_file_range() probe
1082 if test "$sync_file_range" != "yes" ; then
1083   sync_file_range="no"
1084 fi
1085 cat > $TMPC << EOF
1086 #include <stdio.h>
1087 #include <unistd.h>
1088 #include <fcntl.h>
1089 #include <linux/fs.h>
1090 int main(int argc, char **argv)
1091 {
1092   unsigned int flags = SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE |
1093                         SYNC_FILE_RANGE_WAIT_AFTER;
1094   return sync_file_range(0, 0, 0, flags);
1095 }
1096 EOF
1097 if compile_prog "" "" "sync_file_range"; then
1098   sync_file_range="yes"
1099 fi
1100 print_config "sync_file_range" "$sync_file_range"
1101
1102 ##########################################
1103 # ext4 move extent probe
1104 if test "$ext4_me" != "yes" ; then
1105   ext4_me="no"
1106 fi
1107 cat > $TMPC << EOF
1108 #include <fcntl.h>
1109 #include <sys/ioctl.h>
1110 int main(int argc, char **argv)
1111 {
1112   struct move_extent me;
1113   return ioctl(0, EXT4_IOC_MOVE_EXT, &me);
1114 }
1115 EOF
1116 if compile_prog "" "" "ext4 move extent" ; then
1117   ext4_me="yes"
1118 elif test $targetos = "Linux" ; then
1119   # On Linux, just default to it on and let it error at runtime if we really
1120   # don't have it. None of my updated systems have it defined, but it does
1121   # work. Takes a while to bubble back.
1122   ext4_me="yes"
1123 fi
1124 print_config "EXT4 move extent" "$ext4_me"
1125
1126 ##########################################
1127 # splice probe
1128 if test "$linux_splice" != "yes" ; then
1129   linux_splice="no"
1130 fi
1131 cat > $TMPC << EOF
1132 #include <stdio.h>
1133 #include <fcntl.h>
1134 int main(int argc, char **argv)
1135 {
1136   return splice(0, NULL, 0, NULL, 0, SPLICE_F_NONBLOCK);
1137 }
1138 EOF
1139 if compile_prog "" "" "linux splice"; then
1140   linux_splice="yes"
1141 fi
1142 print_config "Linux splice(2)" "$linux_splice"
1143
1144 ##########################################
1145 # GUASI probe
1146 if test "$guasi" != "yes" ; then
1147   guasi="no"
1148 fi
1149 cat > $TMPC << EOF
1150 #include <guasi.h>
1151 #include <guasi_syscalls.h>
1152 int main(int argc, char **argv)
1153 {
1154   guasi_t ctx = guasi_create(0, 0, 0);
1155   return 0;
1156 }
1157 EOF
1158 if compile_prog "" "" "guasi"; then
1159   guasi="yes"
1160 fi
1161 print_config "GUASI" "$guasi"
1162
1163 ##########################################
1164 # libnuma probe
1165 if test "$libnuma" != "yes" ; then
1166   libnuma="no"
1167 fi
1168 cat > $TMPC << EOF
1169 #include <numa.h>
1170 int main(int argc, char **argv)
1171 {
1172   return numa_available();
1173 }
1174 EOF
1175 if test "$disable_numa" != "yes"  && compile_prog "" "-lnuma" "libnuma"; then
1176   libnuma="yes"
1177   LIBS="-lnuma $LIBS"
1178 fi
1179 print_config "libnuma" "$libnuma"
1180
1181 ##########################################
1182 # libnuma 2.x version API, initialize with "no" only if $libnuma is set to "yes"
1183 if test "$libnuma" = "yes" ; then
1184 libnuma_v2="no"
1185 cat > $TMPC << EOF
1186 #include <numa.h>
1187 int main(int argc, char **argv)
1188 {
1189   struct bitmask *mask = numa_parse_nodestring(NULL);
1190   return mask->size == 0;
1191 }
1192 EOF
1193 if compile_prog "" "" "libnuma api"; then
1194   libnuma_v2="yes"
1195 fi
1196 print_config "libnuma v2" "$libnuma_v2"
1197 fi
1198
1199 ##########################################
1200 # strsep() probe
1201 if test "$strsep" != "yes" ; then
1202   strsep="no"
1203 fi
1204 cat > $TMPC << EOF
1205 #include <string.h>
1206 int main(int argc, char **argv)
1207 {
1208   static char *string = "This is a string";
1209   strsep(&string, "needle");
1210   return 0;
1211 }
1212 EOF
1213 if compile_prog "" "" "strsep"; then
1214   strsep="yes"
1215 fi
1216 print_config "strsep" "$strsep"
1217
1218 ##########################################
1219 # strcasestr() probe
1220 if test "$strcasestr" != "yes" ; then
1221   strcasestr="no"
1222 fi
1223 cat > $TMPC << EOF
1224 #include <string.h>
1225 int main(int argc, char **argv)
1226 {
1227   return strcasestr(argv[0], argv[1]) != NULL;
1228 }
1229 EOF
1230 if compile_prog "" "" "strcasestr"; then
1231   strcasestr="yes"
1232 fi
1233 print_config "strcasestr" "$strcasestr"
1234
1235 ##########################################
1236 # strlcat() probe
1237 if test "$strlcat" != "yes" ; then
1238   strlcat="no"
1239 fi
1240 cat > $TMPC << EOF
1241 #include <string.h>
1242 int main(int argc, char **argv)
1243 {
1244   static char dst[64];
1245   static char *string = "This is a string";
1246   memset(dst, 0, sizeof(dst));
1247   strlcat(dst, string, sizeof(dst));
1248   return 0;
1249 }
1250 EOF
1251 if compile_prog "" "" "strlcat"; then
1252   strlcat="yes"
1253 fi
1254 print_config "strlcat" "$strlcat"
1255
1256 ##########################################
1257 # getopt_long_only() probe
1258 if test "$getopt_long_only" != "yes" ; then
1259   getopt_long_only="no"
1260 fi
1261 cat > $TMPC << EOF
1262 #include <unistd.h>
1263 #include <stdio.h>
1264 #include <getopt.h>
1265 int main(int argc, char **argv)
1266 {
1267   int c = getopt_long_only(argc, argv, NULL, NULL, NULL);
1268   return c;
1269 }
1270 EOF
1271 if compile_prog "" "" "getopt_long_only"; then
1272   getopt_long_only="yes"
1273 fi
1274 print_config "getopt_long_only()" "$getopt_long_only"
1275
1276 ##########################################
1277 # inet_aton() probe
1278 if test "$inet_aton" != "yes" ; then
1279   inet_aton="no"
1280 fi
1281 cat > $TMPC << EOF
1282 #include <sys/socket.h>
1283 #include <arpa/inet.h>
1284 #include <stdio.h>
1285 int main(int argc, char **argv)
1286 {
1287   struct in_addr in;
1288   return inet_aton(NULL, &in);
1289 }
1290 EOF
1291 if compile_prog "" "" "inet_aton"; then
1292   inet_aton="yes"
1293 fi
1294 print_config "inet_aton" "$inet_aton"
1295
1296 ##########################################
1297 # socklen_t probe
1298 if test "$socklen_t" != "yes" ; then
1299   socklen_t="no"
1300 fi
1301 cat > $TMPC << EOF
1302 #include <sys/socket.h>
1303 int main(int argc, char **argv)
1304 {
1305   socklen_t len = 0;
1306   return len;
1307 }
1308 EOF
1309 if compile_prog "" "" "socklen_t"; then
1310   socklen_t="yes"
1311 fi
1312 print_config "socklen_t" "$socklen_t"
1313
1314 ##########################################
1315 # Whether or not __thread is supported for TLS
1316 if test "$tls_thread" != "yes" ; then
1317   tls_thread="no"
1318 fi
1319 cat > $TMPC << EOF
1320 #include <stdio.h>
1321 static __thread int ret;
1322 int main(int argc, char **argv)
1323 {
1324   return ret;
1325 }
1326 EOF
1327 if compile_prog "" "" "__thread"; then
1328   tls_thread="yes"
1329 fi
1330 print_config "__thread" "$tls_thread"
1331
1332 ##########################################
1333 # Check if we have required gtk/glib support for gfio
1334 if test "$gfio" != "yes" ; then
1335   gfio="no"
1336 fi
1337 if test "$gfio_check" = "yes" ; then
1338   cat > $TMPC << EOF
1339 #include <glib.h>
1340 #include <cairo.h>
1341 #include <gtk/gtk.h>
1342 int main(void)
1343 {
1344   gdk_threads_enter();
1345   gdk_threads_leave();
1346
1347   return GTK_CHECK_VERSION(2, 18, 0) ? 0 : 1; /* 0 on success */
1348 }
1349 EOF
1350 GTK_CFLAGS=$(pkg-config --cflags gtk+-2.0 gthread-2.0)
1351 ORG_LDFLAGS=$LDFLAGS
1352 LDFLAGS=$(echo $LDFLAGS | sed s/"-static"//g)
1353 if test "$?" != "0" ; then
1354   echo "configure: gtk and gthread not found"
1355   exit 1
1356 fi
1357 GTK_LIBS=$(pkg-config --libs gtk+-2.0 gthread-2.0)
1358 if test "$?" != "0" ; then
1359   echo "configure: gtk and gthread not found"
1360   exit 1
1361 fi
1362 if compile_prog "$GTK_CFLAGS" "$GTK_LIBS" "gfio" ; then
1363   $TMPE
1364   if test "$?" = "0" ; then
1365     gfio="yes"
1366     GFIO_LIBS="$LIBS $GTK_LIBS"
1367     CFLAGS="$CFLAGS $GTK_CFLAGS"
1368   else
1369     echo "GTK found, but need version 2.18 or higher"
1370     gfio="no"
1371   fi
1372 else
1373   echo "Please install gtk and gdk libraries"
1374   gfio="no"
1375 fi
1376 LDFLAGS=$ORG_LDFLAGS
1377 fi
1378
1379 if test "$gfio_check" = "yes" ; then
1380   print_config "gtk 2.18 or higher" "$gfio"
1381 fi
1382
1383 ##########################################
1384 # Check whether we have getrusage(RUSAGE_THREAD)
1385 if test "$rusage_thread" != "yes" ; then
1386   rusage_thread="no"
1387 fi
1388 cat > $TMPC << EOF
1389 #include <sys/time.h>
1390 #include <sys/resource.h>
1391 int main(int argc, char **argv)
1392 {
1393   struct rusage ru;
1394   getrusage(RUSAGE_THREAD, &ru);
1395   return 0;
1396 }
1397 EOF
1398 if compile_prog "" "" "RUSAGE_THREAD"; then
1399   rusage_thread="yes"
1400 fi
1401 print_config "RUSAGE_THREAD" "$rusage_thread"
1402
1403 ##########################################
1404 # Check whether we have SCHED_IDLE
1405 if test "$sched_idle" != "yes" ; then
1406   sched_idle="no"
1407 fi
1408 cat > $TMPC << EOF
1409 #include <sched.h>
1410 int main(int argc, char **argv)
1411 {
1412   struct sched_param p;
1413   return sched_setscheduler(0, SCHED_IDLE, &p);
1414 }
1415 EOF
1416 if compile_prog "" "" "SCHED_IDLE"; then
1417   sched_idle="yes"
1418 fi
1419 print_config "SCHED_IDLE" "$sched_idle"
1420
1421 ##########################################
1422 # Check whether we have TCP_NODELAY
1423 if test "$tcp_nodelay" != "yes" ; then
1424   tcp_nodelay="no"
1425 fi
1426 cat > $TMPC << EOF
1427 #include <stdio.h>
1428 #include <sys/types.h>
1429 #include <sys/socket.h>
1430 #include <netinet/tcp.h>
1431 int main(int argc, char **argv)
1432 {
1433   return getsockopt(0, 0, TCP_NODELAY, NULL, NULL);
1434 }
1435 EOF
1436 if compile_prog "" "" "TCP_NODELAY"; then
1437   tcp_nodelay="yes"
1438 fi
1439 print_config "TCP_NODELAY" "$tcp_nodelay"
1440
1441 ##########################################
1442 # Check whether we have SO_SNDBUF
1443 if test "$window_size" != "yes" ; then
1444   window_size="no"
1445 fi
1446 cat > $TMPC << EOF
1447 #include <stdio.h>
1448 #include <sys/types.h>
1449 #include <sys/socket.h>
1450 #include <netinet/tcp.h>
1451 int main(int argc, char **argv)
1452 {
1453   setsockopt(0, SOL_SOCKET, SO_SNDBUF, NULL, 0);
1454   setsockopt(0, SOL_SOCKET, SO_RCVBUF, NULL, 0);
1455 }
1456 EOF
1457 if compile_prog "" "" "SO_SNDBUF"; then
1458   window_size="yes"
1459 fi
1460 print_config "Net engine window_size" "$window_size"
1461
1462 ##########################################
1463 # Check whether we have TCP_MAXSEG
1464 if test "$mss" != "yes" ; then
1465   mss="no"
1466 fi
1467 cat > $TMPC << EOF
1468 #include <stdio.h>
1469 #include <sys/types.h>
1470 #include <sys/socket.h>
1471 #include <netinet/tcp.h>
1472 #include <arpa/inet.h>
1473 #include <netinet/in.h>
1474 int main(int argc, char **argv)
1475 {
1476   return setsockopt(0, IPPROTO_TCP, TCP_MAXSEG, NULL, 0);
1477 }
1478 EOF
1479 if compile_prog "" "" "TCP_MAXSEG"; then
1480   mss="yes"
1481 fi
1482 print_config "TCP_MAXSEG" "$mss"
1483
1484 ##########################################
1485 # Check whether we have RLIMIT_MEMLOCK
1486 if test "$rlimit_memlock" != "yes" ; then
1487   rlimit_memlock="no"
1488 fi
1489 cat > $TMPC << EOF
1490 #include <sys/time.h>
1491 #include <sys/resource.h>
1492 int main(int argc, char **argv)
1493 {
1494   struct rlimit rl;
1495   return getrlimit(RLIMIT_MEMLOCK, &rl);
1496 }
1497 EOF
1498 if compile_prog "" "" "RLIMIT_MEMLOCK"; then
1499   rlimit_memlock="yes"
1500 fi
1501 print_config "RLIMIT_MEMLOCK" "$rlimit_memlock"
1502
1503 ##########################################
1504 # Check whether we have pwritev/preadv
1505 if test "$pwritev" != "yes" ; then
1506   pwritev="no"
1507 fi
1508 cat > $TMPC << EOF
1509 #include <stdio.h>
1510 #include <sys/uio.h>
1511 int main(int argc, char **argv)
1512 {
1513   return pwritev(0, NULL, 1, 0) + preadv(0, NULL, 1, 0);
1514 }
1515 EOF
1516 if compile_prog "" "" "pwritev"; then
1517   pwritev="yes"
1518 fi
1519 print_config "pwritev/preadv" "$pwritev"
1520
1521 ##########################################
1522 # Check whether we have pwritev2/preadv2
1523 if test "$pwritev2" != "yes" ; then
1524   pwritev2="no"
1525 fi
1526 cat > $TMPC << EOF
1527 #include <stdio.h>
1528 #include <sys/uio.h>
1529 int main(int argc, char **argv)
1530 {
1531   return pwritev2(0, NULL, 1, 0, 0) + preadv2(0, NULL, 1, 0, 0);
1532 }
1533 EOF
1534 if compile_prog "" "" "pwritev2"; then
1535   pwritev2="yes"
1536 fi
1537 print_config "pwritev2/preadv2" "$pwritev2"
1538
1539 ##########################################
1540 # Check whether we have the required functions for ipv6
1541 if test "$ipv6" != "yes" ; then
1542   ipv6="no"
1543 fi
1544 cat > $TMPC << EOF
1545 #include <sys/types.h>
1546 #include <sys/socket.h>
1547 #include <netinet/in.h>
1548 #include <netdb.h>
1549 #include <stdio.h>
1550 int main(int argc, char **argv)
1551 {
1552   struct addrinfo hints;
1553   struct in6_addr addr;
1554   int ret;
1555
1556   ret = getaddrinfo(NULL, NULL, &hints, NULL);
1557   freeaddrinfo(NULL);
1558   printf("%s\n", gai_strerror(ret));
1559   addr = in6addr_any;
1560   return 0;
1561 }
1562 EOF
1563 if compile_prog "" "" "ipv6"; then
1564   ipv6="yes"
1565 fi
1566 print_config "IPv6 helpers" "$ipv6"
1567
1568 ##########################################
1569 # check for http
1570 if test "$http" != "yes" ; then
1571   http="no"
1572 fi
1573 # check for openssl >= 1.1.0, which uses an opaque HMAC_CTX pointer
1574 cat > $TMPC << EOF
1575 #include <curl/curl.h>
1576 #include <openssl/hmac.h>
1577
1578 int main(int argc, char **argv)
1579 {
1580   CURL *curl;
1581   HMAC_CTX *ctx;
1582
1583   curl = curl_easy_init();
1584   curl_easy_cleanup(curl);
1585
1586   ctx = HMAC_CTX_new();
1587   HMAC_CTX_reset(ctx);
1588   HMAC_CTX_free(ctx);
1589   return 0;
1590 }
1591 EOF
1592 # openssl < 1.1.0 uses the HMAC_CTX type directly
1593 cat > $TMPC2 << EOF
1594 #include <curl/curl.h>
1595 #include <openssl/hmac.h>
1596
1597 int main(int argc, char **argv)
1598 {
1599   CURL *curl;
1600   HMAC_CTX ctx;
1601
1602   curl = curl_easy_init();
1603   curl_easy_cleanup(curl);
1604
1605   HMAC_CTX_init(&ctx);
1606   HMAC_CTX_cleanup(&ctx);
1607   return 0;
1608 }
1609 EOF
1610 if test "$disable_http" != "yes"; then
1611   HTTP_LIBS="-lcurl -lssl -lcrypto"
1612   if compile_prog "" "$HTTP_LIBS" "curl-new-ssl"; then
1613     output_sym "CONFIG_HAVE_OPAQUE_HMAC_CTX"
1614     http="yes"
1615     LIBS="$HTTP_LIBS $LIBS"
1616   elif mv $TMPC2 $TMPC && compile_prog "" "$HTTP_LIBS" "curl-old-ssl"; then
1617     http="yes"
1618     LIBS="$HTTP_LIBS $LIBS"
1619   fi
1620 fi
1621 print_config "http engine" "$http"
1622
1623 ##########################################
1624 # check for rados
1625 if test "$rados" != "yes" ; then
1626   rados="no"
1627 fi
1628 cat > $TMPC << EOF
1629 #include <rados/librados.h>
1630
1631 int main(int argc, char **argv)
1632 {
1633   rados_t cluster;
1634   rados_ioctx_t io_ctx;
1635   const char cluster_name[] = "ceph";
1636   const char user_name[] = "client.admin";
1637   const char pool[] = "rados";
1638
1639   /* The rados_create2 signature required was only introduced in ceph 0.65 */
1640   rados_create2(&cluster, cluster_name, user_name, 0);
1641   rados_ioctx_create(cluster, pool, &io_ctx);
1642
1643   return 0;
1644 }
1645 EOF
1646 if test "$disable_rados" != "yes"  && compile_prog "" "-lrados" "rados"; then
1647   LIBS="-lrados $LIBS"
1648   rados="yes"
1649 fi
1650 print_config "Rados engine" "$rados"
1651
1652 ##########################################
1653 # check for rbd
1654 if test "$rbd" != "yes" ; then
1655   rbd="no"
1656 fi
1657 cat > $TMPC << EOF
1658 #include <rbd/librbd.h>
1659
1660 int main(int argc, char **argv)
1661 {
1662   rados_t cluster;
1663   rados_ioctx_t io_ctx;
1664   const char cluster_name[] = "ceph";
1665   const char user_name[] = "client.admin";
1666   const char pool[] = "rbd";
1667   int major, minor, extra;
1668
1669   rbd_version(&major, &minor, &extra);
1670   /* The rados_create2 signature required was only introduced in ceph 0.65 */
1671   rados_create2(&cluster, cluster_name, user_name, 0);
1672   rados_ioctx_create(cluster, pool, &io_ctx);
1673
1674   return 0;
1675 }
1676 EOF
1677 if test "$disable_rbd" != "yes"  && compile_prog "" "-lrbd -lrados" "rbd"; then
1678   LIBS="-lrbd -lrados $LIBS"
1679   rbd="yes"
1680 fi
1681 print_config "Rados Block Device engine" "$rbd"
1682
1683 ##########################################
1684 # check for rbd_poll
1685 if test "$rbd_poll" != "yes" ; then
1686   rbd_poll="no"
1687 fi
1688 if test "$rbd" = "yes"; then
1689 cat > $TMPC << EOF
1690 #include <rbd/librbd.h>
1691 #include <sys/eventfd.h>
1692
1693 int main(int argc, char **argv)
1694 {
1695   rbd_image_t image;
1696   rbd_completion_t comp;
1697
1698   int fd = eventfd(0, EFD_NONBLOCK);
1699   rbd_set_image_notification(image, fd, EVENT_TYPE_EVENTFD);
1700   rbd_poll_io_events(image, comp, 1);
1701
1702   return 0;
1703 }
1704 EOF
1705 if compile_prog "" "-lrbd -lrados" "rbd"; then
1706   rbd_poll="yes"
1707 fi
1708 print_config "rbd_poll" "$rbd_poll"
1709 fi
1710
1711 ##########################################
1712 # check for rbd_invalidate_cache()
1713 if test "$rbd_inval" != "yes" ; then
1714   rbd_inval="no"
1715 fi
1716 if test "$rbd" = "yes"; then
1717 cat > $TMPC << EOF
1718 #include <rbd/librbd.h>
1719
1720 int main(int argc, char **argv)
1721 {
1722   rbd_image_t image;
1723
1724   return rbd_invalidate_cache(image);
1725 }
1726 EOF
1727 if compile_prog "" "-lrbd -lrados" "rbd"; then
1728   rbd_inval="yes"
1729 fi
1730 print_config "rbd_invalidate_cache" "$rbd_inval"
1731 fi
1732
1733 ##########################################
1734 # Check whether we have setvbuf
1735 if test "$setvbuf" != "yes" ; then
1736   setvbuf="no"
1737 fi
1738 cat > $TMPC << EOF
1739 #include <stdio.h>
1740 int main(int argc, char **argv)
1741 {
1742   FILE *f = NULL;
1743   char buf[80];
1744   setvbuf(f, buf, _IOFBF, sizeof(buf));
1745   return 0;
1746 }
1747 EOF
1748 if compile_prog "" "" "setvbuf"; then
1749   setvbuf="yes"
1750 fi
1751 print_config "setvbuf" "$setvbuf"
1752
1753 ##########################################
1754 # check for gfapi
1755 if test "$gfapi" != "yes" ; then
1756   gfapi="no"
1757 fi
1758 cat > $TMPC << EOF
1759 #include <glusterfs/api/glfs.h>
1760
1761 int main(int argc, char **argv)
1762 {
1763   glfs_t *g = glfs_new("foo");
1764
1765   return 0;
1766 }
1767 EOF
1768 if test "$disable_gfapi" != "yes"  && compile_prog "" "-lgfapi -lglusterfs" "gfapi"; then
1769   LIBS="-lgfapi -lglusterfs $LIBS"
1770   gfapi="yes"
1771 fi
1772 print_config "Gluster API engine" "$gfapi"
1773
1774 ##########################################
1775 # check for gfapi fadvise support, initialize with "no" only if $gfapi is set to "yes"
1776 if test "$gfapi" = "yes" ; then
1777 gf_fadvise="no"
1778 cat > $TMPC << EOF
1779 #include <glusterfs/api/glfs.h>
1780
1781 int main(int argc, char **argv)
1782 {
1783   struct glfs_fd *fd;
1784   int ret = glfs_fadvise(fd, 0, 0, 1);
1785
1786   return 0;
1787 }
1788 EOF
1789 if compile_prog "" "-lgfapi -lglusterfs" "gfapi"; then
1790   gf_fadvise="yes"
1791 fi
1792 print_config "Gluster API use fadvise" "$gf_fadvise"
1793 fi
1794
1795 ##########################################
1796 # check for newer gfapi
1797 if test "$gfapi" = "yes" ; then
1798 gf_new="no"
1799 cat > $TMPC << EOF
1800 #include <glusterfs/api/glfs.h>
1801
1802 int main(int argc, char **argv)
1803 {
1804   return glfs_fsync(NULL, NULL, NULL) && glfs_ftruncate(NULL, 0, NULL, NULL);
1805 }
1806 EOF
1807 if compile_prog "" "-lgfapi -lglusterfs" "gf new api"; then
1808   gf_new="yes"
1809 fi
1810 print_config "Gluster new API" "$gf_new"
1811 fi
1812
1813 ##########################################
1814 # check for gfapi trim support
1815 if test "$gf_trim" != "yes" ; then
1816   gf_trim="no"
1817 fi
1818 if test "$gfapi" = "yes" ; then
1819 cat > $TMPC << EOF
1820 #include <glusterfs/api/glfs.h>
1821
1822 int main(int argc, char **argv)
1823 {
1824   return glfs_discard_async(NULL, 0, 0);
1825 }
1826 EOF
1827 if compile_prog "" "-lgfapi -lglusterfs" "gf trim"; then
1828   gf_trim="yes"
1829 fi
1830 print_config "Gluster API trim support" "$gf_trim"
1831 fi
1832
1833 ##########################################
1834 # Check if we support stckf on s390
1835 if test "$s390_z196_facilities" != "yes" ; then
1836   s390_z196_facilities="no"
1837 fi
1838 cat > $TMPC << EOF
1839 #define STFLE_BITS_Z196 45 /* various z196 facilities ... */
1840 int main(int argc, char **argv)
1841 {
1842     /* We want just 1 double word to be returned.  */
1843     register unsigned long reg0 asm("0") = 0;
1844     unsigned long stfle_bits;
1845     asm volatile(".machine push"        "\n\t"
1846                  ".machine \"z9-109\""  "\n\t"
1847                  "stfle %0"             "\n\t"
1848                  ".machine pop"         "\n"
1849                  : "=QS" (stfle_bits), "+d" (reg0)
1850                  : : "cc");
1851
1852     if ((stfle_bits & (1UL << (63 - STFLE_BITS_Z196))) != 0)
1853       return 0;
1854     else
1855       return -1;
1856 }
1857 EOF
1858 if compile_prog "" "" "s390_z196_facilities"; then
1859   $TMPE
1860   if [ $? -eq 0 ]; then
1861         s390_z196_facilities="yes"
1862   fi
1863 fi
1864 print_config "s390_z196_facilities" "$s390_z196_facilities"
1865
1866 ##########################################
1867 # Check if we have required environment variables configured for libhdfs
1868 if test "$libhdfs" = "yes" ; then
1869   hdfs_conf_error=0
1870   if test "$JAVA_HOME" = "" ; then
1871     echo "configure: JAVA_HOME should be defined to jdk/jvm path"
1872     hdfs_conf_error=1
1873   fi
1874   if test "$FIO_LIBHDFS_INCLUDE" = "" ; then
1875     echo "configure: FIO_LIBHDFS_INCLUDE should be defined to libhdfs inlude path"
1876     hdfs_conf_error=1
1877   fi
1878   if test "$FIO_LIBHDFS_LIB" = "" ; then
1879     echo "configure: FIO_LIBHDFS_LIB should be defined to libhdfs library path"
1880     hdfs_conf_error=1
1881   fi
1882   if test "$hdfs_conf_error" = "1" ; then
1883     exit 1
1884   fi
1885   FIO_HDFS_CPU=$cpu
1886   if test "$FIO_HDFS_CPU" = "x86_64" ; then
1887     FIO_HDFS_CPU="amd64"
1888   fi
1889 fi
1890 print_config "HDFS engine" "$libhdfs"
1891
1892 ##########################################
1893 # Check whether we have MTD
1894 if test "$mtd" != "yes" ; then
1895   mtd="no"
1896 fi
1897 cat > $TMPC << EOF
1898 #include <string.h>
1899 #include <mtd/mtd-user.h>
1900 #include <sys/ioctl.h>
1901 int main(int argc, char **argv)
1902 {
1903   struct mtd_write_req ops;
1904   struct mtd_info_user info;
1905   memset(&ops, 0, sizeof(ops));
1906   info.type = MTD_MLCNANDFLASH;
1907   return ioctl(0, MEMGETINFO, &info);
1908 }
1909 EOF
1910 if compile_prog "" "" "mtd"; then
1911   mtd="yes"
1912 fi
1913 print_config "MTD" "$mtd"
1914
1915 ##########################################
1916 # Check whether we have libpmem
1917 if test "$libpmem" != "yes" ; then
1918   libpmem="no"
1919 fi
1920 cat > $TMPC << EOF
1921 #include <libpmem.h>
1922 int main(int argc, char **argv)
1923 {
1924   int rc;
1925   rc = pmem_is_pmem(0, 0);
1926   return 0;
1927 }
1928 EOF
1929 if compile_prog "" "-lpmem" "libpmem"; then
1930   libpmem="yes"
1931   LIBS="-lpmem $LIBS"
1932 fi
1933 print_config "libpmem" "$libpmem"
1934
1935 ##########################################
1936 # Check whether we have libpmemblk
1937 # libpmem is a prerequisite
1938 if test "$libpmemblk" != "yes" ; then
1939   libpmemblk="no"
1940 fi
1941 if test "$libpmem" = "yes"; then
1942   cat > $TMPC << EOF
1943 #include <libpmemblk.h>
1944 int main(int argc, char **argv)
1945 {
1946   PMEMblkpool *pbp;
1947   pbp = pmemblk_open("", 0);
1948   return 0;
1949 }
1950 EOF
1951   if compile_prog "" "-lpmemblk" "libpmemblk"; then
1952     libpmemblk="yes"
1953     LIBS="-lpmemblk $LIBS"
1954   fi
1955 fi
1956 print_config "libpmemblk" "$libpmemblk"
1957
1958 # Choose the ioengines
1959 if test "$libpmem" = "yes" && test "$disable_pmem" = "no"; then
1960   pmem="yes"
1961   devdax="yes"
1962   if test "$libpmemblk" = "yes"; then
1963     pmemblk="yes"
1964   fi
1965 fi
1966
1967 ##########################################
1968 # Report whether pmemblk engine is enabled
1969 print_config "PMDK pmemblk engine" "$pmemblk"
1970
1971 ##########################################
1972 # Report whether dev-dax engine is enabled
1973 print_config "PMDK dev-dax engine" "$devdax"
1974
1975 ##########################################
1976 # Report whether libpmem engine is enabled
1977 print_config "PMDK libpmem engine" "$pmem"
1978
1979 ##########################################
1980 # Check whether we support DDN's IME
1981 if test "$libime" != "yes" ; then
1982   libime="no"
1983 fi
1984 cat > $TMPC << EOF
1985 #include <ime_native.h>
1986 int main(int argc, char **argv)
1987 {
1988   int rc;
1989   ime_native_init();
1990   rc = ime_native_finalize();
1991   return 0;
1992 }
1993 EOF
1994 if compile_prog "-I${ime_path}/include" "-L${ime_path}/lib -lim_client" "libime"; then
1995   libime="yes"
1996   CFLAGS="-I${ime_path}/include $CFLAGS"
1997   LDFLAGS="-Wl,-rpath ${ime_path}/lib -L${ime_path}/lib $LDFLAGS"
1998   LIBS="-lim_client $LIBS"
1999 fi
2000 print_config "DDN's Infinite Memory Engine" "$libime"
2001
2002 ##########################################
2003 # Check if we have required environment variables configured for libiscsi
2004 if test "$libiscsi" = "yes" ; then
2005   if $(pkg-config --atleast-version=1.9.0 libiscsi); then
2006     libiscsi="yes"
2007     libiscsi_cflags=$(pkg-config --cflags libiscsi)
2008     libiscsi_libs=$(pkg-config --libs libiscsi)
2009   else
2010     if test "$libiscsi" = "yes" ; then
2011       echo "libiscsi" "Install libiscsi >= 1.9.0"
2012     fi
2013     libiscsi="no"
2014   fi
2015 fi
2016 print_config "iscsi engine" "$libiscsi"
2017
2018 ##########################################
2019 # Check if we have lex/yacc available
2020 yacc="no"
2021 yacc_is_bison="no"
2022 lex="no"
2023 arith="no"
2024 if test "$disable_lex" = "no" || test -z "$disable_lex" ; then
2025 if test "$targetos" != "SunOS" ; then
2026 LEX=$(which lex 2> /dev/null)
2027 if test -x "$LEX" ; then
2028   lex="yes"
2029 fi
2030 YACC=$(which bison 2> /dev/null)
2031 if test -x "$YACC" ; then
2032   yacc="yes"
2033   yacc_is_bison="yes"
2034 else
2035   YACC=$(which yacc 2> /dev/null)
2036   if test -x "$YACC" ; then
2037     yacc="yes"
2038   fi
2039 fi
2040 if test "$yacc" = "yes" && test "$lex" = "yes" ; then
2041   arith="yes"
2042 fi
2043
2044 if test "$arith" = "yes" ; then
2045 cat > $TMPC << EOF
2046 extern int yywrap(void);
2047
2048 int main(int argc, char **argv)
2049 {
2050   yywrap();
2051   return 0;
2052 }
2053 EOF
2054 if compile_prog "" "-ll" "lex"; then
2055   LIBS="-ll $LIBS"
2056 else
2057   arith="no"
2058 fi
2059 fi
2060 fi
2061 fi
2062
2063 # Check if lex fails using -o
2064 if test "$arith" = "yes" ; then
2065 if test "$force_no_lex_o" = "yes" ; then
2066   lex_use_o="no"
2067 else
2068 $LEX -o lex.yy.c exp/expression-parser.l 2> /dev/null
2069 if test "$?" = "0" ; then
2070   lex_use_o="yes"
2071 else
2072   lex_use_o="no"
2073 fi
2074 fi
2075 fi
2076
2077 print_config "lex/yacc for arithmetic" "$arith"
2078
2079 ##########################################
2080 # Check whether we have setmntent/getmntent
2081 if test "$getmntent" != "yes" ; then
2082   getmntent="no"
2083 fi
2084 cat > $TMPC << EOF
2085 #include <stdio.h>
2086 #include <mntent.h>
2087 int main(int argc, char **argv)
2088 {
2089   FILE *mtab = setmntent(NULL, "r");
2090   struct mntent *mnt = getmntent(mtab);
2091   endmntent(mtab);
2092   return 0;
2093 }
2094 EOF
2095 if compile_prog "" "" "getmntent"; then
2096   getmntent="yes"
2097 fi
2098 print_config "getmntent" "$getmntent"
2099
2100 ##########################################
2101 # Check whether we have getmntinfo
2102 # These are originally added for BSDs, but may also work
2103 # on other operating systems with getmntinfo(3).
2104
2105 # getmntinfo(3) for FreeBSD/DragonFlyBSD/OpenBSD.
2106 # Note that NetBSD needs -Werror to catch warning as error.
2107 if test "$getmntinfo" != "yes" ; then
2108   getmntinfo="no"
2109 fi
2110 cat > $TMPC << EOF
2111 #include <stdio.h>
2112 #include <sys/param.h>
2113 #include <sys/mount.h>
2114 int main(int argc, char **argv)
2115 {
2116   struct statfs *st;
2117   return getmntinfo(&st, MNT_NOWAIT);
2118 }
2119 EOF
2120 if compile_prog "-Werror" "" "getmntinfo"; then
2121   getmntinfo="yes"
2122 fi
2123 print_config "getmntinfo" "$getmntinfo"
2124
2125 # getmntinfo(3) for NetBSD.
2126 if test "$getmntinfo_statvfs" != "yes" ; then
2127   getmntinfo_statvfs="no"
2128 fi
2129 cat > $TMPC << EOF
2130 #include <stdio.h>
2131 #include <sys/statvfs.h>
2132 int main(int argc, char **argv)
2133 {
2134   struct statvfs *st;
2135   return getmntinfo(&st, MNT_NOWAIT);
2136 }
2137 EOF
2138 # Skip the test if the one with statfs arg is detected.
2139 if test "$getmntinfo" != "yes" && compile_prog "-Werror" "" "getmntinfo_statvfs"; then
2140   getmntinfo_statvfs="yes"
2141   print_config "getmntinfo_statvfs" "$getmntinfo_statvfs"
2142 fi
2143
2144 ##########################################
2145 # Check whether we have _Static_assert
2146 if test "$static_assert" != "yes" ; then
2147   static_assert="no"
2148 fi
2149 cat > $TMPC << EOF
2150 #include <assert.h>
2151 #include <stdlib.h>
2152 #include <stddef.h>
2153
2154 struct foo {
2155   int a, b;
2156 };
2157
2158 int main(int argc, char **argv)
2159 {
2160   _Static_assert(offsetof(struct foo, a) == 0 , "Check");
2161   return 0 ;
2162 }
2163 EOF
2164 if compile_prog "" "" "static_assert"; then
2165     static_assert="yes"
2166 fi
2167 print_config "Static Assert" "$static_assert"
2168
2169 ##########################################
2170 # Check whether we have bool / stdbool.h
2171 if test "$have_bool" != "yes" ; then
2172   have_bool="no"
2173 fi
2174 cat > $TMPC << EOF
2175 #include <stdbool.h>
2176 int main(int argc, char **argv)
2177 {
2178   bool var = true;
2179   return var != false;
2180 }
2181 EOF
2182 if compile_prog "" "" "bool"; then
2183   have_bool="yes"
2184 fi
2185 print_config "bool" "$have_bool"
2186
2187 ##########################################
2188 # Check whether we have strndup()
2189 strndup="no"
2190 cat > $TMPC << EOF
2191 #include <string.h>
2192 #include <stdlib.h>
2193 int main(int argc, char **argv)
2194 {
2195   char *res = strndup("test string", 8);
2196
2197   free(res);
2198   return 0;
2199 }
2200 EOF
2201 if compile_prog "" "" "strndup"; then
2202   strndup="yes"
2203 fi
2204 print_config "strndup" "$strndup"
2205
2206 ##########################################
2207 # <valgrind/drd.h> probe
2208 # Note: presence of <valgrind/drd.h> implies that <valgrind/valgrind.h> is
2209 # also available but not the other way around.
2210 if test "$valgrind_dev" != "yes" ; then
2211   valgrind_dev="no"
2212 fi
2213 cat > $TMPC << EOF
2214 #include <valgrind/drd.h>
2215 int main(int argc, char **argv)
2216 {
2217   return 0;
2218 }
2219 EOF
2220 if compile_prog "" "" "valgrind_dev"; then
2221   valgrind_dev="yes"
2222 fi
2223 print_config "Valgrind headers" "$valgrind_dev"
2224
2225 ##########################################
2226 # <linux/blkzoned.h> probe
2227 if test "$linux_blkzoned" != "yes" ; then
2228   linux_blkzoned="no"
2229 fi
2230 cat > $TMPC << EOF
2231 #include <linux/blkzoned.h>
2232 int main(int argc, char **argv)
2233 {
2234   return 0;
2235 }
2236 EOF
2237 if compile_prog "" "" "linux_blkzoned"; then
2238   linux_blkzoned="yes"
2239 fi
2240 print_config "Zoned block device support" "$linux_blkzoned"
2241
2242 ##########################################
2243 # check march=armv8-a+crc+crypto
2244 if test "$march_armv8_a_crc_crypto" != "yes" ; then
2245   march_armv8_a_crc_crypto="no"
2246 fi
2247 if test "$cpu" = "arm64" ; then
2248   cat > $TMPC <<EOF
2249 #include <arm_acle.h>
2250 #include <arm_neon.h>
2251 #include <sys/auxv.h>
2252
2253 int main(void)
2254 {
2255   /* Can we also do a runtime probe? */
2256 #if __linux__
2257   return getauxval(AT_HWCAP);
2258 #else
2259 # error "Don't know how to do runtime probe for ARM CRC32c"
2260 #endif
2261 }
2262 EOF
2263   if compile_prog "-march=armv8-a+crc+crypto" "" "ARM CRC32c"; then
2264     march_armv8_a_crc_crypto="yes"
2265     CFLAGS="$CFLAGS -march=armv8-a+crc+crypto"
2266     march_set="yes"
2267   fi
2268 fi
2269 print_config "march_armv8_a_crc_crypto" "$march_armv8_a_crc_crypto"
2270
2271 ##########################################
2272 # cuda probe
2273 if test "$cuda" != "yes" ; then
2274   cuda="no"
2275 fi
2276 cat > $TMPC << EOF
2277 #include <cuda.h>
2278 int main(int argc, char **argv)
2279 {
2280   return cuInit(0);
2281 }
2282 EOF
2283 if test "$enable_cuda" = "yes" && compile_prog "" "-lcuda" "cuda"; then
2284   cuda="yes"
2285   LIBS="-lcuda $LIBS"
2286 fi
2287 print_config "cuda" "$cuda"
2288
2289 ##########################################
2290 # mkdir() probe. mingw apparently has a one-argument mkdir :/
2291 mkdir_two="no"
2292 cat > $TMPC << EOF
2293 #include <sys/stat.h>
2294 #include <sys/types.h>
2295 int main(int argc, char **argv)
2296 {
2297   return mkdir("/tmp/bla", 0600);
2298 }
2299 EOF
2300 if compile_prog "" "" "mkdir(a, b)"; then
2301   mkdir_two="yes"
2302 fi
2303 print_config "mkdir(a, b)" "$mkdir_two"
2304
2305 ##########################################
2306 # check for cc -march=native
2307 build_native="no"
2308 cat > $TMPC << EOF
2309 int main(int argc, char **argv)
2310 {
2311   return 0;
2312 }
2313 EOF
2314 if test "$disable_native" = "no" && test "$disable_opt" != "yes" && \
2315    compile_prog "-march=native" "" "march=native"; then
2316   build_native="yes"
2317 fi
2318 print_config "Build march=native" "$build_native"
2319
2320 ##########################################
2321 # check for -lcunit
2322 if test "$cunit" != "yes" ; then
2323   cunit="no"
2324 fi
2325 cat > $TMPC << EOF
2326 #include <CUnit/CUnit.h>
2327 #include <CUnit/Basic.h>
2328 int main(void)
2329 {
2330   if (CU_initialize_registry() != CUE_SUCCESS)
2331     return CU_get_error();
2332   CU_basic_set_mode(CU_BRM_VERBOSE);
2333   CU_basic_run_tests();
2334   CU_cleanup_registry();
2335   return CU_get_error();
2336 }
2337 EOF
2338 if compile_prog "" "-lcunit" "CUnit"; then
2339   cunit="yes"
2340 fi
2341 print_config "CUnit" "$cunit"
2342
2343 ##########################################
2344 # check for __kernel_rwf_t
2345 __kernel_rwf_t="no"
2346 cat > $TMPC << EOF
2347 #include <linux/fs.h>
2348 int main(int argc, char **argv)
2349 {
2350   __kernel_rwf_t x;
2351   x = 0;
2352   return x;
2353 }
2354 EOF
2355 if compile_prog "" "" "__kernel_rwf_t"; then
2356   __kernel_rwf_t="yes"
2357 fi
2358 print_config "__kernel_rwf_t" "$__kernel_rwf_t"
2359
2360 ##########################################
2361 # check if gcc has -Wimplicit-fallthrough
2362 fallthrough="no"
2363 cat > $TMPC << EOF
2364 int main(int argc, char **argv)
2365 {
2366   return 0;
2367 }
2368 EOF
2369 if compile_prog "-Wimplicit-fallthrough" "" "-Wimplicit-fallthrough"; then
2370   fallthrough="yes"
2371 fi
2372 print_config "-Wimplicit-fallthrough" "$fallthrough"
2373
2374 ##########################################
2375 # check for MADV_HUGEPAGE support
2376 if test "$thp" != "yes" ; then
2377   thp="no"
2378 fi
2379 if test "$esx" != "yes" ; then
2380   cat > $TMPC <<EOF
2381 #include <sys/mman.h>
2382 int main(void)
2383 {
2384   return madvise(0, 0x1000, MADV_HUGEPAGE);
2385 }
2386 EOF
2387   if compile_prog "" "" "thp" ; then
2388     thp=yes
2389   else
2390     if test "$thp" = "yes" ; then
2391       feature_not_found "Transparent Huge Page" ""
2392     fi
2393     thp=no
2394   fi
2395 fi
2396 print_config "MADV_HUGEPAGE" "$thp"
2397
2398 ##########################################
2399 # check for gettid()
2400 gettid="no"
2401 cat > $TMPC << EOF
2402 #include <unistd.h>
2403 int main(int argc, char **argv)
2404 {
2405   return gettid();
2406 }
2407 EOF
2408 if compile_prog "" "" "gettid"; then
2409   gettid="yes"
2410 fi
2411 print_config "gettid" "$gettid"
2412
2413 #############################################################################
2414
2415 if test "$wordsize" = "64" ; then
2416   output_sym "CONFIG_64BIT"
2417 elif test "$wordsize" = "32" ; then
2418   output_sym "CONFIG_32BIT"
2419 else
2420   fatal "Unknown wordsize!"
2421 fi
2422 if test "$bigendian" = "yes" ; then
2423   output_sym "CONFIG_BIG_ENDIAN"
2424 else
2425   output_sym "CONFIG_LITTLE_ENDIAN"
2426 fi
2427 if test "$zlib" = "yes" ; then
2428   output_sym "CONFIG_ZLIB"
2429 fi
2430 if test "$libaio" = "yes" ; then
2431   output_sym "CONFIG_LIBAIO"
2432 fi
2433 if test "$posix_aio" = "yes" ; then
2434   output_sym "CONFIG_POSIXAIO"
2435 fi
2436 if test "$posix_aio_fsync" = "yes" ; then
2437   output_sym "CONFIG_POSIXAIO_FSYNC"
2438 fi
2439 if test "$posix_pshared" = "yes" ; then
2440   output_sym "CONFIG_PSHARED"
2441 fi
2442 if test "$have_asprintf" = "yes" ; then
2443     output_sym "CONFIG_HAVE_ASPRINTF"
2444 fi
2445 if test "$have_vasprintf" = "yes" ; then
2446     output_sym "CONFIG_HAVE_VASPRINTF"
2447 fi
2448 if test "$linux_fallocate" = "yes" ; then
2449   output_sym "CONFIG_LINUX_FALLOCATE"
2450 fi
2451 if test "$posix_fallocate" = "yes" ; then
2452   output_sym "CONFIG_POSIX_FALLOCATE"
2453 fi
2454 if test "$fdatasync" = "yes" ; then
2455   output_sym "CONFIG_FDATASYNC"
2456 fi
2457 if test "$sync_file_range" = "yes" ; then
2458   output_sym "CONFIG_SYNC_FILE_RANGE"
2459 fi
2460 if test "$sfaa" = "yes" ; then
2461   output_sym "CONFIG_SFAA"
2462 fi
2463 if test "$sync_sync" = "yes" ; then
2464   output_sym "CONFIG_SYNC_SYNC"
2465 fi
2466 if test "$cmp_swap" = "yes" ; then
2467   output_sym "CONFIG_CMP_SWAP"
2468 fi
2469 if test "$libverbs" = "yes" -a "$rdmacm" = "yes" ; then
2470   output_sym "CONFIG_RDMA"
2471 fi
2472 if test "$clock_gettime" = "yes" ; then
2473   output_sym "CONFIG_CLOCK_GETTIME"
2474 fi
2475 if test "$clock_monotonic" = "yes" ; then
2476   output_sym "CONFIG_CLOCK_MONOTONIC"
2477 fi
2478 if test "$clock_monotonic_raw" = "yes" ; then
2479   output_sym "CONFIG_CLOCK_MONOTONIC_RAW"
2480 fi
2481 if test "$clock_monotonic_precise" = "yes" ; then
2482   output_sym "CONFIG_CLOCK_MONOTONIC_PRECISE"
2483 fi
2484 if test "$clockid_t" = "yes"; then
2485   output_sym "CONFIG_CLOCKID_T"
2486 fi
2487 if test "$gettimeofday" = "yes" ; then
2488   output_sym "CONFIG_GETTIMEOFDAY"
2489 fi
2490 if test "$posix_fadvise" = "yes" ; then
2491   output_sym "CONFIG_POSIX_FADVISE"
2492 fi
2493 if test "$linux_3arg_affinity" = "yes" ; then
2494   output_sym "CONFIG_3ARG_AFFINITY"
2495 elif test "$linux_2arg_affinity" = "yes" ; then
2496   output_sym "CONFIG_2ARG_AFFINITY"
2497 fi
2498 if test "$strsep" = "yes" ; then
2499   output_sym "CONFIG_STRSEP"
2500 fi
2501 if test "$strcasestr" = "yes" ; then
2502   output_sym "CONFIG_STRCASESTR"
2503 fi
2504 if test "$strlcat" = "yes" ; then
2505   output_sym "CONFIG_STRLCAT"
2506 fi
2507 if test "$getopt_long_only" = "yes" ; then
2508   output_sym "CONFIG_GETOPT_LONG_ONLY"
2509 fi
2510 if test "$inet_aton" = "yes" ; then
2511   output_sym "CONFIG_INET_ATON"
2512 fi
2513 if test "$socklen_t" = "yes" ; then
2514   output_sym "CONFIG_SOCKLEN_T"
2515 fi
2516 if test "$ext4_me" = "yes" ; then
2517   output_sym "CONFIG_LINUX_EXT4_MOVE_EXTENT"
2518 fi
2519 if test "$linux_splice" = "yes" ; then
2520   output_sym "CONFIG_LINUX_SPLICE"
2521 fi
2522 if test "$guasi" = "yes" ; then
2523   output_sym "CONFIG_GUASI"
2524 fi
2525 if test "$libnuma_v2" = "yes" ; then
2526   output_sym "CONFIG_LIBNUMA"
2527 fi
2528 if test "$solaris_aio" = "yes" ; then
2529   output_sym "CONFIG_SOLARISAIO"
2530 fi
2531 if test "$tls_thread" = "yes" ; then
2532   output_sym "CONFIG_TLS_THREAD"
2533 fi
2534 if test "$rusage_thread" = "yes" ; then
2535   output_sym "CONFIG_RUSAGE_THREAD"
2536 fi
2537 if test "$gfio" = "yes" ; then
2538   output_sym "CONFIG_GFIO"
2539 fi
2540 if test "$esx" = "yes" ; then
2541   output_sym "CONFIG_ESX"
2542   output_sym "CONFIG_NO_SHM"
2543 fi
2544 if test "$sched_idle" = "yes" ; then
2545   output_sym "CONFIG_SCHED_IDLE"
2546 fi
2547 if test "$tcp_nodelay" = "yes" ; then
2548   output_sym "CONFIG_TCP_NODELAY"
2549 fi
2550 if test "$window_size" = "yes" ; then
2551   output_sym "CONFIG_NET_WINDOWSIZE"
2552 fi
2553 if test "$mss" = "yes" ; then
2554   output_sym "CONFIG_NET_MSS"
2555 fi
2556 if test "$rlimit_memlock" = "yes" ; then
2557   output_sym "CONFIG_RLIMIT_MEMLOCK"
2558 fi
2559 if test "$pwritev" = "yes" ; then
2560   output_sym "CONFIG_PWRITEV"
2561 fi
2562 if test "$pwritev2" = "yes" ; then
2563   output_sym "CONFIG_PWRITEV2"
2564 fi
2565 if test "$ipv6" = "yes" ; then
2566   output_sym "CONFIG_IPV6"
2567 fi
2568 if test "$http" = "yes" ; then
2569   output_sym "CONFIG_HTTP"
2570 fi
2571 if test "$rados" = "yes" ; then
2572   output_sym "CONFIG_RADOS"
2573 fi
2574 if test "$rbd" = "yes" ; then
2575   output_sym "CONFIG_RBD"
2576 fi
2577 if test "$rbd_poll" = "yes" ; then
2578   output_sym "CONFIG_RBD_POLL"
2579 fi
2580 if test "$rbd_inval" = "yes" ; then
2581   output_sym "CONFIG_RBD_INVAL"
2582 fi
2583 if test "$setvbuf" = "yes" ; then
2584   output_sym "CONFIG_SETVBUF"
2585 fi
2586 if test "$s390_z196_facilities" = "yes" ; then
2587   output_sym "CONFIG_S390_Z196_FACILITIES"
2588   CFLAGS="$CFLAGS -march=z9-109"
2589   march_set="yes"
2590 fi
2591 if test "$gfapi" = "yes" ; then
2592   output_sym "CONFIG_GFAPI"
2593 fi
2594 if test "$gf_fadvise" = "yes" ; then
2595   output_sym "CONFIG_GF_FADVISE"
2596 fi
2597 if test "$gf_trim" = "yes" ; then
2598   output_sym "CONFIG_GF_TRIM"
2599 fi
2600 if test "$gf_new" = "yes" ; then
2601   output_sym "CONFIG_GF_NEW_API"
2602 fi
2603 if test "$libhdfs" = "yes" ; then
2604   output_sym "CONFIG_LIBHDFS"
2605   echo "FIO_HDFS_CPU=$FIO_HDFS_CPU" >> $config_host_mak
2606   echo "JAVA_HOME=$JAVA_HOME" >> $config_host_mak
2607   echo "FIO_LIBHDFS_INCLUDE=$FIO_LIBHDFS_INCLUDE" >> $config_host_mak
2608   echo "FIO_LIBHDFS_LIB=$FIO_LIBHDFS_LIB" >> $config_host_mak
2609 fi
2610 if test "$mtd" = "yes" ; then
2611   output_sym "CONFIG_MTD"
2612 fi
2613 if test "$pmemblk" = "yes" ; then
2614   output_sym "CONFIG_PMEMBLK"
2615 fi
2616 if test "$devdax" = "yes" ; then
2617   output_sym "CONFIG_LINUX_DEVDAX"
2618 fi
2619 if test "$pmem" = "yes" ; then
2620   output_sym "CONFIG_LIBPMEM"
2621 fi
2622 if test "$libime" = "yes" ; then
2623   output_sym "CONFIG_IME"
2624 fi
2625 if test "$arith" = "yes" ; then
2626   output_sym "CONFIG_ARITHMETIC"
2627   if test "$yacc_is_bison" = "yes" ; then
2628     echo "YACC=$YACC -y" >> $config_host_mak
2629   else
2630     echo "YACC=$YACC" >> $config_host_mak
2631   fi
2632   if test "$lex_use_o" = "yes" ; then
2633     echo "CONFIG_LEX_USE_O=y" >> $config_host_mak
2634   fi
2635 fi
2636 if test "$getmntent" = "yes" ; then
2637   output_sym "CONFIG_GETMNTENT"
2638 fi
2639 if test "$getmntinfo" = "yes" ; then
2640   output_sym "CONFIG_GETMNTINFO"
2641 fi
2642 if test "$getmntinfo_statvfs" = "yes" ; then
2643   output_sym "CONFIG_GETMNTINFO_STATVFS"
2644 fi
2645 if test "$static_assert" = "yes" ; then
2646   output_sym "CONFIG_STATIC_ASSERT"
2647 fi
2648 if test "$have_bool" = "yes" ; then
2649   output_sym "CONFIG_HAVE_BOOL"
2650 fi
2651 if test "$strndup" = "yes" ; then
2652   output_sym "CONFIG_HAVE_STRNDUP"
2653 fi
2654 if test "$disable_opt" = "yes" ; then
2655   output_sym "CONFIG_DISABLE_OPTIMIZATIONS"
2656 fi
2657 if test "$valgrind_dev" = "yes"; then
2658   output_sym "CONFIG_VALGRIND_DEV"
2659 fi
2660 if test "$linux_blkzoned" = "yes" ; then
2661   output_sym "CONFIG_LINUX_BLKZONED"
2662 fi
2663 if test "$zlib" = "no" ; then
2664   echo "Consider installing zlib-dev (zlib-devel, some fio features depend on it."
2665   if test "$build_static" = "yes"; then
2666     echo "Note that some distros have separate packages for static libraries."
2667   fi
2668 fi
2669 if test "$march_armv8_a_crc_crypto" = "yes" ; then
2670   output_sym "ARCH_HAVE_CRC_CRYPTO"
2671 fi
2672 if test "$cuda" = "yes" ; then
2673   output_sym "CONFIG_CUDA"
2674 fi
2675 if test "$mkdir_two" = "yes" ; then
2676   output_sym "CONFIG_HAVE_MKDIR_TWO"
2677 fi
2678 if test "$march_set" = "no" && test "$build_native" = "yes" ; then
2679   output_sym "CONFIG_BUILD_NATIVE"
2680 fi
2681 if test "$cunit" = "yes" ; then
2682   output_sym "CONFIG_HAVE_CUNIT"
2683 fi
2684 if test "$__kernel_rwf_t" = "yes"; then
2685   output_sym "CONFIG_HAVE_KERNEL_RWF_T"
2686 fi
2687 if test "$gettid" = "yes"; then
2688   output_sym "CONFIG_HAVE_GETTID"
2689 fi
2690 if test "$fallthrough" = "yes"; then
2691   CFLAGS="$CFLAGS -Wimplicit-fallthrough"
2692 fi
2693 if test "$thp" = "yes" ; then
2694   output_sym "CONFIG_HAVE_THP"
2695 fi
2696 if test "$libiscsi" = "yes" ; then
2697   output_sym "CONFIG_LIBISCSI"
2698   echo "CONFIG_LIBISCSI=m" >> $config_host_mak
2699   echo "LIBISCSI_CFLAGS=$libiscsi_cflags" >> $config_host_mak
2700   echo "LIBISCSI_LIBS=$libiscsi_libs" >> $config_host_mak
2701 fi
2702 cat > $TMPC << EOF
2703 int main(int argc, char **argv)
2704 {
2705   return 0;
2706 }
2707 EOF
2708 if test "$disable_tcmalloc" != "yes"  && compile_prog "" "-ltcmalloc" "tcmalloc"; then
2709   LIBS="-ltcmalloc $LIBS"
2710   tcmalloc="yes"
2711 else
2712   tcmalloc="no"
2713 fi
2714 print_config "TCMalloc support" "$tcmalloc"
2715
2716 echo "LIBS+=$LIBS" >> $config_host_mak
2717 echo "GFIO_LIBS+=$GFIO_LIBS" >> $config_host_mak
2718 echo "CFLAGS+=$CFLAGS" >> $config_host_mak
2719 echo "LDFLAGS+=$LDFLAGS" >> $config_host_mak
2720 echo "CC=$cc" >> $config_host_mak
2721 echo "BUILD_CFLAGS=$BUILD_CFLAGS $CFLAGS" >> $config_host_mak
2722 echo "INSTALL_PREFIX=$prefix" >> $config_host_mak
2723
2724 if [ `dirname $0` != "." -a ! -e Makefile ]; then
2725     cat > Makefile <<EOF
2726 SRCDIR:=`dirname $0`
2727 include \$(SRCDIR)/Makefile
2728 EOF
2729 fi