blob: a52644f9c7e7b876a13a33d4f32b6ae389132679 [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
Stefan Metzmacher3e63af42020-02-07 15:42:12 +010051 libdevdir="$prefix/lib"
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +010052fi
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
Stefan Metzmacher3e63af42020-02-07 15:42:12 +010060if test x"$libdir" = x"$libdevdir"; then
61 relativelibdir=""
62else
63 relativelibdir="$libdir/"
64fi
Kevin Vigor413ee332019-08-28 09:53:10 -070065
66if test "$show_help" = "yes"; then
67cat <<EOF
68
69Usage: configure [options]
70Options: [defaults in brackets after descriptions]
71 --help print this message
72 --prefix=PATH install in PATH [$prefix]
73 --includedir=PATH install headers in PATH [$includedir]
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +010074 --libdir=PATH install runtime libraries in PATH [$libdir]
75 --libdevdir=PATH install developement libraries in PATH [$libdevdir]
Kevin Vigor413ee332019-08-28 09:53:10 -070076 --mandir=PATH install man pages in PATH [$mandir]
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010077 --datadir=PATH install shared data in PATH [$datadir]
Kevin Vigor413ee332019-08-28 09:53:10 -070078EOF
79exit 0
80fi
Jens Axboef16b83b2019-01-15 11:14:43 -070081
82TMPC="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.c"
83TMPC2="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}-2.c"
84TMPO="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.o"
85TMPE="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.exe"
86
87# NB: do not call "exit" in the trap handler; this is buggy with some shells;
88# see <1285349658-3122-1-git-send-email-loic.minier@linaro.org>
89trap "rm -f $TMPC $TMPC2 $TMPO $TMPE" EXIT INT QUIT TERM
90
91rm -rf config.log
92
93config_host_mak="config-host.mak"
94config_host_h="config-host.h"
95
96rm -rf $config_host_mak
97rm -rf $config_host_h
98
99fatal() {
100 echo $@
101 echo "Configure failed, check config.log and/or the above output"
102 rm -rf $config_host_mak
103 rm -rf $config_host_h
104 exit 1
105}
106
107# Print result for each configuration test
108print_config() {
109 printf "%-30s%s\n" "$1" "$2"
110}
111
112# Default CFLAGS
113CFLAGS="-D_GNU_SOURCE -include config-host.h"
114BUILD_CFLAGS=""
115
116# Print configure header at the top of $config_host_h
117echo "/*" > $config_host_h
118echo " * Automatically generated by configure - do not modify" >> $config_host_h
119printf " * Configured with:" >> $config_host_h
120printf " * '%s'" "$0" "$@" >> $config_host_h
121echo "" >> $config_host_h
122echo " */" >> $config_host_h
123
124echo "# Automatically generated by configure - do not modify" > $config_host_mak
125printf "# Configured with:" >> $config_host_mak
126printf " '%s'" "$0" "$@" >> $config_host_mak
127echo >> $config_host_mak
128
129do_cc() {
130 # Run the compiler, capturing its output to the log.
131 echo $cc "$@" >> config.log
132 $cc "$@" >> config.log 2>&1 || return $?
133 # Test passed. If this is an --enable-werror build, rerun
134 # the test with -Werror and bail out if it fails. This
135 # makes warning-generating-errors in configure test code
136 # obvious to developers.
137 if test "$werror" != "yes"; then
138 return 0
139 fi
140 # Don't bother rerunning the compile if we were already using -Werror
141 case "$*" in
142 *-Werror*)
143 return 0
144 ;;
145 esac
146 echo $cc -Werror "$@" >> config.log
147 $cc -Werror "$@" >> config.log 2>&1 && return $?
148 echo "ERROR: configure test passed without -Werror but failed with -Werror."
149 echo "This is probably a bug in the configure script. The failing command"
150 echo "will be at the bottom of config.log."
151 fatal "You can run configure with --disable-werror to bypass this check."
152}
153
154compile_object() {
155 do_cc $CFLAGS -c -o $TMPO $TMPC
156}
157
158compile_prog() {
159 local_cflags="$1"
160 local_ldflags="$2 $LIBS"
161 echo "Compiling test case $3" >> config.log
162 do_cc $CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
163}
164
165has() {
166 type "$1" >/dev/null 2>&1
167}
168
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100169output_mak() {
170 echo "$1=$2" >> $config_host_mak
171}
172
Jens Axboef16b83b2019-01-15 11:14:43 -0700173output_sym() {
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100174 output_mak "$1" "y"
Jens Axboef16b83b2019-01-15 11:14:43 -0700175 echo "#define $1" >> $config_host_h
176}
177
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100178print_and_output_mak() {
179 print_config "$1" "$2"
180 output_mak "$1" "$2"
181}
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100182print_and_output_mak "prefix" "$prefix"
183print_and_output_mak "includedir" "$includedir"
184print_and_output_mak "libdir" "$libdir"
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +0100185print_and_output_mak "libdevdir" "$libdevdir"
Stefan Metzmacher3e63af42020-02-07 15:42:12 +0100186print_and_output_mak "relativelibdir" "$relativelibdir"
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100187print_and_output_mak "mandir" "$mandir"
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +0100188print_and_output_mak "datadir" "$datadir"
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100189
Jens Axboef16b83b2019-01-15 11:14:43 -0700190##########################################
191# check for __kernel_rwf_t
192__kernel_rwf_t="no"
193cat > $TMPC << EOF
194#include <linux/fs.h>
195int main(int argc, char **argv)
196{
197 __kernel_rwf_t x;
198 x = 0;
199 return x;
200}
201EOF
202if compile_prog "" "" "__kernel_rwf_t"; then
203 __kernel_rwf_t="yes"
204fi
205print_config "__kernel_rwf_t" "$__kernel_rwf_t"
206
Jens Axboee2934e12019-10-01 10:05:16 -0600207##########################################
208# check for __kernel_timespec
209__kernel_timespec="no"
210cat > $TMPC << EOF
211#include <linux/time.h>
Jens Axboed0a15ca2020-02-12 21:16:21 -0700212#include <linux/time_types.h>
Jens Axboee2934e12019-10-01 10:05:16 -0600213int main(int argc, char **argv)
214{
215 struct __kernel_timespec ts;
216 ts.tv_sec = 0;
217 ts.tv_nsec = 1;
218 return 0;
219}
220EOF
221if compile_prog "" "" "__kernel_timespec"; then
222 __kernel_timespec="yes"
223fi
224print_config "__kernel_timespec" "$__kernel_timespec"
225
Jens Axboe0ed392e2020-01-08 18:52:39 -0700226##########################################
227# check for open_how
228open_how="no"
229cat > $TMPC << EOF
230#include <sys/types.h>
231#include <sys/stat.h>
232#include <fcntl.h>
233#include <string.h>
234int main(int argc, char **argv)
235{
236 struct open_how how;
237 how.flags = 0;
238 how.mode = 0;
239 how.resolve = 0;
240 return 0;
241}
242EOF
243if compile_prog "" "" "open_how"; then
244 open_how="yes"
245fi
246print_config "open_how" "$open_how"
247
248
Jens Axboef16b83b2019-01-15 11:14:43 -0700249#############################################################################
250
251if test "$__kernel_rwf_t" = "yes"; then
252 output_sym "CONFIG_HAVE_KERNEL_RWF_T"
253fi
Jens Axboee2934e12019-10-01 10:05:16 -0600254if test "$__kernel_timespec" = "yes"; then
255 output_sym "CONFIG_HAVE_KERNEL_TIMESPEC"
256fi
Jens Axboe0ed392e2020-01-08 18:52:39 -0700257if test "$open_how" = "yes"; then
258 output_sym "CONFIG_HAVE_OPEN_HOW"
259fi
Jens Axboe43324332019-12-23 21:34:03 -0700260
261echo "CC=$cc" >> $config_host_mak
Jens Axboe71690562020-02-12 22:03:13 -0700262
263# generate compat.h
264compat_h="src/include/liburing/compat.h"
265cat > $compat_h << EOF
266/* SPDX-License-Identifier: MIT */
267#ifndef LIBURING_COMPAT_H
268#define LIBURING_COMPAT_H
269
270EOF
271
272if test "$__kernel_rwf_t" != "yes"; then
Jens Axboe401f8af2020-02-20 21:49:13 -0700273cat >> $compat_h << EOF
Jens Axboe71690562020-02-12 22:03:13 -0700274typedef int __kernel_rwf_t;
275
276EOF
277fi
278if test "$__kernel_timespec" != "yes"; then
279cat >> $compat_h << EOF
280struct __kernel_timespec {
281 int64_t tv_sec;
282 long long tv_nsec;
283};
284
285EOF
286else
287cat >> $compat_h << EOF
288#include <linux/time_types.h>
289
290EOF
291fi
292if test "$open_how" != "yes"; then
293cat >> $compat_h << EOF
294#include <inttypes.h>
295
296struct open_how {
297 uint64_t flags;
298 uint16_t mode;
299 uint16_t __padding[3];
300 uint64_t resolve;
301};
302
303EOF
304fi
305
306cat >> $compat_h << EOF
307#endif
308EOF