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