librbd ioengine support
[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 cross_prefix=${cross_prefix-${CROSS_COMPILE}}
134 cc="${CC-${cross_prefix}gcc}"
135
136 # default options
137 show_help="no"
138 exit_val=0
139 gfio="no"
140
141 # parse options
142 for opt do
143   optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
144   case "$opt" in
145   --cpu=*) cpu="$optarg"
146   ;;
147   --cc=*) CC="$optarg"
148   ;;
149   --extra-cflags=*) CFLAGS="$CFLAGS $optarg"
150   ;;
151   --build-32bit-win) build_32bit_win="yes"
152   ;;
153   --enable-gfio)
154   gfio="yes"
155   ;;
156   --disable-numa) disable_numa="yes"
157   ;;
158   --help)
159     show_help="yes"
160     ;;
161   *)
162   echo "Bad option $opt"
163   show_help="yes"
164   exit_val=1
165   esac
166 done
167
168 if test "$show_help" = "yes" ; then
169   echo "--cpu=                 Specify target CPU if auto-detect fails"
170   echo "--cc=                  Specify compiler to use"
171   echo "--extra-cflags=        Specify extra CFLAGS to pass to compiler"
172   echo "--build-32bit-win      Enable 32-bit build on Windows"
173   echo "--enable-gfio          Enable building of gtk gfio"
174   echo "--disable-numa         Disable libnuma even if found"
175   exit $exit_val
176 fi
177
178 if check_define __ANDROID__ ; then
179   targetos="Android"
180 elif check_define __linux__ ; then
181   targetos="Linux"
182 elif check_define __OpenBSD__ ; then
183   targetos='OpenBSD'
184 elif check_define __sun__ ; then
185   targetos='SunOS'
186   CFLAGS="$CFLAGS -D_REENTRANT"
187 else
188   targetos=`uname -s`
189 fi
190
191 echo "# Automatically generated by configure - do not modify" > $config_host_mak
192 printf "# Configured with:" >> $config_host_mak
193 printf " '%s'" "$0" "$@" >> $config_host_mak
194 echo >> $config_host_mak
195 echo "CONFIG_TARGET_OS=$targetos" >> $config_host_mak
196
197 # Some host OSes need non-standard checks for which CPU to use.
198 # Note that these checks are broken for cross-compilation: if you're
199 # cross-compiling to one of these OSes then you'll need to specify
200 # the correct CPU with the --cpu option.
201 case $targetos in
202 Darwin)
203   # on Leopard most of the system is 32-bit, so we have to ask the kernel if
204   # we can run 64-bit userspace code.
205   # If the user didn't specify a CPU explicitly and the kernel says this is
206   # 64 bit hw, then assume x86_64. Otherwise fall through to the usual
207   # detection code.
208   if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then
209     cpu="x86_64"
210   fi
211   ;;
212 SunOS)
213   # `uname -m` returns i86pc even on an x86_64 box, so default based on isainfo
214   if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
215     cpu="x86_64"
216   fi
217   LIBS="-lnsl -lsocket"
218   ;;
219 CYGWIN*)
220   echo "Forcing known good options on Windows"
221   if test -z "$CC" ; then
222     if test ! -z "$build_32bit_win" && test "$build_32bit_win" = "yes"; then
223       CC="i686-w64-mingw32-gcc"
224     else
225       CC="x86_64-w64-mingw32-gcc"
226     fi
227   fi
228   output_sym "CONFIG_LITTLE_ENDIAN"
229   if test ! -z "$build_32bit_win" && test "$build_32bit_win" = "yes"; then
230     output_sym "CONFIG_32BIT"
231   else
232     output_sym "CONFIG_64BIT_LLP64"
233   fi
234   output_sym "CONFIG_FADVISE"
235   output_sym "CONFIG_SOCKLEN_T"
236   output_sym "CONFIG_FADVISE"
237   output_sym "CONFIG_SFAA"
238   output_sym "CONFIG_RUSAGE_THREAD"
239   output_sym "CONFIG_WINDOWSAIO"
240   output_sym "CONFIG_FDATASYNC"
241   output_sym "CONFIG_CLOCK_MONOTONIC"
242   output_sym "CONFIG_GETTIMEOFDAY"
243   output_sym "CONFIG_CLOCK_GETTIME"
244   output_sym "CONFIG_SCHED_IDLE"
245   output_sym "CONFIG_TCP_NODELAY"
246   output_sym "CONFIG_TLS_THREAD"
247   output_sym "CONFIG_IPV6"
248   echo "CC=$CC" >> $config_host_mak
249   echo "BUILD_CFLAGS=$CFLAGS -include config-host.h -D_GNU_SOURCE" >> $config_host_mak
250   exit 0
251   ;;
252 esac
253
254 if test ! -z "$cpu" ; then
255   # command line argument
256   :
257 elif check_define __i386__ ; then
258   cpu="i386"
259 elif check_define __x86_64__ ; then
260   cpu="x86_64"
261 elif check_define __sparc__ ; then
262   if check_define __arch64__ ; then
263     cpu="sparc64"
264   else
265     cpu="sparc"
266   fi
267 elif check_define _ARCH_PPC ; then
268   if check_define _ARCH_PPC64 ; then
269     cpu="ppc64"
270   else
271     cpu="ppc"
272   fi
273 elif check_define __mips__ ; then
274   cpu="mips"
275 elif check_define __ia64__ ; then
276   cpu="ia64"
277 elif check_define __s390__ ; then
278   if check_define __s390x__ ; then
279     cpu="s390x"
280   else
281     cpu="s390"
282   fi
283 elif check_define __arm__ ; then
284   cpu="arm"
285 elif check_define __hppa__ ; then
286   cpu="hppa"
287 else
288   cpu=`uname -m`
289 fi
290
291 # Normalise host CPU name and set ARCH.
292 case "$cpu" in
293   ia64|ppc|ppc64|s390|s390x|sparc64)
294     cpu="$cpu"
295   ;;
296   i386|i486|i586|i686|i86pc|BePC)
297     cpu="i386"
298   ;;
299   x86_64|amd64)
300     cpu="x86_64"
301   ;;
302   armv*b|armv*l|arm)
303     cpu="arm"
304   ;;
305   hppa|parisc|parisc64)
306     cpu="hppa"
307   ;;
308   mips*)
309     cpu="mips"
310   ;;
311   sparc|sun4[cdmuv])
312     cpu="sparc"
313   ;;
314   *)
315   echo "Unknown CPU"
316   ;;
317 esac
318
319 if test -z "$CC" ; then
320   if test "$targetos" = "FreeBSD"; then
321     if has clang; then
322       CC=clang
323     else
324       CC=gcc
325     fi
326   fi
327 fi
328
329 cc="${CC-${cross_prefix}gcc}"
330
331 ##########################################
332 # check cross compile
333
334 cross_compile="no"
335 cat > $TMPC <<EOF
336 int main(void)
337 {
338   return 0;
339 }
340 EOF
341 if compile_prog "" "" "cross"; then
342   $TMPE 2>/dev/null || cross_compile="yes"
343 else
344   fatal "compile test failed"
345 fi
346
347 ##########################################
348 # check endianness
349 bigendian="no"
350 if test "$cross_compile" = "no" ; then
351   cat > $TMPC <<EOF
352 #include <inttypes.h>
353 int main(void)
354 {
355   volatile uint32_t i=0x01234567;
356   return (*((uint8_t*)(&i))) == 0x67;
357 }
358 EOF
359   if compile_prog "" "" "endian"; then
360     $TMPE && bigendian="yes"
361   fi
362 else
363   # If we're cross compiling, try our best to work it out and rely on the
364   # run-time check to fail if we get it wrong.
365   cat > $TMPC <<EOF
366 #include <endian.h>
367 int main(void)
368 {
369 #if __BYTE_ORDER != __BIG_ENDIAN
370 # error "Unknown endianness"
371 #endif
372 }
373 EOF
374   compile_prog "" "" "endian" && bigendian="yes"
375   check_define "__ARMEB__" && bigendian="yes"
376   check_define "__MIPSEB__" && bigendian="yes"
377 fi
378
379
380 echo "Operating system              $targetos"
381 echo "CPU                           $cpu"
382 echo "Big endian                    $bigendian"
383 echo "Compiler                      $cc"
384 echo "Cross compile                 $cross_compile"
385 echo
386
387 ##########################################
388 # check for wordsize
389 wordsize="0"
390 cat > $TMPC <<EOF
391 #include <limits.h>
392 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
393 int main(void)
394 {
395   BUILD_BUG_ON(sizeof(long)*CHAR_BIT != WORDSIZE);
396   return 0;
397 }
398 EOF
399 if compile_prog "-DWORDSIZE=32" "" "wordsize"; then
400   wordsize="32"
401 elif compile_prog "-DWORDSIZE=64" "" "wordsize"; then
402   wordsize="64"
403 else
404   fatal "Unknown wordsize"
405 fi
406 echo "Wordsize                      $wordsize"
407
408 ##########################################
409 # zlib probe
410 zlib="no"
411 cat > $TMPC <<EOF
412 #include <zlib.h>
413 int main(void)
414 {
415   z_stream stream;
416   if (inflateInit(&stream) != Z_OK)
417     return 1;
418   return 0;
419 }
420 EOF
421 if compile_prog "" "-lz" "zlib" ; then
422   zlib=yes
423   LIBS="-lz $LIBS"
424 fi
425 echo "zlib                          $zlib"
426
427 ##########################################
428 # linux-aio probe
429 libaio="no"
430 cat > $TMPC <<EOF
431 #include <libaio.h>
432 #include <stddef.h>
433 int main(void)
434 {
435   io_setup(0, NULL);
436   return 0;
437 }
438 EOF
439 if compile_prog "" "-laio" "libaio" ; then
440   libaio=yes
441   LIBS="-laio $LIBS"
442 else
443   if test "$libaio" = "yes" ; then
444     feature_not_found "linux AIO" "libaio-dev or libaio-devel"
445   fi
446   libaio=no
447 fi
448 echo "Linux AIO support             $libaio"
449
450 ##########################################
451 # posix aio probe
452 posix_aio="no"
453 posix_aio_lrt="no"
454 cat > $TMPC <<EOF
455 #include <aio.h>
456 int main(void)
457 {
458   struct aiocb cb;
459   aio_read(&cb);
460   return 0;
461 }
462 EOF
463 if compile_prog "" "" "posixaio" ; then
464   posix_aio="yes"
465 elif compile_prog "" "-lrt" "posixaio"; then
466   posix_aio="yes"
467   posix_aio_lrt="yes"
468   LIBS="-lrt $LIBS"
469 fi
470 echo "POSIX AIO support             $posix_aio"
471 echo "POSIX AIO support needs -lrt  $posix_aio_lrt"
472
473 ##########################################
474 # posix aio fsync probe
475 posix_aio_fsync="no"
476 if test "$posix_aio" = "yes" ; then
477   cat > $TMPC <<EOF
478 #include <fcntl.h>
479 #include <aio.h>
480 int main(void)
481 {
482   struct aiocb cb;
483   return aio_fsync(O_SYNC, &cb);
484   return 0;
485 }
486 EOF
487   if compile_prog "" "$LIBS" "posix_aio_fsync" ; then
488     posix_aio_fsync=yes
489   fi
490 fi
491 echo "POSIX AIO fsync               $posix_aio_fsync"
492
493 ##########################################
494 # solaris aio probe
495 solaris_aio="no"
496 cat > $TMPC <<EOF
497 #include <sys/types.h>
498 #include <sys/asynch.h>
499 #include <unistd.h>
500 int main(void)
501 {
502   aio_result_t res;
503   return aioread(0, NULL, 0, 0, SEEK_SET, &res);
504   return 0;
505 }
506 EOF
507 if compile_prog "" "-laio" "solarisaio" ; then
508   solaris_aio=yes
509   LIBS="-laio $LIBS"
510 fi
511 echo "Solaris AIO support           $solaris_aio"
512
513 ##########################################
514 # __sync_fetch_and_and test
515 sfaa="no"
516 cat > $TMPC << EOF
517 static int sfaa(int *ptr)
518 {
519   return __sync_fetch_and_add(ptr, 0);
520 }
521
522 int main(int argc, char **argv)
523 {
524   int val = 42;
525   sfaa(&val);
526   return val;
527 }
528 EOF
529 if compile_prog "" "" "__sync_fetch_and_add()" ; then
530     sfaa="yes"
531 fi
532 echo "__sync_fetch_and_add          $sfaa"
533
534 ##########################################
535 # libverbs probe
536 libverbs="no"
537 cat > $TMPC << EOF
538 #include <stdio.h>
539 #include <infiniband/arch.h>
540 int main(int argc, char **argv)
541 {
542   struct ibv_pd *pd = ibv_alloc_pd(NULL);
543   return 0;
544 }
545 EOF
546 if compile_prog "" "-libverbs" "libverbs" ; then
547     libverbs="yes"
548     LIBS="-libverbs $LIBS"
549 fi
550 echo "libverbs                      $libverbs"
551
552 ##########################################
553 # rdmacm probe
554 rdmacm="no"
555 cat > $TMPC << EOF
556 #include <stdio.h>
557 #include <rdma/rdma_cma.h>
558 int main(int argc, char **argv)
559 {
560   rdma_destroy_qp(NULL);
561   return 0;
562 }
563 EOF
564 if compile_prog "" "-lrdmacm" "rdma"; then
565     rdmacm="yes"
566     LIBS="-lrdmacm $LIBS"
567 fi
568 echo "rdmacm                        $rdmacm"
569
570 ##########################################
571 # Linux fallocate probe
572 linux_fallocate="no"
573 cat > $TMPC << EOF
574 #include <stdio.h>
575 #include <fcntl.h>
576 #include <linux/falloc.h>
577 int main(int argc, char **argv)
578 {
579   int r = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 1024);
580   return r;
581 }
582 EOF
583 if compile_prog "" "" "linux_fallocate"; then
584     linux_fallocate="yes"
585 fi
586 echo "Linux fallocate               $linux_fallocate"
587
588 ##########################################
589 # POSIX fadvise probe
590 posix_fadvise="no"
591 cat > $TMPC << EOF
592 #include <stdio.h>
593 #include <fcntl.h>
594 int main(int argc, char **argv)
595 {
596   int r = posix_fadvise(0, 0, 0, POSIX_FADV_NORMAL);
597   return r;
598 }
599 EOF
600 if compile_prog "" "" "posix_fadvise"; then
601     posix_fadvise="yes"
602 fi
603 echo "POSIX fadvise                 $posix_fadvise"
604
605 ##########################################
606 # POSIX fallocate probe
607 posix_fallocate="no"
608 cat > $TMPC << EOF
609 #include <stdio.h>
610 #include <fcntl.h>
611 int main(int argc, char **argv)
612 {
613   int r = posix_fallocate(0, 0, 1024);
614   return r;
615 }
616 EOF
617 if compile_prog "" "" "posix_fallocate"; then
618     posix_fallocate="yes"
619 fi
620 echo "POSIX fallocate               $posix_fallocate"
621
622 ##########################################
623 # sched_set/getaffinity 2 or 3 argument test
624 linux_2arg_affinity="no"
625 linux_3arg_affinity="no"
626 cat > $TMPC << EOF
627 #include <sched.h>
628 int main(int argc, char **argv)
629 {
630   cpu_set_t mask;
631   return sched_setaffinity(0, sizeof(mask), &mask);
632 }
633 EOF
634 if compile_prog "" "" "sched_setaffinity(,,)"; then
635   linux_3arg_affinity="yes"
636 else
637   cat > $TMPC << EOF
638 #include <sched.h>
639 int main(int argc, char **argv)
640 {
641   cpu_set_t mask;
642   return sched_setaffinity(0, &mask);
643 }
644 EOF
645   if compile_prog "" "" "sched_setaffinity(,)"; then
646     linux_2arg_affinity="yes"
647   fi
648 fi
649 echo "sched_setaffinity(3 arg)      $linux_3arg_affinity"
650 echo "sched_setaffinity(2 arg)      $linux_2arg_affinity"
651
652 ##########################################
653 # clock_gettime probe
654 clock_gettime="no"
655 cat > $TMPC << EOF
656 #include <stdio.h>
657 #include <time.h>
658 int main(int argc, char **argv)
659 {
660   return clock_gettime(0, NULL);
661 }
662 EOF
663 if compile_prog "" "" "clock_gettime"; then
664     clock_gettime="yes"
665 elif compile_prog "" "-lrt" "clock_gettime"; then
666     clock_gettime="yes"
667     LIBS="-lrt $LIBS"
668 fi
669 echo "clock_gettime                 $clock_gettime"
670
671 ##########################################
672 # CLOCK_MONOTONIC probe
673 clock_monotonic="no"
674 if test "$clock_gettime" = "yes" ; then
675   cat > $TMPC << EOF
676 #include <stdio.h>
677 #include <time.h>
678 int main(int argc, char **argv)
679 {
680   return clock_gettime(CLOCK_MONOTONIC, NULL);
681 }
682 EOF
683   if compile_prog "" "$LIBS" "clock monotonic"; then
684       clock_monotonic="yes"
685   fi
686 fi
687 echo "CLOCK_MONOTONIC               $clock_monotonic"
688
689 ##########################################
690 # CLOCK_MONOTONIC_PRECISE probe
691 clock_monotonic_precise="no"
692 if test "$clock_gettime" = "yes" ; then
693   cat > $TMPC << EOF
694 #include <stdio.h>
695 #include <time.h>
696 int main(int argc, char **argv)
697 {
698   return clock_gettime(CLOCK_MONOTONIC_PRECISE, NULL);
699 }
700 EOF
701   if compile_prog "" "$LIBS" "clock monotonic precise"; then
702       clock_monotonic_precise="yes"
703   fi
704 fi
705 echo "CLOCK_MONOTONIC_PRECISE       $clock_monotonic_precise"
706
707 ##########################################
708 # gettimeofday() probe
709 gettimeofday="no"
710 cat > $TMPC << EOF
711 #include <sys/time.h>
712 #include <stdio.h>
713 int main(int argc, char **argv)
714 {
715   struct timeval tv;
716   return gettimeofday(&tv, NULL);
717 }
718 EOF
719 if compile_prog "" "" "gettimeofday"; then
720     gettimeofday="yes"
721 fi
722 echo "gettimeofday                  $gettimeofday"
723
724 ##########################################
725 # fdatasync() probe
726 fdatasync="no"
727 cat > $TMPC << EOF
728 #include <stdio.h>
729 #include <unistd.h>
730 int main(int argc, char **argv)
731 {
732   return fdatasync(0);
733 }
734 EOF
735 if compile_prog "" "" "fdatasync"; then
736   fdatasync="yes"
737 fi
738 echo "fdatasync                     $fdatasync"
739
740 ##########################################
741 # sync_file_range() probe
742 sync_file_range="no"
743 cat > $TMPC << EOF
744 #include <stdio.h>
745 #include <unistd.h>
746 #include <fcntl.h>
747 #include <linux/fs.h>
748 int main(int argc, char **argv)
749 {
750   unsigned int flags = SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE |
751                         SYNC_FILE_RANGE_WAIT_AFTER;
752   return sync_file_range(0, 0, 0, flags);
753 }
754 EOF
755 if compile_prog "" "" "sync_file_range"; then
756   sync_file_range="yes"
757 fi
758 echo "sync_file_range               $sync_file_range"
759
760 ##########################################
761 # ext4 move extent probe
762 ext4_me="no"
763 cat > $TMPC << EOF
764 #include <fcntl.h>
765 #include <sys/ioctl.h>
766 int main(int argc, char **argv)
767 {
768   struct move_extent me;
769   return ioctl(0, EXT4_IOC_MOVE_EXT, &me);
770 }
771 EOF
772 if compile_prog "" "" "ext4 move extent" ; then
773   ext4_me="yes"
774 elif test $targetos = "Linux" ; then
775   # On Linux, just default to it on and let it error at runtime if we really
776   # don't have it. None of my updated systems have it defined, but it does
777   # work. Takes a while to bubble back.
778   ext4_me="yes"
779 fi
780 echo "EXT4 move extent              $ext4_me"
781
782 ##########################################
783 # splice probe
784 linux_splice="no"
785 cat > $TMPC << EOF
786 #include <stdio.h>
787 #include <fcntl.h>
788 int main(int argc, char **argv)
789 {
790   return splice(0, NULL, 0, NULL, 0, SPLICE_F_NONBLOCK);
791 }
792 EOF
793 if compile_prog "" "" "linux splice"; then
794   linux_splice="yes"
795 fi
796 echo "Linux splice(2)               $linux_splice"
797
798 ##########################################
799 # GUASI probe
800 guasi="no"
801 cat > $TMPC << EOF
802 #include <guasi.h>
803 #include <guasi_syscalls.h>
804 int main(int argc, char **argv)
805 {
806   guasi_t ctx = guasi_create(0, 0, 0);
807   return 0;
808 }
809 EOF
810 if compile_prog "" "" "guasi"; then
811   guasi="yes"
812 fi
813 echo "GUASI                         $guasi"
814
815 ##########################################
816 # fusion-aw probe
817 fusion_aw="no"
818 cat > $TMPC << EOF
819 #include <nvm/nvm_primitives.h>
820 int main(int argc, char **argv)
821 {
822   nvm_version_t ver_info;
823   nvm_handle_t handle;
824
825   handle = nvm_get_handle(0, &ver_info);
826   return nvm_atomic_write(handle, 0, 0, 0);
827 }
828 EOF
829 if compile_prog "" "-L/usr/lib/fio -L/usr/lib/nvm -lnvm-primitives -lvsl -ldl" "fusion-aw"; then
830   LIBS="-L/usr/lib/fio -L/usr/lib/nvm -lnvm-primitives -lvsl -ldl $LIBS"
831   fusion_aw="yes"
832 fi
833 echo "Fusion-io atomic engine       $fusion_aw"
834
835 ##########################################
836 # libnuma probe
837 libnuma="no"
838 cat > $TMPC << EOF
839 #include <numa.h>
840 int main(int argc, char **argv)
841 {
842   return numa_available();
843 }
844 EOF
845 if test "$disable_numa" != "yes"  && compile_prog "" "-lnuma" "libnuma"; then
846   libnuma="yes"
847   LIBS="-lnuma $LIBS"
848 fi
849 echo "libnuma                       $libnuma"
850
851 ##########################################
852 # libnuma 2.x version API
853 if test "$libnuma" = "yes" ; then
854 libnuma_v2="no"
855 cat > $TMPC << EOF
856 #include <numa.h>
857 int main(int argc, char **argv)
858 {
859   struct bitmask *mask = numa_parse_nodestring(NULL);
860   return 0;
861 }
862 EOF
863 if compile_prog "" "" "libnuma api"; then
864   libnuma_v2="yes"
865 fi
866 echo "libnuma v2                    $libnuma_v2"
867 fi
868
869 ##########################################
870 # strsep() probe
871 strsep="no"
872 cat > $TMPC << EOF
873 #include <string.h>
874 int main(int argc, char **argv)
875 {
876   strsep(NULL, NULL);
877   return 0;
878 }
879 EOF
880 if compile_prog "" "" "strsep"; then
881   strsep="yes"
882 fi
883 echo "strsep                        $strsep"
884
885 ##########################################
886 # strcasestr() probe
887 strcasestr="no"
888 cat > $TMPC << EOF
889 #include <string.h>
890 int main(int argc, char **argv)
891 {
892   return strcasestr(argv[0], argv[1]) != NULL;
893 }
894 EOF
895 if compile_prog "" "" "strcasestr"; then
896   strcasestr="yes"
897 fi
898 echo "strcasestr                    $strcasestr"
899
900 ##########################################
901 # getopt_long_only() probe
902 getopt_long_only="no"
903 cat > $TMPC << EOF
904 #include <unistd.h>
905 #include <stdio.h>
906 #include <getopt.h>
907 int main(int argc, char **argv)
908 {
909   int c = getopt_long_only(argc, argv, NULL, NULL, NULL);
910   return c;
911 }
912 EOF
913 if compile_prog "" "" "getopt_long_only"; then
914   getopt_long_only="yes"
915 fi
916 echo "getopt_long_only()            $getopt_long_only"
917
918 ##########################################
919 # inet_aton() probe
920 inet_aton="no"
921 cat > $TMPC << EOF
922 #include <sys/socket.h>
923 #include <arpa/inet.h>
924 #include <stdio.h>
925 int main(int argc, char **argv)
926 {
927   struct in_addr in;
928   return inet_aton(NULL, &in);
929 }
930 EOF
931 if compile_prog "" "" "inet_aton"; then
932   inet_aton="yes"
933 fi
934 echo "inet_aton                     $inet_aton"
935
936 ##########################################
937 # socklen_t probe
938 socklen_t="no"
939 cat > $TMPC << EOF
940 #include <sys/socket.h>
941 int main(int argc, char **argv)
942 {
943   socklen_t len = 0;
944   return len;
945 }
946 EOF
947 if compile_prog "" "" "socklen_t"; then
948   socklen_t="yes"
949 fi
950 echo "socklen_t                     $socklen_t"
951
952 ##########################################
953 # Whether or not __thread is supported for TLS
954 tls_thread="no"
955 cat > $TMPC << EOF
956 #include <stdio.h>
957 static __thread int ret;
958 int main(int argc, char **argv)
959 {
960   return ret;
961 }
962 EOF
963 if compile_prog "" "" "__thread"; then
964   tls_thread="yes"
965 fi
966 echo "__thread                      $tls_thread"
967
968 ##########################################
969 # Check if we have required gtk/glib support for gfio
970 if test "$gfio" = "yes" ; then
971   cat > $TMPC << EOF
972 #include <glib.h>
973 #include <cairo.h>
974 #include <gtk/gtk.h>
975 int main(void)
976 {
977   gdk_threads_enter();
978   gdk_threads_leave();
979
980   printf("%d", GTK_CHECK_VERSION(2, 18, 0));
981 }
982 EOF
983 GTK_CFLAGS=$(pkg-config --cflags gtk+-2.0 gthread-2.0)
984 if test "$?" != "0" ; then
985   echo "configure: gtk and gthread not found"
986   exit 1
987 fi
988 GTK_LIBS=$(pkg-config --libs gtk+-2.0 gthread-2.0)
989 if test "$?" != "0" ; then
990   echo "configure: gtk and gthread not found"
991   exit 1
992 fi
993 if compile_prog "$GTK_CFLAGS" "$GTK_LIBS" "gfio" ; then
994   r=$($TMPE)
995   if test "$r" != "0" ; then
996     gfio="yes"
997     LIBS="$LIBS $GTK_LIBS"
998     CFLAGS="$CFLAGS $GTK_CFLAGS"
999   else
1000     echo "GTK found, but need version 2.18 or higher"
1001     gfio="no"
1002   fi
1003 else
1004   echo "Please install gtk and gdk libraries"
1005   gfio="no"
1006 fi
1007 fi
1008
1009 echo "gtk 2.18 or higher            $gfio"
1010
1011 # Check whether we have getrusage(RUSAGE_THREAD)
1012 rusage_thread="no"
1013 cat > $TMPC << EOF
1014 #include <sys/time.h>
1015 #include <sys/resource.h>
1016 int main(int argc, char **argv)
1017 {
1018   struct rusage ru;
1019   getrusage(RUSAGE_THREAD, &ru);
1020   return 0;
1021 }
1022 EOF
1023 if compile_prog "" "" "RUSAGE_THREAD"; then
1024   rusage_thread="yes"
1025 fi
1026 echo "RUSAGE_THREAD                 $rusage_thread"
1027
1028 ##########################################
1029 # Check whether we have SCHED_IDLE
1030 sched_idle="no"
1031 cat > $TMPC << EOF
1032 #include <sched.h>
1033 int main(int argc, char **argv)
1034 {
1035   struct sched_param p;
1036   return sched_setscheduler(0, SCHED_IDLE, &p);
1037 }
1038 EOF
1039 if compile_prog "" "" "SCHED_IDLE"; then
1040   sched_idle="yes"
1041 fi
1042 echo "SCHED_IDLE                    $sched_idle"
1043
1044 ##########################################
1045 # Check whether we have TCP_NODELAY
1046 tcp_nodelay="no"
1047 cat > $TMPC << EOF
1048 #include <stdio.h>
1049 #include <sys/types.h>
1050 #include <sys/socket.h>
1051 #include <netinet/tcp.h>
1052 int main(int argc, char **argv)
1053 {
1054   return getsockopt(0, 0, TCP_NODELAY, NULL, NULL);
1055 }
1056 EOF
1057 if compile_prog "" "" "TCP_NODELAY"; then
1058   tcp_nodelay="yes"
1059 fi
1060 echo "TCP_NODELAY                   $tcp_nodelay"
1061
1062 ##########################################
1063 # Check whether we have RLIMIT_MEMLOCK
1064 rlimit_memlock="no"
1065 cat > $TMPC << EOF
1066 #include <sys/time.h>
1067 #include <sys/resource.h>
1068 int main(int argc, char **argv)
1069 {
1070   struct rlimit rl;
1071   return getrlimit(RLIMIT_MEMLOCK, &rl);
1072 }
1073 EOF
1074 if compile_prog "" "" "RLIMIT_MEMLOCK"; then
1075   rlimit_memlock="yes"
1076 fi
1077 echo "RLIMIT_MEMLOCK                $rlimit_memlock"
1078
1079 ##########################################
1080 # Check whether we have pwritev/preadv
1081 pwritev="no"
1082 cat > $TMPC << EOF
1083 #include <stdio.h>
1084 #include <sys/uio.h>
1085 int main(int argc, char **argv)
1086 {
1087   return pwritev(0, NULL, 1, 0) + preadv(0, NULL, 1, 0);
1088 }
1089 EOF
1090 if compile_prog "" "" "pwritev"; then
1091   pwritev="yes"
1092 fi
1093 echo "pwritev/preadv                $pwritev"
1094
1095 ##########################################
1096 # Check whether we have the required functions for ipv6
1097 ipv6="no"
1098 cat > $TMPC << EOF
1099 #include <sys/types.h>
1100 #include <sys/socket.h>
1101 #include <netinet/in.h>
1102 #include <netdb.h>
1103 #include <stdio.h>
1104 int main(int argc, char **argv)
1105 {
1106   struct addrinfo hints;
1107   struct in6_addr addr;
1108   int ret;
1109
1110   ret = getaddrinfo(NULL, NULL, &hints, NULL);
1111   freeaddrinfo(NULL);
1112   printf("%s\n", gai_strerror(ret));
1113   addr = in6addr_any;
1114   return 0;
1115 }
1116 EOF
1117 if compile_prog "" "" "ipv6"; then
1118   ipv6="yes"
1119 fi
1120 echo "IPv6 helpers                  $ipv6"
1121
1122 ##########################################
1123 # check for rbd
1124 rbd="no"
1125 cat > $TMPC << EOF
1126 #include <rbd/librbd.h>
1127
1128 int main(int argc, char **argv)
1129 {
1130
1131   rados_t cluster;
1132   rados_ioctx_t io_ctx;
1133   const char pool[] = "rbd";
1134
1135   int major, minor, extra;
1136   rbd_version(&major, &minor, &extra);
1137
1138   rados_ioctx_create(cluster, pool, &io_ctx);
1139   return 0;
1140 }
1141 EOF
1142 if compile_prog "" "-lrbd -lrados" "rbd"; then
1143   LIBS="-lrbd -lrados $LIBS"
1144   rbd="yes"
1145 fi
1146 echo "Rados Block Device engine     $rbd"
1147
1148
1149 #############################################################################
1150
1151 if test "$wordsize" = "64" ; then
1152   output_sym "CONFIG_64BIT"
1153 elif test "$wordsize" = "32" ; then
1154   output_sym "CONFIG_32BIT"
1155 else
1156   fatal "Unknown wordsize!"
1157 fi
1158 if test "$bigendian" = "yes" ; then
1159   output_sym "CONFIG_BIG_ENDIAN"
1160 else
1161   output_sym "CONFIG_LITTLE_ENDIAN"
1162 fi
1163 if test "$zlib" = "yes" ; then
1164   output_sym "CONFIG_ZLIB"
1165 fi
1166 if test "$libaio" = "yes" ; then
1167   output_sym "CONFIG_LIBAIO"
1168 fi
1169 if test "$posix_aio" = "yes" ; then
1170   output_sym "CONFIG_POSIXAIO"
1171 fi
1172 if test "$posix_aio_fsync" = "yes" ; then
1173   output_sym "CONFIG_POSIXAIO_FSYNC"
1174 fi
1175 if test "$linux_fallocate" = "yes" ; then
1176   output_sym "CONFIG_LINUX_FALLOCATE"
1177 fi
1178 if test "$posix_fallocate" = "yes" ; then
1179   output_sym "CONFIG_POSIX_FALLOCATE"
1180 fi
1181 if test "$fdatasync" = "yes" ; then
1182   output_sym "CONFIG_FDATASYNC"
1183 fi
1184 if test "$sync_file_range" = "yes" ; then
1185   output_sym "CONFIG_SYNC_FILE_RANGE"
1186 fi
1187 if test "$sfaa" = "yes" ; then
1188   output_sym "CONFIG_SFAA"
1189 fi
1190 if test "$libverbs" = "yes" -a "$rdmacm" = "yes" ; then
1191   output_sym "CONFIG_RDMA"
1192 fi
1193 if test "$clock_gettime" = "yes" ; then
1194   output_sym "CONFIG_CLOCK_GETTIME"
1195 fi
1196 if test "$clock_monotonic" = "yes" ; then
1197   output_sym "CONFIG_CLOCK_MONOTONIC"
1198 fi
1199 if test "$clock_monotonic_precise" = "yes" ; then
1200   output_sym "CONFIG_CLOCK_MONOTONIC_PRECISE"
1201 fi
1202 if test "$gettimeofday" = "yes" ; then
1203   output_sym "CONFIG_GETTIMEOFDAY"
1204 fi
1205 if test "$posix_fadvise" = "yes" ; then
1206   output_sym "CONFIG_POSIX_FADVISE"
1207 fi
1208 if test "$linux_3arg_affinity" = "yes" ; then
1209   output_sym "CONFIG_3ARG_AFFINITY"
1210 elif test "$linux_2arg_affinity" = "yes" ; then
1211   output_sym "CONFIG_2ARG_AFFINITY"
1212 fi
1213 if test "$strsep" = "yes" ; then
1214   output_sym "CONFIG_STRSEP"
1215 fi
1216 if test "$strcasestr" = "yes" ; then
1217   output_sym "CONFIG_STRCASESTR"
1218 fi
1219 if test "$getopt_long_only" = "yes" ; then
1220   output_sym "CONFIG_GETOPT_LONG_ONLY"
1221 fi
1222 if test "$inet_aton" = "yes" ; then
1223   output_sym "CONFIG_INET_ATON"
1224 fi
1225 if test "$socklen_t" = "yes" ; then
1226   output_sym "CONFIG_SOCKLEN_T"
1227 fi
1228 if test "$ext4_me" = "yes" ; then
1229   output_sym "CONFIG_LINUX_EXT4_MOVE_EXTENT"
1230 fi
1231 if test "$linux_splice" = "yes" ; then
1232   output_sym "CONFIG_LINUX_SPLICE"
1233 fi
1234 if test "$guasi" = "yes" ; then
1235   output_sym "CONFIG_GUASI"
1236 fi
1237 if test "$fusion_aw" = "yes" ; then
1238   output_sym "CONFIG_FUSION_AW"
1239 fi
1240 if test "$libnuma_v2" = "yes" ; then
1241   output_sym "CONFIG_LIBNUMA"
1242 fi
1243 if test "$solaris_aio" = "yes" ; then
1244   output_sym "CONFIG_SOLARISAIO"
1245 fi
1246 if test "$tls_thread" = "yes" ; then
1247   output_sym "CONFIG_TLS_THREAD"
1248 fi
1249 if test "$rusage_thread" = "yes" ; then
1250   output_sym "CONFIG_RUSAGE_THREAD"
1251 fi
1252 if test "$gfio" = "yes" ; then
1253   echo "CONFIG_GFIO=y" >> $config_host_mak
1254 fi
1255 if test "$sched_idle" = "yes" ; then
1256   output_sym "CONFIG_SCHED_IDLE"
1257 fi
1258 if test "$tcp_nodelay" = "yes" ; then
1259   output_sym "CONFIG_TCP_NODELAY"
1260 fi
1261 if test "$rlimit_memlock" = "yes" ; then
1262   output_sym "CONFIG_RLIMIT_MEMLOCK"
1263 fi
1264 if test "$pwritev" = "yes" ; then
1265   output_sym "CONFIG_PWRITEV"
1266 fi
1267 if test "$ipv6" = "yes" ; then
1268   output_sym "CONFIG_IPV6"
1269 fi
1270 if test "$rbd" = "yes" ; then
1271   output_sym "CONFIG_RBD"
1272 fi
1273
1274 echo "LIBS+=$LIBS" >> $config_host_mak
1275 echo "CFLAGS+=$CFLAGS" >> $config_host_mak
1276 echo "CC=$cc" >> $config_host_mak
1277 echo "BUILD_CFLAGS=$BUILD_CFLAGS $CFLAGS" >> $config_host_mak