blob: 9fb43b39572502fd57706a69a7faed034ef2ca2b [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 ;;
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +010025 --libdevdir=*) libdevdir="$optarg"
26 ;;
Kevin Vigor413ee332019-08-28 09:53:10 -070027 --mandir=*) mandir="$optarg"
28 ;;
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010029 --datadir=*) datadir="$optarg"
30 ;;
Jens Axboe43324332019-12-23 21:34:03 -070031 --cc=*) cc="$optarg"
32 ;;
Kevin Vigor413ee332019-08-28 09:53:10 -070033 *)
34 echo "ERROR: unkown option $opt"
35 echo "Try '$0 --help' for more information"
36 exit 1
37 ;;
38 esac
39done
40
41if test -z "$prefix"; then
42 prefix=/usr
43fi
44if test -z "$includedir"; then
45 includedir="$prefix/include"
46fi
47if test -z "$libdir"; then
48 libdir="$prefix/lib"
49fi
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +010050if test -z "$libdevdir"; then
51 libdevdir="$libdir"
52fi
Kevin Vigor413ee332019-08-28 09:53:10 -070053if test -z "$mandir"; then
54 mandir="$prefix/man"
55fi
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010056if test -z "$datadir"; then
57 datadir="$prefix/share"
58fi
59
Kevin Vigor413ee332019-08-28 09:53:10 -070060
61if test "$show_help" = "yes"; then
62cat <<EOF
63
64Usage: configure [options]
65Options: [defaults in brackets after descriptions]
66 --help print this message
67 --prefix=PATH install in PATH [$prefix]
68 --includedir=PATH install headers in PATH [$includedir]
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +010069 --libdir=PATH install runtime libraries in PATH [$libdir]
70 --libdevdir=PATH install developement libraries in PATH [$libdevdir]
Kevin Vigor413ee332019-08-28 09:53:10 -070071 --mandir=PATH install man pages in PATH [$mandir]
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010072 --datadir=PATH install shared data in PATH [$datadir]
Kevin Vigor413ee332019-08-28 09:53:10 -070073EOF
74exit 0
75fi
Jens Axboef16b83b2019-01-15 11:14:43 -070076
77TMPC="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.c"
78TMPC2="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}-2.c"
79TMPO="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.o"
80TMPE="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.exe"
81
82# NB: do not call "exit" in the trap handler; this is buggy with some shells;
83# see <1285349658-3122-1-git-send-email-loic.minier@linaro.org>
84trap "rm -f $TMPC $TMPC2 $TMPO $TMPE" EXIT INT QUIT TERM
85
86rm -rf config.log
87
88config_host_mak="config-host.mak"
89config_host_h="config-host.h"
90
91rm -rf $config_host_mak
92rm -rf $config_host_h
93
94fatal() {
95 echo $@
96 echo "Configure failed, check config.log and/or the above output"
97 rm -rf $config_host_mak
98 rm -rf $config_host_h
99 exit 1
100}
101
102# Print result for each configuration test
103print_config() {
104 printf "%-30s%s\n" "$1" "$2"
105}
106
107# Default CFLAGS
108CFLAGS="-D_GNU_SOURCE -include config-host.h"
109BUILD_CFLAGS=""
110
111# Print configure header at the top of $config_host_h
112echo "/*" > $config_host_h
113echo " * Automatically generated by configure - do not modify" >> $config_host_h
114printf " * Configured with:" >> $config_host_h
115printf " * '%s'" "$0" "$@" >> $config_host_h
116echo "" >> $config_host_h
117echo " */" >> $config_host_h
118
119echo "# Automatically generated by configure - do not modify" > $config_host_mak
120printf "# Configured with:" >> $config_host_mak
121printf " '%s'" "$0" "$@" >> $config_host_mak
122echo >> $config_host_mak
123
124do_cc() {
125 # Run the compiler, capturing its output to the log.
126 echo $cc "$@" >> config.log
127 $cc "$@" >> config.log 2>&1 || return $?
128 # Test passed. If this is an --enable-werror build, rerun
129 # the test with -Werror and bail out if it fails. This
130 # makes warning-generating-errors in configure test code
131 # obvious to developers.
132 if test "$werror" != "yes"; then
133 return 0
134 fi
135 # Don't bother rerunning the compile if we were already using -Werror
136 case "$*" in
137 *-Werror*)
138 return 0
139 ;;
140 esac
141 echo $cc -Werror "$@" >> config.log
142 $cc -Werror "$@" >> config.log 2>&1 && return $?
143 echo "ERROR: configure test passed without -Werror but failed with -Werror."
144 echo "This is probably a bug in the configure script. The failing command"
145 echo "will be at the bottom of config.log."
146 fatal "You can run configure with --disable-werror to bypass this check."
147}
148
149compile_object() {
150 do_cc $CFLAGS -c -o $TMPO $TMPC
151}
152
153compile_prog() {
154 local_cflags="$1"
155 local_ldflags="$2 $LIBS"
156 echo "Compiling test case $3" >> config.log
157 do_cc $CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
158}
159
160has() {
161 type "$1" >/dev/null 2>&1
162}
163
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100164output_mak() {
165 echo "$1=$2" >> $config_host_mak
166}
167
Jens Axboef16b83b2019-01-15 11:14:43 -0700168output_sym() {
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100169 output_mak "$1" "y"
Jens Axboef16b83b2019-01-15 11:14:43 -0700170 echo "#define $1" >> $config_host_h
171}
172
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100173print_and_output_mak() {
174 print_config "$1" "$2"
175 output_mak "$1" "$2"
176}
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100177print_and_output_mak "prefix" "$prefix"
178print_and_output_mak "includedir" "$includedir"
179print_and_output_mak "libdir" "$libdir"
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +0100180print_and_output_mak "libdevdir" "$libdevdir"
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100181print_and_output_mak "mandir" "$mandir"
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +0100182print_and_output_mak "datadir" "$datadir"
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100183
Jens Axboef16b83b2019-01-15 11:14:43 -0700184##########################################
185# check for __kernel_rwf_t
186__kernel_rwf_t="no"
187cat > $TMPC << EOF
188#include <linux/fs.h>
189int main(int argc, char **argv)
190{
191 __kernel_rwf_t x;
192 x = 0;
193 return x;
194}
195EOF
196if compile_prog "" "" "__kernel_rwf_t"; then
197 __kernel_rwf_t="yes"
198fi
199print_config "__kernel_rwf_t" "$__kernel_rwf_t"
200
Jens Axboee2934e12019-10-01 10:05:16 -0600201##########################################
202# check for __kernel_timespec
203__kernel_timespec="no"
204cat > $TMPC << EOF
205#include <linux/time.h>
206int main(int argc, char **argv)
207{
208 struct __kernel_timespec ts;
209 ts.tv_sec = 0;
210 ts.tv_nsec = 1;
211 return 0;
212}
213EOF
214if compile_prog "" "" "__kernel_timespec"; then
215 __kernel_timespec="yes"
216fi
217print_config "__kernel_timespec" "$__kernel_timespec"
218
Jens Axboe0ed392e2020-01-08 18:52:39 -0700219##########################################
220# check for open_how
221open_how="no"
222cat > $TMPC << EOF
223#include <sys/types.h>
224#include <sys/stat.h>
225#include <fcntl.h>
226#include <string.h>
227int main(int argc, char **argv)
228{
229 struct open_how how;
230 how.flags = 0;
231 how.mode = 0;
232 how.resolve = 0;
233 return 0;
234}
235EOF
236if compile_prog "" "" "open_how"; then
237 open_how="yes"
238fi
239print_config "open_how" "$open_how"
240
241
Jens Axboef16b83b2019-01-15 11:14:43 -0700242#############################################################################
243
244if test "$__kernel_rwf_t" = "yes"; then
245 output_sym "CONFIG_HAVE_KERNEL_RWF_T"
246fi
Jens Axboee2934e12019-10-01 10:05:16 -0600247if test "$__kernel_timespec" = "yes"; then
248 output_sym "CONFIG_HAVE_KERNEL_TIMESPEC"
249fi
Jens Axboe0ed392e2020-01-08 18:52:39 -0700250if test "$open_how" = "yes"; then
251 output_sym "CONFIG_HAVE_OPEN_HOW"
252fi
Jens Axboe43324332019-12-23 21:34:03 -0700253
254echo "CC=$cc" >> $config_host_mak