Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 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=gcc |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 13 | |
| 14 | for opt do |
| 15 | optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)') |
| 16 | case "$opt" in |
| 17 | --help|-h) show_help=yes |
| 18 | ;; |
| 19 | --prefix=*) prefix="$optarg" |
| 20 | ;; |
| 21 | --includedir=*) includedir="$optarg" |
| 22 | ;; |
| 23 | --libdir=*) libdir="$optarg" |
| 24 | ;; |
Stefan Metzmacher | b57dbc2 | 2020-02-06 18:07:56 +0100 | [diff] [blame] | 25 | --libdevdir=*) libdevdir="$optarg" |
| 26 | ;; |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 27 | --mandir=*) mandir="$optarg" |
| 28 | ;; |
Johannes Thumshirn | 6e3f6f3 | 2019-11-28 11:26:06 +0100 | [diff] [blame] | 29 | --datadir=*) datadir="$optarg" |
| 30 | ;; |
Jens Axboe | 4332433 | 2019-12-23 21:34:03 -0700 | [diff] [blame] | 31 | --cc=*) cc="$optarg" |
| 32 | ;; |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 33 | *) |
| 34 | echo "ERROR: unkown option $opt" |
| 35 | echo "Try '$0 --help' for more information" |
| 36 | exit 1 |
| 37 | ;; |
| 38 | esac |
| 39 | done |
| 40 | |
| 41 | if test -z "$prefix"; then |
| 42 | prefix=/usr |
| 43 | fi |
| 44 | if test -z "$includedir"; then |
| 45 | includedir="$prefix/include" |
| 46 | fi |
| 47 | if test -z "$libdir"; then |
| 48 | libdir="$prefix/lib" |
| 49 | fi |
Stefan Metzmacher | b57dbc2 | 2020-02-06 18:07:56 +0100 | [diff] [blame] | 50 | if test -z "$libdevdir"; then |
Stefan Metzmacher | 3e63af4 | 2020-02-07 15:42:12 +0100 | [diff] [blame] | 51 | libdevdir="$prefix/lib" |
Stefan Metzmacher | b57dbc2 | 2020-02-06 18:07:56 +0100 | [diff] [blame] | 52 | fi |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 53 | if test -z "$mandir"; then |
| 54 | mandir="$prefix/man" |
| 55 | fi |
Johannes Thumshirn | 6e3f6f3 | 2019-11-28 11:26:06 +0100 | [diff] [blame] | 56 | if test -z "$datadir"; then |
| 57 | datadir="$prefix/share" |
| 58 | fi |
| 59 | |
Stefan Metzmacher | 3e63af4 | 2020-02-07 15:42:12 +0100 | [diff] [blame] | 60 | if test x"$libdir" = x"$libdevdir"; then |
| 61 | relativelibdir="" |
| 62 | else |
| 63 | relativelibdir="$libdir/" |
| 64 | fi |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 65 | |
| 66 | if test "$show_help" = "yes"; then |
| 67 | cat <<EOF |
| 68 | |
| 69 | Usage: configure [options] |
| 70 | Options: [defaults in brackets after descriptions] |
| 71 | --help print this message |
| 72 | --prefix=PATH install in PATH [$prefix] |
| 73 | --includedir=PATH install headers in PATH [$includedir] |
Stefan Metzmacher | b57dbc2 | 2020-02-06 18:07:56 +0100 | [diff] [blame] | 74 | --libdir=PATH install runtime libraries in PATH [$libdir] |
| 75 | --libdevdir=PATH install developement libraries in PATH [$libdevdir] |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 76 | --mandir=PATH install man pages in PATH [$mandir] |
Johannes Thumshirn | 6e3f6f3 | 2019-11-28 11:26:06 +0100 | [diff] [blame] | 77 | --datadir=PATH install shared data in PATH [$datadir] |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 78 | EOF |
| 79 | exit 0 |
| 80 | fi |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 81 | |
| 82 | TMPC="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.c" |
| 83 | TMPC2="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}-2.c" |
| 84 | TMPO="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.o" |
| 85 | TMPE="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.exe" |
| 86 | |
| 87 | # NB: do not call "exit" in the trap handler; this is buggy with some shells; |
| 88 | # see <1285349658-3122-1-git-send-email-loic.minier@linaro.org> |
| 89 | trap "rm -f $TMPC $TMPC2 $TMPO $TMPE" EXIT INT QUIT TERM |
| 90 | |
| 91 | rm -rf config.log |
| 92 | |
| 93 | config_host_mak="config-host.mak" |
| 94 | config_host_h="config-host.h" |
| 95 | |
| 96 | rm -rf $config_host_mak |
| 97 | rm -rf $config_host_h |
| 98 | |
| 99 | fatal() { |
| 100 | echo $@ |
| 101 | echo "Configure failed, check config.log and/or the above output" |
| 102 | rm -rf $config_host_mak |
| 103 | rm -rf $config_host_h |
| 104 | exit 1 |
| 105 | } |
| 106 | |
| 107 | # Print result for each configuration test |
| 108 | print_config() { |
| 109 | printf "%-30s%s\n" "$1" "$2" |
| 110 | } |
| 111 | |
| 112 | # Default CFLAGS |
| 113 | CFLAGS="-D_GNU_SOURCE -include config-host.h" |
| 114 | BUILD_CFLAGS="" |
| 115 | |
| 116 | # Print configure header at the top of $config_host_h |
| 117 | echo "/*" > $config_host_h |
| 118 | echo " * Automatically generated by configure - do not modify" >> $config_host_h |
| 119 | printf " * Configured with:" >> $config_host_h |
| 120 | printf " * '%s'" "$0" "$@" >> $config_host_h |
| 121 | echo "" >> $config_host_h |
| 122 | echo " */" >> $config_host_h |
| 123 | |
| 124 | echo "# Automatically generated by configure - do not modify" > $config_host_mak |
| 125 | printf "# Configured with:" >> $config_host_mak |
| 126 | printf " '%s'" "$0" "$@" >> $config_host_mak |
| 127 | echo >> $config_host_mak |
| 128 | |
| 129 | do_cc() { |
| 130 | # Run the compiler, capturing its output to the log. |
| 131 | echo $cc "$@" >> config.log |
| 132 | $cc "$@" >> config.log 2>&1 || return $? |
| 133 | # Test passed. If this is an --enable-werror build, rerun |
| 134 | # the test with -Werror and bail out if it fails. This |
| 135 | # makes warning-generating-errors in configure test code |
| 136 | # obvious to developers. |
| 137 | if test "$werror" != "yes"; then |
| 138 | return 0 |
| 139 | fi |
| 140 | # Don't bother rerunning the compile if we were already using -Werror |
| 141 | case "$*" in |
| 142 | *-Werror*) |
| 143 | return 0 |
| 144 | ;; |
| 145 | esac |
| 146 | echo $cc -Werror "$@" >> config.log |
| 147 | $cc -Werror "$@" >> config.log 2>&1 && return $? |
| 148 | echo "ERROR: configure test passed without -Werror but failed with -Werror." |
| 149 | echo "This is probably a bug in the configure script. The failing command" |
| 150 | echo "will be at the bottom of config.log." |
| 151 | fatal "You can run configure with --disable-werror to bypass this check." |
| 152 | } |
| 153 | |
| 154 | compile_object() { |
| 155 | do_cc $CFLAGS -c -o $TMPO $TMPC |
| 156 | } |
| 157 | |
| 158 | compile_prog() { |
| 159 | local_cflags="$1" |
| 160 | local_ldflags="$2 $LIBS" |
| 161 | echo "Compiling test case $3" >> config.log |
| 162 | do_cc $CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags |
| 163 | } |
| 164 | |
| 165 | has() { |
| 166 | type "$1" >/dev/null 2>&1 |
| 167 | } |
| 168 | |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 169 | output_mak() { |
| 170 | echo "$1=$2" >> $config_host_mak |
| 171 | } |
| 172 | |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 173 | output_sym() { |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 174 | output_mak "$1" "y" |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 175 | echo "#define $1" >> $config_host_h |
| 176 | } |
| 177 | |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 178 | print_and_output_mak() { |
| 179 | print_config "$1" "$2" |
| 180 | output_mak "$1" "$2" |
| 181 | } |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 182 | print_and_output_mak "prefix" "$prefix" |
| 183 | print_and_output_mak "includedir" "$includedir" |
| 184 | print_and_output_mak "libdir" "$libdir" |
Stefan Metzmacher | b57dbc2 | 2020-02-06 18:07:56 +0100 | [diff] [blame] | 185 | print_and_output_mak "libdevdir" "$libdevdir" |
Stefan Metzmacher | 3e63af4 | 2020-02-07 15:42:12 +0100 | [diff] [blame] | 186 | print_and_output_mak "relativelibdir" "$relativelibdir" |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 187 | print_and_output_mak "mandir" "$mandir" |
Johannes Thumshirn | 6e3f6f3 | 2019-11-28 11:26:06 +0100 | [diff] [blame] | 188 | print_and_output_mak "datadir" "$datadir" |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 189 | |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 190 | ########################################## |
| 191 | # check for __kernel_rwf_t |
| 192 | __kernel_rwf_t="no" |
| 193 | cat > $TMPC << EOF |
| 194 | #include <linux/fs.h> |
| 195 | int main(int argc, char **argv) |
| 196 | { |
| 197 | __kernel_rwf_t x; |
| 198 | x = 0; |
| 199 | return x; |
| 200 | } |
| 201 | EOF |
| 202 | if compile_prog "" "" "__kernel_rwf_t"; then |
| 203 | __kernel_rwf_t="yes" |
| 204 | fi |
| 205 | print_config "__kernel_rwf_t" "$__kernel_rwf_t" |
| 206 | |
Jens Axboe | e2934e1 | 2019-10-01 10:05:16 -0600 | [diff] [blame] | 207 | ########################################## |
| 208 | # check for __kernel_timespec |
| 209 | __kernel_timespec="no" |
| 210 | cat > $TMPC << EOF |
| 211 | #include <linux/time.h> |
Jens Axboe | d0a15ca | 2020-02-12 21:16:21 -0700 | [diff] [blame] | 212 | #include <linux/time_types.h> |
Jens Axboe | e2934e1 | 2019-10-01 10:05:16 -0600 | [diff] [blame] | 213 | int main(int argc, char **argv) |
| 214 | { |
| 215 | struct __kernel_timespec ts; |
| 216 | ts.tv_sec = 0; |
| 217 | ts.tv_nsec = 1; |
| 218 | return 0; |
| 219 | } |
| 220 | EOF |
| 221 | if compile_prog "" "" "__kernel_timespec"; then |
| 222 | __kernel_timespec="yes" |
| 223 | fi |
| 224 | print_config "__kernel_timespec" "$__kernel_timespec" |
| 225 | |
Jens Axboe | 0ed392e | 2020-01-08 18:52:39 -0700 | [diff] [blame] | 226 | ########################################## |
| 227 | # check for open_how |
| 228 | open_how="no" |
| 229 | cat > $TMPC << EOF |
| 230 | #include <sys/types.h> |
| 231 | #include <sys/stat.h> |
| 232 | #include <fcntl.h> |
| 233 | #include <string.h> |
| 234 | int main(int argc, char **argv) |
| 235 | { |
| 236 | struct open_how how; |
| 237 | how.flags = 0; |
| 238 | how.mode = 0; |
| 239 | how.resolve = 0; |
| 240 | return 0; |
| 241 | } |
| 242 | EOF |
| 243 | if compile_prog "" "" "open_how"; then |
| 244 | open_how="yes" |
| 245 | fi |
| 246 | print_config "open_how" "$open_how" |
| 247 | |
| 248 | |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 249 | ############################################################################# |
| 250 | |
| 251 | if test "$__kernel_rwf_t" = "yes"; then |
| 252 | output_sym "CONFIG_HAVE_KERNEL_RWF_T" |
| 253 | fi |
Jens Axboe | e2934e1 | 2019-10-01 10:05:16 -0600 | [diff] [blame] | 254 | if test "$__kernel_timespec" = "yes"; then |
| 255 | output_sym "CONFIG_HAVE_KERNEL_TIMESPEC" |
| 256 | fi |
Jens Axboe | 0ed392e | 2020-01-08 18:52:39 -0700 | [diff] [blame] | 257 | if test "$open_how" = "yes"; then |
| 258 | output_sym "CONFIG_HAVE_OPEN_HOW" |
| 259 | fi |
Jens Axboe | 4332433 | 2019-12-23 21:34:03 -0700 | [diff] [blame] | 260 | |
| 261 | echo "CC=$cc" >> $config_host_mak |
Jens Axboe | 7169056 | 2020-02-12 22:03:13 -0700 | [diff] [blame] | 262 | |
| 263 | # generate compat.h |
| 264 | compat_h="src/include/liburing/compat.h" |
| 265 | cat > $compat_h << EOF |
| 266 | /* SPDX-License-Identifier: MIT */ |
| 267 | #ifndef LIBURING_COMPAT_H |
| 268 | #define LIBURING_COMPAT_H |
| 269 | |
| 270 | EOF |
| 271 | |
| 272 | if test "$__kernel_rwf_t" != "yes"; then |
| 273 | cat > $compat_h << EOF |
| 274 | typedef int __kernel_rwf_t; |
| 275 | |
| 276 | EOF |
| 277 | fi |
| 278 | if test "$__kernel_timespec" != "yes"; then |
| 279 | cat >> $compat_h << EOF |
| 280 | struct __kernel_timespec { |
| 281 | int64_t tv_sec; |
| 282 | long long tv_nsec; |
| 283 | }; |
| 284 | |
| 285 | EOF |
| 286 | else |
| 287 | cat >> $compat_h << EOF |
| 288 | #include <linux/time_types.h> |
| 289 | |
| 290 | EOF |
| 291 | fi |
| 292 | if test "$open_how" != "yes"; then |
| 293 | cat >> $compat_h << EOF |
| 294 | #include <inttypes.h> |
| 295 | |
| 296 | struct open_how { |
| 297 | uint64_t flags; |
| 298 | uint16_t mode; |
| 299 | uint16_t __padding[3]; |
| 300 | uint64_t resolve; |
| 301 | }; |
| 302 | |
| 303 | EOF |
| 304 | fi |
| 305 | |
| 306 | cat >> $compat_h << EOF |
| 307 | #endif |
| 308 | EOF |