blob: 518a5b03e8ddc838eceb4a95fe1501868b24428a [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
Bart Van Assche532eddd2020-06-28 12:58:21 -070012cc=${CC:-gcc}
13cxx=${CXX:-g++}
Kevin Vigor413ee332019-08-28 09:53:10 -070014
15for opt do
16 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
17 case "$opt" in
18 --help|-h) show_help=yes
19 ;;
20 --prefix=*) prefix="$optarg"
21 ;;
22 --includedir=*) includedir="$optarg"
23 ;;
24 --libdir=*) libdir="$optarg"
25 ;;
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +010026 --libdevdir=*) libdevdir="$optarg"
27 ;;
Kevin Vigor413ee332019-08-28 09:53:10 -070028 --mandir=*) mandir="$optarg"
29 ;;
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010030 --datadir=*) datadir="$optarg"
31 ;;
Jens Axboe43324332019-12-23 21:34:03 -070032 --cc=*) cc="$optarg"
33 ;;
Jens Axboed9f95372020-06-28 07:33:31 -060034 --cxx=*) cxx="$optarg"
35 ;;
Kevin Vigor413ee332019-08-28 09:53:10 -070036 *)
Tobias Klauser3fd5bd02020-07-08 23:25:50 +020037 echo "ERROR: unknown option $opt"
Kevin Vigor413ee332019-08-28 09:53:10 -070038 echo "Try '$0 --help' for more information"
39 exit 1
40 ;;
41 esac
42done
43
44if test -z "$prefix"; then
45 prefix=/usr
46fi
47if test -z "$includedir"; then
48 includedir="$prefix/include"
49fi
50if test -z "$libdir"; then
51 libdir="$prefix/lib"
52fi
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +010053if test -z "$libdevdir"; then
Stefan Metzmacher3e63af42020-02-07 15:42:12 +010054 libdevdir="$prefix/lib"
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +010055fi
Kevin Vigor413ee332019-08-28 09:53:10 -070056if test -z "$mandir"; then
57 mandir="$prefix/man"
58fi
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010059if test -z "$datadir"; then
60 datadir="$prefix/share"
61fi
62
Stefan Metzmacher3e63af42020-02-07 15:42:12 +010063if test x"$libdir" = x"$libdevdir"; then
64 relativelibdir=""
65else
66 relativelibdir="$libdir/"
67fi
Kevin Vigor413ee332019-08-28 09:53:10 -070068
69if test "$show_help" = "yes"; then
70cat <<EOF
71
72Usage: configure [options]
73Options: [defaults in brackets after descriptions]
74 --help print this message
75 --prefix=PATH install in PATH [$prefix]
76 --includedir=PATH install headers in PATH [$includedir]
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +010077 --libdir=PATH install runtime libraries in PATH [$libdir]
Tobias Klauser3fd5bd02020-07-08 23:25:50 +020078 --libdevdir=PATH install development libraries in PATH [$libdevdir]
Kevin Vigor413ee332019-08-28 09:53:10 -070079 --mandir=PATH install man pages in PATH [$mandir]
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010080 --datadir=PATH install shared data in PATH [$datadir]
Kevin Vigor413ee332019-08-28 09:53:10 -070081EOF
82exit 0
83fi
Jens Axboef16b83b2019-01-15 11:14:43 -070084
85TMPC="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.c"
86TMPC2="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}-2.c"
87TMPO="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.o"
88TMPE="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.exe"
89
90# NB: do not call "exit" in the trap handler; this is buggy with some shells;
91# see <1285349658-3122-1-git-send-email-loic.minier@linaro.org>
92trap "rm -f $TMPC $TMPC2 $TMPO $TMPE" EXIT INT QUIT TERM
93
94rm -rf config.log
95
96config_host_mak="config-host.mak"
97config_host_h="config-host.h"
98
99rm -rf $config_host_mak
100rm -rf $config_host_h
101
102fatal() {
103 echo $@
104 echo "Configure failed, check config.log and/or the above output"
105 rm -rf $config_host_mak
106 rm -rf $config_host_h
107 exit 1
108}
109
110# Print result for each configuration test
111print_config() {
112 printf "%-30s%s\n" "$1" "$2"
113}
114
115# Default CFLAGS
116CFLAGS="-D_GNU_SOURCE -include config-host.h"
117BUILD_CFLAGS=""
118
119# Print configure header at the top of $config_host_h
120echo "/*" > $config_host_h
121echo " * Automatically generated by configure - do not modify" >> $config_host_h
122printf " * Configured with:" >> $config_host_h
123printf " * '%s'" "$0" "$@" >> $config_host_h
124echo "" >> $config_host_h
125echo " */" >> $config_host_h
126
127echo "# Automatically generated by configure - do not modify" > $config_host_mak
128printf "# Configured with:" >> $config_host_mak
129printf " '%s'" "$0" "$@" >> $config_host_mak
130echo >> $config_host_mak
131
Jens Axboed9f95372020-06-28 07:33:31 -0600132do_cxx() {
133 # Run the compiler, capturing its output to the log.
134 echo $cxx "$@" >> config.log
135 $cxx "$@" >> config.log 2>&1 || return $?
136 return 0
137}
138
Jens Axboef16b83b2019-01-15 11:14:43 -0700139do_cc() {
140 # Run the compiler, capturing its output to the log.
141 echo $cc "$@" >> config.log
142 $cc "$@" >> config.log 2>&1 || return $?
143 # Test passed. If this is an --enable-werror build, rerun
144 # the test with -Werror and bail out if it fails. This
145 # makes warning-generating-errors in configure test code
146 # obvious to developers.
147 if test "$werror" != "yes"; then
148 return 0
149 fi
150 # Don't bother rerunning the compile if we were already using -Werror
151 case "$*" in
152 *-Werror*)
153 return 0
154 ;;
155 esac
156 echo $cc -Werror "$@" >> config.log
157 $cc -Werror "$@" >> config.log 2>&1 && return $?
158 echo "ERROR: configure test passed without -Werror but failed with -Werror."
159 echo "This is probably a bug in the configure script. The failing command"
160 echo "will be at the bottom of config.log."
161 fatal "You can run configure with --disable-werror to bypass this check."
162}
163
Jens Axboef16b83b2019-01-15 11:14:43 -0700164compile_prog() {
165 local_cflags="$1"
166 local_ldflags="$2 $LIBS"
167 echo "Compiling test case $3" >> config.log
168 do_cc $CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
169}
170
Jens Axboed9f95372020-06-28 07:33:31 -0600171compile_prog_cxx() {
172 local_cflags="$1"
173 local_ldflags="$2 $LIBS"
174 echo "Compiling test case $3" >> config.log
175 do_cxx $CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
176}
177
Jens Axboef16b83b2019-01-15 11:14:43 -0700178has() {
179 type "$1" >/dev/null 2>&1
180}
181
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100182output_mak() {
183 echo "$1=$2" >> $config_host_mak
184}
185
Jens Axboef16b83b2019-01-15 11:14:43 -0700186output_sym() {
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100187 output_mak "$1" "y"
Jens Axboef16b83b2019-01-15 11:14:43 -0700188 echo "#define $1" >> $config_host_h
189}
190
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100191print_and_output_mak() {
192 print_config "$1" "$2"
193 output_mak "$1" "$2"
194}
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100195print_and_output_mak "prefix" "$prefix"
196print_and_output_mak "includedir" "$includedir"
197print_and_output_mak "libdir" "$libdir"
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +0100198print_and_output_mak "libdevdir" "$libdevdir"
Stefan Metzmacher3e63af42020-02-07 15:42:12 +0100199print_and_output_mak "relativelibdir" "$relativelibdir"
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100200print_and_output_mak "mandir" "$mandir"
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +0100201print_and_output_mak "datadir" "$datadir"
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100202
Jens Axboef16b83b2019-01-15 11:14:43 -0700203##########################################
204# check for __kernel_rwf_t
205__kernel_rwf_t="no"
206cat > $TMPC << EOF
207#include <linux/fs.h>
208int main(int argc, char **argv)
209{
210 __kernel_rwf_t x;
211 x = 0;
212 return x;
213}
214EOF
215if compile_prog "" "" "__kernel_rwf_t"; then
216 __kernel_rwf_t="yes"
217fi
218print_config "__kernel_rwf_t" "$__kernel_rwf_t"
219
Jens Axboee2934e12019-10-01 10:05:16 -0600220##########################################
221# check for __kernel_timespec
222__kernel_timespec="no"
223cat > $TMPC << EOF
224#include <linux/time.h>
Jens Axboed0a15ca2020-02-12 21:16:21 -0700225#include <linux/time_types.h>
Jens Axboee2934e12019-10-01 10:05:16 -0600226int main(int argc, char **argv)
227{
228 struct __kernel_timespec ts;
229 ts.tv_sec = 0;
230 ts.tv_nsec = 1;
231 return 0;
232}
233EOF
234if compile_prog "" "" "__kernel_timespec"; then
235 __kernel_timespec="yes"
236fi
237print_config "__kernel_timespec" "$__kernel_timespec"
238
Jens Axboe0ed392e2020-01-08 18:52:39 -0700239##########################################
240# check for open_how
241open_how="no"
242cat > $TMPC << EOF
243#include <sys/types.h>
244#include <sys/stat.h>
245#include <fcntl.h>
246#include <string.h>
247int main(int argc, char **argv)
248{
249 struct open_how how;
250 how.flags = 0;
251 how.mode = 0;
252 how.resolve = 0;
253 return 0;
254}
255EOF
256if compile_prog "" "" "open_how"; then
257 open_how="yes"
258fi
259print_config "open_how" "$open_how"
260
Jens Axboe802b9a22020-04-09 09:58:59 -0600261##########################################
262# check for statx
263statx="no"
264cat > $TMPC << EOF
265#include <sys/types.h>
266#include <sys/stat.h>
267#include <unistd.h>
268#include <fcntl.h>
269#include <string.h>
270#include <linux/stat.h>
271int main(int argc, char **argv)
272{
273 struct statx x;
274
275 return memset(&x, 0, sizeof(x)) != NULL;
276}
277EOF
278if compile_prog "" "" "statx"; then
279 statx="yes"
280fi
281print_config "statx" "$statx"
Jens Axboe0ed392e2020-01-08 18:52:39 -0700282
Jens Axboed9f95372020-06-28 07:33:31 -0600283##########################################
284# check for C++
285has_cxx="no"
286cat > $TMPC << EOF
287#include <iostream>
288int main(int argc, char **argv)
289{
290 std::cout << "Test";
291 return 0;
292}
293EOF
294if compile_prog_cxx "" "" "C++"; then
295 has_cxx="yes"
296fi
297print_config "C++" "$has_cxx"
298
Jens Axboef16b83b2019-01-15 11:14:43 -0700299#############################################################################
300
301if test "$__kernel_rwf_t" = "yes"; then
302 output_sym "CONFIG_HAVE_KERNEL_RWF_T"
303fi
Jens Axboee2934e12019-10-01 10:05:16 -0600304if test "$__kernel_timespec" = "yes"; then
305 output_sym "CONFIG_HAVE_KERNEL_TIMESPEC"
306fi
Jens Axboe0ed392e2020-01-08 18:52:39 -0700307if test "$open_how" = "yes"; then
308 output_sym "CONFIG_HAVE_OPEN_HOW"
309fi
Jens Axboe802b9a22020-04-09 09:58:59 -0600310if test "$statx" = "yes"; then
311 output_sym "CONFIG_HAVE_STATX"
312fi
Jens Axboed9f95372020-06-28 07:33:31 -0600313if test "$has_cxx" = "yes"; then
314 output_sym "CONFIG_HAVE_CXX"
315fi
Jens Axboe43324332019-12-23 21:34:03 -0700316
317echo "CC=$cc" >> $config_host_mak
Bart Van Assche532eddd2020-06-28 12:58:21 -0700318print_config "CC" "$cc"
Jens Axboed9f95372020-06-28 07:33:31 -0600319echo "CXX=$cxx" >> $config_host_mak
Bart Van Assche532eddd2020-06-28 12:58:21 -0700320print_config "CXX" "$cxx"
Jens Axboe71690562020-02-12 22:03:13 -0700321
322# generate compat.h
323compat_h="src/include/liburing/compat.h"
324cat > $compat_h << EOF
325/* SPDX-License-Identifier: MIT */
326#ifndef LIBURING_COMPAT_H
327#define LIBURING_COMPAT_H
328
329EOF
330
331if test "$__kernel_rwf_t" != "yes"; then
Jens Axboe401f8af2020-02-20 21:49:13 -0700332cat >> $compat_h << EOF
Jens Axboe71690562020-02-12 22:03:13 -0700333typedef int __kernel_rwf_t;
334
335EOF
336fi
337if test "$__kernel_timespec" != "yes"; then
338cat >> $compat_h << EOF
Milan P. Stanić81717782020-04-29 22:34:02 +0200339#include <stdint.h>
340
Jens Axboe71690562020-02-12 22:03:13 -0700341struct __kernel_timespec {
342 int64_t tv_sec;
343 long long tv_nsec;
344};
345
346EOF
347else
348cat >> $compat_h << EOF
349#include <linux/time_types.h>
350
351EOF
352fi
353if test "$open_how" != "yes"; then
354cat >> $compat_h << EOF
355#include <inttypes.h>
356
357struct open_how {
358 uint64_t flags;
Jens Axboeab778332020-02-24 16:43:08 -0700359 uint64_t mode;
Jens Axboe71690562020-02-12 22:03:13 -0700360 uint64_t resolve;
361};
362
363EOF
364fi
365
366cat >> $compat_h << EOF
367#endif
368EOF