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