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