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