3 # Fio configure script. Heavily influenced by the manual qemu configure
4 # script. Sad this this is easier than autoconf and enemies.
7 # set temporary file name
8 if test ! -z "$TMPDIR" ; then
10 elif test ! -z "$TEMPDIR" ; then
16 TMPC="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.c"
17 TMPO="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.o"
18 TMPE="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.exe"
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
26 config_host_mak="config-host.mak"
27 config_host_h="config-host.h"
29 rm -rf $config_host_mak
34 echo "Configure failed, check config.log and/or the above output"
35 rm -rf $config_host_mak
41 CFLAGS="-D_GNU_SOURCE -include config-host.h"
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
49 echo "#" >> config.log
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
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
70 # Don't bother rerunning the compile if we were already using -Werror
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."
85 do_cc $CFLAGS -c -o $TMPO $TMPC
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
99 echo "ERROR: User requested feature $feature"
100 echo "ERROR: configure was not able to find it"
105 type "$1" >/dev/null 2>&1
111 #error $1 not defined
122 echo "$1=y" >> $config_host_mak
123 echo "#define $1" >> $config_host_h
129 cross_prefix=${cross_prefix-${CROSS_COMPILE}}
130 cc="${CC-${cross_prefix}gcc}"
137 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
139 --cpu=*) cpu="$optarg"
143 --extra-cflags=*) CFLAGS="$CFLAGS $optarg"
145 --build-32bit-win=*) build_32bit_win="$optarg"
151 echo "Bad option $opt"
157 if test "$show_help" = "yes" ; then
158 echo "--cpu= Specify target CPU if auto-detect fails"
159 echo "--cc= Specify compiler to use"
160 echo "--extra-cflags= Specify extra CFLAGS to pass to compiler"
161 echo "--build-32bit-win= Specify yes for a 32-bit build on Windows"
165 if check_define __ANDROID__ ; then
167 elif check_define __linux__ ; then
169 elif check_define __OpenBSD__ ; then
171 elif check_define __sun__ ; then
177 echo "# Automatically generated by configure - do not modify" > $config_host_mak
178 printf "# Configured with:" >> $config_host_mak
179 printf " '%s'" "$0" "$@" >> $config_host_mak
180 echo >> $config_host_mak
181 echo "CONFIG_TARGET_OS=$targetos" >> $config_host_mak
183 # Some host OSes need non-standard checks for which CPU to use.
184 # Note that these checks are broken for cross-compilation: if you're
185 # cross-compiling to one of these OSes then you'll need to specify
186 # the correct CPU with the --cpu option.
189 # on Leopard most of the system is 32-bit, so we have to ask the kernel if
190 # we can run 64-bit userspace code.
191 # If the user didn't specify a CPU explicitly and the kernel says this is
192 # 64 bit hw, then assume x86_64. Otherwise fall through to the usual
194 if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then
199 # `uname -m` returns i86pc even on an x86_64 box, so default based on isainfo
200 if test -z "$cpu" && test "$(isainfo -k)" = "amd64"; then
203 LIBS="-lnsl -lsocket"
206 echo "Forcing known good options on Windows"
207 if test -z "$CC" ; then
208 if test ! -z "$build_32bit_win" && test "$build_32bit_win" = "yes"; then
209 CC="i686-w64-mingw32-gcc"
211 CC="x86_64-w64-mingw32-gcc"
214 output_sym "CONFIG_LITTLE_ENDIAN"
215 if test ! -z "$build_32bit_win" && test "$build_32bit_win" = "yes"; then
216 output_sym "CONFIG_32BIT"
218 output_sym "CONFIG_64BIT_LLP64"
220 output_sym "CONFIG_FADVISE"
221 output_sym "CONFIG_SOCKLEN_T"
222 output_sym "CONFIG_FADVISE"
223 output_sym "CONFIG_SFAA"
224 output_sym "CONFIG_RUSAGE_THREAD"
225 output_sym "CONFIG_WINDOWSAIO"
226 output_sym "CONFIG_FDATASYNC"
227 output_sym "CONFIG_CLOCK_MONOTONIC"
228 output_sym "CONFIG_GETTIMEOFDAY"
229 output_sym "CONFIG_CLOCK_GETTIME"
230 output_sym "CONFIG_SCHED_IDLE"
231 output_sym "CONFIG_TCP_NODELAY"
232 echo "CC=$CC" >> $config_host_mak
233 echo "BUILD_CFLAGS=$CFLAGS -include config-host.h -D_GNU_SOURCE" >> $config_host_mak
238 if test ! -z "$cpu" ; then
239 # command line argument
241 elif check_define __i386__ ; then
243 elif check_define __x86_64__ ; then
245 elif check_define __sparc__ ; then
246 if check_define __arch64__ ; then
251 elif check_define _ARCH_PPC ; then
252 if check_define _ARCH_PPC64 ; then
257 elif check_define __mips__ ; then
259 elif check_define __ia64__ ; then
261 elif check_define __s390__ ; then
262 if check_define __s390x__ ; then
267 elif check_define __arm__ ; then
269 elif check_define __hppa__ ; then
275 # Normalise host CPU name and set ARCH.
277 ia64|ppc|ppc64|s390|s390x|sparc64)
280 i386|i486|i586|i686|i86pc|BePC)
289 hppa|parisc|parisc64)
303 if test -z "$CC" ; then
304 if test "$targetos" = "FreeBSD"; then
313 cc="${CC-${cross_prefix}gcc}"
315 ##########################################
316 # check cross compile
325 if compile_prog "" "" "cross"; then
326 $TMPE 2>/dev/null || cross_compile="yes"
328 fatal "compile test failed"
331 ##########################################
334 if test "$cross_compile" = "no" ; then
336 #include <inttypes.h>
339 volatile uint32_t i=0x01234567;
340 return (*((uint8_t*)(&i))) == 0x67;
343 if compile_prog "" "" "endian"; then
344 $TMPE && bigendian="yes"
347 # If we're cross compiling, try our best to work it out and rely on the
348 # run-time check to fail if we get it wrong.
353 #if __BYTE_ORDER != __BIG_ENDIAN
354 # error "Unknown endianness"
358 compile_prog "" "" "endian" && bigendian="yes"
359 check_define "__ARMEB__" && bigendian="yes"
360 check_define "__MIPSEB__" && bigendian="yes"
364 echo "Operating system $targetos"
366 echo "Big endian $bigendian"
368 echo "Cross compile $cross_compile"
371 ##########################################
376 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
379 BUILD_BUG_ON(sizeof(long)*CHAR_BIT != WORDSIZE);
383 if compile_prog "-DWORDSIZE=32" "" "wordsize"; then
385 elif compile_prog "-DWORDSIZE=64" "" "wordsize"; then
388 fatal "Unknown wordsize"
390 echo "Wordsize $wordsize"
392 ##########################################
404 if compile_prog "" "-laio" "libaio" ; then
408 if test "$libaio" = "yes" ; then
409 feature_not_found "linux AIO"
413 echo "Linux AIO support $libaio"
415 ##########################################
428 if compile_prog "" "" "posixaio" ; then
430 elif compile_prog "" "-lrt" "posixaio"; then
435 echo "POSIX AIO support $posix_aio"
436 echo "POSIX AIO support needs -lrt $posix_aio_lrt"
438 ##########################################
439 # posix aio fsync probe
441 if test "$posix_aio" = "yes" ; then
448 return aio_fsync(O_SYNC, &cb);
452 if compile_prog "" "$LIBS" "posix_aio_fsync" ; then
456 echo "POSIX AIO fsync $posix_aio_fsync"
458 ##########################################
462 #include <sys/types.h>
463 #include <sys/asynch.h>
468 return aioread(0, NULL, 0, 0, SEEK_SET, &res);
472 if compile_prog "" "-laio" "solarisaio" ; then
476 echo "Solaris AIO support $solaris_aio"
478 ##########################################
479 # __sync_fetch_and_and test
482 static int sfaa(int *ptr)
484 return __sync_fetch_and_add(ptr, 0);
487 int main(int argc, char **argv)
494 if compile_prog "" "" "__sync_fetch_and_add()" ; then
497 echo "__sync_fetch_and_add $sfaa"
499 ##########################################
504 #include <infiniband/arch.h>
505 int main(int argc, char **argv)
507 struct ibv_pd *pd = ibv_alloc_pd(NULL);
511 if compile_prog "" "-libverbs" "libverbs" ; then
513 LIBS="-libverbs $LIBS"
515 echo "libverbs $libverbs"
517 ##########################################
522 #include <rdma/rdma_cma.h>
523 int main(int argc, char **argv)
525 rdma_destroy_qp(NULL);
529 if compile_prog "" "-lrdmacm" "rdma"; then
531 LIBS="-lrdmacm $LIBS"
533 echo "rdmacm $rdmacm"
535 ##########################################
536 # Linux fallocate probe
540 #include <linux/falloc.h>
541 int main(int argc, char **argv)
543 int r = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 1024);
547 if compile_prog "" "" "linux_fallocate"; then
548 linux_fallocate="yes"
550 echo "Linux fallocate $linux_fallocate"
552 ##########################################
553 # POSIX fadvise probe
558 int main(int argc, char **argv)
560 int r = posix_fadvise(0, 0, 0, POSIX_FADV_NORMAL);
564 if compile_prog "" "" "posix_fadvise"; then
567 echo "POSIX fadvise $posix_fadvise"
569 ##########################################
570 # POSIX fallocate probe
575 int main(int argc, char **argv)
577 int r = posix_fallocate(0, 0, 1024);
581 if compile_prog "" "" "posix_fallocate"; then
582 posix_fallocate="yes"
584 echo "POSIX fallocate $posix_fallocate"
586 ##########################################
587 # sched_set/getaffinity 2 or 3 argument test
588 linux_2arg_affinity="no"
589 linux_3arg_affinity="no"
592 int main(int argc, char **argv)
595 return sched_setaffinity(0, sizeof(mask), &mask);
598 if compile_prog "" "" "sched_setaffinity(,,)"; then
599 linux_3arg_affinity="yes"
603 int main(int argc, char **argv)
606 return sched_setaffinity(0, &mask);
609 if compile_prog "" "" "sched_setaffinity(,)"; then
610 linux_2arg_affinity="yes"
613 echo "sched_setaffinity(3 arg) $linux_3arg_affinity"
614 echo "sched_setaffinity(2 arg) $linux_2arg_affinity"
616 ##########################################
617 # clock_gettime probe
622 int main(int argc, char **argv)
624 return clock_gettime(0, NULL);
627 if compile_prog "" "" "clock_gettime"; then
629 elif compile_prog "" "-lrt" "clock_gettime"; then
633 echo "clock_gettime $clock_gettime"
635 ##########################################
636 # CLOCK_MONOTONIC probe
638 if test "$clock_gettime" = "yes" ; then
642 int main(int argc, char **argv)
644 return clock_gettime(CLOCK_MONOTONIC, NULL);
647 if compile_prog "" "$LIBS" "clock monotonic"; then
648 clock_monotonic="yes"
651 echo "CLOCK_MONOTONIC $clock_monotonic"
653 ##########################################
654 # CLOCK_MONOTONIC_PRECISE probe
655 clock_monotonic_precise="no"
656 if test "$clock_gettime" = "yes" ; then
660 int main(int argc, char **argv)
662 return clock_gettime(CLOCK_MONOTONIC_PRECISE, NULL);
665 if compile_prog "" "$LIBS" "clock monotonic precise"; then
666 clock_monotonic_precise="yes"
669 echo "CLOCK_MONOTONIC_PRECISE $clock_monotonic_precise"
671 ##########################################
672 # gettimeofday() probe
675 #include <sys/time.h>
677 int main(int argc, char **argv)
680 return gettimeofday(&tv, NULL);
683 if compile_prog "" "" "gettimeofday"; then
686 echo "gettimeofday $gettimeofday"
688 ##########################################
694 int main(int argc, char **argv)
699 if compile_prog "" "" "fdatasync"; then
702 echo "fdatasync $fdatasync"
704 ##########################################
705 # sync_file_range() probe
711 #include <linux/fs.h>
712 int main(int argc, char **argv)
714 unsigned int flags = SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE |
715 SYNC_FILE_RANGE_WAIT_AFTER;
716 return sync_file_range(0, 0, 0, flags);
719 if compile_prog "" "" "sync_file_range"; then
720 sync_file_range="yes"
722 echo "sync_file_range $sync_file_range"
724 ##########################################
725 # ext4 move extent probe
729 #include <sys/ioctl.h>
730 int main(int argc, char **argv)
732 struct move_extent me;
733 return ioctl(0, EXT4_IOC_MOVE_EXT, &me);
736 if compile_prog "" "" "ext4 move extent" ; then
738 elif test $targetos = "Linux" ; then
739 # On Linux, just default to it on and let it error at runtime if we really
740 # don't have it. None of my updated systems have it defined, but it does
741 # work. Takes a while to bubble back.
744 echo "EXT4 move extent $ext4_me"
746 ##########################################
752 int main(int argc, char **argv)
754 return splice(0, NULL, 0, NULL, 0, SPLICE_F_NONBLOCK);
757 if compile_prog "" "" "linux splice"; then
760 echo "Linux splice(2) $linux_splice"
762 ##########################################
767 #include <guasi_syscalls.h>
768 int main(int argc, char **argv)
770 guasi_t ctx = guasi_create(0, 0, 0);
774 if compile_prog "" "" "guasi"; then
779 ##########################################
783 #include <nvm/vectored_write.h>
784 int main(int argc, char **argv)
786 struct vsl_iovec iov;
787 return vsl_vectored_write(0, &iov, 0, O_ATOMIC);
790 if compile_prog "" "-L/usr/lib/fio -lnvm-primitives" "fusion-aw"; then
791 LIBS="-L/usr/lib/fio -lnvm-primitives $LIBS"
794 echo "Fusion-io atomic engine $fusion_aw"
796 ##########################################
801 int main(int argc, char **argv)
803 return numa_available();
806 if compile_prog "" "-lnuma" "libnuma"; then
810 echo "libnuma $libnuma"
812 ##########################################
813 # libnuma 2.x version API
814 if test "$libnuma" = "yes" ; then
818 int main(int argc, char **argv)
820 struct bitmask *mask = numa_parse_nodestring(NULL);
824 if compile_prog "" "" "libnuma api"; then
827 echo "libnuma v2 $libnuma_v2"
830 ##########################################
835 int main(int argc, char **argv)
841 if compile_prog "" "" "strsep"; then
844 echo "strsep $strsep"
846 ##########################################
851 int main(int argc, char **argv)
853 strcasestr(NULL, NULL);
857 if compile_prog "" "" "strcasestr"; then
860 echo "strcasestr $strcasestr"
862 ##########################################
863 # getopt_long_only() probe
864 getopt_long_only="no"
868 int main(int argc, char **argv)
870 int c = getopt_long_only(argc, argv, NULL, NULL, NULL);
874 if compile_prog "" "" "getopt_long_only"; then
875 getopt_long_only="yes"
877 echo "getopt_long_only() $getopt_long_only"
879 ##########################################
883 #include <sys/socket.h>
884 #include <arpa/inet.h>
886 int main(int argc, char **argv)
889 return inet_aton(NULL, &in);
892 if compile_prog "" "" "inet_aton"; then
895 echo "inet_aton $inet_aton"
897 ##########################################
901 #include <sys/socket.h>
902 int main(int argc, char **argv)
908 if compile_prog "" "" "socklen_t"; then
911 echo "socklen_t $socklen_t"
913 ##########################################
914 # Whether or not __thread is supported for TLS
918 static int __thread ret;
919 int main(int argc, char **argv)
924 if compile_prog "" "" "__thread"; then
927 echo "__thread $tls_thread"
929 ##########################################
930 # Check whether we have getrusage(RUSAGE_THREAD)
933 #include <sys/time.h>
934 #include <sys/resource.h>
935 int main(int argc, char **argv)
938 getrusage(RUSAGE_THREAD, &ru);
942 if compile_prog "" "" "RUSAGE_THREAD"; then
945 echo "RUSAGE_THREAD $rusage_thread"
947 ##########################################
948 # Check whether we have SCHED_IDLE
952 int main(int argc, char **argv)
954 struct sched_param p;
955 return sched_setscheduler(0, SCHED_IDLE, &p);
958 if compile_prog "" "" "SCHED_IDLE"; then
961 echo "SCHED_IDLE $sched_idle"
963 ##########################################
964 # Check whether we have TCP_NODELAY
968 #include <sys/types.h>
969 #include <sys/socket.h>
970 #include <netinet/tcp.h>
971 int main(int argc, char **argv)
973 return getsockopt(0, 0, TCP_NODELAY, NULL, NULL);
976 if compile_prog "" "" "TCP_NODELAY"; then
979 echo "TCP_NODELAY $tcp_nodelay"
981 ##########################################
982 # Check whether we have RLIMIT_MEMLOCK
985 #include <sys/time.h>
986 #include <sys/resource.h>
987 int main(int argc, char **argv)
990 return getrlimit(RLIMIT_MEMLOCK, &rl);
993 if compile_prog "" "" "RLIMIT_MEMLOCK"; then
996 echo "RLIMIT_MEMLOCK $rlimit_memlock"
998 #############################################################################
1000 if test "$wordsize" = "64" ; then
1001 output_sym "CONFIG_64BIT"
1002 elif test "$wordsize" = "32" ; then
1003 output_sym "CONFIG_32BIT"
1005 fatal "Unknown wordsize!"
1007 if test "$bigendian" = "yes" ; then
1008 output_sym "CONFIG_BIG_ENDIAN"
1010 output_sym "CONFIG_LITTLE_ENDIAN"
1012 if test "$libaio" = "yes" ; then
1013 output_sym "CONFIG_LIBAIO"
1015 if test "$posix_aio" = "yes" ; then
1016 output_sym "CONFIG_POSIXAIO"
1018 if test "$posix_aio_fsync" = "yes" ; then
1019 output_sym "CONFIG_POSIXAIO_FSYNC"
1021 if test "$linux_fallocate" = "yes" ; then
1022 output_sym "CONFIG_LINUX_FALLOCATE"
1024 if test "$posix_fallocate" = "yes" ; then
1025 output_sym "CONFIG_POSIX_FALLOCATE"
1027 if test "$fdatasync" = "yes" ; then
1028 output_sym "CONFIG_FDATASYNC"
1030 if test "$sync_file_range" = "yes" ; then
1031 output_sym "CONFIG_SYNC_FILE_RANGE"
1033 if test "$sfaa" = "yes" ; then
1034 output_sym "CONFIG_SFAA"
1036 if test "$libverbs" = "yes" -a "rdmacm" = "yes" ; then
1037 output_sym "CONFIG_RDMA"
1039 if test "$clock_gettime" = "yes" ; then
1040 output_sym "CONFIG_CLOCK_GETTIME"
1042 if test "$clock_monotonic" = "yes" ; then
1043 output_sym "CONFIG_CLOCK_MONOTONIC"
1045 if test "$clock_monotonic_precise" = "yes" ; then
1046 output_sym "CONFIG_CLOCK_MONOTONIC_PRECISE"
1048 if test "$gettimeofday" = "yes" ; then
1049 output_sym "CONFIG_GETTIMEOFDAY"
1051 if test "$posix_fadvise" = "yes" ; then
1052 output_sym "CONFIG_POSIX_FADVISE"
1054 if test "$linux_3arg_affinity" = "yes" ; then
1055 output_sym "CONFIG_3ARG_AFFINITY"
1056 elif test "$linux_2arg_affinity" = "yes" ; then
1057 output_sym "CONFIG_2ARG_AFFINITY"
1059 if test "$strsep" = "yes" ; then
1060 output_sym "CONFIG_STRSEP"
1062 if test "$strcasestr" = "yes" ; then
1063 output_sym "CONFIG_STRCASESTR"
1065 if test "$getopt_long_only" = "yes" ; then
1066 output_sym "CONFIG_GETOPT_LONG_ONLY"
1068 if test "$inet_aton" = "yes" ; then
1069 output_sym "CONFIG_INET_ATON"
1071 if test "$socklen_t" = "yes" ; then
1072 output_sym "CONFIG_SOCKLEN_T"
1074 if test "$ext4_me" = "yes" ; then
1075 output_sym "CONFIG_LINUX_EXT4_MOVE_EXTENT"
1077 if test "$linux_splice" = "yes" ; then
1078 output_sym "CONFIG_LINUX_SPLICE"
1080 if test "$guasi" = "yes" ; then
1081 output_sym "CONFIG_GUASI"
1083 if test "$fusion_aw" = "yes" ; then
1084 output_sym "CONFIG_FUSION_AW"
1086 if test "$libnuma_v2" = "yes" ; then
1087 output_sym "CONFIG_LIBNUMA"
1089 if test "$solaris_aio" = "yes" ; then
1090 output_sym "CONFIG_SOLARISAIO"
1092 if test "$tls_thread" = "yes" ; then
1093 output_sym "CONFIG_TLS_THREAD"
1095 if test "$rusage_thread" = "yes" ; then
1096 output_sym "CONFIG_RUSAGE_THREAD"
1098 if test "$sched_idle" = "yes" ; then
1099 output_sym "CONFIG_SCHED_IDLE"
1101 if test "$tcp_nodelay" = "yes" ; then
1102 output_sym "CONFIG_TCP_NODELAY"
1104 if test "$rlimit_memlock" = "yes" ; then
1105 output_sym "CONFIG_RLIMIT_MEMLOCK"
1108 echo "LIBS+=$LIBS" >> $config_host_mak
1109 echo "CC=$cc" >> $config_host_mak
1110 echo "BUILD_CFLAGS=$BUILD_CFLAGS $CFLAGS" >> $config_host_mak