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