Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 1 | #!/bin/sh |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 2 | |
Bart Van Assche | 532eddd | 2020-06-28 12:58:21 -0700 | [diff] [blame] | 3 | cc=${CC:-gcc} |
| 4 | cxx=${CXX:-g++} |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 5 | |
| 6 | for 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 Metzmacher | b57dbc2 | 2020-02-06 18:07:56 +0100 | [diff] [blame] | 17 | --libdevdir=*) libdevdir="$optarg" |
| 18 | ;; |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 19 | --mandir=*) mandir="$optarg" |
| 20 | ;; |
Johannes Thumshirn | 6e3f6f3 | 2019-11-28 11:26:06 +0100 | [diff] [blame] | 21 | --datadir=*) datadir="$optarg" |
| 22 | ;; |
Jens Axboe | 4332433 | 2019-12-23 21:34:03 -0700 | [diff] [blame] | 23 | --cc=*) cc="$optarg" |
| 24 | ;; |
Jens Axboe | d9f9537 | 2020-06-28 07:33:31 -0600 | [diff] [blame] | 25 | --cxx=*) cxx="$optarg" |
| 26 | ;; |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 27 | *) |
Tobias Klauser | 3fd5bd0 | 2020-07-08 23:25:50 +0200 | [diff] [blame] | 28 | echo "ERROR: unknown option $opt" |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 29 | echo "Try '$0 --help' for more information" |
| 30 | exit 1 |
| 31 | ;; |
| 32 | esac |
| 33 | done |
| 34 | |
| 35 | if test -z "$prefix"; then |
| 36 | prefix=/usr |
| 37 | fi |
| 38 | if test -z "$includedir"; then |
| 39 | includedir="$prefix/include" |
| 40 | fi |
| 41 | if test -z "$libdir"; then |
| 42 | libdir="$prefix/lib" |
| 43 | fi |
Stefan Metzmacher | b57dbc2 | 2020-02-06 18:07:56 +0100 | [diff] [blame] | 44 | if test -z "$libdevdir"; then |
Stefan Metzmacher | 3e63af4 | 2020-02-07 15:42:12 +0100 | [diff] [blame] | 45 | libdevdir="$prefix/lib" |
Stefan Metzmacher | b57dbc2 | 2020-02-06 18:07:56 +0100 | [diff] [blame] | 46 | fi |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 47 | if test -z "$mandir"; then |
| 48 | mandir="$prefix/man" |
| 49 | fi |
Johannes Thumshirn | 6e3f6f3 | 2019-11-28 11:26:06 +0100 | [diff] [blame] | 50 | if test -z "$datadir"; then |
| 51 | datadir="$prefix/share" |
| 52 | fi |
| 53 | |
Stefan Metzmacher | 3e63af4 | 2020-02-07 15:42:12 +0100 | [diff] [blame] | 54 | if test x"$libdir" = x"$libdevdir"; then |
| 55 | relativelibdir="" |
| 56 | else |
| 57 | relativelibdir="$libdir/" |
| 58 | fi |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 59 | |
| 60 | if test "$show_help" = "yes"; then |
| 61 | cat <<EOF |
| 62 | |
| 63 | Usage: configure [options] |
| 64 | Options: [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 Metzmacher | b57dbc2 | 2020-02-06 18:07:56 +0100 | [diff] [blame] | 68 | --libdir=PATH install runtime libraries in PATH [$libdir] |
Tobias Klauser | 3fd5bd0 | 2020-07-08 23:25:50 +0200 | [diff] [blame] | 69 | --libdevdir=PATH install development libraries in PATH [$libdevdir] |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 70 | --mandir=PATH install man pages in PATH [$mandir] |
Johannes Thumshirn | 6e3f6f3 | 2019-11-28 11:26:06 +0100 | [diff] [blame] | 71 | --datadir=PATH install shared data in PATH [$datadir] |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 72 | EOF |
| 73 | exit 0 |
| 74 | fi |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 75 | |
Guillem Jover | 6a89214 | 2020-10-23 15:14:48 +0200 | [diff] [blame] | 76 | TMPC="$(mktemp --tmpdir fio-conf-XXXXXXXXXX.c)" |
| 77 | TMPC2="$(mktemp --tmpdir fio-conf-XXXXXXXXXX-2.c)" |
| 78 | TMPO="$(mktemp --tmpdir fio-conf-XXXXXXXXXX.o)" |
| 79 | TMPE="$(mktemp --tmpdir fio-conf-XXXXXXXXXX.exe)" |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 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> |
| 83 | trap "rm -f $TMPC $TMPC2 $TMPO $TMPE" EXIT INT QUIT TERM |
| 84 | |
| 85 | rm -rf config.log |
| 86 | |
| 87 | config_host_mak="config-host.mak" |
| 88 | config_host_h="config-host.h" |
| 89 | |
| 90 | rm -rf $config_host_mak |
| 91 | rm -rf $config_host_h |
| 92 | |
| 93 | fatal() { |
| 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 |
| 102 | print_config() { |
| 103 | printf "%-30s%s\n" "$1" "$2" |
| 104 | } |
| 105 | |
| 106 | # Default CFLAGS |
| 107 | CFLAGS="-D_GNU_SOURCE -include config-host.h" |
| 108 | BUILD_CFLAGS="" |
| 109 | |
| 110 | # Print configure header at the top of $config_host_h |
| 111 | echo "/*" > $config_host_h |
| 112 | echo " * Automatically generated by configure - do not modify" >> $config_host_h |
| 113 | printf " * Configured with:" >> $config_host_h |
| 114 | printf " * '%s'" "$0" "$@" >> $config_host_h |
| 115 | echo "" >> $config_host_h |
| 116 | echo " */" >> $config_host_h |
| 117 | |
| 118 | echo "# Automatically generated by configure - do not modify" > $config_host_mak |
| 119 | printf "# Configured with:" >> $config_host_mak |
| 120 | printf " '%s'" "$0" "$@" >> $config_host_mak |
| 121 | echo >> $config_host_mak |
| 122 | |
Jens Axboe | d9f9537 | 2020-06-28 07:33:31 -0600 | [diff] [blame] | 123 | do_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 Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 130 | do_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 Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 155 | compile_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 Axboe | d9f9537 | 2020-06-28 07:33:31 -0600 | [diff] [blame] | 162 | compile_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 Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 169 | has() { |
| 170 | type "$1" >/dev/null 2>&1 |
| 171 | } |
| 172 | |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 173 | output_mak() { |
| 174 | echo "$1=$2" >> $config_host_mak |
| 175 | } |
| 176 | |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 177 | output_sym() { |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 178 | output_mak "$1" "y" |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 179 | echo "#define $1" >> $config_host_h |
| 180 | } |
| 181 | |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 182 | print_and_output_mak() { |
| 183 | print_config "$1" "$2" |
| 184 | output_mak "$1" "$2" |
| 185 | } |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 186 | print_and_output_mak "prefix" "$prefix" |
| 187 | print_and_output_mak "includedir" "$includedir" |
| 188 | print_and_output_mak "libdir" "$libdir" |
Stefan Metzmacher | b57dbc2 | 2020-02-06 18:07:56 +0100 | [diff] [blame] | 189 | print_and_output_mak "libdevdir" "$libdevdir" |
Stefan Metzmacher | 3e63af4 | 2020-02-07 15:42:12 +0100 | [diff] [blame] | 190 | print_and_output_mak "relativelibdir" "$relativelibdir" |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 191 | print_and_output_mak "mandir" "$mandir" |
Johannes Thumshirn | 6e3f6f3 | 2019-11-28 11:26:06 +0100 | [diff] [blame] | 192 | print_and_output_mak "datadir" "$datadir" |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 193 | |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 194 | ########################################## |
| 195 | # check for __kernel_rwf_t |
| 196 | __kernel_rwf_t="no" |
| 197 | cat > $TMPC << EOF |
| 198 | #include <linux/fs.h> |
| 199 | int main(int argc, char **argv) |
| 200 | { |
| 201 | __kernel_rwf_t x; |
| 202 | x = 0; |
| 203 | return x; |
| 204 | } |
| 205 | EOF |
| 206 | if compile_prog "" "" "__kernel_rwf_t"; then |
| 207 | __kernel_rwf_t="yes" |
| 208 | fi |
| 209 | print_config "__kernel_rwf_t" "$__kernel_rwf_t" |
| 210 | |
Jens Axboe | e2934e1 | 2019-10-01 10:05:16 -0600 | [diff] [blame] | 211 | ########################################## |
| 212 | # check for __kernel_timespec |
| 213 | __kernel_timespec="no" |
| 214 | cat > $TMPC << EOF |
| 215 | #include <linux/time.h> |
Jens Axboe | d0a15ca | 2020-02-12 21:16:21 -0700 | [diff] [blame] | 216 | #include <linux/time_types.h> |
Jens Axboe | e2934e1 | 2019-10-01 10:05:16 -0600 | [diff] [blame] | 217 | int 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 | } |
| 224 | EOF |
| 225 | if compile_prog "" "" "__kernel_timespec"; then |
| 226 | __kernel_timespec="yes" |
| 227 | fi |
| 228 | print_config "__kernel_timespec" "$__kernel_timespec" |
| 229 | |
Jens Axboe | 0ed392e | 2020-01-08 18:52:39 -0700 | [diff] [blame] | 230 | ########################################## |
| 231 | # check for open_how |
| 232 | open_how="no" |
| 233 | cat > $TMPC << EOF |
| 234 | #include <sys/types.h> |
| 235 | #include <sys/stat.h> |
| 236 | #include <fcntl.h> |
| 237 | #include <string.h> |
| 238 | int 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 | } |
| 246 | EOF |
| 247 | if compile_prog "" "" "open_how"; then |
| 248 | open_how="yes" |
| 249 | fi |
| 250 | print_config "open_how" "$open_how" |
| 251 | |
Jens Axboe | 802b9a2 | 2020-04-09 09:58:59 -0600 | [diff] [blame] | 252 | ########################################## |
| 253 | # check for statx |
| 254 | statx="no" |
| 255 | cat > $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> |
| 262 | int main(int argc, char **argv) |
| 263 | { |
| 264 | struct statx x; |
| 265 | |
| 266 | return memset(&x, 0, sizeof(x)) != NULL; |
| 267 | } |
| 268 | EOF |
| 269 | if compile_prog "" "" "statx"; then |
| 270 | statx="yes" |
| 271 | fi |
| 272 | print_config "statx" "$statx" |
Jens Axboe | 0ed392e | 2020-01-08 18:52:39 -0700 | [diff] [blame] | 273 | |
Jens Axboe | d9f9537 | 2020-06-28 07:33:31 -0600 | [diff] [blame] | 274 | ########################################## |
| 275 | # check for C++ |
| 276 | has_cxx="no" |
| 277 | cat > $TMPC << EOF |
| 278 | #include <iostream> |
| 279 | int main(int argc, char **argv) |
| 280 | { |
| 281 | std::cout << "Test"; |
| 282 | return 0; |
| 283 | } |
| 284 | EOF |
| 285 | if compile_prog_cxx "" "" "C++"; then |
| 286 | has_cxx="yes" |
| 287 | fi |
| 288 | print_config "C++" "$has_cxx" |
| 289 | |
Simon Zeni | 1cf969d | 2020-10-27 22:31:21 -0400 | [diff] [blame] | 290 | ########################################## |
| 291 | # check for ucontext support |
| 292 | has_ucontext="no" |
| 293 | cat > $TMPC << EOF |
| 294 | #include <ucontext.h> |
| 295 | int main(int argc, char **argv) |
| 296 | { |
| 297 | ucontext_t ctx; |
| 298 | getcontext(&ctx); |
| 299 | return 0; |
| 300 | } |
| 301 | EOF |
| 302 | if compile_prog "" "" "has_ucontext"; then |
| 303 | has_ucontext="yes" |
| 304 | fi |
| 305 | print_config "has_ucontext" "$has_ucontext" |
| 306 | |
| 307 | |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 308 | ############################################################################# |
| 309 | |
| 310 | if test "$__kernel_rwf_t" = "yes"; then |
| 311 | output_sym "CONFIG_HAVE_KERNEL_RWF_T" |
| 312 | fi |
Jens Axboe | e2934e1 | 2019-10-01 10:05:16 -0600 | [diff] [blame] | 313 | if test "$__kernel_timespec" = "yes"; then |
| 314 | output_sym "CONFIG_HAVE_KERNEL_TIMESPEC" |
| 315 | fi |
Jens Axboe | 0ed392e | 2020-01-08 18:52:39 -0700 | [diff] [blame] | 316 | if test "$open_how" = "yes"; then |
| 317 | output_sym "CONFIG_HAVE_OPEN_HOW" |
| 318 | fi |
Jens Axboe | 802b9a2 | 2020-04-09 09:58:59 -0600 | [diff] [blame] | 319 | if test "$statx" = "yes"; then |
| 320 | output_sym "CONFIG_HAVE_STATX" |
| 321 | fi |
Jens Axboe | d9f9537 | 2020-06-28 07:33:31 -0600 | [diff] [blame] | 322 | if test "$has_cxx" = "yes"; then |
| 323 | output_sym "CONFIG_HAVE_CXX" |
| 324 | fi |
Simon Zeni | 1cf969d | 2020-10-27 22:31:21 -0400 | [diff] [blame] | 325 | if test "$has_ucontext" = "yes"; then |
| 326 | output_sym "CONFIG_HAVE_UCONTEXT" |
| 327 | fi |
Jens Axboe | 4332433 | 2019-12-23 21:34:03 -0700 | [diff] [blame] | 328 | |
| 329 | echo "CC=$cc" >> $config_host_mak |
Bart Van Assche | 532eddd | 2020-06-28 12:58:21 -0700 | [diff] [blame] | 330 | print_config "CC" "$cc" |
Jens Axboe | d9f9537 | 2020-06-28 07:33:31 -0600 | [diff] [blame] | 331 | echo "CXX=$cxx" >> $config_host_mak |
Bart Van Assche | 532eddd | 2020-06-28 12:58:21 -0700 | [diff] [blame] | 332 | print_config "CXX" "$cxx" |
Jens Axboe | 7169056 | 2020-02-12 22:03:13 -0700 | [diff] [blame] | 333 | |
| 334 | # generate compat.h |
| 335 | compat_h="src/include/liburing/compat.h" |
| 336 | cat > $compat_h << EOF |
| 337 | /* SPDX-License-Identifier: MIT */ |
| 338 | #ifndef LIBURING_COMPAT_H |
| 339 | #define LIBURING_COMPAT_H |
| 340 | |
| 341 | EOF |
| 342 | |
| 343 | if test "$__kernel_rwf_t" != "yes"; then |
Jens Axboe | 401f8af | 2020-02-20 21:49:13 -0700 | [diff] [blame] | 344 | cat >> $compat_h << EOF |
Jens Axboe | 7169056 | 2020-02-12 22:03:13 -0700 | [diff] [blame] | 345 | typedef int __kernel_rwf_t; |
| 346 | |
| 347 | EOF |
| 348 | fi |
| 349 | if test "$__kernel_timespec" != "yes"; then |
| 350 | cat >> $compat_h << EOF |
Milan P. Stanić | 8171778 | 2020-04-29 22:34:02 +0200 | [diff] [blame] | 351 | #include <stdint.h> |
| 352 | |
Jens Axboe | 7169056 | 2020-02-12 22:03:13 -0700 | [diff] [blame] | 353 | struct __kernel_timespec { |
| 354 | int64_t tv_sec; |
| 355 | long long tv_nsec; |
| 356 | }; |
| 357 | |
| 358 | EOF |
| 359 | else |
| 360 | cat >> $compat_h << EOF |
| 361 | #include <linux/time_types.h> |
| 362 | |
| 363 | EOF |
| 364 | fi |
| 365 | if test "$open_how" != "yes"; then |
| 366 | cat >> $compat_h << EOF |
| 367 | #include <inttypes.h> |
| 368 | |
| 369 | struct open_how { |
| 370 | uint64_t flags; |
Jens Axboe | ab77833 | 2020-02-24 16:43:08 -0700 | [diff] [blame] | 371 | uint64_t mode; |
Jens Axboe | 7169056 | 2020-02-12 22:03:13 -0700 | [diff] [blame] | 372 | uint64_t resolve; |
| 373 | }; |
| 374 | |
| 375 | EOF |
| 376 | fi |
| 377 | |
| 378 | cat >> $compat_h << EOF |
| 379 | #endif |
| 380 | EOF |