blob: 54cf5f6a09c03629b04162e15da025c719ff13fa [file] [log] [blame]
Jens Axboef16b83b2019-01-15 11:14:43 -07001#!/bin/sh
2#
3# set temporary file name
4if test ! -z "$TMPDIR" ; then
5 TMPDIR1="${TMPDIR}"
6elif test ! -z "$TEMPDIR" ; then
7 TMPDIR1="${TEMPDIR}"
8else
9 TMPDIR1="/tmp"
10fi
11
12cc=gcc
Kevin Vigor413ee332019-08-28 09:53:10 -070013
14for opt do
15 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
16 case "$opt" in
17 --help|-h) show_help=yes
18 ;;
19 --prefix=*) prefix="$optarg"
20 ;;
21 --includedir=*) includedir="$optarg"
22 ;;
23 --libdir=*) libdir="$optarg"
24 ;;
25 --mandir=*) mandir="$optarg"
26 ;;
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010027 --datadir=*) datadir="$optarg"
28 ;;
Jens Axboe43324332019-12-23 21:34:03 -070029 --cc=*) cc="$optarg"
30 ;;
Kevin Vigor413ee332019-08-28 09:53:10 -070031 *)
32 echo "ERROR: unkown option $opt"
33 echo "Try '$0 --help' for more information"
34 exit 1
35 ;;
36 esac
37done
38
39if test -z "$prefix"; then
40 prefix=/usr
41fi
42if test -z "$includedir"; then
43 includedir="$prefix/include"
44fi
45if test -z "$libdir"; then
46 libdir="$prefix/lib"
47fi
48if test -z "$mandir"; then
49 mandir="$prefix/man"
50fi
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010051if test -z "$datadir"; then
52 datadir="$prefix/share"
53fi
54
Kevin Vigor413ee332019-08-28 09:53:10 -070055
56if test "$show_help" = "yes"; then
57cat <<EOF
58
59Usage: configure [options]
60Options: [defaults in brackets after descriptions]
61 --help print this message
62 --prefix=PATH install in PATH [$prefix]
63 --includedir=PATH install headers in PATH [$includedir]
64 --libdir=PATH install libraries in PATH [$libdir]
65 --mandir=PATH install man pages in PATH [$mandir]
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010066 --datadir=PATH install shared data in PATH [$datadir]
Kevin Vigor413ee332019-08-28 09:53:10 -070067EOF
68exit 0
69fi
Jens Axboef16b83b2019-01-15 11:14:43 -070070
71TMPC="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.c"
72TMPC2="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}-2.c"
73TMPO="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.o"
74TMPE="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.exe"
75
76# NB: do not call "exit" in the trap handler; this is buggy with some shells;
77# see <1285349658-3122-1-git-send-email-loic.minier@linaro.org>
78trap "rm -f $TMPC $TMPC2 $TMPO $TMPE" EXIT INT QUIT TERM
79
80rm -rf config.log
81
82config_host_mak="config-host.mak"
83config_host_h="config-host.h"
84
85rm -rf $config_host_mak
86rm -rf $config_host_h
87
88fatal() {
89 echo $@
90 echo "Configure failed, check config.log and/or the above output"
91 rm -rf $config_host_mak
92 rm -rf $config_host_h
93 exit 1
94}
95
96# Print result for each configuration test
97print_config() {
98 printf "%-30s%s\n" "$1" "$2"
99}
100
101# Default CFLAGS
102CFLAGS="-D_GNU_SOURCE -include config-host.h"
103BUILD_CFLAGS=""
104
105# Print configure header at the top of $config_host_h
106echo "/*" > $config_host_h
107echo " * Automatically generated by configure - do not modify" >> $config_host_h
108printf " * Configured with:" >> $config_host_h
109printf " * '%s'" "$0" "$@" >> $config_host_h
110echo "" >> $config_host_h
111echo " */" >> $config_host_h
112
113echo "# Automatically generated by configure - do not modify" > $config_host_mak
114printf "# Configured with:" >> $config_host_mak
115printf " '%s'" "$0" "$@" >> $config_host_mak
116echo >> $config_host_mak
117
118do_cc() {
119 # Run the compiler, capturing its output to the log.
120 echo $cc "$@" >> config.log
121 $cc "$@" >> config.log 2>&1 || return $?
122 # Test passed. If this is an --enable-werror build, rerun
123 # the test with -Werror and bail out if it fails. This
124 # makes warning-generating-errors in configure test code
125 # obvious to developers.
126 if test "$werror" != "yes"; then
127 return 0
128 fi
129 # Don't bother rerunning the compile if we were already using -Werror
130 case "$*" in
131 *-Werror*)
132 return 0
133 ;;
134 esac
135 echo $cc -Werror "$@" >> config.log
136 $cc -Werror "$@" >> config.log 2>&1 && return $?
137 echo "ERROR: configure test passed without -Werror but failed with -Werror."
138 echo "This is probably a bug in the configure script. The failing command"
139 echo "will be at the bottom of config.log."
140 fatal "You can run configure with --disable-werror to bypass this check."
141}
142
143compile_object() {
144 do_cc $CFLAGS -c -o $TMPO $TMPC
145}
146
147compile_prog() {
148 local_cflags="$1"
149 local_ldflags="$2 $LIBS"
150 echo "Compiling test case $3" >> config.log
151 do_cc $CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
152}
153
154has() {
155 type "$1" >/dev/null 2>&1
156}
157
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100158output_mak() {
159 echo "$1=$2" >> $config_host_mak
160}
161
Jens Axboef16b83b2019-01-15 11:14:43 -0700162output_sym() {
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100163 output_mak "$1" "y"
Jens Axboef16b83b2019-01-15 11:14:43 -0700164 echo "#define $1" >> $config_host_h
165}
166
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100167print_and_output_mak() {
168 print_config "$1" "$2"
169 output_mak "$1" "$2"
170}
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100171print_and_output_mak "prefix" "$prefix"
172print_and_output_mak "includedir" "$includedir"
173print_and_output_mak "libdir" "$libdir"
174print_and_output_mak "mandir" "$mandir"
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +0100175print_and_output_mak "datadir" "$datadir"
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100176
Jens Axboef16b83b2019-01-15 11:14:43 -0700177##########################################
178# check for __kernel_rwf_t
179__kernel_rwf_t="no"
180cat > $TMPC << EOF
181#include <linux/fs.h>
182int main(int argc, char **argv)
183{
184 __kernel_rwf_t x;
185 x = 0;
186 return x;
187}
188EOF
189if compile_prog "" "" "__kernel_rwf_t"; then
190 __kernel_rwf_t="yes"
191fi
192print_config "__kernel_rwf_t" "$__kernel_rwf_t"
193
Jens Axboee2934e12019-10-01 10:05:16 -0600194##########################################
195# check for __kernel_timespec
196__kernel_timespec="no"
197cat > $TMPC << EOF
198#include <linux/time.h>
199int main(int argc, char **argv)
200{
201 struct __kernel_timespec ts;
202 ts.tv_sec = 0;
203 ts.tv_nsec = 1;
204 return 0;
205}
206EOF
207if compile_prog "" "" "__kernel_timespec"; then
208 __kernel_timespec="yes"
209fi
210print_config "__kernel_timespec" "$__kernel_timespec"
211
Jens Axboe0ed392e2020-01-08 18:52:39 -0700212##########################################
213# check for open_how
214open_how="no"
215cat > $TMPC << EOF
216#include <sys/types.h>
217#include <sys/stat.h>
218#include <fcntl.h>
219#include <string.h>
220int main(int argc, char **argv)
221{
222 struct open_how how;
223 how.flags = 0;
224 how.mode = 0;
225 how.resolve = 0;
226 return 0;
227}
228EOF
229if compile_prog "" "" "open_how"; then
230 open_how="yes"
231fi
232print_config "open_how" "$open_how"
233
234
Jens Axboef16b83b2019-01-15 11:14:43 -0700235#############################################################################
236
237if test "$__kernel_rwf_t" = "yes"; then
238 output_sym "CONFIG_HAVE_KERNEL_RWF_T"
239fi
Jens Axboee2934e12019-10-01 10:05:16 -0600240if test "$__kernel_timespec" = "yes"; then
241 output_sym "CONFIG_HAVE_KERNEL_TIMESPEC"
242fi
Jens Axboe0ed392e2020-01-08 18:52:39 -0700243if test "$open_how" = "yes"; then
244 output_sym "CONFIG_HAVE_OPEN_HOW"
245fi
Jens Axboe43324332019-12-23 21:34:03 -0700246
247echo "CC=$cc" >> $config_host_mak