blob: 3b96cde90a48b8ae13e2926f6d3e1bcc1dd79083 [file] [log] [blame]
Jens Axboef16b83b2019-01-15 11:14:43 -07001#!/bin/sh
Jens Axboef16b83b2019-01-15 11:14:43 -07002
Bart Van Assche532eddd2020-06-28 12:58:21 -07003cc=${CC:-gcc}
4cxx=${CXX:-g++}
Kevin Vigor413ee332019-08-28 09:53:10 -07005
6for opt do
7 optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
8 case "$opt" in
9 --help|-h) show_help=yes
10 ;;
11 --prefix=*) prefix="$optarg"
12 ;;
13 --includedir=*) includedir="$optarg"
14 ;;
15 --libdir=*) libdir="$optarg"
16 ;;
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +010017 --libdevdir=*) libdevdir="$optarg"
18 ;;
Kevin Vigor413ee332019-08-28 09:53:10 -070019 --mandir=*) mandir="$optarg"
20 ;;
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010021 --datadir=*) datadir="$optarg"
22 ;;
Jens Axboe43324332019-12-23 21:34:03 -070023 --cc=*) cc="$optarg"
24 ;;
Jens Axboed9f95372020-06-28 07:33:31 -060025 --cxx=*) cxx="$optarg"
26 ;;
Kevin Vigor413ee332019-08-28 09:53:10 -070027 *)
Tobias Klauser3fd5bd02020-07-08 23:25:50 +020028 echo "ERROR: unknown option $opt"
Kevin Vigor413ee332019-08-28 09:53:10 -070029 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
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +010044if test -z "$libdevdir"; then
Stefan Metzmacher3e63af42020-02-07 15:42:12 +010045 libdevdir="$prefix/lib"
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +010046fi
Kevin Vigor413ee332019-08-28 09:53:10 -070047if test -z "$mandir"; then
48 mandir="$prefix/man"
49fi
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010050if test -z "$datadir"; then
51 datadir="$prefix/share"
52fi
53
Stefan Metzmacher3e63af42020-02-07 15:42:12 +010054if test x"$libdir" = x"$libdevdir"; then
55 relativelibdir=""
56else
57 relativelibdir="$libdir/"
58fi
Kevin Vigor413ee332019-08-28 09:53:10 -070059
60if test "$show_help" = "yes"; then
61cat <<EOF
62
63Usage: configure [options]
64Options: [defaults in brackets after descriptions]
65 --help print this message
66 --prefix=PATH install in PATH [$prefix]
67 --includedir=PATH install headers in PATH [$includedir]
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +010068 --libdir=PATH install runtime libraries in PATH [$libdir]
Tobias Klauser3fd5bd02020-07-08 23:25:50 +020069 --libdevdir=PATH install development libraries in PATH [$libdevdir]
Kevin Vigor413ee332019-08-28 09:53:10 -070070 --mandir=PATH install man pages in PATH [$mandir]
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +010071 --datadir=PATH install shared data in PATH [$datadir]
Kevin Vigor413ee332019-08-28 09:53:10 -070072EOF
73exit 0
74fi
Jens Axboef16b83b2019-01-15 11:14:43 -070075
Guillem Jover6a892142020-10-23 15:14:48 +020076TMPC="$(mktemp --tmpdir fio-conf-XXXXXXXXXX.c)"
77TMPC2="$(mktemp --tmpdir fio-conf-XXXXXXXXXX-2.c)"
78TMPO="$(mktemp --tmpdir fio-conf-XXXXXXXXXX.o)"
79TMPE="$(mktemp --tmpdir fio-conf-XXXXXXXXXX.exe)"
Jens Axboef16b83b2019-01-15 11:14:43 -070080
81# NB: do not call "exit" in the trap handler; this is buggy with some shells;
82# see <1285349658-3122-1-git-send-email-loic.minier@linaro.org>
83trap "rm -f $TMPC $TMPC2 $TMPO $TMPE" EXIT INT QUIT TERM
84
85rm -rf config.log
86
87config_host_mak="config-host.mak"
88config_host_h="config-host.h"
89
90rm -rf $config_host_mak
91rm -rf $config_host_h
92
93fatal() {
94 echo $@
95 echo "Configure failed, check config.log and/or the above output"
96 rm -rf $config_host_mak
97 rm -rf $config_host_h
98 exit 1
99}
100
101# Print result for each configuration test
102print_config() {
103 printf "%-30s%s\n" "$1" "$2"
104}
105
106# Default CFLAGS
107CFLAGS="-D_GNU_SOURCE -include config-host.h"
108BUILD_CFLAGS=""
109
110# Print configure header at the top of $config_host_h
111echo "/*" > $config_host_h
112echo " * Automatically generated by configure - do not modify" >> $config_host_h
113printf " * Configured with:" >> $config_host_h
114printf " * '%s'" "$0" "$@" >> $config_host_h
115echo "" >> $config_host_h
116echo " */" >> $config_host_h
117
118echo "# Automatically generated by configure - do not modify" > $config_host_mak
119printf "# Configured with:" >> $config_host_mak
120printf " '%s'" "$0" "$@" >> $config_host_mak
121echo >> $config_host_mak
122
Jens Axboed9f95372020-06-28 07:33:31 -0600123do_cxx() {
124 # Run the compiler, capturing its output to the log.
125 echo $cxx "$@" >> config.log
126 $cxx "$@" >> config.log 2>&1 || return $?
127 return 0
128}
129
Jens Axboef16b83b2019-01-15 11:14:43 -0700130do_cc() {
131 # Run the compiler, capturing its output to the log.
132 echo $cc "$@" >> config.log
133 $cc "$@" >> config.log 2>&1 || return $?
134 # Test passed. If this is an --enable-werror build, rerun
135 # the test with -Werror and bail out if it fails. This
136 # makes warning-generating-errors in configure test code
137 # obvious to developers.
138 if test "$werror" != "yes"; then
139 return 0
140 fi
141 # Don't bother rerunning the compile if we were already using -Werror
142 case "$*" in
143 *-Werror*)
144 return 0
145 ;;
146 esac
147 echo $cc -Werror "$@" >> config.log
148 $cc -Werror "$@" >> config.log 2>&1 && return $?
149 echo "ERROR: configure test passed without -Werror but failed with -Werror."
150 echo "This is probably a bug in the configure script. The failing command"
151 echo "will be at the bottom of config.log."
152 fatal "You can run configure with --disable-werror to bypass this check."
153}
154
Jens Axboef16b83b2019-01-15 11:14:43 -0700155compile_prog() {
156 local_cflags="$1"
157 local_ldflags="$2 $LIBS"
158 echo "Compiling test case $3" >> config.log
159 do_cc $CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
160}
161
Jens Axboed9f95372020-06-28 07:33:31 -0600162compile_prog_cxx() {
163 local_cflags="$1"
164 local_ldflags="$2 $LIBS"
165 echo "Compiling test case $3" >> config.log
166 do_cxx $CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags
167}
168
Jens Axboef16b83b2019-01-15 11:14:43 -0700169has() {
170 type "$1" >/dev/null 2>&1
171}
172
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100173output_mak() {
174 echo "$1=$2" >> $config_host_mak
175}
176
Jens Axboef16b83b2019-01-15 11:14:43 -0700177output_sym() {
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100178 output_mak "$1" "y"
Jens Axboef16b83b2019-01-15 11:14:43 -0700179 echo "#define $1" >> $config_host_h
180}
181
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100182print_and_output_mak() {
183 print_config "$1" "$2"
184 output_mak "$1" "$2"
185}
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100186print_and_output_mak "prefix" "$prefix"
187print_and_output_mak "includedir" "$includedir"
188print_and_output_mak "libdir" "$libdir"
Stefan Metzmacherb57dbc22020-02-06 18:07:56 +0100189print_and_output_mak "libdevdir" "$libdevdir"
Stefan Metzmacher3e63af42020-02-07 15:42:12 +0100190print_and_output_mak "relativelibdir" "$relativelibdir"
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100191print_and_output_mak "mandir" "$mandir"
Johannes Thumshirn6e3f6f32019-11-28 11:26:06 +0100192print_and_output_mak "datadir" "$datadir"
Stefan Hajnoczifd26c1a2019-05-25 09:58:30 +0100193
Jens Axboef16b83b2019-01-15 11:14:43 -0700194##########################################
195# check for __kernel_rwf_t
196__kernel_rwf_t="no"
197cat > $TMPC << EOF
198#include <linux/fs.h>
199int main(int argc, char **argv)
200{
201 __kernel_rwf_t x;
202 x = 0;
203 return x;
204}
205EOF
206if compile_prog "" "" "__kernel_rwf_t"; then
207 __kernel_rwf_t="yes"
208fi
209print_config "__kernel_rwf_t" "$__kernel_rwf_t"
210
Jens Axboee2934e12019-10-01 10:05:16 -0600211##########################################
212# check for __kernel_timespec
213__kernel_timespec="no"
214cat > $TMPC << EOF
215#include <linux/time.h>
Jens Axboed0a15ca2020-02-12 21:16:21 -0700216#include <linux/time_types.h>
Jens Axboee2934e12019-10-01 10:05:16 -0600217int main(int argc, char **argv)
218{
219 struct __kernel_timespec ts;
220 ts.tv_sec = 0;
221 ts.tv_nsec = 1;
222 return 0;
223}
224EOF
225if compile_prog "" "" "__kernel_timespec"; then
226 __kernel_timespec="yes"
227fi
228print_config "__kernel_timespec" "$__kernel_timespec"
229
Jens Axboe0ed392e2020-01-08 18:52:39 -0700230##########################################
231# check for open_how
232open_how="no"
233cat > $TMPC << EOF
234#include <sys/types.h>
235#include <sys/stat.h>
236#include <fcntl.h>
237#include <string.h>
238int main(int argc, char **argv)
239{
240 struct open_how how;
241 how.flags = 0;
242 how.mode = 0;
243 how.resolve = 0;
244 return 0;
245}
246EOF
247if compile_prog "" "" "open_how"; then
248 open_how="yes"
249fi
250print_config "open_how" "$open_how"
251
Jens Axboe802b9a22020-04-09 09:58:59 -0600252##########################################
253# check for statx
254statx="no"
255cat > $TMPC << EOF
256#include <sys/types.h>
257#include <sys/stat.h>
258#include <unistd.h>
259#include <fcntl.h>
260#include <string.h>
261#include <linux/stat.h>
262int main(int argc, char **argv)
263{
264 struct statx x;
265
266 return memset(&x, 0, sizeof(x)) != NULL;
267}
268EOF
269if compile_prog "" "" "statx"; then
270 statx="yes"
271fi
272print_config "statx" "$statx"
Jens Axboe0ed392e2020-01-08 18:52:39 -0700273
Jens Axboed9f95372020-06-28 07:33:31 -0600274##########################################
275# check for C++
276has_cxx="no"
277cat > $TMPC << EOF
278#include <iostream>
279int main(int argc, char **argv)
280{
281 std::cout << "Test";
282 return 0;
283}
284EOF
285if compile_prog_cxx "" "" "C++"; then
286 has_cxx="yes"
287fi
288print_config "C++" "$has_cxx"
289
Simon Zeni1cf969d2020-10-27 22:31:21 -0400290##########################################
291# check for ucontext support
292has_ucontext="no"
293cat > $TMPC << EOF
294#include <ucontext.h>
295int main(int argc, char **argv)
296{
297 ucontext_t ctx;
298 getcontext(&ctx);
299 return 0;
300}
301EOF
302if compile_prog "" "" "has_ucontext"; then
303 has_ucontext="yes"
304fi
305print_config "has_ucontext" "$has_ucontext"
306
307
Jens Axboef16b83b2019-01-15 11:14:43 -0700308#############################################################################
309
310if test "$__kernel_rwf_t" = "yes"; then
311 output_sym "CONFIG_HAVE_KERNEL_RWF_T"
312fi
Jens Axboee2934e12019-10-01 10:05:16 -0600313if test "$__kernel_timespec" = "yes"; then
314 output_sym "CONFIG_HAVE_KERNEL_TIMESPEC"
315fi
Jens Axboe0ed392e2020-01-08 18:52:39 -0700316if test "$open_how" = "yes"; then
317 output_sym "CONFIG_HAVE_OPEN_HOW"
318fi
Jens Axboe802b9a22020-04-09 09:58:59 -0600319if test "$statx" = "yes"; then
320 output_sym "CONFIG_HAVE_STATX"
321fi
Jens Axboed9f95372020-06-28 07:33:31 -0600322if test "$has_cxx" = "yes"; then
323 output_sym "CONFIG_HAVE_CXX"
324fi
Simon Zeni1cf969d2020-10-27 22:31:21 -0400325if test "$has_ucontext" = "yes"; then
326 output_sym "CONFIG_HAVE_UCONTEXT"
327fi
Jens Axboe43324332019-12-23 21:34:03 -0700328
329echo "CC=$cc" >> $config_host_mak
Bart Van Assche532eddd2020-06-28 12:58:21 -0700330print_config "CC" "$cc"
Jens Axboed9f95372020-06-28 07:33:31 -0600331echo "CXX=$cxx" >> $config_host_mak
Bart Van Assche532eddd2020-06-28 12:58:21 -0700332print_config "CXX" "$cxx"
Jens Axboe71690562020-02-12 22:03:13 -0700333
334# generate compat.h
335compat_h="src/include/liburing/compat.h"
336cat > $compat_h << EOF
337/* SPDX-License-Identifier: MIT */
338#ifndef LIBURING_COMPAT_H
339#define LIBURING_COMPAT_H
340
341EOF
342
343if test "$__kernel_rwf_t" != "yes"; then
Jens Axboe401f8af2020-02-20 21:49:13 -0700344cat >> $compat_h << EOF
Jens Axboe71690562020-02-12 22:03:13 -0700345typedef int __kernel_rwf_t;
346
347EOF
348fi
349if test "$__kernel_timespec" != "yes"; then
350cat >> $compat_h << EOF
Milan P. Stanić81717782020-04-29 22:34:02 +0200351#include <stdint.h>
352
Jens Axboe71690562020-02-12 22:03:13 -0700353struct __kernel_timespec {
354 int64_t tv_sec;
355 long long tv_nsec;
356};
357
358EOF
359else
360cat >> $compat_h << EOF
361#include <linux/time_types.h>
362
363EOF
364fi
365if test "$open_how" != "yes"; then
366cat >> $compat_h << EOF
367#include <inttypes.h>
368
369struct open_how {
370 uint64_t flags;
Jens Axboeab778332020-02-24 16:43:08 -0700371 uint64_t mode;
Jens Axboe71690562020-02-12 22:03:13 -0700372 uint64_t resolve;
373};
374
375EOF
376fi
377
378cat >> $compat_h << EOF
379#endif
380EOF