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