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