blob: babbae1fafc24f70d47d138eb05bff77b121cc1d [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 ;;
Kevin Vigor413ee332019-08-28 09:53:10 -070029 *)
30 echo "ERROR: unkown option $opt"
31 echo "Try '$0 --help' for more information"
32 exit 1
33 ;;
34 esac
35done
36
37if test -z "$prefix"; then
38 prefix=/usr
39fi
40if test -z "$includedir"; then
41 includedir="$prefix/include"
42fi
43if test -z "$libdir"; then
44 libdir="$prefix/lib"
45fi
46if test -z "$mandir"; then
47 mandir="$prefix/man"
48fi
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010049if test -z "$datadir"; then
50 datadir="$prefix/share"
51fi
52
Kevin Vigor413ee332019-08-28 09:53:10 -070053
54if test "$show_help" = "yes"; then
55cat <<EOF
56
57Usage: configure [options]
58Options: [defaults in brackets after descriptions]
59 --help print this message
60 --prefix=PATH install in PATH [$prefix]
61 --includedir=PATH install headers in PATH [$includedir]
62 --libdir=PATH install libraries in PATH [$libdir]
63 --mandir=PATH install man pages in PATH [$mandir]
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010064 --datadir=PATH install shared data in PATH [$datadir]
Kevin Vigor413ee332019-08-28 09:53:10 -070065EOF
66exit 0
67fi
Jens Axboef16b83b2019-01-15 11:14:43 -070068
69TMPC="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.c"
70TMPC2="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}-2.c"
71TMPO="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.o"
72TMPE="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.exe"
73
74# NB: do not call "exit" in the trap handler; this is buggy with some shells;
75# see <1285349658-3122-1-git-send-email-loic.minier@linaro.org>
76trap "rm -f $TMPC $TMPC2 $TMPO $TMPE" EXIT INT QUIT TERM
77
78rm -rf config.log
79
80config_host_mak="config-host.mak"
81config_host_h="config-host.h"
82
83rm -rf $config_host_mak
84rm -rf $config_host_h
85
86fatal() {
87 echo $@
88 echo "Configure failed, check config.log and/or the above output"
89 rm -rf $config_host_mak
90 rm -rf $config_host_h
91 exit 1
92}
93
94# Print result for each configuration test
95print_config() {
96 printf "%-30s%s\n" "$1" "$2"
97}
98
99# Default CFLAGS
100CFLAGS="-D_GNU_SOURCE -include config-host.h"
101BUILD_CFLAGS=""
102
103# Print configure header at the top of $config_host_h
104echo "/*" > $config_host_h
105echo " * Automatically generated by configure - do not modify" >> $config_host_h
106printf " * Configured with:" >> $config_host_h
107printf " * '%s'" "$0" "$@" >> $config_host_h
108echo "" >> $config_host_h
109echo " */" >> $config_host_h
110
111echo "# Automatically generated by configure - do not modify" > $config_host_mak
112printf "# Configured with:" >> $config_host_mak
113printf " '%s'" "$0" "$@" >> $config_host_mak
114echo >> $config_host_mak
115
116do_cc() {
117 # Run the compiler, capturing its output to the log.
118 echo $cc "$@" >> config.log
119 $cc "$@" >> config.log 2>&1 || return $?
120 # Test passed. If this is an --enable-werror build, rerun
121 # the test with -Werror and bail out if it fails. This
122 # makes warning-generating-errors in configure test code
123 # obvious to developers.
124 if test "$werror" != "yes"; then
125 return 0
126 fi
127 # Don't bother rerunning the compile if we were already using -Werror
128 case "$*" in
129 *-Werror*)
130 return 0
131 ;;
132 esac
133 echo $cc -Werror "$@" >> config.log
134 $cc -Werror "$@" >> config.log 2>&1 && return $?
135 echo "ERROR: configure test passed without -Werror but failed with -Werror."
136 echo "This is probably a bug in the configure script. The failing command"
137 echo "will be at the bottom of config.log."
138 fatal "You can run configure with --disable-werror to bypass this check."
139}
140
141compile_object() {
142 do_cc $CFLAGS -c -o $TMPO $TMPC
143}
144
145compile_prog() {
146 local_cflags="$1"
147 local_ldflags="$2 $LIBS"
148 echo "Compiling test case $3" >> config.log
149 do_cc $CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
150}
151
152has() {
153 type "$1" >/dev/null 2>&1
154}
155
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100156output_mak() {
157 echo "$1=$2" >> $config_host_mak
158}
159
Jens Axboef16b83b2019-01-15 11:14:43 -0700160output_sym() {
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100161 output_mak "$1" "y"
Jens Axboef16b83b2019-01-15 11:14:43 -0700162 echo "#define $1" >> $config_host_h
163}
164
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100165print_and_output_mak() {
166 print_config "$1" "$2"
167 output_mak "$1" "$2"
168}
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100169print_and_output_mak "prefix" "$prefix"
170print_and_output_mak "includedir" "$includedir"
171print_and_output_mak "libdir" "$libdir"
172print_and_output_mak "mandir" "$mandir"
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +0100173print_and_output_mak "datadir" "$datadir"
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100174
Jens Axboef16b83b2019-01-15 11:14:43 -0700175##########################################
176# check for __kernel_rwf_t
177__kernel_rwf_t="no"
178cat > $TMPC << EOF
179#include <linux/fs.h>
180int main(int argc, char **argv)
181{
182 __kernel_rwf_t x;
183 x = 0;
184 return x;
185}
186EOF
187if compile_prog "" "" "__kernel_rwf_t"; then
188 __kernel_rwf_t="yes"
189fi
190print_config "__kernel_rwf_t" "$__kernel_rwf_t"
191
Jens Axboee2934e12019-10-01 10:05:16 -0600192##########################################
193# check for __kernel_timespec
194__kernel_timespec="no"
195cat > $TMPC << EOF
196#include <linux/time.h>
197int main(int argc, char **argv)
198{
199 struct __kernel_timespec ts;
200 ts.tv_sec = 0;
201 ts.tv_nsec = 1;
202 return 0;
203}
204EOF
205if compile_prog "" "" "__kernel_timespec"; then
206 __kernel_timespec="yes"
207fi
208print_config "__kernel_timespec" "$__kernel_timespec"
209
Jens Axboef16b83b2019-01-15 11:14:43 -0700210#############################################################################
211
212if test "$__kernel_rwf_t" = "yes"; then
213 output_sym "CONFIG_HAVE_KERNEL_RWF_T"
214fi
Jens Axboee2934e12019-10-01 10:05:16 -0600215if test "$__kernel_timespec" = "yes"; then
216 output_sym "CONFIG_HAVE_KERNEL_TIMESPEC"
217fi