]> git.proxmox.com Git - ceph.git/blob - ceph/src/liburing/configure
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / liburing / configure
1 #!/bin/sh
2 #
3 # set temporary file name
4 if test ! -z "$TMPDIR" ; then
5 TMPDIR1="${TMPDIR}"
6 elif test ! -z "$TEMPDIR" ; then
7 TMPDIR1="${TEMPDIR}"
8 else
9 TMPDIR1="/tmp"
10 fi
11
12 cc=${CC:-gcc}
13 cxx=${CXX:-g++}
14
15 for 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 ;;
26 --libdevdir=*) libdevdir="$optarg"
27 ;;
28 --mandir=*) mandir="$optarg"
29 ;;
30 --datadir=*) datadir="$optarg"
31 ;;
32 --cc=*) cc="$optarg"
33 ;;
34 --cxx=*) cxx="$optarg"
35 ;;
36 *)
37 echo "ERROR: unknown option $opt"
38 echo "Try '$0 --help' for more information"
39 exit 1
40 ;;
41 esac
42 done
43
44 if test -z "$prefix"; then
45 prefix=/usr
46 fi
47 if test -z "$includedir"; then
48 includedir="$prefix/include"
49 fi
50 if test -z "$libdir"; then
51 libdir="$prefix/lib"
52 fi
53 if test -z "$libdevdir"; then
54 libdevdir="$prefix/lib"
55 fi
56 if test -z "$mandir"; then
57 mandir="$prefix/man"
58 fi
59 if test -z "$datadir"; then
60 datadir="$prefix/share"
61 fi
62
63 if test x"$libdir" = x"$libdevdir"; then
64 relativelibdir=""
65 else
66 relativelibdir="$libdir/"
67 fi
68
69 if test "$show_help" = "yes"; then
70 cat <<EOF
71
72 Usage: configure [options]
73 Options: [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]
77 --libdir=PATH install runtime libraries in PATH [$libdir]
78 --libdevdir=PATH install development libraries in PATH [$libdevdir]
79 --mandir=PATH install man pages in PATH [$mandir]
80 --datadir=PATH install shared data in PATH [$datadir]
81 EOF
82 exit 0
83 fi
84
85 TMPC="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.c"
86 TMPC2="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}-2.c"
87 TMPO="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.o"
88 TMPE="${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>
92 trap "rm -f $TMPC $TMPC2 $TMPO $TMPE" EXIT INT QUIT TERM
93
94 rm -rf config.log
95
96 config_host_mak="config-host.mak"
97 config_host_h="config-host.h"
98
99 rm -rf $config_host_mak
100 rm -rf $config_host_h
101
102 fatal() {
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
111 print_config() {
112 printf "%-30s%s\n" "$1" "$2"
113 }
114
115 # Default CFLAGS
116 CFLAGS="-D_GNU_SOURCE -include config-host.h"
117 BUILD_CFLAGS=""
118
119 # Print configure header at the top of $config_host_h
120 echo "/*" > $config_host_h
121 echo " * Automatically generated by configure - do not modify" >> $config_host_h
122 printf " * Configured with:" >> $config_host_h
123 printf " * '%s'" "$0" "$@" >> $config_host_h
124 echo "" >> $config_host_h
125 echo " */" >> $config_host_h
126
127 echo "# Automatically generated by configure - do not modify" > $config_host_mak
128 printf "# Configured with:" >> $config_host_mak
129 printf " '%s'" "$0" "$@" >> $config_host_mak
130 echo >> $config_host_mak
131
132 do_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
139 do_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
164 compile_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
171 compile_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
178 has() {
179 type "$1" >/dev/null 2>&1
180 }
181
182 output_mak() {
183 echo "$1=$2" >> $config_host_mak
184 }
185
186 output_sym() {
187 output_mak "$1" "y"
188 echo "#define $1" >> $config_host_h
189 }
190
191 print_and_output_mak() {
192 print_config "$1" "$2"
193 output_mak "$1" "$2"
194 }
195 print_and_output_mak "prefix" "$prefix"
196 print_and_output_mak "includedir" "$includedir"
197 print_and_output_mak "libdir" "$libdir"
198 print_and_output_mak "libdevdir" "$libdevdir"
199 print_and_output_mak "relativelibdir" "$relativelibdir"
200 print_and_output_mak "mandir" "$mandir"
201 print_and_output_mak "datadir" "$datadir"
202
203 ##########################################
204 # check for __kernel_rwf_t
205 __kernel_rwf_t="no"
206 cat > $TMPC << EOF
207 #include <linux/fs.h>
208 int main(int argc, char **argv)
209 {
210 __kernel_rwf_t x;
211 x = 0;
212 return x;
213 }
214 EOF
215 if compile_prog "" "" "__kernel_rwf_t"; then
216 __kernel_rwf_t="yes"
217 fi
218 print_config "__kernel_rwf_t" "$__kernel_rwf_t"
219
220 ##########################################
221 # check for __kernel_timespec
222 __kernel_timespec="no"
223 cat > $TMPC << EOF
224 #include <linux/time.h>
225 #include <linux/time_types.h>
226 int 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 }
233 EOF
234 if compile_prog "" "" "__kernel_timespec"; then
235 __kernel_timespec="yes"
236 fi
237 print_config "__kernel_timespec" "$__kernel_timespec"
238
239 ##########################################
240 # check for open_how
241 open_how="no"
242 cat > $TMPC << EOF
243 #include <sys/types.h>
244 #include <sys/stat.h>
245 #include <fcntl.h>
246 #include <string.h>
247 int 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 }
255 EOF
256 if compile_prog "" "" "open_how"; then
257 open_how="yes"
258 fi
259 print_config "open_how" "$open_how"
260
261 ##########################################
262 # check for statx
263 statx="no"
264 cat > $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>
271 int main(int argc, char **argv)
272 {
273 struct statx x;
274
275 return memset(&x, 0, sizeof(x)) != NULL;
276 }
277 EOF
278 if compile_prog "" "" "statx"; then
279 statx="yes"
280 fi
281 print_config "statx" "$statx"
282
283 ##########################################
284 # check for C++
285 has_cxx="no"
286 cat > $TMPC << EOF
287 #include <iostream>
288 int main(int argc, char **argv)
289 {
290 std::cout << "Test";
291 return 0;
292 }
293 EOF
294 if compile_prog_cxx "" "" "C++"; then
295 has_cxx="yes"
296 fi
297 print_config "C++" "$has_cxx"
298
299 #############################################################################
300
301 if test "$__kernel_rwf_t" = "yes"; then
302 output_sym "CONFIG_HAVE_KERNEL_RWF_T"
303 fi
304 if test "$__kernel_timespec" = "yes"; then
305 output_sym "CONFIG_HAVE_KERNEL_TIMESPEC"
306 fi
307 if test "$open_how" = "yes"; then
308 output_sym "CONFIG_HAVE_OPEN_HOW"
309 fi
310 if test "$statx" = "yes"; then
311 output_sym "CONFIG_HAVE_STATX"
312 fi
313 if test "$has_cxx" = "yes"; then
314 output_sym "CONFIG_HAVE_CXX"
315 fi
316
317 echo "CC=$cc" >> $config_host_mak
318 print_config "CC" "$cc"
319 echo "CXX=$cxx" >> $config_host_mak
320 print_config "CXX" "$cxx"
321
322 # generate compat.h
323 compat_h="src/include/liburing/compat.h"
324 cat > $compat_h << EOF
325 /* SPDX-License-Identifier: MIT */
326 #ifndef LIBURING_COMPAT_H
327 #define LIBURING_COMPAT_H
328
329 EOF
330
331 if test "$__kernel_rwf_t" != "yes"; then
332 cat >> $compat_h << EOF
333 typedef int __kernel_rwf_t;
334
335 EOF
336 fi
337 if test "$__kernel_timespec" != "yes"; then
338 cat >> $compat_h << EOF
339 #include <stdint.h>
340
341 struct __kernel_timespec {
342 int64_t tv_sec;
343 long long tv_nsec;
344 };
345
346 EOF
347 else
348 cat >> $compat_h << EOF
349 #include <linux/time_types.h>
350
351 EOF
352 fi
353 if test "$open_how" != "yes"; then
354 cat >> $compat_h << EOF
355 #include <inttypes.h>
356
357 struct open_how {
358 uint64_t flags;
359 uint64_t mode;
360 uint64_t resolve;
361 };
362
363 EOF
364 fi
365
366 cat >> $compat_h << EOF
367 #endif
368 EOF