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"
42 EXTFLAGS="-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 "EXTFLAGS=$CFLAGS -include config-host.h -D_GNU_SOURCE" >> $config_host_mak
237 output_sym "CONFIG_32BIT"
238 output_sym "CONFIG_LITTLE_ENDIAN"
239 output_sym "CONFIG_SOCKLEN_T"
240 output_sym "CONFIG_GETTIMEOFDAY"
241 output_sym "CONFIG_CLOCK_GETTIME"
242 output_sym "CONFIG_CLOCK_MONOTONIC"
243 echo "CC=$cc" >> $config_host_mak
244 echo "EXTFLAGS=$CFLAGS -include config-host.h -D_GNU_SOURCE" >> $config_host_mak
248 if test ! -z "$cpu" ; then
249 # command line argument
251 elif check_define __i386__ ; then
253 elif check_define __x86_64__ ; then
255 elif check_define __sparc__ ; then
256 if check_define __arch64__ ; then
261 elif check_define _ARCH_PPC ; then
262 if check_define _ARCH_PPC64 ; then
267 elif check_define __mips__ ; then
269 elif check_define __ia64__ ; then
271 elif check_define __s390__ ; then
272 if check_define __s390x__ ; then
277 elif check_define __arm__ ; then
279 elif check_define __hppa__ ; then
285 # Normalise host CPU name and set ARCH.
287 ia64|ppc|ppc64|s390|s390x|sparc64)
290 i386|i486|i586|i686|i86pc|BePC)
299 hppa|parisc|parisc64)
313 if test -z "$CC" ; then
314 if test "$targetos" = "FreeBSD"; then
323 cc="${CC-${cross_prefix}gcc}"
325 ##########################################
326 # check cross compile
335 if compile_prog "" "" "cross"; then
336 $TMPE 2>/dev/null || cross_compile="yes"
338 fatal "compile test failed"
341 ##########################################
344 if test "$cross_compile" = "no" ; then
346 #include <inttypes.h>
349 volatile uint32_t i=0x01234567;
350 return (*((uint8_t*)(&i))) == 0x67;
353 if compile_prog "" "" "endian"; then
354 $TMPE && bigendian="yes"
357 # If we're cross compiling, try our best to work it out and rely on the
358 # run-time check to fail if we get it wrong.
363 #if __BYTE_ORDER != __BIG_ENDIAN
364 # error "Unknown endianness"
368 compile_prog "" "" "endian" && bigendian="yes"
369 check_define "__ARMEB__" && bigendian="yes"
370 check_define "__MIPSEB__" && bigendian="yes"
374 echo "Operating system $targetos"
376 echo "Big endian $bigendian"
378 echo "Cross compile $cross_compile"
381 ##########################################
386 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
389 BUILD_BUG_ON(sizeof(long)*CHAR_BIT != WORDSIZE);
393 if compile_prog "-DWORDSIZE=32" "" "wordsize"; then
395 elif compile_prog "-DWORDSIZE=64" "" "wordsize"; then
398 fatal "Unknown wordsize"
400 echo "Wordsize $wordsize"
402 ##########################################
414 if compile_prog "" "-laio" "libaio" ; then
418 if test "$libaio" = "yes" ; then
419 feature_not_found "linux AIO"
423 echo "Linux AIO support $libaio"
425 ##########################################
438 if compile_prog "" "" "posixaio" ; then
440 elif compile_prog "" "-lrt" "posixaio"; then
445 echo "POSIX AIO support $posix_aio"
446 echo "POSIX AIO support needs -lrt $posix_aio_lrt"
448 ##########################################
449 # posix aio fsync probe
451 if test "$posix_aio" = "yes" ; then
458 return aio_fsync(O_SYNC, &cb);
462 if compile_prog "" "$LIBS" "posix_aio_fsync" ; then
466 echo "POSIX AIO fsync $posix_aio_fsync"
468 ##########################################
472 #include <sys/types.h>
473 #include <sys/asynch.h>
478 return aioread(0, NULL, 0, 0, SEEK_SET, &res);
482 if compile_prog "" "-laio" "solarisaio" ; then
486 echo "Solaris AIO support $solaris_aio"
488 ##########################################
489 # __sync_fetch_and_and test
492 static int sfaa(int *ptr)
494 return __sync_fetch_and_add(ptr, 0);
497 int main(int argc, char **argv)
504 if compile_prog "" "" "__sync_fetch_and_add()" ; then
507 echo "__sync_fetch_and_add $sfaa"
509 ##########################################
514 #include <infiniband/arch.h>
515 int main(int argc, char **argv)
517 struct ibv_pd *pd = ibv_alloc_pd(NULL);
521 if compile_prog "" "-libverbs" "libverbs" ; then
523 LIBS="-libverbs $LIBS"
525 echo "libverbs $libverbs"
527 ##########################################
532 #include <rdma/rdma_cma.h>
533 int main(int argc, char **argv)
535 rdma_destroy_qp(NULL);
539 if compile_prog "" "-lrdmacm" "rdma"; then
541 LIBS="-lrdmacm $LIBS"
543 echo "rdmacm $rdmacm"
545 ##########################################
546 # Linux fallocate probe
550 #include <linux/falloc.h>
551 int main(int argc, char **argv)
553 int r = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 1024);
557 if compile_prog "" "" "linux_fallocate"; then
558 linux_fallocate="yes"
560 echo "Linux fallocate $linux_fallocate"
562 ##########################################
563 # POSIX fadvise probe
568 int main(int argc, char **argv)
570 int r = posix_fadvise(0, 0, 0, POSIX_FADV_NORMAL);
574 if compile_prog "" "" "posix_fadvise"; then
577 echo "POSIX fadvise $posix_fadvise"
579 ##########################################
580 # POSIX fallocate probe
585 int main(int argc, char **argv)
587 int r = posix_fallocate(0, 0, 1024);
591 if compile_prog "" "" "posix_fallocate"; then
592 posix_fallocate="yes"
594 echo "POSIX fallocate $posix_fallocate"
596 ##########################################
597 # sched_set/getaffinity 2 or 3 argument test
598 linux_2arg_affinity="no"
599 linux_3arg_affinity="no"
602 int main(int argc, char **argv)
605 return sched_setaffinity(0, sizeof(mask), &mask);
608 if compile_prog "" "" "sched_setaffinity(,,)"; then
609 linux_3arg_affinity="yes"
613 int main(int argc, char **argv)
616 return sched_setaffinity(0, &mask);
619 if compile_prog "" "" "sched_setaffinity(,)"; then
620 linux_2arg_affinity="yes"
623 echo "sched_setaffinity(3 arg) $linux_3arg_affinity"
624 echo "sched_setaffinity(2 arg) $linux_2arg_affinity"
626 ##########################################
627 # clock_gettime probe
632 int main(int argc, char **argv)
634 return clock_gettime(0, NULL);
637 if compile_prog "" "" "clock_gettime"; then
639 elif compile_prog "" "-lrt" "clock_gettime"; then
643 echo "clock_gettime $clock_gettime"
645 ##########################################
646 # CLOCK_MONOTONIC probe
648 if test "$clock_gettime" = "yes" ; then
652 int main(int argc, char **argv)
654 return clock_gettime(CLOCK_MONOTONIC, NULL);
657 if compile_prog "" "$LIBS" "clock monotonic"; then
658 clock_monotonic="yes"
661 echo "CLOCK_MONOTONIC $clock_monotonic"
663 ##########################################
664 # CLOCK_MONOTONIC_PRECISE probe
665 clock_monotonic_precise="no"
666 if test "$clock_gettime" = "yes" ; then
670 int main(int argc, char **argv)
672 return clock_gettime(CLOCK_MONOTONIC_PRECISE, NULL);
675 if compile_prog "" "$LIBS" "clock monotonic precise"; then
676 clock_monotonic_precise="yes"
679 echo "CLOCK_MONOTONIC_PRECISE $clock_monotonic_precise"
681 ##########################################
682 # gettimeofday() probe
685 #include <sys/time.h>
687 int main(int argc, char **argv)
690 return gettimeofday(&tv, NULL);
693 if compile_prog "" "" "gettimeofday"; then
696 echo "gettimeofday $gettimeofday"
698 ##########################################
704 int main(int argc, char **argv)
709 if compile_prog "" "" "fdatasync"; then
712 echo "fdatasync $fdatasync"
714 ##########################################
715 # sync_file_range() probe
721 #include <linux/fs.h>
722 int main(int argc, char **argv)
724 unsigned int flags = SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE |
725 SYNC_FILE_RANGE_WAIT_AFTER;
726 return sync_file_range(0, 0, 0, flags);
729 if compile_prog "" "" "sync_file_range"; then
730 sync_file_range="yes"
732 echo "sync_file_range $sync_file_range"
734 ##########################################
735 # ext4 move extent probe
739 #include <sys/ioctl.h>
740 int main(int argc, char **argv)
742 struct move_extent me;
743 return ioctl(0, EXT4_IOC_MOVE_EXT, &me);
746 if compile_prog "" "" "ext4 move extent" ; then
748 elif test $targetos = "Linux" ; then
749 # On Linux, just default to it on and let it error at runtime if we really
750 # don't have it. None of my updated systems have it defined, but it does
751 # work. Takes a while to bubble back.
754 echo "EXT4 move extent $ext4_me"
756 ##########################################
762 int main(int argc, char **argv)
764 return splice(0, NULL, 0, NULL, 0, SPLICE_F_NONBLOCK);
767 if compile_prog "" "" "linux splice"; then
770 echo "Linux splice(2) $linux_splice"
772 ##########################################
777 #include <guasi_syscalls.h>
778 int main(int argc, char **argv)
780 guasi_t ctx = guasi_create(0, 0, 0);
784 if compile_prog "" "" "guasi"; then
789 ##########################################
793 #include <nvm/vectored_write.h>
794 int main(int argc, char **argv)
796 struct vsl_iovec iov;
797 return vsl_vectored_write(0, &iov, 0, O_ATOMIC);
800 if compile_prog "" "-L/usr/lib/fio -lnvm-primitives" "fusion-aw"; then
801 LIBS="-L/usr/lib/fio -lnvm-primitives $LIBS"
804 echo "Fusion-io atomic engine $fusion_aw"
806 ##########################################
811 int main(int argc, char **argv)
813 return numa_available();
816 if compile_prog "" "-lnuma" "libnuma"; then
820 echo "libnuma $libnuma"
822 ##########################################
827 int main(int argc, char **argv)
833 if compile_prog "" "" "strsep"; then
836 echo "strsep $strsep"
838 ##########################################
839 # getopt_long_only() probe
840 getopt_long_only="no"
844 int main(int argc, char **argv)
846 int c = getopt_long_only(argc, argv, NULL, NULL, NULL);
850 if compile_prog "" "" "getopt_long_only"; then
851 getopt_long_only="yes"
853 echo "getopt_long_only() $getopt_long_only"
855 ##########################################
859 #include <sys/socket.h>
860 #include <arpa/inet.h>
862 int main(int argc, char **argv)
865 return inet_aton(NULL, &in);
868 if compile_prog "" "" "inet_aton"; then
871 echo "inet_aton $inet_aton"
873 ##########################################
878 #include <netinet/in.h>
879 int main(int argc, char **argv)
885 if compile_prog "" "" "socklen_t"; then
888 echo "socklen_t $socklen_t"
890 ##########################################
891 # Whether or not __thread is supported for TLS
895 static int __thread ret;
896 int main(int argc, char **argv)
901 if compile_prog "" "" "__thread"; then
904 echo "__thread $tls_thread"
906 ##########################################
907 # Check whether we have getrusage(RUSAGE_THREAD)
910 #include <sys/time.h>
911 #include <sys/resource.h>
912 int main(int argc, char **argv)
915 getrusage(RUSAGE_THREAD, &ru);
919 if compile_prog "" "" "RUSAGE_THREAD"; then
922 echo "RUSAGE_THREAD $rusage_thread"
924 ##########################################
925 # Check whether we have SCHED_IDLE
929 int main(int argc, char **argv)
931 struct sched_param p;
932 return sched_setscheduler(0, SCHED_IDLE, &p);
935 if compile_prog "" "" "SCHED_IDLE"; then
938 echo "SCHED_IDLE $sched_idle"
940 ##########################################
941 # Check whether we have TCP_NODELAY
945 #include <sys/types.h>
946 #include <sys/socket.h>
947 #include <netinet/tcp.h>
948 int main(int argc, char **argv)
950 return getsockopt(0, 0, TCP_NODELAY, NULL, NULL);
953 if compile_prog "" "" "TCP_NODELAY"; then
956 echo "TCP_NODELAY $tcp_nodelay"
958 ##########################################
959 # Check whether we have RLIMIT_MEMLOCK
962 #include <sys/time.h>
963 #include <sys/resource.h>
964 int main(int argc, char **argv)
967 return getrlimit(RLIMIT_MEMLOCK, &rl);
970 if compile_prog "" "" "RLIMIT_MEMLOCK"; then
973 echo "RLIMIT_MEMLOCK $rlimit_memlock"
975 #############################################################################
977 if test "$wordsize" = "64" ; then
978 output_sym "CONFIG_64BIT"
979 elif test "$wordsize" = "32" ; then
980 output_sym "CONFIG_32BIT"
982 fatal "Unknown wordsize!"
984 if test "$bigendian" = "yes" ; then
985 output_sym "CONFIG_BIG_ENDIAN"
987 output_sym "CONFIG_LITTLE_ENDIAN"
989 if test "$libaio" = "yes" ; then
990 output_sym "CONFIG_LIBAIO"
992 if test "$posix_aio" = "yes" ; then
993 output_sym "CONFIG_POSIXAIO"
995 if test "$posix_aio_fsync" = "yes" ; then
996 output_sym "CONFIG_POSIXAIO_FSYNC"
998 if test "$linux_fallocate" = "yes" ; then
999 output_sym "CONFIG_LINUX_FALLOCATE"
1001 if test "$posix_fallocate" = "yes" ; then
1002 output_sym "CONFIG_POSIX_FALLOCATE"
1004 if test "$fdatasync" = "yes" ; then
1005 output_sym "CONFIG_FDATASYNC"
1007 if test "$sync_file_range" = "yes" ; then
1008 output_sym "CONFIG_SYNC_FILE_RANGE"
1010 if test "$sfaa" = "yes" ; then
1011 output_sym "CONFIG_SFAA"
1013 if test "$libverbs" = "yes" -o "rdmacm" = "yes" ; then
1014 output_sym "CONFIG_RDMA"
1016 if test "$clock_gettime" = "yes" ; then
1017 output_sym "CONFIG_CLOCK_GETTIME"
1019 if test "$clock_monotonic" = "yes" ; then
1020 output_sym "CONFIG_CLOCK_MONOTONIC"
1022 if test "$clock_monotonic_precise" = "yes" ; then
1023 output_sym "CONFIG_CLOCK_MONOTONIC_PRECISE"
1025 if test "$gettimeofday" = "yes" ; then
1026 output_sym "CONFIG_GETTIMEOFDAY"
1028 if test "$posix_fadvise" = "yes" ; then
1029 output_sym "CONFIG_POSIX_FADVISE"
1031 if test "$linux_3arg_affinity" = "yes" ; then
1032 output_sym "CONFIG_3ARG_AFFINITY"
1033 elif test "$linux_2arg_affinity" = "yes" ; then
1034 output_sym "CONFIG_2ARG_AFFINITY"
1036 if test "$strsep" = "yes" ; then
1037 output_sym "CONFIG_STRSEP"
1039 if test "$getopt_long_only" = "yes" ; then
1040 output_sym "CONFIG_GETOPT_LONG_ONLY"
1042 if test "$inet_aton" = "yes" ; then
1043 output_sym "CONFIG_INET_ATON"
1045 if test "$socklen_t" = "yes" ; then
1046 output_sym "CONFIG_SOCKLEN_T"
1048 if test "$ext4_me" = "yes" ; then
1049 output_sym "CONFIG_LINUX_EXT4_MOVE_EXTENT"
1051 if test "$linux_splice" = "yes" ; then
1052 output_sym "CONFIG_LINUX_SPLICE"
1054 if test "$guasi" = "yes" ; then
1055 output_sym "CONFIG_GUASI"
1057 if test "$fusion_aw" = "yes" ; then
1058 output_sym "CONFIG_FUSION_AW"
1060 if test "$libnuma" = "yes" ; then
1061 output_sym "CONFIG_LIBNUMA"
1063 if test "$solaris_aio" = "yes" ; then
1064 output_sym "CONFIG_SOLARISAIO"
1066 if test "$tls_thread" = "yes" ; then
1067 output_sym "CONFIG_TLS_THREAD"
1069 if test "$rusage_thread" = "yes" ; then
1070 output_sym "CONFIG_RUSAGE_THREAD"
1072 if test "$sched_idle" = "yes" ; then
1073 output_sym "CONFIG_SCHED_IDLE"
1075 #if test "$tcp_nodelay" = "yes" ; then
1076 #output_sym "CONFIG_TCP_NODELAY"
1078 if test "$rlimit_memlock" = "yes" ; then
1079 output_sym "CONFIG_RLIMIT_MEMLOCK"
1082 echo "LIBS+=$LIBS" >> $config_host_mak
1083 echo "CC=$cc" >> $config_host_mak
1084 echo "EXTFLAGS=$EXTFLAGS $CFLAGS" >> $config_host_mak