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 | ;; |
| 25 | --mandir=*) mandir="$optarg" |
| 26 | ;; |
Johannes Thumshirn | 6e3f6f3 | 2019-11-28 11:26:06 +0100 | [diff] [blame] | 27 | --datadir=*) datadir="$optarg" |
| 28 | ;; |
Jens Axboe | 4332433 | 2019-12-23 21:34:03 -0700 | [diff] [blame^] | 29 | --cc=*) cc="$optarg" |
| 30 | ;; |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 31 | *) |
| 32 | echo "ERROR: unkown option $opt" |
| 33 | echo "Try '$0 --help' for more information" |
| 34 | exit 1 |
| 35 | ;; |
| 36 | esac |
| 37 | done |
| 38 | |
| 39 | if test -z "$prefix"; then |
| 40 | prefix=/usr |
| 41 | fi |
| 42 | if test -z "$includedir"; then |
| 43 | includedir="$prefix/include" |
| 44 | fi |
| 45 | if test -z "$libdir"; then |
| 46 | libdir="$prefix/lib" |
| 47 | fi |
| 48 | if test -z "$mandir"; then |
| 49 | mandir="$prefix/man" |
| 50 | fi |
Johannes Thumshirn | 6e3f6f3 | 2019-11-28 11:26:06 +0100 | [diff] [blame] | 51 | if test -z "$datadir"; then |
| 52 | datadir="$prefix/share" |
| 53 | fi |
| 54 | |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 55 | |
| 56 | if test "$show_help" = "yes"; then |
| 57 | cat <<EOF |
| 58 | |
| 59 | Usage: configure [options] |
| 60 | Options: [defaults in brackets after descriptions] |
| 61 | --help print this message |
| 62 | --prefix=PATH install in PATH [$prefix] |
| 63 | --includedir=PATH install headers in PATH [$includedir] |
| 64 | --libdir=PATH install libraries in PATH [$libdir] |
| 65 | --mandir=PATH install man pages in PATH [$mandir] |
Johannes Thumshirn | 6e3f6f3 | 2019-11-28 11:26:06 +0100 | [diff] [blame] | 66 | --datadir=PATH install shared data in PATH [$datadir] |
Kevin Vigor | 413ee33 | 2019-08-28 09:53:10 -0700 | [diff] [blame] | 67 | EOF |
| 68 | exit 0 |
| 69 | fi |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 70 | |
| 71 | TMPC="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.c" |
| 72 | TMPC2="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}-2.c" |
| 73 | TMPO="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.o" |
| 74 | TMPE="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.exe" |
| 75 | |
| 76 | # NB: do not call "exit" in the trap handler; this is buggy with some shells; |
| 77 | # see <1285349658-3122-1-git-send-email-loic.minier@linaro.org> |
| 78 | trap "rm -f $TMPC $TMPC2 $TMPO $TMPE" EXIT INT QUIT TERM |
| 79 | |
| 80 | rm -rf config.log |
| 81 | |
| 82 | config_host_mak="config-host.mak" |
| 83 | config_host_h="config-host.h" |
| 84 | |
| 85 | rm -rf $config_host_mak |
| 86 | rm -rf $config_host_h |
| 87 | |
| 88 | fatal() { |
| 89 | echo $@ |
| 90 | echo "Configure failed, check config.log and/or the above output" |
| 91 | rm -rf $config_host_mak |
| 92 | rm -rf $config_host_h |
| 93 | exit 1 |
| 94 | } |
| 95 | |
| 96 | # Print result for each configuration test |
| 97 | print_config() { |
| 98 | printf "%-30s%s\n" "$1" "$2" |
| 99 | } |
| 100 | |
| 101 | # Default CFLAGS |
| 102 | CFLAGS="-D_GNU_SOURCE -include config-host.h" |
| 103 | BUILD_CFLAGS="" |
| 104 | |
| 105 | # Print configure header at the top of $config_host_h |
| 106 | echo "/*" > $config_host_h |
| 107 | echo " * Automatically generated by configure - do not modify" >> $config_host_h |
| 108 | printf " * Configured with:" >> $config_host_h |
| 109 | printf " * '%s'" "$0" "$@" >> $config_host_h |
| 110 | echo "" >> $config_host_h |
| 111 | echo " */" >> $config_host_h |
| 112 | |
| 113 | echo "# Automatically generated by configure - do not modify" > $config_host_mak |
| 114 | printf "# Configured with:" >> $config_host_mak |
| 115 | printf " '%s'" "$0" "$@" >> $config_host_mak |
| 116 | echo >> $config_host_mak |
| 117 | |
| 118 | do_cc() { |
| 119 | # Run the compiler, capturing its output to the log. |
| 120 | echo $cc "$@" >> config.log |
| 121 | $cc "$@" >> config.log 2>&1 || return $? |
| 122 | # Test passed. If this is an --enable-werror build, rerun |
| 123 | # the test with -Werror and bail out if it fails. This |
| 124 | # makes warning-generating-errors in configure test code |
| 125 | # obvious to developers. |
| 126 | if test "$werror" != "yes"; then |
| 127 | return 0 |
| 128 | fi |
| 129 | # Don't bother rerunning the compile if we were already using -Werror |
| 130 | case "$*" in |
| 131 | *-Werror*) |
| 132 | return 0 |
| 133 | ;; |
| 134 | esac |
| 135 | echo $cc -Werror "$@" >> config.log |
| 136 | $cc -Werror "$@" >> config.log 2>&1 && return $? |
| 137 | echo "ERROR: configure test passed without -Werror but failed with -Werror." |
| 138 | echo "This is probably a bug in the configure script. The failing command" |
| 139 | echo "will be at the bottom of config.log." |
| 140 | fatal "You can run configure with --disable-werror to bypass this check." |
| 141 | } |
| 142 | |
| 143 | compile_object() { |
| 144 | do_cc $CFLAGS -c -o $TMPO $TMPC |
| 145 | } |
| 146 | |
| 147 | compile_prog() { |
| 148 | local_cflags="$1" |
| 149 | local_ldflags="$2 $LIBS" |
| 150 | echo "Compiling test case $3" >> config.log |
| 151 | do_cc $CFLAGS $local_cflags -o $TMPE $TMPC $LDFLAGS $local_ldflags |
| 152 | } |
| 153 | |
| 154 | has() { |
| 155 | type "$1" >/dev/null 2>&1 |
| 156 | } |
| 157 | |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 158 | output_mak() { |
| 159 | echo "$1=$2" >> $config_host_mak |
| 160 | } |
| 161 | |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 162 | output_sym() { |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 163 | output_mak "$1" "y" |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 164 | echo "#define $1" >> $config_host_h |
| 165 | } |
| 166 | |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 167 | print_and_output_mak() { |
| 168 | print_config "$1" "$2" |
| 169 | output_mak "$1" "$2" |
| 170 | } |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 171 | print_and_output_mak "prefix" "$prefix" |
| 172 | print_and_output_mak "includedir" "$includedir" |
| 173 | print_and_output_mak "libdir" "$libdir" |
| 174 | print_and_output_mak "mandir" "$mandir" |
Johannes Thumshirn | 6e3f6f3 | 2019-11-28 11:26:06 +0100 | [diff] [blame] | 175 | print_and_output_mak "datadir" "$datadir" |
Stefan Hajnoczi | fd26c1a | 2019-05-25 09:58:30 +0100 | [diff] [blame] | 176 | |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 177 | ########################################## |
| 178 | # check for __kernel_rwf_t |
| 179 | __kernel_rwf_t="no" |
| 180 | cat > $TMPC << EOF |
| 181 | #include <linux/fs.h> |
| 182 | int main(int argc, char **argv) |
| 183 | { |
| 184 | __kernel_rwf_t x; |
| 185 | x = 0; |
| 186 | return x; |
| 187 | } |
| 188 | EOF |
| 189 | if compile_prog "" "" "__kernel_rwf_t"; then |
| 190 | __kernel_rwf_t="yes" |
| 191 | fi |
| 192 | print_config "__kernel_rwf_t" "$__kernel_rwf_t" |
| 193 | |
Jens Axboe | e2934e1 | 2019-10-01 10:05:16 -0600 | [diff] [blame] | 194 | ########################################## |
| 195 | # check for __kernel_timespec |
| 196 | __kernel_timespec="no" |
| 197 | cat > $TMPC << EOF |
| 198 | #include <linux/time.h> |
| 199 | int main(int argc, char **argv) |
| 200 | { |
| 201 | struct __kernel_timespec ts; |
| 202 | ts.tv_sec = 0; |
| 203 | ts.tv_nsec = 1; |
| 204 | return 0; |
| 205 | } |
| 206 | EOF |
| 207 | if compile_prog "" "" "__kernel_timespec"; then |
| 208 | __kernel_timespec="yes" |
| 209 | fi |
| 210 | print_config "__kernel_timespec" "$__kernel_timespec" |
| 211 | |
Jens Axboe | f16b83b | 2019-01-15 11:14:43 -0700 | [diff] [blame] | 212 | ############################################################################# |
| 213 | |
| 214 | if test "$__kernel_rwf_t" = "yes"; then |
| 215 | output_sym "CONFIG_HAVE_KERNEL_RWF_T" |
| 216 | fi |
Jens Axboe | e2934e1 | 2019-10-01 10:05:16 -0600 | [diff] [blame] | 217 | if test "$__kernel_timespec" = "yes"; then |
| 218 | output_sym "CONFIG_HAVE_KERNEL_TIMESPEC" |
| 219 | fi |
Jens Axboe | 4332433 | 2019-12-23 21:34:03 -0700 | [diff] [blame^] | 220 | |
| 221 | echo "CC=$cc" >> $config_host_mak |