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