blob: a3c51fbdb82f06ebd8f9e5d274bab36cb37d33cd [file] [log] [blame]
Jens Axboe67bf9822013-01-10 11:23:19 +01001#!/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"
Jens Axboe4feafb12013-01-24 23:07:55 -070027config_host_h="config-host.h"
28
29rm -rf $config_host_mak
30rm -rf $config_host_h
Jens Axboe67bf9822013-01-10 11:23:19 +010031
Jens Axboed7145a72013-02-11 13:21:54 +010032fatal() {
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
Jens Axboe44404c52013-01-24 14:20:09 -070040# Default CFLAGS
Jens Axboeaf4862b2013-03-29 08:55:32 -060041CFLAGS="-D_GNU_SOURCE -include config-host.h"
42BUILD_CFLAGS=""
Jens Axboe44404c52013-01-24 14:20:09 -070043
Jens Axboe67bf9822013-01-10 11:23:19 +010044# 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
Jens Axboe7560fe72013-01-25 08:52:28 -070051# 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
Jens Axboe67bf9822013-01-10 11:23:19 +010059do_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."
Jens Axboed7145a72013-02-11 13:21:54 +010081 fatal "You can run configure with --disable-werror to bypass this check."
Jens Axboe67bf9822013-01-10 11:23:19 +010082}
83
84compile_object() {
85 do_cc $CFLAGS -c -o $TMPO $TMPC
86}
87
88compile_prog() {
89 local_cflags="$1"
Jens Axboeadaa46d2013-02-28 22:10:22 +010090 local_ldflags="$2 $LIBS"
Jens Axboe67bf9822013-01-10 11:23:19 +010091 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
97
98 echo "ERROR"
99 echo "ERROR: User requested feature $feature"
100 echo "ERROR: configure was not able to find it"
Jens Axboed7145a72013-02-11 13:21:54 +0100101 fatal "ERROR"
Jens Axboe67bf9822013-01-10 11:23:19 +0100102}
103
104has() {
105 type "$1" >/dev/null 2>&1
106}
107
108check_define() {
109 cat > $TMPC <<EOF
110#if !defined($1)
111#error $1 not defined
112#endif
113int main(void)
114{
115 return 0;
116}
117EOF
118 compile_object
119}
120
Jens Axboe4feafb12013-01-24 23:07:55 -0700121output_sym() {
122 echo "$1=y" >> $config_host_mak
123 echo "#define $1" >> $config_host_h
124}
125
Jens Axboe67bf9822013-01-10 11:23:19 +0100126targetos=""
127cpu=""
128
Aaron Carroll53cd4ee2013-03-14 16:57:38 +1100129cross_prefix=${cross_prefix-${CROSS_COMPILE}}
Jens Axboe67bf9822013-01-10 11:23:19 +0100130cc="${CC-${cross_prefix}gcc}"
131
Jens Axboe899fab32013-01-29 10:06:30 +0100132show_help="no"
133exit_val=0
134
Jens Axboecb1125b2013-01-23 13:47:54 -0700135# parse options
136for opt do
137 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
138 case "$opt" in
Jens Axboe8b156d82013-02-10 15:48:34 +0100139 --cpu=*) cpu="$optarg"
140 ;;
Jens Axboecb1125b2013-01-23 13:47:54 -0700141 --cc=*) CC="$optarg"
142 ;;
Jens Axboe208e4c82013-01-29 09:26:07 +0100143 --extra-cflags=*) CFLAGS="$CFLAGS $optarg"
144 ;;
Huadong Liu74097112013-02-05 08:43:14 +0100145 --build-32bit-win=*) build_32bit_win="$optarg"
146 ;;
Jens Axboe899fab32013-01-29 10:06:30 +0100147 --help)
148 show_help="yes"
149 ;;
Jens Axboecb1125b2013-01-23 13:47:54 -0700150 *)
151 echo "Bad option $opt"
Jens Axboe899fab32013-01-29 10:06:30 +0100152 show_help="yes"
153 exit_val=1
Jens Axboecb1125b2013-01-23 13:47:54 -0700154 esac
155done
156
Jens Axboe899fab32013-01-29 10:06:30 +0100157if test "$show_help" = "yes" ; then
Jens Axboe8b156d82013-02-10 15:48:34 +0100158 echo "--cpu= Specify target CPU if auto-detect fails"
Jens Axboe899fab32013-01-29 10:06:30 +0100159 echo "--cc= Specify compiler to use"
160 echo "--extra-cflags= Specify extra CFLAGS to pass to compiler"
Bruce Cran723d7b32013-02-05 17:44:19 +0000161 echo "--build-32bit-win= Specify yes for a 32-bit build on Windows"
Jens Axboe899fab32013-01-29 10:06:30 +0100162 exit $exit_val
163fi
164
Aaron Carroll6d0e9f82013-02-12 09:58:14 +0100165if check_define __ANDROID__ ; then
166 targetos="Android"
167elif check_define __linux__ ; then
Jens Axboe67bf9822013-01-10 11:23:19 +0100168 targetos="Linux"
Jens Axboe67bf9822013-01-10 11:23:19 +0100169elif check_define __OpenBSD__ ; then
170 targetos='OpenBSD'
171elif check_define __sun__ ; then
172 targetos='SunOS'
173else
174 targetos=`uname -s`
175fi
176
Aaron Carroll53cd4ee2013-03-14 16:57:38 +1100177echo "# Automatically generated by configure - do not modify" > $config_host_mak
178printf "# Configured with:" >> $config_host_mak
179printf " '%s'" "$0" "$@" >> $config_host_mak
180echo >> $config_host_mak
181echo "CONFIG_TARGET_OS=$targetos" >> $config_host_mak
182
Jens Axboe67bf9822013-01-10 11:23:19 +0100183# 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.
187case $targetos in
188Darwin)
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
193 # detection code.
194 if test -z "$cpu" && test "$(sysctl -n hw.optional.x86_64)" = "1"; then
195 cpu="x86_64"
196 fi
197 ;;
198SunOS)
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
201 cpu="x86_64"
202 fi
Jens Axboeadaa46d2013-02-28 22:10:22 +0100203 LIBS="-lnsl -lsocket"
Jens Axboecfd94f72013-01-23 16:23:48 -0700204 ;;
205CYGWIN*)
206 echo "Forcing known good options on Windows"
Jens Axboe4578d012013-01-23 16:26:12 -0700207 if test -z "$CC" ; then
Huadong Liu74097112013-02-05 08:43:14 +0100208 if test ! -z "$build_32bit_win" && test "$build_32bit_win" = "yes"; then
209 CC="i686-w64-mingw32-gcc"
210 else
211 CC="x86_64-w64-mingw32-gcc"
212 fi
Jens Axboe4578d012013-01-23 16:26:12 -0700213 fi
Jens Axboe4feafb12013-01-24 23:07:55 -0700214 output_sym "CONFIG_LITTLE_ENDIAN"
Huadong Liu74097112013-02-05 08:43:14 +0100215 if test ! -z "$build_32bit_win" && test "$build_32bit_win" = "yes"; then
216 output_sym "CONFIG_32BIT"
217 else
218 output_sym "CONFIG_64BIT_LLP64"
219 fi
Jens Axboe4feafb12013-01-24 23:07:55 -0700220 output_sym "CONFIG_FADVISE"
221 output_sym "CONFIG_SOCKLEN_T"
Jens Axboe4feafb12013-01-24 23:07:55 -0700222 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"
Bruce Cran59308a62013-02-02 20:59:31 +0000227 output_sym "CONFIG_CLOCK_MONOTONIC"
Bruce Crandc0518c2013-01-28 16:07:15 +0000228 output_sym "CONFIG_GETTIMEOFDAY"
229 output_sym "CONFIG_CLOCK_GETTIME"
Jens Axboe7e09a9f2013-01-30 13:58:58 +0100230 output_sym "CONFIG_SCHED_IDLE"
Jens Axboe1eafa372013-01-31 10:19:51 +0100231 output_sym "CONFIG_TCP_NODELAY"
Jens Axboe4feafb12013-01-24 23:07:55 -0700232 echo "CC=$CC" >> $config_host_mak
Jens Axboeaf4862b2013-03-29 08:55:32 -0600233 echo "BUILD_CFLAGS=$CFLAGS -include config-host.h -D_GNU_SOURCE" >> $config_host_mak
Jens Axboecfd94f72013-01-23 16:23:48 -0700234 exit 0
Aaron Carroll6d0e9f82013-02-12 09:58:14 +0100235 ;;
Jens Axboe67bf9822013-01-10 11:23:19 +0100236esac
237
238if test ! -z "$cpu" ; then
239 # command line argument
240 :
241elif check_define __i386__ ; then
242 cpu="i386"
243elif check_define __x86_64__ ; then
244 cpu="x86_64"
245elif check_define __sparc__ ; then
246 if check_define __arch64__ ; then
247 cpu="sparc64"
248 else
249 cpu="sparc"
250 fi
251elif check_define _ARCH_PPC ; then
252 if check_define _ARCH_PPC64 ; then
253 cpu="ppc64"
254 else
255 cpu="ppc"
256 fi
257elif check_define __mips__ ; then
258 cpu="mips"
259elif check_define __ia64__ ; then
260 cpu="ia64"
261elif check_define __s390__ ; then
262 if check_define __s390x__ ; then
263 cpu="s390x"
264 else
265 cpu="s390"
266 fi
267elif check_define __arm__ ; then
268 cpu="arm"
269elif check_define __hppa__ ; then
270 cpu="hppa"
271else
272 cpu=`uname -m`
273fi
274
275# Normalise host CPU name and set ARCH.
276case "$cpu" in
277 ia64|ppc|ppc64|s390|s390x|sparc64)
278 cpu="$cpu"
279 ;;
280 i386|i486|i586|i686|i86pc|BePC)
281 cpu="i386"
282 ;;
283 x86_64|amd64)
284 cpu="x86_64"
285 ;;
286 armv*b|armv*l|arm)
287 cpu="arm"
288 ;;
289 hppa|parisc|parisc64)
290 cpu="hppa"
291 ;;
292 mips*)
293 cpu="mips"
294 ;;
295 sparc|sun4[cdmuv])
296 cpu="sparc"
297 ;;
298 *)
Jens Axboe8b156d82013-02-10 15:48:34 +0100299 echo "Unknown CPU"
Jens Axboe67bf9822013-01-10 11:23:19 +0100300 ;;
301esac
302
Jens Axboedcbbf5b2013-01-25 14:35:27 -0700303if test -z "$CC" ; then
Jens Axboe67bf9822013-01-10 11:23:19 +0100304 if test "$targetos" = "FreeBSD"; then
305 if has clang; then
306 CC=clang
307 else
308 CC=gcc
309 fi
Jens Axboe67bf9822013-01-10 11:23:19 +0100310 fi
311fi
312
313cc="${CC-${cross_prefix}gcc}"
314
Jens Axboe0dcebdf2013-01-23 15:42:16 -0700315##########################################
Aaron Carroll1a17cfd2013-03-14 16:57:40 +1100316# check cross compile
317
318cross_compile="no"
319cat > $TMPC <<EOF
320int main(void)
321{
322 return 0;
323}
324EOF
325if compile_prog "" "" "cross"; then
326 $TMPE 2>/dev/null || cross_compile="yes"
327else
328 fatal "compile test failed"
329fi
330
331##########################################
Jens Axboe0dcebdf2013-01-23 15:42:16 -0700332# check endianness
333bigendian="no"
Aaron Carroll1a17cfd2013-03-14 16:57:40 +1100334if test "$cross_compile" = "no" ; then
335 cat > $TMPC <<EOF
Jens Axboe0dcebdf2013-01-23 15:42:16 -0700336#include <inttypes.h>
337int main(void)
338{
339 volatile uint32_t i=0x01234567;
340 return (*((uint8_t*)(&i))) == 0x67;
341}
342EOF
Aaron Carroll1a17cfd2013-03-14 16:57:40 +1100343 if compile_prog "" "" "endian"; then
344 $TMPE && bigendian="yes"
345 fi
346else
347 # If we're cross compiling, try our best to work it out and rely on the
348 # run-time check to fail if we get it wrong.
349 cat > $TMPC <<EOF
350#include <endian.h>
351int main(void)
352{
353#if __BYTE_ORDER != __BIG_ENDIAN
354# error "Unknown endianness"
355#endif
356}
357EOF
358 compile_prog "" "" "endian" && bigendian="yes"
359 check_define "__ARMEB__" && bigendian="yes"
360 check_define "__MIPSEB__" && bigendian="yes"
Jens Axboe0dcebdf2013-01-23 15:42:16 -0700361fi
362
363
Jens Axboe67bf9822013-01-10 11:23:19 +0100364echo "Operating system $targetos"
365echo "CPU $cpu"
Jens Axboe0dcebdf2013-01-23 15:42:16 -0700366echo "Big endian $bigendian"
Jens Axboe67bf9822013-01-10 11:23:19 +0100367echo "Compiler $cc"
Aaron Carroll1a17cfd2013-03-14 16:57:40 +1100368echo "Cross compile $cross_compile"
Jens Axboe67bf9822013-01-10 11:23:19 +0100369echo
370
371##########################################
372# check for wordsize
373wordsize="0"
374cat > $TMPC <<EOF
Aaron Carroll142429e2013-03-14 16:57:39 +1100375#include <limits.h>
376#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
Jens Axboe67bf9822013-01-10 11:23:19 +0100377int main(void)
378{
Aaron Carroll142429e2013-03-14 16:57:39 +1100379 BUILD_BUG_ON(sizeof(long)*CHAR_BIT != WORDSIZE);
Jens Axboe67bf9822013-01-10 11:23:19 +0100380 return 0;
381}
382EOF
Aaron Carroll142429e2013-03-14 16:57:39 +1100383if compile_prog "-DWORDSIZE=32" "" "wordsize"; then
384 wordsize="32"
385elif compile_prog "-DWORDSIZE=64" "" "wordsize"; then
386 wordsize="64"
387else
388 fatal "Unknown wordsize"
Jens Axboe67bf9822013-01-10 11:23:19 +0100389fi
390echo "Wordsize $wordsize"
391
392##########################################
393# linux-aio probe
394libaio="no"
395cat > $TMPC <<EOF
396#include <libaio.h>
397#include <stddef.h>
398int main(void)
399{
400 io_setup(0, NULL);
401 return 0;
402}
403EOF
404if compile_prog "" "-laio" "libaio" ; then
405 libaio=yes
406 LIBS="-laio $LIBS"
407else
408 if test "$libaio" = "yes" ; then
409 feature_not_found "linux AIO"
410 fi
411 libaio=no
412fi
413echo "Linux AIO support $libaio"
414
415##########################################
416# posix aio probe
417posix_aio="no"
418posix_aio_lrt="no"
419cat > $TMPC <<EOF
420#include <aio.h>
421int main(void)
422{
423 struct aiocb cb;
424 aio_read(&cb);
425 return 0;
426}
427EOF
428if compile_prog "" "" "posixaio" ; then
429 posix_aio="yes"
430elif compile_prog "" "-lrt" "posixaio"; then
431 posix_aio="yes"
432 posix_aio_lrt="yes"
433 LIBS="-lrt $LIBS"
434fi
435echo "POSIX AIO support $posix_aio"
436echo "POSIX AIO support needs -lrt $posix_aio_lrt"
437
438##########################################
439# posix aio fsync probe
440posix_aio_fsync="no"
441if test "$posix_aio" = "yes" ; then
442 cat > $TMPC <<EOF
443#include <fcntl.h>
444#include <aio.h>
445int main(void)
446{
447 struct aiocb cb;
448 return aio_fsync(O_SYNC, &cb);
449 return 0;
450}
451EOF
452 if compile_prog "" "$LIBS" "posix_aio_fsync" ; then
453 posix_aio_fsync=yes
454 fi
455fi
456echo "POSIX AIO fsync $posix_aio_fsync"
457
458##########################################
459# solaris aio probe
460solaris_aio="no"
461cat > $TMPC <<EOF
462#include <sys/types.h>
463#include <sys/asynch.h>
464#include <unistd.h>
465int main(void)
466{
467 aio_result_t res;
468 return aioread(0, NULL, 0, 0, SEEK_SET, &res);
469 return 0;
470}
471EOF
472if compile_prog "" "-laio" "solarisaio" ; then
473 solaris_aio=yes
474 LIBS="-laio $LIBS"
475fi
476echo "Solaris AIO support $solaris_aio"
477
478##########################################
479# __sync_fetch_and_and test
480sfaa="no"
481cat > $TMPC << EOF
482static int sfaa(int *ptr)
483{
Jens Axboe9c639a72013-02-28 22:13:29 +0100484 return __sync_fetch_and_add(ptr, 0);
Jens Axboe67bf9822013-01-10 11:23:19 +0100485}
486
487int main(int argc, char **argv)
488{
489 int val = 42;
490 sfaa(&val);
491 return val;
492}
493EOF
494if compile_prog "" "" "__sync_fetch_and_add()" ; then
495 sfaa="yes"
496fi
Jens Axboe9c639a72013-02-28 22:13:29 +0100497echo "__sync_fetch_and_add $sfaa"
Jens Axboe67bf9822013-01-10 11:23:19 +0100498
499##########################################
500# libverbs probe
501libverbs="no"
502cat > $TMPC << EOF
503#include <stdio.h>
504#include <infiniband/arch.h>
505int main(int argc, char **argv)
506{
507 struct ibv_pd *pd = ibv_alloc_pd(NULL);
508 return 0;
509}
510EOF
511if compile_prog "" "-libverbs" "libverbs" ; then
512 libverbs="yes"
513 LIBS="-libverbs $LIBS"
514fi
515echo "libverbs $libverbs"
516
517##########################################
518# rdmacm probe
519rdmacm="no"
520cat > $TMPC << EOF
521#include <stdio.h>
522#include <rdma/rdma_cma.h>
523int main(int argc, char **argv)
524{
525 rdma_destroy_qp(NULL);
526 return 0;
527}
528EOF
529if compile_prog "" "-lrdmacm" "rdma"; then
530 rdmacm="yes"
531 LIBS="-lrdmacm $LIBS"
532fi
533echo "rdmacm $rdmacm"
534
535##########################################
536# Linux fallocate probe
537linux_fallocate="no"
538cat > $TMPC << EOF
539#include <stdio.h>
540#include <linux/falloc.h>
541int main(int argc, char **argv)
542{
543 int r = fallocate(0, FALLOC_FL_KEEP_SIZE, 0, 1024);
544 return r;
545}
546EOF
547if compile_prog "" "" "linux_fallocate"; then
548 linux_fallocate="yes"
549fi
550echo "Linux fallocate $linux_fallocate"
551
552##########################################
553# POSIX fadvise probe
554posix_fadvise="no"
555cat > $TMPC << EOF
556#include <stdio.h>
557#include <fcntl.h>
558int main(int argc, char **argv)
559{
560 int r = posix_fadvise(0, 0, 0, POSIX_FADV_NORMAL);
561 return r;
562}
563EOF
564if compile_prog "" "" "posix_fadvise"; then
565 posix_fadvise="yes"
566fi
567echo "POSIX fadvise $posix_fadvise"
568
569##########################################
570# POSIX fallocate probe
571posix_fallocate="no"
572cat > $TMPC << EOF
573#include <stdio.h>
574#include <fcntl.h>
575int main(int argc, char **argv)
576{
577 int r = posix_fallocate(0, 0, 1024);
578 return r;
579}
580EOF
581if compile_prog "" "" "posix_fallocate"; then
582 posix_fallocate="yes"
583fi
584echo "POSIX fallocate $posix_fallocate"
585
586##########################################
587# sched_set/getaffinity 2 or 3 argument test
588linux_2arg_affinity="no"
589linux_3arg_affinity="no"
590cat > $TMPC << EOF
Jens Axboe67bf9822013-01-10 11:23:19 +0100591#include <sched.h>
592int main(int argc, char **argv)
593{
594 cpu_set_t mask;
595 return sched_setaffinity(0, sizeof(mask), &mask);
596}
597EOF
598if compile_prog "" "" "sched_setaffinity(,,)"; then
599 linux_3arg_affinity="yes"
600else
601 cat > $TMPC << EOF
Jens Axboe67bf9822013-01-10 11:23:19 +0100602#include <sched.h>
603int main(int argc, char **argv)
604{
605 cpu_set_t mask;
606 return sched_setaffinity(0, &mask);
607}
608EOF
609 if compile_prog "" "" "sched_setaffinity(,)"; then
610 linux_2arg_affinity="yes"
611 fi
612fi
613echo "sched_setaffinity(3 arg) $linux_3arg_affinity"
614echo "sched_setaffinity(2 arg) $linux_2arg_affinity"
615
616##########################################
617# clock_gettime probe
618clock_gettime="no"
619cat > $TMPC << EOF
620#include <stdio.h>
621#include <time.h>
622int main(int argc, char **argv)
623{
624 return clock_gettime(0, NULL);
625}
626EOF
627if compile_prog "" "" "clock_gettime"; then
628 clock_gettime="yes"
629elif compile_prog "" "-lrt" "clock_gettime"; then
630 clock_gettime="yes"
631 LIBS="-lrt $LIBS"
632fi
633echo "clock_gettime $clock_gettime"
634
635##########################################
636# CLOCK_MONOTONIC probe
637clock_monotonic="no"
638if test "$clock_gettime" = "yes" ; then
639 cat > $TMPC << EOF
640#include <stdio.h>
641#include <time.h>
642int main(int argc, char **argv)
643{
644 return clock_gettime(CLOCK_MONOTONIC, NULL);
645}
646EOF
647 if compile_prog "" "$LIBS" "clock monotonic"; then
648 clock_monotonic="yes"
649 fi
650fi
651echo "CLOCK_MONOTONIC $clock_monotonic"
652
653##########################################
654# CLOCK_MONOTONIC_PRECISE probe
655clock_monotonic_precise="no"
656if test "$clock_gettime" = "yes" ; then
657 cat > $TMPC << EOF
658#include <stdio.h>
659#include <time.h>
660int main(int argc, char **argv)
661{
662 return clock_gettime(CLOCK_MONOTONIC_PRECISE, NULL);
663}
664EOF
665 if compile_prog "" "$LIBS" "clock monotonic precise"; then
666 clock_monotonic_precise="yes"
667 fi
668fi
669echo "CLOCK_MONOTONIC_PRECISE $clock_monotonic_precise"
670
671##########################################
672# gettimeofday() probe
673gettimeofday="no"
674cat > $TMPC << EOF
675#include <sys/time.h>
676#include <stdio.h>
677int main(int argc, char **argv)
678{
679 struct timeval tv;
680 return gettimeofday(&tv, NULL);
681}
682EOF
683if compile_prog "" "" "gettimeofday"; then
684 gettimeofday="yes"
685fi
686echo "gettimeofday $gettimeofday"
687
688##########################################
689# fdatasync() probe
690fdatasync="no"
691cat > $TMPC << EOF
692#include <stdio.h>
693#include <unistd.h>
694int main(int argc, char **argv)
695{
696 return fdatasync(0);
697}
698EOF
699if compile_prog "" "" "fdatasync"; then
700 fdatasync="yes"
701fi
702echo "fdatasync $fdatasync"
703
704##########################################
705# sync_file_range() probe
706sync_file_range="no"
707cat > $TMPC << EOF
708#include <stdio.h>
709#include <unistd.h>
Jens Axboe67bf9822013-01-10 11:23:19 +0100710#include <fcntl.h>
711#include <linux/fs.h>
712int main(int argc, char **argv)
713{
714 unsigned int flags = SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE |
715 SYNC_FILE_RANGE_WAIT_AFTER;
716 return sync_file_range(0, 0, 0, flags);
717}
718EOF
719if compile_prog "" "" "sync_file_range"; then
720 sync_file_range="yes"
721fi
722echo "sync_file_range $sync_file_range"
723
724##########################################
725# ext4 move extent probe
726ext4_me="no"
727cat > $TMPC << EOF
728#include <fcntl.h>
729#include <sys/ioctl.h>
730int main(int argc, char **argv)
731{
732 struct move_extent me;
733 return ioctl(0, EXT4_IOC_MOVE_EXT, &me);
734}
735EOF
Jens Axboec7165b82013-01-12 10:27:53 +0100736if compile_prog "" "" "ext4 move extent" ; then
737 ext4_me="yes"
738elif test $targetos = "Linux" ; then
739 # On Linux, just default to it on and let it error at runtime if we really
740 # don't have it. None of my updated systems have it defined, but it does
741 # work. Takes a while to bubble back.
Jens Axboe67bf9822013-01-10 11:23:19 +0100742 ext4_me="yes"
743fi
744echo "EXT4 move extent $ext4_me"
745
746##########################################
747# splice probe
748linux_splice="no"
749cat > $TMPC << EOF
Jens Axboe67bf9822013-01-10 11:23:19 +0100750#include <stdio.h>
751#include <fcntl.h>
752int main(int argc, char **argv)
753{
754 return splice(0, NULL, 0, NULL, 0, SPLICE_F_NONBLOCK);
755}
756EOF
757if compile_prog "" "" "linux splice"; then
758 linux_splice="yes"
759fi
760echo "Linux splice(2) $linux_splice"
761
762##########################################
763# GUASI probe
764guasi="no"
765cat > $TMPC << EOF
766#include <guasi.h>
767#include <guasi_syscalls.h>
768int main(int argc, char **argv)
769{
770 guasi_t ctx = guasi_create(0, 0, 0);
771 return 0;
772}
773EOF
774if compile_prog "" "" "guasi"; then
775 guasi="yes"
776fi
777echo "GUASI $guasi"
778
779##########################################
780# fusion-aw probe
781fusion_aw="no"
782cat > $TMPC << EOF
Jens Axboe99db6562013-01-14 19:33:40 +0100783#include <nvm/vectored_write.h>
Jens Axboe67bf9822013-01-10 11:23:19 +0100784int main(int argc, char **argv)
785{
786 struct vsl_iovec iov;
787 return vsl_vectored_write(0, &iov, 0, O_ATOMIC);
788}
789EOF
Jens Axboe99db6562013-01-14 19:33:40 +0100790if compile_prog "" "-L/usr/lib/fio -lnvm-primitives" "fusion-aw"; then
791 LIBS="-L/usr/lib/fio -lnvm-primitives $LIBS"
Jens Axboe67bf9822013-01-10 11:23:19 +0100792 fusion_aw="yes"
793fi
794echo "Fusion-io atomic engine $fusion_aw"
795
796##########################################
797# libnuma probe
798libnuma="no"
799cat > $TMPC << EOF
800#include <numa.h>
801int main(int argc, char **argv)
802{
803 return numa_available();
804}
805EOF
806if compile_prog "" "-lnuma" "libnuma"; then
807 libnuma="yes"
808 LIBS="-lnuma $LIBS"
809fi
810echo "libnuma $libnuma"
811
812##########################################
Jens Axboe50206d92013-03-25 13:20:08 -0600813# libnuma 2.x version API
814if test "$libnuma" = "yes" ; then
815libnuma_v2="no"
816cat > $TMPC << EOF
817#include <numa.h>
818int main(int argc, char **argv)
819{
820 struct bitmask *mask = numa_parse_nodestring(NULL);
821 return 0;
822}
823EOF
824if compile_prog "" "" "libnuma api"; then
825 libnuma_v2="yes"
826fi
827echo "libnuma v2 $libnuma_v2"
828fi
829
830##########################################
Jens Axboe67bf9822013-01-10 11:23:19 +0100831# strsep() probe
832strsep="no"
833cat > $TMPC << EOF
834#include <string.h>
835int main(int argc, char **argv)
836{
837 strsep(NULL, NULL);
838 return 0;
839}
840EOF
841if compile_prog "" "" "strsep"; then
842 strsep="yes"
843fi
844echo "strsep $strsep"
845
846##########################################
847# getopt_long_only() probe
848getopt_long_only="no"
849cat > $TMPC << EOF
850#include <unistd.h>
851#include <stdio.h>
852int main(int argc, char **argv)
853{
854 int c = getopt_long_only(argc, argv, NULL, NULL, NULL);
855 return c;
856}
857EOF
858if compile_prog "" "" "getopt_long_only"; then
859 getopt_long_only="yes"
860fi
861echo "getopt_long_only() $getopt_long_only"
862
863##########################################
864# inet_aton() probe
865inet_aton="no"
866cat > $TMPC << EOF
867#include <sys/socket.h>
868#include <arpa/inet.h>
869#include <stdio.h>
870int main(int argc, char **argv)
871{
872 struct in_addr in;
873 return inet_aton(NULL, &in);
874}
875EOF
876if compile_prog "" "" "inet_aton"; then
877 inet_aton="yes"
878fi
879echo "inet_aton $inet_aton"
880
881##########################################
882# socklen_t probe
883socklen_t="no"
884cat > $TMPC << EOF
Aaron Carrollf6482612013-03-14 16:57:41 +1100885#include <sys/socket.h>
Jens Axboe67bf9822013-01-10 11:23:19 +0100886int main(int argc, char **argv)
887{
888 socklen_t len = 0;
889 return len;
890}
891EOF
892if compile_prog "" "" "socklen_t"; then
893 socklen_t="yes"
894fi
895echo "socklen_t $socklen_t"
896
897##########################################
898# Whether or not __thread is supported for TLS
899tls_thread="no"
900cat > $TMPC << EOF
901#include <stdio.h>
902static int __thread ret;
903int main(int argc, char **argv)
904{
905 return ret;
906}
907EOF
908if compile_prog "" "" "__thread"; then
909 tls_thread="yes"
910fi
911echo "__thread $tls_thread"
912
Jens Axboe44404c52013-01-24 14:20:09 -0700913##########################################
914# Check whether we have getrusage(RUSAGE_THREAD)
915rusage_thread="no"
916cat > $TMPC << EOF
917#include <sys/time.h>
918#include <sys/resource.h>
919int main(int argc, char **argv)
920{
921 struct rusage ru;
922 getrusage(RUSAGE_THREAD, &ru);
923 return 0;
924}
925EOF
926if compile_prog "" "" "RUSAGE_THREAD"; then
927 rusage_thread="yes"
928fi
929echo "RUSAGE_THREAD $rusage_thread"
930
Jens Axboe7e09a9f2013-01-30 13:58:58 +0100931##########################################
932# Check whether we have SCHED_IDLE
933sched_idle="no"
934cat > $TMPC << EOF
935#include <sched.h>
936int main(int argc, char **argv)
937{
938 struct sched_param p;
939 return sched_setscheduler(0, SCHED_IDLE, &p);
940}
941EOF
942if compile_prog "" "" "SCHED_IDLE"; then
943 sched_idle="yes"
944fi
945echo "SCHED_IDLE $sched_idle"
946
Jens Axboe1eafa372013-01-31 10:19:51 +0100947##########################################
948# Check whether we have TCP_NODELAY
949tcp_nodelay="no"
950cat > $TMPC << EOF
951#include <stdio.h>
952#include <sys/types.h>
953#include <sys/socket.h>
954#include <netinet/tcp.h>
955int main(int argc, char **argv)
956{
957 return getsockopt(0, 0, TCP_NODELAY, NULL, NULL);
958}
959EOF
960if compile_prog "" "" "TCP_NODELAY"; then
961 tcp_nodelay="yes"
962fi
963echo "TCP_NODELAY $tcp_nodelay"
964
Jens Axboe38b93542013-02-28 08:28:05 +0100965##########################################
966# Check whether we have RLIMIT_MEMLOCK
967rlimit_memlock="no"
968cat > $TMPC << EOF
969#include <sys/time.h>
970#include <sys/resource.h>
971int main(int argc, char **argv)
972{
973 struct rlimit rl;
974 return getrlimit(RLIMIT_MEMLOCK, &rl);
975}
976EOF
977if compile_prog "" "" "RLIMIT_MEMLOCK"; then
978 rlimit_memlock="yes"
979fi
980echo "RLIMIT_MEMLOCK $rlimit_memlock"
981
Jens Axboe67bf9822013-01-10 11:23:19 +0100982#############################################################################
983
Jens Axboe67bf9822013-01-10 11:23:19 +0100984if test "$wordsize" = "64" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -0700985 output_sym "CONFIG_64BIT"
Jens Axboe67bf9822013-01-10 11:23:19 +0100986elif test "$wordsize" = "32" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -0700987 output_sym "CONFIG_32BIT"
Jens Axboe67bf9822013-01-10 11:23:19 +0100988else
Jens Axboed7145a72013-02-11 13:21:54 +0100989 fatal "Unknown wordsize!"
Jens Axboe67bf9822013-01-10 11:23:19 +0100990fi
Jens Axboe0dcebdf2013-01-23 15:42:16 -0700991if test "$bigendian" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -0700992 output_sym "CONFIG_BIG_ENDIAN"
Jens Axboe0dcebdf2013-01-23 15:42:16 -0700993else
Jens Axboe4feafb12013-01-24 23:07:55 -0700994 output_sym "CONFIG_LITTLE_ENDIAN"
Jens Axboe0dcebdf2013-01-23 15:42:16 -0700995fi
Jens Axboe67bf9822013-01-10 11:23:19 +0100996if test "$libaio" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -0700997 output_sym "CONFIG_LIBAIO"
Jens Axboe67bf9822013-01-10 11:23:19 +0100998fi
999if test "$posix_aio" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001000 output_sym "CONFIG_POSIXAIO"
Jens Axboe67bf9822013-01-10 11:23:19 +01001001fi
1002if test "$posix_aio_fsync" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001003 output_sym "CONFIG_POSIXAIO_FSYNC"
Jens Axboe67bf9822013-01-10 11:23:19 +01001004fi
1005if test "$linux_fallocate" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001006 output_sym "CONFIG_LINUX_FALLOCATE"
Jens Axboe67bf9822013-01-10 11:23:19 +01001007fi
1008if test "$posix_fallocate" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001009 output_sym "CONFIG_POSIX_FALLOCATE"
Jens Axboe67bf9822013-01-10 11:23:19 +01001010fi
1011if test "$fdatasync" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001012 output_sym "CONFIG_FDATASYNC"
Jens Axboe67bf9822013-01-10 11:23:19 +01001013fi
1014if test "$sync_file_range" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001015 output_sym "CONFIG_SYNC_FILE_RANGE"
Jens Axboe67bf9822013-01-10 11:23:19 +01001016fi
1017if test "$sfaa" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001018 output_sym "CONFIG_SFAA"
Jens Axboe67bf9822013-01-10 11:23:19 +01001019fi
Jens Axboed9d9db02013-03-28 12:52:17 -06001020if test "$libverbs" = "yes" -a "rdmacm" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001021 output_sym "CONFIG_RDMA"
Jens Axboe67bf9822013-01-10 11:23:19 +01001022fi
1023if test "$clock_gettime" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001024 output_sym "CONFIG_CLOCK_GETTIME"
Jens Axboe67bf9822013-01-10 11:23:19 +01001025fi
1026if test "$clock_monotonic" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001027 output_sym "CONFIG_CLOCK_MONOTONIC"
Jens Axboe67bf9822013-01-10 11:23:19 +01001028fi
1029if test "$clock_monotonic_precise" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001030 output_sym "CONFIG_CLOCK_MONOTONIC_PRECISE"
Jens Axboe67bf9822013-01-10 11:23:19 +01001031fi
1032if test "$gettimeofday" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001033 output_sym "CONFIG_GETTIMEOFDAY"
Jens Axboe67bf9822013-01-10 11:23:19 +01001034fi
1035if test "$posix_fadvise" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001036 output_sym "CONFIG_POSIX_FADVISE"
Jens Axboe67bf9822013-01-10 11:23:19 +01001037fi
1038if test "$linux_3arg_affinity" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001039 output_sym "CONFIG_3ARG_AFFINITY"
Jens Axboe67bf9822013-01-10 11:23:19 +01001040elif test "$linux_2arg_affinity" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001041 output_sym "CONFIG_2ARG_AFFINITY"
Jens Axboe67bf9822013-01-10 11:23:19 +01001042fi
1043if test "$strsep" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001044 output_sym "CONFIG_STRSEP"
Jens Axboe67bf9822013-01-10 11:23:19 +01001045fi
1046if test "$getopt_long_only" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001047 output_sym "CONFIG_GETOPT_LONG_ONLY"
Jens Axboe67bf9822013-01-10 11:23:19 +01001048fi
1049if test "$inet_aton" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001050 output_sym "CONFIG_INET_ATON"
Jens Axboe67bf9822013-01-10 11:23:19 +01001051fi
1052if test "$socklen_t" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001053 output_sym "CONFIG_SOCKLEN_T"
Jens Axboe67bf9822013-01-10 11:23:19 +01001054fi
1055if test "$ext4_me" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001056 output_sym "CONFIG_LINUX_EXT4_MOVE_EXTENT"
Jens Axboe67bf9822013-01-10 11:23:19 +01001057fi
1058if test "$linux_splice" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001059 output_sym "CONFIG_LINUX_SPLICE"
Jens Axboe67bf9822013-01-10 11:23:19 +01001060fi
1061if test "$guasi" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001062 output_sym "CONFIG_GUASI"
Jens Axboe67bf9822013-01-10 11:23:19 +01001063fi
1064if test "$fusion_aw" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001065 output_sym "CONFIG_FUSION_AW"
Jens Axboe67bf9822013-01-10 11:23:19 +01001066fi
Jens Axboe50206d92013-03-25 13:20:08 -06001067if test "$libnuma_v2" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001068 output_sym "CONFIG_LIBNUMA"
Jens Axboe67bf9822013-01-10 11:23:19 +01001069fi
1070if test "$solaris_aio" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001071 output_sym "CONFIG_SOLARISAIO"
Jens Axboe67bf9822013-01-10 11:23:19 +01001072fi
1073if test "$tls_thread" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001074 output_sym "CONFIG_TLS_THREAD"
Jens Axboe67bf9822013-01-10 11:23:19 +01001075fi
Jens Axboe44404c52013-01-24 14:20:09 -07001076if test "$rusage_thread" = "yes" ; then
Jens Axboe4feafb12013-01-24 23:07:55 -07001077 output_sym "CONFIG_RUSAGE_THREAD"
Jens Axboe44404c52013-01-24 14:20:09 -07001078fi
Jens Axboe7e09a9f2013-01-30 13:58:58 +01001079if test "$sched_idle" = "yes" ; then
1080 output_sym "CONFIG_SCHED_IDLE"
1081fi
Jens Axboe44583e02013-03-18 15:34:41 -06001082if test "$tcp_nodelay" = "yes" ; then
1083 output_sym "CONFIG_TCP_NODELAY"
1084fi
Jens Axboe38b93542013-02-28 08:28:05 +01001085if test "$rlimit_memlock" = "yes" ; then
1086 output_sym "CONFIG_RLIMIT_MEMLOCK"
1087fi
Jens Axboe67bf9822013-01-10 11:23:19 +01001088
1089echo "LIBS+=$LIBS" >> $config_host_mak
1090echo "CC=$cc" >> $config_host_mak
Jens Axboeaf4862b2013-03-29 08:55:32 -06001091echo "BUILD_CFLAGS=$BUILD_CFLAGS $CFLAGS" >> $config_host_mak