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