Add a comment to clarify 941bda94
[fio.git] / configure
1 #!/bin/sh
2 #
3 # Fio configure script. Heavily influenced by the manual qemu configure
4 # script. Sad this 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 TMPO="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.o"
18 TMPE="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.exe"
19
20 # NB: do not call "exit" in the trap handler; this is buggy with some shells;
21 # see <1285349658-3122-1-git-send-email-loic.minier@linaro.org>
22 trap "rm -f $TMPC $TMPO $TMPE" EXIT INT QUIT TERM
23
24 rm -rf config.log
25
26 config_host_mak="config-host.mak"
27 config_host_h="config-host.h"
28
29 rm -rf $config_host_mak
30 rm -rf $config_host_h
31
32 fatal() {
33   echo $@
34   echo "Configure failed, check config.log and/or the above output"
35   rm -rf $config_host_mak
36   rm -rf $config_host_h
37   exit 1
38 }
39
40 # Default CFLAGS
41 CFLAGS="-D_GNU_SOURCE -include config-host.h"
42 BUILD_CFLAGS=""
43
44 # Print a helpful header at the top of config.log
45 echo "# FIO configure log $(date)" >> config.log
46 printf "# Configured with:" >> config.log
47 printf " '%s'" "$0" "$@" >> config.log
48 echo >> config.log
49 echo "#" >> config.log
50
51 # Print configure header at the top of $config_host_h
52 echo "/*" > $config_host_h
53 echo " * Automatically generated by configure - do not modify" >> $config_host_h
54 printf " * Configured with:" >> $config_host_h
55 printf " * '%s'" "$0" "$@" >> $config_host_h
56 echo "" >> $config_host_h
57 echo " */" >> $config_host_h
58
59 do_cc() {
60     # Run the compiler, capturing its output to the log.
61     echo $cc "$@" >> config.log
62     $cc "$@" >> config.log 2>&1 || return $?
63     # Test passed. If this is an --enable-werror build, rerun
64     # the test with -Werror and bail out if it fails. This
65     # makes warning-generating-errors in configure test code
66     # obvious to developers.
67     if test "$werror" != "yes"; then
68         return 0
69     fi
70     # Don't bother rerunning the compile if we were already using -Werror
71     case "$*" in
72         *-Werror*)
73            return 0
74         ;;
75     esac
76     echo $cc -Werror "$@" >> config.log
77     $cc -Werror "$@" >> config.log 2>&1 && return $?
78     echo "ERROR: configure test passed without -Werror but failed with -Werror."
79     echo "This is probably a bug in the configure script. The failing command"
80     echo "will be at the bottom of config.log."
81     fatal "You can run configure with --disable-werror to bypass this check."
82 }
83
84 compile_object() {
85   do_cc $CFLAGS -c -o $TMPO $TMPC
86 }
87
88 compile_prog() {
89   local_cflags="$1"
90   local_ldflags="$2 $LIBS"
91   echo "Compiling test case $3" >> config.log
92   do_cc $CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
93 }
94
95 feature_not_found() {
96   feature=$1
97   packages=$2
98
99   echo "ERROR"
100   echo "ERROR: User requested feature $feature"
101   if test ! -z "$packages" ; then
102     echo "ERROR: That feature needs $packages installed"
103   fi
104   echo "ERROR: configure was not able to find it"
105   fatal "ERROR"
106 }
107
108 has() {
109   type "$1" >/dev/null 2>&1
110 }
111
112 check_define() {
113   cat > $TMPC <<EOF
114 #if !defined($1)
115 #error $1 not defined
116 #endif
117 int main(void)
118 {
119   return 0;
120 }
121 EOF
122   compile_object
123 }
124
125 output_sym() {
126   echo "$1=y" >> $config_host_mak
127   echo "#define $1" >> $config_host_h
128 }
129
130 targetos=""
131 cpu=""
132
133 # default options
134 show_help="no"
135 exit_val=0
136 gfio_check="no"
137 libhdfs="no"
138 pmemblk="no"
139 devdax="no"
140 disable_lex=""
141 disable_pmem="no"
142 prefix=/usr/local
143
144 # parse options
145 for opt do
146   optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
147   case "$opt" in
148   --prefix=*) prefix="$optarg"
149   ;;
150   --cpu=*) cpu="$optarg"
151   ;;
152   #  esx is cross compiled and cannot be detect through simple uname calls
153   --esx)
154   esx="yes"
155   ;;
156   --cc=*) CC="$optarg"
157   ;;
158   --extra-cflags=*) CFLAGS="$CFLAGS $optarg"
159   ;;
160   --build-32bit-win) build_32bit_win="yes"
161   ;;
162   --build-static) build_static="yes"
163   ;;
164   --enable-gfio)
165   gfio_check="yes"
166   ;;
167   --disable-numa) disable_numa="yes"
168   ;;
169   --disable-rbd) disable_rbd="yes"
170   ;;
171   --disable-rbd-blkin) disable_rbd_blkin="yes"
172   ;;
173   --disable-gfapi) disable_gfapi="yes"
174   ;;
175   --enable-libhdfs) libhdfs="yes"
176   ;;
177   --disable-lex) disable_lex="yes"
178   ;;
179   --enable-lex) disable_lex="no"
180   ;;
181   --disable-shm) no_shm="yes"
182   ;;
183   --disable-optimizations) disable_opt="yes"
184   ;;
185   --disable-pmem) disable_pmem="yes"
186   ;;
187   --help)
188     show_help="yes"
189     ;;
190   *)
191   echo "Bad option $opt"
192   show_help="yes"
193   exit_val=1
194   esac
195 done
196
197 if test "$show_help" = "yes" ; then
198   echo "--prefix=              Use this directory as installation prefix"
199   echo "--cpu=                 Specify target CPU if auto-detect fails"
200   echo "--cc=                  Specify compiler to use"
201   echo "--extra-cflags=        Specify extra CFLAGS to pass to compiler"
202   echo "--build-32bit-win      Enable 32-bit build on Windows"
203   echo "--build-static         Build a static fio"
204   echo "--esx                  Configure build options for esx"
205   echo "--enable-gfio          Enable building of gtk gfio"
206   echo "--disable-numa         Disable libnuma even if found"
207   echo "--disable-gfapi        Disable gfapi"
208   echo "--enable-libhdfs       Enable hdfs support"
209   echo "--disable-lex          Disable use of lex/yacc for math"
210   echo "--disable-pmem         Disable pmem based engines even if found"
211   echo "--enable-lex           Enable use of lex/yacc for math"
212   echo "--disable-shm          Disable SHM support"
213   echo "--disable-optimizations Don't enable compiler optimizations"
214   exit $exit_val
215 fi
216
217 cross_prefix=${cross_prefix-${CROSS_COMPILE}}
218 cc="${CC-${cross_prefix}gcc}"
219
220 if check_define __ANDROID__ ; then
221   targetos="Android"
222 elif check_define __linux__ ; then
223   targetos="Linux"
224 elif check_define __OpenBSD__ ; then
225   targetos='OpenBSD'
226 elif check_define __sun__ ; then
227   targetos='SunOS'
228   CFLAGS="$CFLAGS -D_REENTRANT"
229 elif check_define _WIN32 ; then
230   targetos='CYGWIN'
231 else
232   targetos=`uname -s`
233 fi
234
235 echo "# Automatically generated by configure - do not modify" > $config_host_mak
236 printf "# Configured with:" >> $config_host_mak
237 printf " '%s'" "$0" "$@" >> $config_host_mak
238 echo >> $config_host_mak
239 echo "CONFIG_TARGET_OS=$targetos" >> $config_host_mak
240
241 if test "$no_shm" = "yes" ; then
242   output_sym "CONFIG_NO_SHM"
243 fi
244
245 if test "$disable_opt" = "yes" ; then
246   output_sym "CONFIG_FIO_NO_OPT"
247 fi
248
249 # Some host OSes need non-standard checks for which CPU to use.
250 # Note that these checks are broken for cross-compilation: if you're
251 # cross-compiling to one of these OSes then you'll need to specify
252 # the correct CPU with the --cpu option.
253 case $targetos in
254 AIX)
255   # Unless explicitly enabled, turn off lex.
256   if test -z "$disable_lex" ; then
257     disable_lex="yes"
258   else
259     force_no_lex_o="yes"
260   fi
261   ;;
262 Darwin)
263   # on Leopard most of the system is 32-bit, so we have to ask the kernel if
264   # we can run 64-bit userspace code.
265   # If the user didn't specify a CPU explicitly and the kernel says this is
266   # 64 bit hw, then assume x86_64. Otherwise fall through to the usual
267   # detection code.
268   if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then
269     cpu="x86_64"
270   fi
271   # Error at compile time linking of weak/partial symbols if possible...
272 cat > $TMPC <<EOF
273 int main(void)
274 {
275   return 0;
276 }
277 EOF
278   if compile_prog "" "-Wl,-no_weak_imports" "disable weak symbols"; then
279     echo "Disabling weak symbols"
280     LDFLAGS="$LDFLAGS -Wl,-no_weak_imports"
281   fi
282   ;;
283 SunOS)
284   # `uname -m` returns i86pc even on an x86_64 box, so default based on isainfo
285   if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
286     cpu="x86_64"
287   fi
288   LIBS="-lnsl -lsocket"
289   ;;
290 CYGWIN*)
291   echo "Forcing known good options on Windows"
292   if test -z "$CC" ; then
293     if test ! -z "$build_32bit_win" && test "$build_32bit_win" = "yes"; then
294       CC="i686-w64-mingw32-gcc"
295       if test -e "../zlib/contrib/vstudio/vc14/x86/ZlibStatReleaseWithoutAsm/zlibstat.lib"; then
296         echo "Building with zlib support"
297         output_sym "CONFIG_ZLIB"
298         echo "LIBS=../zlib/contrib/vstudio/vc14/x86/ZlibStatReleaseWithoutAsm/zlibstat.lib" >> $config_host_mak
299       fi
300     else
301       CC="x86_64-w64-mingw32-gcc"
302       if test -e "../zlib/contrib/vstudio/vc14/x64/ZlibStatReleaseWithoutAsm/zlibstat.lib"; then
303         echo "Building with zlib support"
304         output_sym "CONFIG_ZLIB"
305         echo "LIBS=../zlib/contrib/vstudio/vc14/x64/ZlibStatReleaseWithoutAsm/zlibstat.lib" >> $config_host_mak
306       fi
307     fi
308   fi
309   output_sym "CONFIG_LITTLE_ENDIAN"
310   if test ! -z "$build_32bit_win" && test "$build_32bit_win" = "yes"; then
311     output_sym "CONFIG_32BIT"
312   else
313     output_sym "CONFIG_64BIT_LLP64"
314   fi
315   output_sym "CONFIG_FADVISE"
316   output_sym "CONFIG_SOCKLEN_T"
317   output_sym "CONFIG_FADVISE"
318   output_sym "CONFIG_SFAA"
319   output_sym "CONFIG_RUSAGE_THREAD"
320   output_sym "CONFIG_WINDOWSAIO"
321   output_sym "CONFIG_FDATASYNC"
322   output_sym "CONFIG_CLOCK_MONOTONIC"
323   output_sym "CONFIG_GETTIMEOFDAY"
324   output_sym "CONFIG_CLOCK_GETTIME"
325   output_sym "CONFIG_SCHED_IDLE"
326   output_sym "CONFIG_TCP_NODELAY"
327   output_sym "CONFIG_TLS_THREAD"
328   output_sym "CONFIG_IPV6"
329   echo "CC=$CC" >> $config_host_mak
330   echo "BUILD_CFLAGS=$CFLAGS -I../zlib -include config-host.h -D_GNU_SOURCE" >> $config_host_mak
331
332   exit 0
333   ;;
334 esac
335
336 if test ! -z "$cpu" ; then
337   # command line argument
338   :
339 elif check_define __i386__ ; then
340   cpu="i386"
341 elif check_define __x86_64__ ; then
342   cpu="x86_64"
343 elif check_define __sparc__ ; then
344   if check_define __arch64__ ; then
345     cpu="sparc64"
346   else
347     cpu="sparc"
348   fi
349 elif check_define _ARCH_PPC ; then
350   if check_define _ARCH_PPC64 ; then
351     cpu="ppc64"
352   else
353     cpu="ppc"
354   fi
355 elif check_define __mips__ ; then
356   cpu="mips"
357 elif check_define __ia64__ ; then
358   cpu="ia64"
359 elif check_define __s390__ ; then
360   if check_define __s390x__ ; then
361     cpu="s390x"
362   else
363     cpu="s390"
364   fi
365 elif check_define __arm__ ; then
366   cpu="arm"
367 elif check_define __aarch64__ ; then
368   cpu="aarch64"
369 elif check_define __hppa__ ; then
370   cpu="hppa"
371 else
372   cpu=`uname -m`
373 fi
374
375 # Normalise host CPU name and set ARCH.
376 case "$cpu" in
377   ia64|ppc|ppc64|s390|s390x|sparc64)
378     cpu="$cpu"
379   ;;
380   i386|i486|i586|i686|i86pc|BePC)
381     cpu="i386"
382   ;;
383   x86_64|amd64)
384     cpu="x86_64"
385   ;;
386   armv*b|armv*l|arm)
387     cpu="arm"
388   ;;
389   aarch64)
390     cpu="arm64"
391   ;;
392   hppa|parisc|parisc64)
393     cpu="hppa"
394   ;;
395   mips*)
396     cpu="mips"
397   ;;
398   sparc|sun4[cdmuv])
399     cpu="sparc"
400   ;;
401   *)
402   echo "Unknown CPU"
403   ;;
404 esac
405
406 if test -z "$CC" ; then
407   if test "$targetos" = "FreeBSD"; then
408     if has clang; then
409       CC=clang
410     else
411       CC=gcc
412     fi
413   fi
414 fi
415
416 cc="${CC-${cross_prefix}gcc}"
417
418 ##########################################
419 # check cross compile
420
421 cross_compile="no"
422 cat > $TMPC <<EOF
423 int main(void)
424 {
425   return 0;
426 }
427 EOF
428 if compile_prog "" "" "cross"; then
429   $TMPE 2>/dev/null || cross_compile="yes"
430 else
431   fatal "compile test failed"
432 fi
433
434 ##########################################
435 # check endianness
436 bigendian="no"
437 if test "$cross_compile" = "no" ; then
438   cat > $TMPC <<EOF
439 #include <inttypes.h>
440 int main(void)
441 {
442   volatile uint32_t i=0x01234567;
443   return (*((uint8_t*)(&i))) == 0x67;
444 }
445 EOF
446   if compile_prog "" "" "endian"; then
447     $TMPE && bigendian="yes"
448   fi
449 else
450   # If we're cross compiling, try our best to work it out and rely on the
451   # run-time check to fail if we get it wrong.
452   cat > $TMPC <<EOF
453 #include <endian.h>
454 int main(void)
455 {
456 #if __BYTE_ORDER != __BIG_ENDIAN
457 # error "Unknown endianness"
458 #endif
459 }
460 EOF
461   compile_prog "" "" "endian" && bigendian="yes"
462   check_define "__ARMEB__" && bigendian="yes"
463   check_define "__MIPSEB__" && bigendian="yes"
464 fi
465
466
467 echo "Operating system              $targetos"
468 echo "CPU                           $cpu"
469 echo "Big endian                    $bigendian"
470 echo "Compiler                      $cc"
471 echo "Cross compile                 $cross_compile"
472 echo
473
474 ##########################################
475 # See if we need to build a static build
476 if test "$build_static" = "yes" ; then
477   CFLAGS="$CFLAGS -ffunction-sections -fdata-sections"
478   LDFLAGS="$LDFLAGS -static -Wl,--gc-sections"
479 else
480   build_static="no"
481 fi
482 echo "Static build                  $build_static"
483
484 ##########################################
485 # check for wordsize
486 wordsize="0"
487 cat > $TMPC <<EOF
488 #include <limits.h>
489 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
490 int main(void)
491 {
492   BUILD_BUG_ON(sizeof(long)*CHAR_BIT != WORDSIZE);
493   return 0;
494 }
495 EOF
496 if compile_prog "-DWORDSIZE=32" "" "wordsize"; then
497   wordsize="32"
498 elif compile_prog "-DWORDSIZE=64" "" "wordsize"; then
499   wordsize="64"
500 else
501   fatal "Unknown wordsize"
502 fi
503 echo "Wordsize                      $wordsize"
504
505 ##########################################
506 # zlib probe
507 zlib="no"
508 cat > $TMPC <<EOF
509 #include <zlib.h>
510 int main(void)
511 {
512   z_stream stream;
513   if (inflateInit(&stream) != Z_OK)
514     return 1;
515   return 0;
516 }
517 EOF
518 if compile_prog "" "-lz" "zlib" ; then
519   zlib=yes
520   LIBS="-lz $LIBS"
521 fi
522 echo "zlib                          $zlib"
523
524 ##########################################
525 # linux-aio probe
526 libaio="no"
527 if test "$esx" != "yes" ; then
528   cat > $TMPC <<EOF
529 #include <libaio.h>
530 #include <stddef.h>
531 int main(void)
532 {
533   io_setup(0, NULL);
534   return 0;
535 }
536 EOF
537   if compile_prog "" "-laio" "libaio" ; then
538     libaio=yes
539     LIBS="-laio $LIBS"
540   else
541     if test "$libaio" = "yes" ; then
542       feature_not_found "linux AIO" "libaio-dev or libaio-devel"
543     fi
544     libaio=no
545   fi
546 fi
547 echo "Linux AIO support             $libaio"
548
549 ##########################################
550 # posix aio probe
551 posix_aio="no"
552 posix_aio_lrt="no"
553 cat > $TMPC <<EOF
554 #include <aio.h>
555 int main(void)
556 {
557   struct aiocb cb;
558   aio_read(&cb);
559   return 0;
560 }
561 EOF
562 if compile_prog "" "" "posixaio" ; then
563   posix_aio="yes"
564 elif compile_prog "" "-lrt" "posixaio"; then
565   posix_aio="yes"
566   posix_aio_lrt="yes"
567   LIBS="-lrt $LIBS"
568 fi
569 echo "POSIX AIO support             $posix_aio"
570 echo "POSIX AIO support needs -lrt  $posix_aio_lrt"
571
572 ##########################################
573 # posix aio fsync probe
574 posix_aio_fsync="no"
575 if test "$posix_aio" = "yes" ; then
576   cat > $TMPC <<EOF
577 #include <fcntl.h>
578 #include <aio.h>
579 int main(void)
580 {
581   struct aiocb cb;
582   return aio_fsync(O_SYNC, &cb);
583   return 0;
584 }
585 EOF
586   if compile_prog "" "$LIBS" "posix_aio_fsync" ; then
587     posix_aio_fsync=yes
588   fi
589 fi
590 echo "POSIX AIO fsync               $posix_aio_fsync"
591
592 ##########################################
593 # solaris aio probe
594 solaris_aio="no"
595 cat > $TMPC <<EOF
596 #include <sys/types.h>
597 #include <sys/asynch.h>
598 #include <unistd.h>
599 int main(void)
600 {
601   aio_result_t res;
602   return aioread(0, NULL, 0, 0, SEEK_SET, &res);
603   return 0;
604 }
605 EOF
606 if compile_prog "" "-laio" "solarisaio" ; then
607   solaris_aio=yes
608   LIBS="-laio $LIBS"
609 fi
610 echo "Solaris AIO support           $solaris_aio"
611
612 ##########################################
613 # __sync_fetch_and_add test
614 sfaa="no"
615 cat > $TMPC << EOF
616 #include <inttypes.h>
617 static int sfaa(uint64_t *ptr)
618 {
619   return __sync_fetch_and_add(ptr, 0);
620 }
621
622 int main(int argc, char **argv)
623 {
624   uint64_t val = 42;
625   sfaa(&val);
626   return val;
627 }
628 EOF
629 if compile_prog "" "" "__sync_fetch_and_add()" ; then
630     sfaa="yes"
631 fi
632 echo "__sync_fetch_and_add          $sfaa"
633
634 ##########################################
635 # libverbs probe
636 libverbs="no"
637 cat > $TMPC << EOF
638 #include <stdio.h>
639 #include <infiniband/arch.h>
640 int main(int argc, char **argv)
641 {
642   struct ibv_pd *pd = ibv_alloc_pd(NULL);
643   return 0;
644 }
645 EOF
646 if compile_prog "" "-libverbs" "libverbs" ; then
647     libverbs="yes"
648     LIBS="-libverbs $LIBS"
649 fi
650 echo "libverbs                      $libverbs"
651
652 ##########################################
653 # rdmacm probe
654 rdmacm="no"
655 cat > $TMPC << EOF
656 #include <stdio.h>
657 #include <rdma/rdma_cma.h>
658 int main(int argc, char **argv)
659 {
660   rdma_destroy_qp(NULL);
661   return 0;
662 }
663 EOF
664 if compile_prog "" "-lrdmacm" "rdma"; then
665     rdmacm="yes"
666     LIBS="-lrdmacm $LIBS"
667 fi
668 echo "rdmacm                        $rdmacm"
669
670 ##########################################
671 # Linux fallocate probe
672 linux_fallocate="no"
673 cat > $TMPC << EOF
674 #include <stdio.h>
675 #include <fcntl.h>
676 #include <linux/falloc.h>
677 int main(int argc, char **argv)
678 {
679   int r = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 1024);
680   return r;
681 }
682 EOF
683 if compile_prog "" "" "linux_fallocate"; then
684     linux_fallocate="yes"
685 fi
686 echo "Linux fallocate               $linux_fallocate"
687
688 ##########################################
689 # POSIX fadvise probe
690 posix_fadvise="no"
691 cat > $TMPC << EOF
692 #include <stdio.h>
693 #include <fcntl.h>
694 int main(int argc, char **argv)
695 {
696   int r = posix_fadvise(0, 0, 0, POSIX_FADV_NORMAL);
697   return r;
698 }
699 EOF
700 if compile_prog "" "" "posix_fadvise"; then
701     posix_fadvise="yes"
702 fi
703 echo "POSIX fadvise                 $posix_fadvise"
704
705 ##########################################
706 # POSIX fallocate probe
707 posix_fallocate="no"
708 cat > $TMPC << EOF
709 #include <stdio.h>
710 #include <fcntl.h>
711 int main(int argc, char **argv)
712 {
713   int r = posix_fallocate(0, 0, 1024);
714   return r;
715 }
716 EOF
717 if compile_prog "" "" "posix_fallocate"; then
718     posix_fallocate="yes"
719 fi
720 echo "POSIX fallocate               $posix_fallocate"
721
722 ##########################################
723 # sched_set/getaffinity 2 or 3 argument test
724 linux_2arg_affinity="no"
725 linux_3arg_affinity="no"
726 cat > $TMPC << EOF
727 #include <sched.h>
728 int main(int argc, char **argv)
729 {
730   cpu_set_t mask;
731   return sched_setaffinity(0, sizeof(mask), &mask);
732 }
733 EOF
734 if compile_prog "" "" "sched_setaffinity(,,)"; then
735   linux_3arg_affinity="yes"
736 else
737   cat > $TMPC << EOF
738 #include <sched.h>
739 int main(int argc, char **argv)
740 {
741   cpu_set_t mask;
742   return sched_setaffinity(0, &mask);
743 }
744 EOF
745   if compile_prog "" "" "sched_setaffinity(,)"; then
746     linux_2arg_affinity="yes"
747   fi
748 fi
749 echo "sched_setaffinity(3 arg)      $linux_3arg_affinity"
750 echo "sched_setaffinity(2 arg)      $linux_2arg_affinity"
751
752 ##########################################
753 # clock_gettime probe
754 clock_gettime="no"
755 cat > $TMPC << EOF
756 #include <stdio.h>
757 #include <time.h>
758 int main(int argc, char **argv)
759 {
760   return clock_gettime(0, NULL);
761 }
762 EOF
763 if compile_prog "" "" "clock_gettime"; then
764     clock_gettime="yes"
765 elif compile_prog "" "-lrt" "clock_gettime"; then
766     clock_gettime="yes"
767     LIBS="-lrt $LIBS"
768 fi
769 echo "clock_gettime                 $clock_gettime"
770
771 ##########################################
772 # CLOCK_MONOTONIC probe
773 clock_monotonic="no"
774 if test "$clock_gettime" = "yes" ; then
775   cat > $TMPC << EOF
776 #include <stdio.h>
777 #include <time.h>
778 int main(int argc, char **argv)
779 {
780   return clock_gettime(CLOCK_MONOTONIC, NULL);
781 }
782 EOF
783   if compile_prog "" "$LIBS" "clock monotonic"; then
784       clock_monotonic="yes"
785   fi
786 fi
787 echo "CLOCK_MONOTONIC               $clock_monotonic"
788
789 ##########################################
790 # CLOCK_MONOTONIC_RAW probe
791 clock_monotonic_raw="no"
792 if test "$clock_gettime" = "yes" ; then
793   cat > $TMPC << EOF
794 #include <stdio.h>
795 #include <time.h>
796 int main(int argc, char **argv)
797 {
798   return clock_gettime(CLOCK_MONOTONIC_RAW, NULL);
799 }
800 EOF
801   if compile_prog "" "$LIBS" "clock monotonic"; then
802       clock_monotonic_raw="yes"
803   fi
804 fi
805 echo "CLOCK_MONOTONIC_RAW           $clock_monotonic_raw"
806
807 ##########################################
808 # CLOCK_MONOTONIC_PRECISE probe
809 clock_monotonic_precise="no"
810 if test "$clock_gettime" = "yes" ; then
811   cat > $TMPC << EOF
812 #include <stdio.h>
813 #include <time.h>
814 int main(int argc, char **argv)
815 {
816   return clock_gettime(CLOCK_MONOTONIC_PRECISE, NULL);
817 }
818 EOF
819   if compile_prog "" "$LIBS" "clock monotonic precise"; then
820       clock_monotonic_precise="yes"
821   fi
822 fi
823 echo "CLOCK_MONOTONIC_PRECISE       $clock_monotonic_precise"
824
825 ##########################################
826 # clockid_t probe
827 clockid_t="no"
828 cat > $TMPC << EOF
829 #include <time.h>
830 int main(int argc, char **argv)
831 {
832   volatile clockid_t cid;
833   memset(&cid, 0, sizeof(cid));
834   return 0;
835 }
836 EOF
837 if compile_prog "" "$LIBS" "clockid_t"; then
838   clockid_t="yes"
839 fi
840 echo "clockid_t                     $clockid_t"
841
842 ##########################################
843 # gettimeofday() probe
844 gettimeofday="no"
845 cat > $TMPC << EOF
846 #include <sys/time.h>
847 #include <stdio.h>
848 int main(int argc, char **argv)
849 {
850   struct timeval tv;
851   return gettimeofday(&tv, NULL);
852 }
853 EOF
854 if compile_prog "" "" "gettimeofday"; then
855     gettimeofday="yes"
856 fi
857 echo "gettimeofday                  $gettimeofday"
858
859 ##########################################
860 # fdatasync() probe
861 fdatasync="no"
862 cat > $TMPC << EOF
863 #include <stdio.h>
864 #include <unistd.h>
865 int main(int argc, char **argv)
866 {
867   return fdatasync(0);
868 }
869 EOF
870 if compile_prog "" "" "fdatasync"; then
871   fdatasync="yes"
872 fi
873 echo "fdatasync                     $fdatasync"
874
875 ##########################################
876 # sync_file_range() probe
877 sync_file_range="no"
878 cat > $TMPC << EOF
879 #include <stdio.h>
880 #include <unistd.h>
881 #include <fcntl.h>
882 #include <linux/fs.h>
883 int main(int argc, char **argv)
884 {
885   unsigned int flags = SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE |
886                         SYNC_FILE_RANGE_WAIT_AFTER;
887   return sync_file_range(0, 0, 0, flags);
888 }
889 EOF
890 if compile_prog "" "" "sync_file_range"; then
891   sync_file_range="yes"
892 fi
893 echo "sync_file_range               $sync_file_range"
894
895 ##########################################
896 # ext4 move extent probe
897 ext4_me="no"
898 cat > $TMPC << EOF
899 #include <fcntl.h>
900 #include <sys/ioctl.h>
901 int main(int argc, char **argv)
902 {
903   struct move_extent me;
904   return ioctl(0, EXT4_IOC_MOVE_EXT, &me);
905 }
906 EOF
907 if compile_prog "" "" "ext4 move extent" ; then
908   ext4_me="yes"
909 elif test $targetos = "Linux" ; then
910   # On Linux, just default to it on and let it error at runtime if we really
911   # don't have it. None of my updated systems have it defined, but it does
912   # work. Takes a while to bubble back.
913   ext4_me="yes"
914 fi
915 echo "EXT4 move extent              $ext4_me"
916
917 ##########################################
918 # splice probe
919 linux_splice="no"
920 cat > $TMPC << EOF
921 #include <stdio.h>
922 #include <fcntl.h>
923 int main(int argc, char **argv)
924 {
925   return splice(0, NULL, 0, NULL, 0, SPLICE_F_NONBLOCK);
926 }
927 EOF
928 if compile_prog "" "" "linux splice"; then
929   linux_splice="yes"
930 fi
931 echo "Linux splice(2)               $linux_splice"
932
933 ##########################################
934 # GUASI probe
935 guasi="no"
936 cat > $TMPC << EOF
937 #include <guasi.h>
938 #include <guasi_syscalls.h>
939 int main(int argc, char **argv)
940 {
941   guasi_t ctx = guasi_create(0, 0, 0);
942   return 0;
943 }
944 EOF
945 if compile_prog "" "" "guasi"; then
946   guasi="yes"
947 fi
948 echo "GUASI                         $guasi"
949
950 ##########################################
951 # fusion-aw probe
952 fusion_aw="no"
953 cat > $TMPC << EOF
954 #include <nvm/nvm_primitives.h>
955 int main(int argc, char **argv)
956 {
957   nvm_version_t ver_info;
958   nvm_handle_t handle;
959
960   handle = nvm_get_handle(0, &ver_info);
961   return nvm_atomic_write(handle, 0, 0, 0);
962 }
963 EOF
964 if compile_prog "" "-L/usr/lib/fio -L/usr/lib/nvm -lnvm-primitives -ldl -lpthread" "fusion-aw"; then
965   LIBS="-L/usr/lib/fio -L/usr/lib/nvm -lnvm-primitives -ldl -lpthread $LIBS"
966   fusion_aw="yes"
967 fi
968 echo "Fusion-io atomic engine       $fusion_aw"
969
970 ##########################################
971 # libnuma probe
972 libnuma="no"
973 cat > $TMPC << EOF
974 #include <numa.h>
975 int main(int argc, char **argv)
976 {
977   return numa_available();
978 }
979 EOF
980 if test "$disable_numa" != "yes"  && compile_prog "" "-lnuma" "libnuma"; then
981   libnuma="yes"
982   LIBS="-lnuma $LIBS"
983 fi
984 echo "libnuma                       $libnuma"
985
986 ##########################################
987 # libnuma 2.x version API
988 if test "$libnuma" = "yes" ; then
989 libnuma_v2="no"
990 cat > $TMPC << EOF
991 #include <numa.h>
992 int main(int argc, char **argv)
993 {
994   struct bitmask *mask = numa_parse_nodestring(NULL);
995   return mask->size == 0;
996 }
997 EOF
998 if compile_prog "" "" "libnuma api"; then
999   libnuma_v2="yes"
1000 fi
1001 echo "libnuma v2                    $libnuma_v2"
1002 fi
1003
1004 ##########################################
1005 # strsep() probe
1006 strsep="no"
1007 cat > $TMPC << EOF
1008 #include <string.h>
1009 int main(int argc, char **argv)
1010 {
1011   static char *string = "This is a string";
1012   strsep(&string, "needle");
1013   return 0;
1014 }
1015 EOF
1016 if compile_prog "" "" "strsep"; then
1017   strsep="yes"
1018 fi
1019 echo "strsep                        $strsep"
1020
1021 ##########################################
1022 # strcasestr() probe
1023 strcasestr="no"
1024 cat > $TMPC << EOF
1025 #include <string.h>
1026 int main(int argc, char **argv)
1027 {
1028   return strcasestr(argv[0], argv[1]) != NULL;
1029 }
1030 EOF
1031 if compile_prog "" "" "strcasestr"; then
1032   strcasestr="yes"
1033 fi
1034 echo "strcasestr                    $strcasestr"
1035
1036 ##########################################
1037 # strlcat() probe
1038 strlcat="no"
1039 cat > $TMPC << EOF
1040 #include <string.h>
1041 int main(int argc, char **argv)
1042 {
1043   static char dst[64];
1044   static char *string = "This is a string";
1045   memset(dst, 0, sizeof(dst));
1046   strlcat(dst, string, sizeof(dst));
1047   return 0;
1048 }
1049 EOF
1050 if compile_prog "" "" "strlcat"; then
1051   strlcat="yes"
1052 fi
1053 echo "strlcat                       $strlcat"
1054
1055 ##########################################
1056 # getopt_long_only() probe
1057 getopt_long_only="no"
1058 cat > $TMPC << EOF
1059 #include <unistd.h>
1060 #include <stdio.h>
1061 #include <getopt.h>
1062 int main(int argc, char **argv)
1063 {
1064   int c = getopt_long_only(argc, argv, NULL, NULL, NULL);
1065   return c;
1066 }
1067 EOF
1068 if compile_prog "" "" "getopt_long_only"; then
1069   getopt_long_only="yes"
1070 fi
1071 echo "getopt_long_only()            $getopt_long_only"
1072
1073 ##########################################
1074 # inet_aton() probe
1075 inet_aton="no"
1076 cat > $TMPC << EOF
1077 #include <sys/socket.h>
1078 #include <arpa/inet.h>
1079 #include <stdio.h>
1080 int main(int argc, char **argv)
1081 {
1082   struct in_addr in;
1083   return inet_aton(NULL, &in);
1084 }
1085 EOF
1086 if compile_prog "" "" "inet_aton"; then
1087   inet_aton="yes"
1088 fi
1089 echo "inet_aton                     $inet_aton"
1090
1091 ##########################################
1092 # socklen_t probe
1093 socklen_t="no"
1094 cat > $TMPC << EOF
1095 #include <sys/socket.h>
1096 int main(int argc, char **argv)
1097 {
1098   socklen_t len = 0;
1099   return len;
1100 }
1101 EOF
1102 if compile_prog "" "" "socklen_t"; then
1103   socklen_t="yes"
1104 fi
1105 echo "socklen_t                     $socklen_t"
1106
1107 ##########################################
1108 # Whether or not __thread is supported for TLS
1109 tls_thread="no"
1110 cat > $TMPC << EOF
1111 #include <stdio.h>
1112 static __thread int ret;
1113 int main(int argc, char **argv)
1114 {
1115   return ret;
1116 }
1117 EOF
1118 if compile_prog "" "" "__thread"; then
1119   tls_thread="yes"
1120 fi
1121 echo "__thread                      $tls_thread"
1122
1123 ##########################################
1124 # Check if we have required gtk/glib support for gfio
1125 gfio="no"
1126 if test "$gfio_check" = "yes" ; then
1127   cat > $TMPC << EOF
1128 #include <glib.h>
1129 #include <cairo.h>
1130 #include <gtk/gtk.h>
1131 int main(void)
1132 {
1133   gdk_threads_enter();
1134   gdk_threads_leave();
1135
1136   printf("%d", GTK_CHECK_VERSION(2, 18, 0));
1137 }
1138 EOF
1139 GTK_CFLAGS=$(pkg-config --cflags gtk+-2.0 gthread-2.0)
1140 ORG_LDFLAGS=$LDFLAGS
1141 LDFLAGS=$(echo $LDFLAGS | sed s/"-static"//g)
1142 if test "$?" != "0" ; then
1143   echo "configure: gtk and gthread not found"
1144   exit 1
1145 fi
1146 GTK_LIBS=$(pkg-config --libs gtk+-2.0 gthread-2.0)
1147 if test "$?" != "0" ; then
1148   echo "configure: gtk and gthread not found"
1149   exit 1
1150 fi
1151 if compile_prog "$GTK_CFLAGS" "$GTK_LIBS" "gfio" ; then
1152   r=$($TMPE)
1153   if test "$r" != "0" ; then
1154     gfio="yes"
1155     GFIO_LIBS="$LIBS $GTK_LIBS"
1156     CFLAGS="$CFLAGS $GTK_CFLAGS"
1157   else
1158     echo "GTK found, but need version 2.18 or higher"
1159     gfio="no"
1160   fi
1161 else
1162   echo "Please install gtk and gdk libraries"
1163   gfio="no"
1164 fi
1165 LDFLAGS=$ORG_LDFLAGS
1166 fi
1167
1168 if test "$gfio_check" = "yes" ; then
1169   echo "gtk 2.18 or higher            $gfio"
1170 fi
1171
1172 # Check whether we have getrusage(RUSAGE_THREAD)
1173 rusage_thread="no"
1174 cat > $TMPC << EOF
1175 #include <sys/time.h>
1176 #include <sys/resource.h>
1177 int main(int argc, char **argv)
1178 {
1179   struct rusage ru;
1180   getrusage(RUSAGE_THREAD, &ru);
1181   return 0;
1182 }
1183 EOF
1184 if compile_prog "" "" "RUSAGE_THREAD"; then
1185   rusage_thread="yes"
1186 fi
1187 echo "RUSAGE_THREAD                 $rusage_thread"
1188
1189 ##########################################
1190 # Check whether we have SCHED_IDLE
1191 sched_idle="no"
1192 cat > $TMPC << EOF
1193 #include <sched.h>
1194 int main(int argc, char **argv)
1195 {
1196   struct sched_param p;
1197   return sched_setscheduler(0, SCHED_IDLE, &p);
1198 }
1199 EOF
1200 if compile_prog "" "" "SCHED_IDLE"; then
1201   sched_idle="yes"
1202 fi
1203 echo "SCHED_IDLE                    $sched_idle"
1204
1205 ##########################################
1206 # Check whether we have TCP_NODELAY
1207 tcp_nodelay="no"
1208 cat > $TMPC << EOF
1209 #include <stdio.h>
1210 #include <sys/types.h>
1211 #include <sys/socket.h>
1212 #include <netinet/tcp.h>
1213 int main(int argc, char **argv)
1214 {
1215   return getsockopt(0, 0, TCP_NODELAY, NULL, NULL);
1216 }
1217 EOF
1218 if compile_prog "" "" "TCP_NODELAY"; then
1219   tcp_nodelay="yes"
1220 fi
1221 echo "TCP_NODELAY                   $tcp_nodelay"
1222
1223 ##########################################
1224 # Check whether we have SO_SNDBUF
1225 window_size="no"
1226 cat > $TMPC << EOF
1227 #include <stdio.h>
1228 #include <sys/types.h>
1229 #include <sys/socket.h>
1230 #include <netinet/tcp.h>
1231 int main(int argc, char **argv)
1232 {
1233   setsockopt(0, SOL_SOCKET, SO_SNDBUF, NULL, 0);
1234   setsockopt(0, SOL_SOCKET, SO_RCVBUF, NULL, 0);
1235 }
1236 EOF
1237 if compile_prog "" "" "SO_SNDBUF"; then
1238   window_size="yes"
1239 fi
1240 echo "Net engine window_size        $window_size"
1241
1242 ##########################################
1243 # Check whether we have TCP_MAXSEG
1244 mss="no"
1245 cat > $TMPC << EOF
1246 #include <stdio.h>
1247 #include <sys/types.h>
1248 #include <sys/socket.h>
1249 #include <netinet/tcp.h>
1250 #include <arpa/inet.h>
1251 #include <netinet/in.h>
1252 int main(int argc, char **argv)
1253 {
1254   return setsockopt(0, IPPROTO_TCP, TCP_MAXSEG, NULL, 0);
1255 }
1256 EOF
1257 if compile_prog "" "" "TCP_MAXSEG"; then
1258   mss="yes"
1259 fi
1260 echo "TCP_MAXSEG                    $mss"
1261
1262 ##########################################
1263 # Check whether we have RLIMIT_MEMLOCK
1264 rlimit_memlock="no"
1265 cat > $TMPC << EOF
1266 #include <sys/time.h>
1267 #include <sys/resource.h>
1268 int main(int argc, char **argv)
1269 {
1270   struct rlimit rl;
1271   return getrlimit(RLIMIT_MEMLOCK, &rl);
1272 }
1273 EOF
1274 if compile_prog "" "" "RLIMIT_MEMLOCK"; then
1275   rlimit_memlock="yes"
1276 fi
1277 echo "RLIMIT_MEMLOCK                $rlimit_memlock"
1278
1279 ##########################################
1280 # Check whether we have pwritev/preadv
1281 pwritev="no"
1282 cat > $TMPC << EOF
1283 #include <stdio.h>
1284 #include <sys/uio.h>
1285 int main(int argc, char **argv)
1286 {
1287   return pwritev(0, NULL, 1, 0) + preadv(0, NULL, 1, 0);
1288 }
1289 EOF
1290 if compile_prog "" "" "pwritev"; then
1291   pwritev="yes"
1292 fi
1293 echo "pwritev/preadv                $pwritev"
1294
1295 ##########################################
1296 # Check whether we have pwritev2/preadv2
1297 pwritev2="no"
1298 cat > $TMPC << EOF
1299 #include <stdio.h>
1300 #include <sys/uio.h>
1301 int main(int argc, char **argv)
1302 {
1303   return pwritev2(0, NULL, 1, 0, 0) + preadv2(0, NULL, 1, 0, 0);
1304 }
1305 EOF
1306 if compile_prog "" "" "pwritev2"; then
1307   pwritev2="yes"
1308 fi
1309 echo "pwritev2/preadv2              $pwritev2"
1310
1311 ##########################################
1312 # Check whether we have the required functions for ipv6
1313 ipv6="no"
1314 cat > $TMPC << EOF
1315 #include <sys/types.h>
1316 #include <sys/socket.h>
1317 #include <netinet/in.h>
1318 #include <netdb.h>
1319 #include <stdio.h>
1320 int main(int argc, char **argv)
1321 {
1322   struct addrinfo hints;
1323   struct in6_addr addr;
1324   int ret;
1325
1326   ret = getaddrinfo(NULL, NULL, &hints, NULL);
1327   freeaddrinfo(NULL);
1328   printf("%s\n", gai_strerror(ret));
1329   addr = in6addr_any;
1330   return 0;
1331 }
1332 EOF
1333 if compile_prog "" "" "ipv6"; then
1334   ipv6="yes"
1335 fi
1336 echo "IPv6 helpers                  $ipv6"
1337
1338 ##########################################
1339 # check for rbd
1340 rbd="no"
1341 cat > $TMPC << EOF
1342 #include <rbd/librbd.h>
1343
1344 int main(int argc, char **argv)
1345 {
1346
1347   rados_t cluster;
1348   rados_ioctx_t io_ctx;
1349   const char pool[] = "rbd";
1350
1351   int major, minor, extra;
1352   rbd_version(&major, &minor, &extra);
1353
1354   rados_ioctx_create(cluster, pool, &io_ctx);
1355   return 0;
1356 }
1357 EOF
1358 if test "$disable_rbd" != "yes"  && compile_prog "" "-lrbd -lrados" "rbd"; then
1359   LIBS="-lrbd -lrados $LIBS"
1360   rbd="yes"
1361 fi
1362 echo "Rados Block Device engine     $rbd"
1363
1364 ##########################################
1365 # check for rbd_poll
1366 rbd_poll="no"
1367 if test "$rbd" = "yes"; then
1368 cat > $TMPC << EOF
1369 #include <rbd/librbd.h>
1370 #include <sys/eventfd.h>
1371
1372 int main(int argc, char **argv)
1373 {
1374   rbd_image_t image;
1375   rbd_completion_t comp;
1376
1377   int fd = eventfd(0, EFD_NONBLOCK);
1378   rbd_set_image_notification(image, fd, EVENT_TYPE_EVENTFD);
1379   rbd_poll_io_events(image, comp, 1);
1380
1381   return 0;
1382 }
1383 EOF
1384 if compile_prog "" "-lrbd -lrados" "rbd"; then
1385   rbd_poll="yes"
1386 fi
1387 echo "rbd_poll                      $rbd_poll"
1388 fi
1389
1390 ##########################################
1391 # check for rbd_invaidate_cache()
1392 rbd_inval="no"
1393 if test "$rbd" = "yes"; then
1394 cat > $TMPC << EOF
1395 #include <rbd/librbd.h>
1396
1397 int main(int argc, char **argv)
1398 {
1399   rbd_image_t image;
1400
1401   return rbd_invalidate_cache(image);
1402 }
1403 EOF
1404 if compile_prog "" "-lrbd -lrados" "rbd"; then
1405   rbd_inval="yes"
1406 fi
1407 echo "rbd_invalidate_cache          $rbd_inval"
1408 fi
1409
1410 ##########################################
1411 # check for blkin
1412 rbd_blkin="no"
1413 cat > $TMPC << EOF
1414 #include <rbd/librbd.h>
1415 #include <zipkin_c.h>
1416
1417 int main(int argc, char **argv)
1418 {
1419   int r;
1420   struct blkin_trace_info t_info;
1421   blkin_init_trace_info(&t_info);
1422   rbd_completion_t completion;
1423   rbd_image_t image;
1424   uint64_t off;
1425   size_t len;
1426   const char *buf;
1427   r = rbd_aio_write_traced(image, off, len, buf, completion, &t_info);
1428   return 0;
1429 }
1430 EOF
1431 if test "$disable_rbd" != "yes" && test "$disable_rbd_blkin" != "yes" \
1432  && compile_prog "" "-lrbd -lrados -lblkin" "rbd_blkin"; then
1433   LIBS="-lblkin $LIBS"
1434   rbd_blkin="yes"
1435 fi
1436 echo "rbd blkin tracing             $rbd_blkin"
1437
1438 ##########################################
1439 # Check whether we have setvbuf
1440 setvbuf="no"
1441 cat > $TMPC << EOF
1442 #include <stdio.h>
1443 int main(int argc, char **argv)
1444 {
1445   FILE *f = NULL;
1446   char buf[80];
1447   setvbuf(f, buf, _IOFBF, sizeof(buf));
1448   return 0;
1449 }
1450 EOF
1451 if compile_prog "" "" "setvbuf"; then
1452   setvbuf="yes"
1453 fi
1454 echo "setvbuf                       $setvbuf"
1455
1456 # check for gfapi
1457 gfapi="no"
1458 cat > $TMPC << EOF
1459 #include <glusterfs/api/glfs.h>
1460
1461 int main(int argc, char **argv)
1462 {
1463
1464   glfs_t *g = glfs_new("foo");
1465
1466   return 0;
1467 }
1468 EOF
1469 if test "$disable_gfapi" != "yes"  && compile_prog "" "-lgfapi -lglusterfs" "gfapi"; then
1470   LIBS="-lgfapi -lglusterfs $LIBS"
1471   gfapi="yes"
1472 fi
1473  echo "Gluster API engine            $gfapi"
1474
1475 ##########################################
1476 # check for gfapi fadvise support
1477 if test "$gfapi" = "yes" ; then
1478 gf_fadvise="no"
1479 cat > $TMPC << EOF
1480 #include <glusterfs/api/glfs.h>
1481
1482 int main(int argc, char **argv)
1483 {
1484   struct glfs_fd *fd;
1485   int ret = glfs_fadvise(fd, 0, 0, 1);
1486
1487   return 0;
1488 }
1489 EOF
1490 if compile_prog "" "-lgfapi -lglusterfs" "gfapi"; then
1491   gf_fadvise="yes"
1492 fi
1493 echo "Gluster API use fadvise       $gf_fadvise"
1494 fi
1495
1496 ##########################################
1497 # check for gfapi trim support
1498 gf_trim="no"
1499 if test "$gfapi" = "yes" ; then
1500 cat > $TMPC << EOF
1501 #include <glusterfs/api/glfs.h>
1502
1503 int main(int argc, char **argv)
1504 {
1505   return glfs_discard_async(NULL, 0, 0);
1506 }
1507 EOF
1508 if compile_prog "" "-lgfapi -lglusterfs" "gf trim"; then
1509   gf_trim="yes"
1510 fi
1511 echo "Gluster API trim support      $gf_trim"
1512 fi
1513
1514 ##########################################
1515 # Check if we support stckf on s390
1516 s390_z196_facilities="no"
1517 cat > $TMPC << EOF
1518 #define STFLE_BITS_Z196 45 /* various z196 facilities ... */
1519 int main(int argc, char **argv)
1520 {
1521     /* We want just 1 double word to be returned.  */
1522     register unsigned long reg0 asm("0") = 0;
1523     unsigned long stfle_bits;
1524     asm volatile(".machine push"        "\n\t"
1525                  ".machine \"z9-109\""  "\n\t"
1526                  "stfle %0"             "\n\t"
1527                  ".machine pop"         "\n"
1528                  : "=QS" (stfle_bits), "+d" (reg0)
1529                  : : "cc");
1530
1531     if ((stfle_bits & (1UL << (63 - STFLE_BITS_Z196))) != 0)
1532       return 0;
1533     else
1534       return -1;
1535 }
1536 EOF
1537 if compile_prog "" "" "s390_z196_facilities"; then
1538   $TMPE
1539   if [[ $? -eq 0 ]]; then
1540         s390_z196_facilities="yes"
1541   fi
1542 fi
1543 echo "s390_z196_facilities          $s390_z196_facilities"
1544
1545 ##########################################
1546 # Check if we have required environment variables configured for libhdfs
1547 if test "$libhdfs" = "yes" ; then
1548   hdfs_conf_error=0
1549   if test "$JAVA_HOME" = "" ; then
1550     echo "configure: JAVA_HOME should be defined to jdk/jvm path"
1551     hdfs_conf_error=1
1552   fi
1553   if test "$FIO_LIBHDFS_INCLUDE" = "" ; then
1554     echo "configure: FIO_LIBHDFS_INCLUDE should be defined to libhdfs inlude path"
1555     hdfs_conf_error=1
1556   fi
1557   if test "$FIO_LIBHDFS_LIB" = "" ; then
1558     echo "configure: FIO_LIBHDFS_LIB should be defined to libhdfs library path"
1559     hdfs_conf_error=1
1560   fi
1561   if test "$hdfs_conf_error" = "1" ; then
1562     exit 1
1563   fi
1564   FIO_HDFS_CPU=$cpu
1565   if test "$FIO_HDFS_CPU" = "x86_64" ; then
1566     FIO_HDFS_CPU="amd64"
1567   fi
1568 fi
1569 echo "HDFS engine                   $libhdfs"
1570
1571 ##########################################
1572 # Check whether we have MTD
1573 mtd="no"
1574 cat > $TMPC << EOF
1575 #include <string.h>
1576 #include <mtd/mtd-user.h>
1577 #include <sys/ioctl.h>
1578 int main(int argc, char **argv)
1579 {
1580   struct mtd_write_req ops;
1581   struct mtd_info_user info;
1582   memset(&ops, 0, sizeof(ops));
1583   info.type = MTD_MLCNANDFLASH;
1584   return ioctl(0, MEMGETINFO, &info);
1585 }
1586 EOF
1587 if compile_prog "" "" "mtd"; then
1588   mtd="yes"
1589 fi
1590 echo "MTD                           $mtd"
1591
1592 ##########################################
1593 # Check whether we have libpmem
1594 libpmem="no"
1595 cat > $TMPC << EOF
1596 #include <libpmem.h>
1597 int main(int argc, char **argv)
1598 {
1599   int rc;
1600   rc = pmem_is_pmem(0, 0);
1601   return 0;
1602 }
1603 EOF
1604 if compile_prog "" "-lpmem" "libpmem"; then
1605   libpmem="yes"
1606   LIBS="-lpmem $LIBS"
1607 fi
1608 echo "libpmem                       $libpmem"
1609
1610 ##########################################
1611 # Check whether we have libpmemblk
1612 # libpmem is a prerequisite
1613 libpmemblk="no"
1614 if test "$libpmem" = "yes"; then
1615   cat > $TMPC << EOF
1616 #include <libpmemblk.h>
1617 int main(int argc, char **argv)
1618 {
1619   PMEMblkpool *pbp;
1620   pbp = pmemblk_open("", 0);
1621   return 0;
1622 }
1623 EOF
1624   if compile_prog "" "-lpmemblk" "libpmemblk"; then
1625     libpmemblk="yes"
1626     LIBS="-lpmemblk $LIBS"
1627   fi
1628 fi
1629 echo "libpmemblk                    $libpmemblk"
1630
1631 # Choose the ioengines
1632 if test "$libpmem" = "yes" && test "$disable_pmem" = "no"; then
1633   devdax="yes"
1634   if test "$libpmemblk" = "yes"; then
1635     pmemblk="yes"
1636   fi
1637 fi
1638
1639 ##########################################
1640 # Report whether pmemblk engine is enabled
1641 echo "NVML pmemblk engine           $pmemblk"
1642
1643 ##########################################
1644 # Report whether dev-dax engine is enabled
1645 echo "NVML dev-dax engine           $devdax"
1646
1647 # Check if we have lex/yacc available
1648 yacc="no"
1649 yacc_is_bison="no"
1650 lex="no"
1651 arith="no"
1652 if test "$disable_lex" = "no" || test -z "$disable_lex" ; then
1653 if test "$targetos" != "SunOS" ; then
1654 LEX=$(which lex 2> /dev/null)
1655 if test -x "$LEX" ; then
1656   lex="yes"
1657 fi
1658 YACC=$(which bison 2> /dev/null)
1659 if test -x "$YACC" ; then
1660   yacc="yes"
1661   yacc_is_bison="yes"
1662 else
1663   YACC=$(which yacc 2> /dev/null)
1664   if test -x "$YACC" ; then
1665     yacc="yes"
1666   fi
1667 fi
1668 if test "$yacc" = "yes" && test "$lex" = "yes" ; then
1669   arith="yes"
1670 fi
1671
1672 if test "$arith" = "yes" ; then
1673 cat > $TMPC << EOF
1674 extern int yywrap(void);
1675
1676 int main(int argc, char **argv)
1677 {
1678   yywrap();
1679   return 0;
1680 }
1681 EOF
1682 if compile_prog "" "-ll" "lex"; then
1683   LIBS="-ll $LIBS"
1684 else
1685   arith="no"
1686 fi
1687 fi
1688 fi
1689 fi
1690
1691 # Check if lex fails using -o
1692 if test "$arith" = "yes" ; then
1693 if test "$force_no_lex_o" = "yes" ; then
1694   lex_use_o="no"
1695 else
1696 $LEX -o lex.yy.c exp/expression-parser.l 2> /dev/null
1697 if test "$?" = "0" ; then
1698   lex_use_o="yes"
1699 else
1700   lex_use_o="no"
1701 fi
1702 fi
1703 fi
1704
1705 echo "lex/yacc for arithmetic       $arith"
1706
1707 ##########################################
1708 # Check whether we have setmntent/getmntent
1709 getmntent="no"
1710 cat > $TMPC << EOF
1711 #include <stdio.h>
1712 #include <mntent.h>
1713 int main(int argc, char **argv)
1714 {
1715   FILE *mtab = setmntent(NULL, "r");
1716   struct mntent *mnt = getmntent(mtab);
1717   endmntent(mtab);
1718   return 0;
1719 }
1720 EOF
1721 if compile_prog "" "" "getmntent"; then
1722   getmntent="yes"
1723 fi
1724 echo "getmntent                     $getmntent"
1725
1726 ##########################################
1727 # Check whether we have getmntinfo
1728 # These are originally added for BSDs, but may also work
1729 # on other operating systems with getmntinfo(3).
1730
1731 # getmntinfo(3) for FreeBSD/DragonFlyBSD/OpenBSD.
1732 # Note that NetBSD needs -Werror to catch warning as error.
1733 getmntinfo="no"
1734 cat > $TMPC << EOF
1735 #include <stdio.h>
1736 #include <sys/param.h>
1737 #include <sys/mount.h>
1738 int main(int argc, char **argv)
1739 {
1740   struct statfs *st;
1741   return getmntinfo(&st, MNT_NOWAIT);
1742 }
1743 EOF
1744 if compile_prog "-Werror" "" "getmntinfo"; then
1745   getmntinfo="yes"
1746 fi
1747 echo "getmntinfo                    $getmntinfo"
1748
1749 # getmntinfo(3) for NetBSD.
1750 getmntinfo_statvfs="no"
1751 cat > $TMPC << EOF
1752 #include <stdio.h>
1753 #include <sys/statvfs.h>
1754 int main(int argc, char **argv)
1755 {
1756   struct statvfs *st;
1757   return getmntinfo(&st, MNT_NOWAIT);
1758 }
1759 EOF
1760 # Skip the test if the one with statfs arg is detected.
1761 if test "$getmntinfo" != "yes" && compile_prog "-Werror" "" "getmntinfo_statvfs"; then
1762   getmntinfo_statvfs="yes"
1763   echo "getmntinfo_statvfs            $getmntinfo_statvfs"
1764 fi
1765
1766 ##########################################
1767 # Check whether we have _Static_assert
1768 static_assert="no"
1769 cat > $TMPC << EOF
1770 #include <assert.h>
1771 #include <stdlib.h>
1772 #undef offsetof
1773 #ifdef __compiler_offsetof
1774 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
1775 #else
1776 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
1777 #endif
1778
1779 #define container_of(ptr, type, member) ({                      \
1780         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
1781         (type *)( (char *)__mptr - offsetof(type,member) );})
1782
1783 struct foo {
1784   int a, b;
1785 };
1786
1787 int main(int argc, char **argv)
1788 {
1789   _Static_assert(offsetof(struct foo, a) == 0 , "Check");
1790   return 0 ;
1791 }
1792 EOF
1793 if compile_prog "" "" "static_assert"; then
1794     static_assert="yes"
1795 fi
1796 echo "Static Assert                 $static_assert"
1797
1798 ##########################################
1799 # Check whether we have bool / stdbool.h
1800 have_bool="no"
1801 cat > $TMPC << EOF
1802 #include <stdbool.h>
1803 int main(int argc, char **argv)
1804 {
1805   bool var = true;
1806   return var != false;
1807 }
1808 EOF
1809 if compile_prog "" "" "bool"; then
1810   have_bool="yes"
1811 fi
1812 echo "bool                          $have_bool"
1813
1814 ##########################################
1815 # check march=armv8-a+crc+crypto
1816 march_armv8_a_crc_crypto="no"
1817 if test "$cpu" = "arm64" ; then
1818   cat > $TMPC <<EOF
1819 int main(void)
1820 {
1821   return 0;
1822 }
1823 EOF
1824   if compile_prog "-march=armv8-a+crc+crypto" "" ""; then
1825     march_armv8_a_crc_crypto="yes"
1826     CFLAGS="$CFLAGS -march=armv8-a+crc+crypto -DARCH_HAVE_CRC_CRYPTO"
1827   fi
1828 fi
1829 echo "march_armv8_a_crc_crypto      $march_armv8_a_crc_crypto"
1830
1831
1832 #############################################################################
1833
1834 if test "$wordsize" = "64" ; then
1835   output_sym "CONFIG_64BIT"
1836 elif test "$wordsize" = "32" ; then
1837   output_sym "CONFIG_32BIT"
1838 else
1839   fatal "Unknown wordsize!"
1840 fi
1841 if test "$bigendian" = "yes" ; then
1842   output_sym "CONFIG_BIG_ENDIAN"
1843 else
1844   output_sym "CONFIG_LITTLE_ENDIAN"
1845 fi
1846 if test "$zlib" = "yes" ; then
1847   output_sym "CONFIG_ZLIB"
1848 fi
1849 if test "$libaio" = "yes" ; then
1850   output_sym "CONFIG_LIBAIO"
1851 fi
1852 if test "$posix_aio" = "yes" ; then
1853   output_sym "CONFIG_POSIXAIO"
1854 fi
1855 if test "$posix_aio_fsync" = "yes" ; then
1856   output_sym "CONFIG_POSIXAIO_FSYNC"
1857 fi
1858 if test "$linux_fallocate" = "yes" ; then
1859   output_sym "CONFIG_LINUX_FALLOCATE"
1860 fi
1861 if test "$posix_fallocate" = "yes" ; then
1862   output_sym "CONFIG_POSIX_FALLOCATE"
1863 fi
1864 if test "$fdatasync" = "yes" ; then
1865   output_sym "CONFIG_FDATASYNC"
1866 fi
1867 if test "$sync_file_range" = "yes" ; then
1868   output_sym "CONFIG_SYNC_FILE_RANGE"
1869 fi
1870 if test "$sfaa" = "yes" ; then
1871   output_sym "CONFIG_SFAA"
1872 fi
1873 if test "$libverbs" = "yes" -a "$rdmacm" = "yes" ; then
1874   output_sym "CONFIG_RDMA"
1875 fi
1876 if test "$clock_gettime" = "yes" ; then
1877   output_sym "CONFIG_CLOCK_GETTIME"
1878 fi
1879 if test "$clock_monotonic" = "yes" ; then
1880   output_sym "CONFIG_CLOCK_MONOTONIC"
1881 fi
1882 if test "$clock_monotonic_raw" = "yes" ; then
1883   output_sym "CONFIG_CLOCK_MONOTONIC_RAW"
1884 fi
1885 if test "$clock_monotonic_precise" = "yes" ; then
1886   output_sym "CONFIG_CLOCK_MONOTONIC_PRECISE"
1887 fi
1888 if test "$clockid_t" = "yes"; then
1889   output_sym "CONFIG_CLOCKID_T"
1890 fi
1891 if test "$gettimeofday" = "yes" ; then
1892   output_sym "CONFIG_GETTIMEOFDAY"
1893 fi
1894 if test "$posix_fadvise" = "yes" ; then
1895   output_sym "CONFIG_POSIX_FADVISE"
1896 fi
1897 if test "$linux_3arg_affinity" = "yes" ; then
1898   output_sym "CONFIG_3ARG_AFFINITY"
1899 elif test "$linux_2arg_affinity" = "yes" ; then
1900   output_sym "CONFIG_2ARG_AFFINITY"
1901 fi
1902 if test "$strsep" = "yes" ; then
1903   output_sym "CONFIG_STRSEP"
1904 fi
1905 if test "$strcasestr" = "yes" ; then
1906   output_sym "CONFIG_STRCASESTR"
1907 fi
1908 if test "$strlcat" = "yes" ; then
1909   output_sym "CONFIG_STRLCAT"
1910 fi
1911 if test "$getopt_long_only" = "yes" ; then
1912   output_sym "CONFIG_GETOPT_LONG_ONLY"
1913 fi
1914 if test "$inet_aton" = "yes" ; then
1915   output_sym "CONFIG_INET_ATON"
1916 fi
1917 if test "$socklen_t" = "yes" ; then
1918   output_sym "CONFIG_SOCKLEN_T"
1919 fi
1920 if test "$ext4_me" = "yes" ; then
1921   output_sym "CONFIG_LINUX_EXT4_MOVE_EXTENT"
1922 fi
1923 if test "$linux_splice" = "yes" ; then
1924   output_sym "CONFIG_LINUX_SPLICE"
1925 fi
1926 if test "$guasi" = "yes" ; then
1927   output_sym "CONFIG_GUASI"
1928 fi
1929 if test "$fusion_aw" = "yes" ; then
1930   output_sym "CONFIG_FUSION_AW"
1931 fi
1932 if test "$libnuma_v2" = "yes" ; then
1933   output_sym "CONFIG_LIBNUMA"
1934 fi
1935 if test "$solaris_aio" = "yes" ; then
1936   output_sym "CONFIG_SOLARISAIO"
1937 fi
1938 if test "$tls_thread" = "yes" ; then
1939   output_sym "CONFIG_TLS_THREAD"
1940 fi
1941 if test "$rusage_thread" = "yes" ; then
1942   output_sym "CONFIG_RUSAGE_THREAD"
1943 fi
1944 if test "$gfio" = "yes" ; then
1945   echo "CONFIG_GFIO=y" >> $config_host_mak
1946 fi
1947 if test "$esx" = "yes" ; then
1948   output_sym "CONFIG_ESX"
1949   output_sym "CONFIG_NO_SHM"
1950 fi
1951 if test "$sched_idle" = "yes" ; then
1952   output_sym "CONFIG_SCHED_IDLE"
1953 fi
1954 if test "$tcp_nodelay" = "yes" ; then
1955   output_sym "CONFIG_TCP_NODELAY"
1956 fi
1957 if test "$window_size" = "yes" ; then
1958   output_sym "CONFIG_NET_WINDOWSIZE"
1959 fi
1960 if test "$mss" = "yes" ; then
1961   output_sym "CONFIG_NET_MSS"
1962 fi
1963 if test "$rlimit_memlock" = "yes" ; then
1964   output_sym "CONFIG_RLIMIT_MEMLOCK"
1965 fi
1966 if test "$pwritev" = "yes" ; then
1967   output_sym "CONFIG_PWRITEV"
1968 fi
1969 if test "$pwritev2" = "yes" ; then
1970   output_sym "CONFIG_PWRITEV2"
1971 fi
1972 if test "$ipv6" = "yes" ; then
1973   output_sym "CONFIG_IPV6"
1974 fi
1975 if test "$rbd" = "yes" ; then
1976   output_sym "CONFIG_RBD"
1977 fi
1978 if test "$rbd_poll" = "yes" ; then
1979   output_sym "CONFIG_RBD_POLL"
1980 fi
1981 if test "$rbd_inval" = "yes" ; then
1982   output_sym "CONFIG_RBD_INVAL"
1983 fi
1984 if test "$rbd_blkin" = "yes" ; then
1985   output_sym "CONFIG_RBD_BLKIN"
1986 fi
1987 if test "$setvbuf" = "yes" ; then
1988   output_sym "CONFIG_SETVBUF"
1989 fi
1990 if test "$s390_z196_facilities" = "yes" ; then
1991   output_sym "CONFIG_S390_Z196_FACILITIES"
1992   CFLAGS="$CFLAGS -march=z9-109"
1993 fi
1994 if test "$gfapi" = "yes" ; then
1995   output_sym "CONFIG_GFAPI"
1996 fi
1997 if test "$gf_fadvise" = "yes" ; then
1998   output_sym "CONFIG_GF_FADVISE"
1999 fi
2000 if test "$gf_trim" = "yes" ; then
2001   output_sym "CONFIG_GF_TRIM"
2002 fi
2003 if test "$libhdfs" = "yes" ; then
2004   output_sym "CONFIG_LIBHDFS"
2005   echo "FIO_HDFS_CPU=$FIO_HDFS_CPU" >> $config_host_mak
2006   echo "JAVA_HOME=$JAVA_HOME" >> $config_host_mak
2007   echo "FIO_LIBHDFS_INCLUDE=$FIO_LIBHDFS_INCLUDE" >> $config_host_mak
2008   echo "FIO_LIBHDFS_LIB=$FIO_LIBHDFS_LIB" >> $config_host_mak
2009  fi
2010 if test "$mtd" = "yes" ; then
2011   output_sym "CONFIG_MTD"
2012 fi
2013 if test "$pmemblk" = "yes" ; then
2014   output_sym "CONFIG_PMEMBLK"
2015 fi
2016 if test "$devdax" = "yes" ; then
2017   output_sym "CONFIG_LINUX_DEVDAX"
2018 fi
2019 if test "$arith" = "yes" ; then
2020   output_sym "CONFIG_ARITHMETIC"
2021   if test "$yacc_is_bison" = "yes" ; then
2022     echo "YACC=$YACC -y" >> $config_host_mak
2023   else
2024     echo "YACC=$YACC" >> $config_host_mak
2025   fi
2026   if test "$lex_use_o" = "yes" ; then
2027     echo "CONFIG_LEX_USE_O=y" >> $config_host_mak
2028   fi
2029 fi
2030 if test "$getmntent" = "yes" ; then
2031   output_sym "CONFIG_GETMNTENT"
2032 fi
2033 if test "$getmntinfo" = "yes" ; then
2034   output_sym "CONFIG_GETMNTINFO"
2035 fi
2036 if test "$getmntinfo_statvfs" = "yes" ; then
2037   output_sym "CONFIG_GETMNTINFO_STATVFS"
2038 fi
2039 if test "$static_assert" = "yes" ; then
2040   output_sym "CONFIG_STATIC_ASSERT"
2041 fi
2042 if test "$have_bool" = "yes" ; then
2043   output_sym "CONFIG_HAVE_BOOL"
2044 fi
2045
2046 if test "$zlib" = "no" ; then
2047   echo "Consider installing zlib-dev (zlib-devel), some fio features depend on it."
2048 fi
2049
2050 echo "LIBS+=$LIBS" >> $config_host_mak
2051 echo "GFIO_LIBS+=$GFIO_LIBS" >> $config_host_mak
2052 echo "CFLAGS+=$CFLAGS" >> $config_host_mak
2053 echo "LDFLAGS+=$LDFLAGS" >> $config_host_mak
2054 echo "CC=$cc" >> $config_host_mak
2055 echo "BUILD_CFLAGS=$BUILD_CFLAGS $CFLAGS" >> $config_host_mak
2056 echo "INSTALL_PREFIX=$prefix" >> $config_host_mak
2057
2058 if [ `dirname $0` != "." -a ! -e Makefile ]; then
2059     cat > Makefile <<EOF
2060 SRCDIR:=`dirname $0`
2061 include \$(SRCDIR)/Makefile
2062 EOF
2063 fi