• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3cc=${CC:-gcc}
4cxx=${CXX:-g++}
5
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  ;;
17  --libdevdir=*) libdevdir="$optarg"
18  ;;
19  --mandir=*) mandir="$optarg"
20  ;;
21  --datadir=*) datadir="$optarg"
22  ;;
23  --cc=*) cc="$optarg"
24  ;;
25  --cxx=*) cxx="$optarg"
26  ;;
27  *)
28    echo "ERROR: unknown 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 "$libdevdir"; then
45  libdevdir="$prefix/lib"
46fi
47if test -z "$mandir"; then
48  mandir="$prefix/man"
49fi
50if test -z "$datadir"; then
51  datadir="$prefix/share"
52fi
53
54if test x"$libdir" = x"$libdevdir"; then
55  relativelibdir=""
56else
57  relativelibdir="$libdir/"
58fi
59
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]
68  --libdir=PATH            install runtime libraries in PATH [$libdir]
69  --libdevdir=PATH         install development libraries in PATH [$libdevdir]
70  --mandir=PATH            install man pages in PATH [$mandir]
71  --datadir=PATH           install shared data in PATH [$datadir]
72EOF
73exit 0
74fi
75
76TMPC="$(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)"
80
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
123do_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
130do_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
155compile_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
162compile_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
169has() {
170  type "$1" >/dev/null 2>&1
171}
172
173output_mak() {
174  echo "$1=$2" >> $config_host_mak
175}
176
177output_sym() {
178  output_mak "$1" "y"
179  echo "#define $1" >> $config_host_h
180}
181
182print_and_output_mak() {
183  print_config "$1" "$2"
184  output_mak "$1" "$2"
185}
186print_and_output_mak "prefix" "$prefix"
187print_and_output_mak "includedir" "$includedir"
188print_and_output_mak "libdir" "$libdir"
189print_and_output_mak "libdevdir" "$libdevdir"
190print_and_output_mak "relativelibdir" "$relativelibdir"
191print_and_output_mak "mandir" "$mandir"
192print_and_output_mak "datadir" "$datadir"
193
194##########################################
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
211##########################################
212# check for __kernel_timespec
213__kernel_timespec="no"
214cat > $TMPC << EOF
215#include <linux/time.h>
216#include <linux/time_types.h>
217int 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
230##########################################
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
252##########################################
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"
273
274##########################################
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
290##########################################
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
308#############################################################################
309
310if test "$__kernel_rwf_t" = "yes"; then
311  output_sym "CONFIG_HAVE_KERNEL_RWF_T"
312fi
313if test "$__kernel_timespec" = "yes"; then
314  output_sym "CONFIG_HAVE_KERNEL_TIMESPEC"
315fi
316if test "$open_how" = "yes"; then
317  output_sym "CONFIG_HAVE_OPEN_HOW"
318fi
319if test "$statx" = "yes"; then
320  output_sym "CONFIG_HAVE_STATX"
321fi
322if test "$has_cxx" = "yes"; then
323  output_sym "CONFIG_HAVE_CXX"
324fi
325if test "$has_ucontext" = "yes"; then
326  output_sym "CONFIG_HAVE_UCONTEXT"
327fi
328
329echo "CC=$cc" >> $config_host_mak
330print_config "CC" "$cc"
331echo "CXX=$cxx" >> $config_host_mak
332print_config "CXX" "$cxx"
333
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
344cat >> $compat_h << EOF
345typedef int __kernel_rwf_t;
346
347EOF
348fi
349if test "$__kernel_timespec" != "yes"; then
350cat >> $compat_h << EOF
351#include <stdint.h>
352
353struct __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;
371	uint64_t	mode;
372	uint64_t	resolve;
373};
374
375EOF
376fi
377
378cat >> $compat_h << EOF
379#endif
380EOF
381