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