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