Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | usage () { |
| 4 | cat <<EOF |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 5 | Usage: $0 [OPTION]... [VAR=VALUE]... [TARGET] |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 6 | |
| 7 | To assign environment variables (e.g., CC, CFLAGS...), specify them as |
| 8 | VAR=VALUE. See below for descriptions of some of the useful variables. |
| 9 | |
| 10 | Defaults for the options are specified in brackets. |
| 11 | |
Petr Hosek | 2f853dd | 2015-11-18 12:07:32 -0800 | [diff] [blame] | 12 | Configuration: |
| 13 | --srcdir=DIR source directory [detected] |
| 14 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 15 | Installation directories: |
| 16 | --prefix=PREFIX main installation prefix [/usr/local/musl] |
| 17 | --exec-prefix=EPREFIX installation prefix for executable files [PREFIX] |
| 18 | |
| 19 | Fine tuning of the installation directories: |
| 20 | --bindir=DIR user executables [EPREFIX/bin] |
| 21 | --libdir=DIR library files for the linker [PREFIX/lib] |
| 22 | --includedir=DIR include files for the C compiler [PREFIX/include] |
| 23 | --syslibdir=DIR location for the dynamic linker [/lib] |
| 24 | |
| 25 | System types: |
| 26 | --target=TARGET configure to run on target TARGET [detected] |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 27 | --host=HOST same as --target |
Rich Felker | 2d49c22 | 2016-04-29 19:50:33 -0400 | [diff] [blame] | 28 | --build=BUILD build system type; used only to infer cross-compiling |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 29 | |
| 30 | Optional features: |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 31 | --enable-optimize=... optimize listed components for speed over size [auto] |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 32 | --enable-debug build with debugging information [disabled] |
| 33 | --enable-warnings build with recommended warnings flags [disabled] |
Rich Felker | dc2f368 | 2017-08-11 00:17:00 -0400 | [diff] [blame] | 34 | --enable-visibility use global visibility options to optimize PIC [no] |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 35 | --enable-wrapper=... build given musl toolchain wrapper [auto] |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 36 | --disable-shared inhibit building shared library [enabled] |
| 37 | --disable-static inhibit building static library [enabled] |
| 38 | |
| 39 | Some influential environment variables: |
| 40 | CC C compiler command [detected] |
| 41 | CFLAGS C compiler flags [-Os -pipe ...] |
Rich Felker | 94e920d | 2012-08-14 22:50:16 -0400 | [diff] [blame] | 42 | CROSS_COMPILE prefix for cross compiler and tools [none] |
Rich Felker | 2c1cd23 | 2012-09-10 15:30:52 -0400 | [diff] [blame] | 43 | LIBCC compiler runtime library [detected] |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 44 | |
| 45 | Use these variables to override the choices made by configure. |
| 46 | |
| 47 | EOF |
| 48 | exit 0 |
| 49 | } |
| 50 | |
| 51 | # Helper functions |
| 52 | |
Rich Felker | 453f462 | 2013-08-16 18:19:47 -0400 | [diff] [blame] | 53 | quote () { |
| 54 | tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; } |
| 55 | $1 |
| 56 | EOF |
Rich Felker | e449974 | 2013-08-20 13:51:46 -0400 | [diff] [blame] | 57 | printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#" |
Rich Felker | 453f462 | 2013-08-16 18:19:47 -0400 | [diff] [blame] | 58 | } |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 59 | echo () { printf "%s\n" "$*" ; } |
| 60 | fail () { echo "$*" ; exit 1 ; } |
| 61 | fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; } |
| 62 | cmdexists () { type "$1" >/dev/null 2>&1 ; } |
| 63 | trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; } |
| 64 | |
Rich Felker | 3d9e3a3 | 2012-11-08 17:20:50 -0500 | [diff] [blame] | 65 | stripdir () { |
| 66 | while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 67 | } |
| 68 | |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 69 | trycppif () { |
| 70 | printf "checking preprocessor condition %s... " "$1" |
Rich Felker | df06578 | 2013-07-18 20:37:19 -0400 | [diff] [blame] | 71 | echo "typedef int x;" > "$tmpc" |
| 72 | echo "#if $1" >> "$tmpc" |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 73 | echo "#error yes" >> "$tmpc" |
| 74 | echo "#endif" >> "$tmpc" |
| 75 | if $CC $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
| 76 | printf "false\n" |
| 77 | return 1 |
| 78 | else |
| 79 | printf "true\n" |
| 80 | return 0 |
| 81 | fi |
| 82 | } |
| 83 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 84 | tryflag () { |
| 85 | printf "checking whether compiler accepts %s... " "$2" |
| 86 | echo "typedef int x;" > "$tmpc" |
Shiz | fc431d3 | 2015-05-28 05:52:22 +0200 | [diff] [blame] | 87 | if $CC $CFLAGS_TRY $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 88 | printf "yes\n" |
| 89 | eval "$1=\"\${$1} \$2\"" |
| 90 | eval "$1=\${$1# }" |
| 91 | return 0 |
| 92 | else |
| 93 | printf "no\n" |
| 94 | return 1 |
| 95 | fi |
| 96 | } |
| 97 | |
Rich Felker | 08f70a3 | 2012-06-06 20:45:52 -0400 | [diff] [blame] | 98 | tryldflag () { |
| 99 | printf "checking whether linker accepts %s... " "$2" |
Rich Felker | 67a0383 | 2012-06-07 00:23:58 -0400 | [diff] [blame] | 100 | echo "typedef int x;" > "$tmpc" |
Shiz | fc431d3 | 2015-05-28 05:52:22 +0200 | [diff] [blame] | 101 | if $CC $LDFLAGS_TRY -nostdlib -shared "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
Rich Felker | 08f70a3 | 2012-06-06 20:45:52 -0400 | [diff] [blame] | 102 | printf "yes\n" |
| 103 | eval "$1=\"\${$1} \$2\"" |
| 104 | eval "$1=\${$1# }" |
| 105 | return 0 |
| 106 | else |
| 107 | printf "no\n" |
| 108 | return 1 |
| 109 | fi |
| 110 | } |
| 111 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 112 | |
| 113 | |
| 114 | # Beginning of actual script |
| 115 | |
Rich Felker | 08f70a3 | 2012-06-06 20:45:52 -0400 | [diff] [blame] | 116 | CFLAGS_C99FSE= |
| 117 | CFLAGS_AUTO= |
Rich Felker | 4a1f55e | 2013-08-01 17:12:23 -0400 | [diff] [blame] | 118 | CFLAGS_MEMOPS= |
Rich Felker | 1ef849c | 2015-04-13 20:13:10 -0400 | [diff] [blame] | 119 | CFLAGS_NOSSP= |
Shiz | fc431d3 | 2015-05-28 05:52:22 +0200 | [diff] [blame] | 120 | CFLAGS_TRY= |
Rich Felker | 08f70a3 | 2012-06-06 20:45:52 -0400 | [diff] [blame] | 121 | LDFLAGS_AUTO= |
Shiz | fc431d3 | 2015-05-28 05:52:22 +0200 | [diff] [blame] | 122 | LDFLAGS_TRY= |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 123 | OPTIMIZE_GLOBS= |
Petr Hosek | 2f853dd | 2015-11-18 12:07:32 -0800 | [diff] [blame] | 124 | srcdir= |
Rich Felker | 3d9e3a3 | 2012-11-08 17:20:50 -0500 | [diff] [blame] | 125 | prefix=/usr/local/musl |
| 126 | exec_prefix='$(prefix)' |
| 127 | bindir='$(exec_prefix)/bin' |
| 128 | libdir='$(prefix)/lib' |
| 129 | includedir='$(prefix)/include' |
| 130 | syslibdir='/lib' |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 131 | tools= |
| 132 | tool_libs= |
Rich Felker | 2d49c22 | 2016-04-29 19:50:33 -0400 | [diff] [blame] | 133 | build= |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 134 | target= |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 135 | optimize=auto |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 136 | debug=no |
Rich Felker | 3d9e3a3 | 2012-11-08 17:20:50 -0500 | [diff] [blame] | 137 | warnings=no |
Rich Felker | dc2f368 | 2017-08-11 00:17:00 -0400 | [diff] [blame] | 138 | visibility=no |
Rich Felker | d79b277 | 2014-06-10 12:11:12 -0400 | [diff] [blame] | 139 | shared=auto |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 140 | static=yes |
Rich Felker | 9ca4dae | 2014-05-19 10:33:28 -0400 | [diff] [blame] | 141 | wrapper=auto |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 142 | gcc_wrapper=no |
Shiz | fb58545 | 2015-06-28 23:08:21 +0200 | [diff] [blame] | 143 | clang_wrapper=no |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 144 | |
| 145 | for arg ; do |
| 146 | case "$arg" in |
Rich Felker | 47314f1 | 2016-02-02 21:14:09 -0500 | [diff] [blame] | 147 | --help|-h) usage ;; |
Petr Hosek | 2f853dd | 2015-11-18 12:07:32 -0800 | [diff] [blame] | 148 | --srcdir=*) srcdir=${arg#*=} ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 149 | --prefix=*) prefix=${arg#*=} ;; |
| 150 | --exec-prefix=*) exec_prefix=${arg#*=} ;; |
| 151 | --bindir=*) bindir=${arg#*=} ;; |
| 152 | --libdir=*) libdir=${arg#*=} ;; |
| 153 | --includedir=*) includedir=${arg#*=} ;; |
| 154 | --syslibdir=*) syslibdir=${arg#*=} ;; |
| 155 | --enable-shared|--enable-shared=yes) shared=yes ;; |
| 156 | --disable-shared|--enable-shared=no) shared=no ;; |
| 157 | --enable-static|--enable-static=yes) static=yes ;; |
| 158 | --disable-static|--enable-static=no) static=no ;; |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 159 | --enable-optimize) optimize=yes ;; |
| 160 | --enable-optimize=*) optimize=${arg#*=} ;; |
| 161 | --disable-optimize) optimize=no ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 162 | --enable-debug|--enable-debug=yes) debug=yes ;; |
| 163 | --disable-debug|--enable-debug=no) debug=no ;; |
| 164 | --enable-warnings|--enable-warnings=yes) warnings=yes ;; |
| 165 | --disable-warnings|--enable-warnings=no) warnings=no ;; |
Rich Felker | dc2f368 | 2017-08-11 00:17:00 -0400 | [diff] [blame] | 166 | --enable-visibility=auto) visibility=auto ;; |
Rich Felker | de2b67f | 2015-04-19 22:05:29 -0400 | [diff] [blame] | 167 | --enable-visibility|--enable-visibility=yes) visibility=yes ;; |
| 168 | --disable-visibility|--enable-visibility=no) visibility=no ;; |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 169 | --enable-wrapper|--enable-wrapper=yes) wrapper=detect ;; |
Shiz | fb58545 | 2015-06-28 23:08:21 +0200 | [diff] [blame] | 170 | --enable-wrapper=all) wrapper=yes ; gcc_wrapper=yes ; clang_wrapper=yes ;; |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 171 | --enable-wrapper=gcc) wrapper=yes ; gcc_wrapper=yes ;; |
Shiz | fb58545 | 2015-06-28 23:08:21 +0200 | [diff] [blame] | 172 | --enable-wrapper=clang) wrapper=yes ; clang_wrapper=yes ;; |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 173 | --disable-wrapper|--enable-wrapper=no) wrapper=no ;; |
| 174 | --enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ; gcc_wrapper=yes ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 175 | --disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;; |
LeMay, Michael | 6bc7d9c | 2016-05-04 03:29:42 +0000 | [diff] [blame] | 176 | --enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;; |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 177 | --host=*|--target=*) target=${arg#*=} ;; |
Rich Felker | 2d49c22 | 2016-04-29 19:50:33 -0400 | [diff] [blame] | 178 | --build=*) build=${arg#*=} ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 179 | -* ) echo "$0: unknown option $arg" ;; |
| 180 | CC=*) CC=${arg#*=} ;; |
| 181 | CFLAGS=*) CFLAGS=${arg#*=} ;; |
| 182 | CPPFLAGS=*) CPPFLAGS=${arg#*=} ;; |
| 183 | LDFLAGS=*) LDFLAGS=${arg#*=} ;; |
Rich Felker | 94e920d | 2012-08-14 22:50:16 -0400 | [diff] [blame] | 184 | CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;; |
Rich Felker | 2c1cd23 | 2012-09-10 15:30:52 -0400 | [diff] [blame] | 185 | LIBCC=*) LIBCC=${arg#*=} ;; |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 186 | *=*) ;; |
Rich Felker | 2d49c22 | 2016-04-29 19:50:33 -0400 | [diff] [blame] | 187 | *) build=$arg ; target=$arg ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 188 | esac |
| 189 | done |
| 190 | |
Petr Hosek | 2f853dd | 2015-11-18 12:07:32 -0800 | [diff] [blame] | 191 | for i in srcdir prefix exec_prefix bindir libdir includedir syslibdir ; do |
Rich Felker | 3d9e3a3 | 2012-11-08 17:20:50 -0500 | [diff] [blame] | 192 | stripdir $i |
| 193 | done |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 194 | |
| 195 | # |
Petr Hosek | 2f853dd | 2015-11-18 12:07:32 -0800 | [diff] [blame] | 196 | # Get the source dir for out-of-tree builds |
| 197 | # |
| 198 | if test -z "$srcdir" ; then |
| 199 | srcdir="${0%/configure}" |
| 200 | stripdir srcdir |
| 201 | fi |
| 202 | abs_builddir="$(pwd)" || fail "$0: cannot determine working directory" |
| 203 | abs_srcdir="$(cd $srcdir && pwd)" || fail "$0: invalid source directory $srcdir" |
| 204 | test "$abs_srcdir" = "$abs_builddir" && srcdir=. |
| 205 | test "$srcdir" != "." -a -f Makefile -a ! -h Makefile && fail "$0: Makefile already exists in the working directory" |
| 206 | |
| 207 | # |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 208 | # Get a temp filename we can use |
| 209 | # |
| 210 | i=0 |
| 211 | set -C |
| 212 | while : ; do i=$(($i+1)) |
| 213 | tmpc="./conf$$-$PPID-$i.c" |
Rich Felker | 6c0cba8 | 2012-11-18 23:15:47 -0500 | [diff] [blame] | 214 | 2>|/dev/null > "$tmpc" && break |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 215 | test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc" |
| 216 | done |
| 217 | set +C |
| 218 | trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP |
| 219 | |
| 220 | # |
Rich Felker | 2d49c22 | 2016-04-29 19:50:33 -0400 | [diff] [blame] | 221 | # Check whether we are cross-compiling, and set a default |
| 222 | # CROSS_COMPILE prefix if none was provided. |
| 223 | # |
| 224 | test "$target" && \ |
| 225 | test "$target" != "$build" && \ |
| 226 | test -z "$CROSS_COMPILE" && \ |
| 227 | CROSS_COMPILE="$target-" |
| 228 | |
| 229 | # |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 230 | # Find a C compiler to use |
| 231 | # |
| 232 | printf "checking for C compiler... " |
Rich Felker | 94e920d | 2012-08-14 22:50:16 -0400 | [diff] [blame] | 233 | trycc ${CROSS_COMPILE}gcc |
| 234 | trycc ${CROSS_COMPILE}c99 |
| 235 | trycc ${CROSS_COMPILE}cc |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 236 | printf "%s\n" "$CC" |
| 237 | test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; } |
| 238 | |
Rich Felker | 8945667 | 2014-05-12 14:22:57 -0400 | [diff] [blame] | 239 | printf "checking whether C compiler works... " |
| 240 | echo "typedef int x;" > "$tmpc" |
| 241 | if output=$($CC $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" 2>&1) ; then |
| 242 | printf "yes\n" |
| 243 | else |
| 244 | printf "no; compiler output follows:\n%s\n" "$output" |
| 245 | exit 1 |
| 246 | fi |
| 247 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 248 | # |
Shiz | fc431d3 | 2015-05-28 05:52:22 +0200 | [diff] [blame] | 249 | # Figure out options to force errors on unknown flags. |
| 250 | # |
| 251 | tryflag CFLAGS_TRY -Werror=unknown-warning-option |
| 252 | tryflag CFLAGS_TRY -Werror=unused-command-line-argument |
Dmitry Golovin | 9d12a6a | 2017-06-09 17:10:47 +0300 | [diff] [blame] | 253 | tryflag CFLAGS_TRY -Werror=ignored-optimization-argument |
Shiz | fc431d3 | 2015-05-28 05:52:22 +0200 | [diff] [blame] | 254 | tryldflag LDFLAGS_TRY -Werror=unknown-warning-option |
| 255 | tryldflag LDFLAGS_TRY -Werror=unused-command-line-argument |
| 256 | |
| 257 | # |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 258 | # Need to know if the compiler is gcc or clang to decide which toolchain |
| 259 | # wrappers to build. |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 260 | # |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 261 | printf "checking for C compiler family... " |
| 262 | cc_ver="$(LC_ALL=C $CC -v 2>&1)" |
| 263 | cc_family=unknown |
| 264 | if fnmatch '*gcc\ version*' "$cc_ver" ; then |
| 265 | cc_family=gcc |
Shiz | fb58545 | 2015-06-28 23:08:21 +0200 | [diff] [blame] | 266 | elif fnmatch '*clang\ version*' "$cc_ver" ; then |
| 267 | cc_family=clang |
Rich Felker | 9ca4dae | 2014-05-19 10:33:28 -0400 | [diff] [blame] | 268 | fi |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 269 | echo "$cc_family" |
Rich Felker | 9ca4dae | 2014-05-19 10:33:28 -0400 | [diff] [blame] | 270 | |
| 271 | # |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 272 | # Figure out toolchain wrapper to build |
Rich Felker | 9ca4dae | 2014-05-19 10:33:28 -0400 | [diff] [blame] | 273 | # |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 274 | if test "$wrapper" = auto -o "$wrapper" = detect ; then |
Shiz | f8db6f7 | 2015-06-28 23:08:20 +0200 | [diff] [blame] | 275 | echo "#include <stdlib.h>" > "$tmpc" |
| 276 | echo "#if ! __GLIBC__" >> "$tmpc" |
| 277 | echo "#error no" >> "$tmpc" |
| 278 | echo "#endif" >> "$tmpc" |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 279 | printf "checking for toolchain wrapper to build... " |
Shiz | f8db6f7 | 2015-06-28 23:08:20 +0200 | [diff] [blame] | 280 | if test "$wrapper" = auto && ! $CC -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
| 281 | echo "none" |
| 282 | elif test "$cc_family" = gcc ; then |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 283 | gcc_wrapper=yes |
Shiz | f8db6f7 | 2015-06-28 23:08:20 +0200 | [diff] [blame] | 284 | echo "gcc" |
Shiz | fb58545 | 2015-06-28 23:08:21 +0200 | [diff] [blame] | 285 | elif test "$cc_family" = clang ; then |
| 286 | clang_wrapper=yes |
| 287 | echo "clang" |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 288 | else |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 289 | echo "none" |
| 290 | if test "$wrapper" = detect ; then |
| 291 | fail "$0: could not find an appropriate toolchain wrapper" |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 292 | fi |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 293 | fi |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 294 | fi |
| 295 | |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 296 | if test "$gcc_wrapper" = yes ; then |
Petr Hosek | 2f853dd | 2015-11-18 12:07:32 -0800 | [diff] [blame] | 297 | tools="$tools obj/musl-gcc" |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 298 | tool_libs="$tool_libs lib/musl-gcc.specs" |
| 299 | fi |
Shiz | fb58545 | 2015-06-28 23:08:21 +0200 | [diff] [blame] | 300 | if test "$clang_wrapper" = yes ; then |
Petr Hosek | 2f853dd | 2015-11-18 12:07:32 -0800 | [diff] [blame] | 301 | tools="$tools obj/musl-clang obj/ld.musl-clang" |
Shiz | fb58545 | 2015-06-28 23:08:21 +0200 | [diff] [blame] | 302 | fi |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 303 | |
| 304 | # |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 305 | # Find the target architecture |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 306 | # |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 307 | printf "checking target system type... " |
Rich Felker | 01e5a1b | 2012-10-18 23:02:53 -0400 | [diff] [blame] | 308 | test -n "$target" || target=$($CC -dumpmachine 2>/dev/null) || target=unknown |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 309 | printf "%s\n" "$target" |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 310 | |
| 311 | # |
| 312 | # Convert to just ARCH |
| 313 | # |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 314 | case "$target" in |
Rich Felker | 0b8f0c5 | 2014-02-28 13:12:40 -0500 | [diff] [blame] | 315 | # Catch these early to simplify matching for 32-bit archs |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 316 | arm*) ARCH=arm ;; |
Szabolcs Nagy | 01ef3dd | 2015-03-10 21:18:41 +0000 | [diff] [blame] | 317 | aarch64*) ARCH=aarch64 ;; |
Rich Felker | 4c101e1 | 2016-02-19 00:10:23 -0500 | [diff] [blame] | 318 | i?86-nt32*) ARCH=nt32 ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 319 | i?86*) ARCH=i386 ;; |
Rich Felker | f162c06 | 2014-03-17 17:38:22 -0400 | [diff] [blame] | 320 | x86_64-x32*|x32*|x86_64*x32) ARCH=x32 ;; |
Rich Felker | 4c101e1 | 2016-02-19 00:10:23 -0500 | [diff] [blame] | 321 | x86_64-nt64*) ARCH=nt64 ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 322 | x86_64*) ARCH=x86_64 ;; |
Szabolcs Nagy | fff8801 | 2016-08-24 12:40:10 +0200 | [diff] [blame] | 323 | mips64*|mipsisa64*) ARCH=mips64 ;; |
Rich Felker | 0b8f0c5 | 2014-02-28 13:12:40 -0500 | [diff] [blame] | 324 | mips*) ARCH=mips ;; |
| 325 | microblaze*) ARCH=microblaze ;; |
Stefan Kristiansson | 200d154 | 2014-07-17 22:09:10 +0300 | [diff] [blame] | 326 | or1k*) ARCH=or1k ;; |
Bobby Bingham | c0ede9e | 2016-04-30 19:18:17 -0500 | [diff] [blame] | 327 | powerpc64*) ARCH=powerpc64 ;; |
Rich Felker | 0b8f0c5 | 2014-02-28 13:12:40 -0500 | [diff] [blame] | 328 | powerpc*) ARCH=powerpc ;; |
| 329 | sh[1-9bel-]*|sh|superh*) ARCH=sh ;; |
Bobby Bingham | 1509494 | 2016-11-11 21:52:05 -0600 | [diff] [blame] | 330 | s390x*) ARCH=s390x ;; |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 331 | unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;; |
| 332 | *) fail "$0: unknown or unsupported target \"$target\"" ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 333 | esac |
| 334 | |
| 335 | # |
| 336 | # Try to get a conforming C99 freestanding environment |
| 337 | # |
| 338 | tryflag CFLAGS_C99FSE -std=c99 |
| 339 | tryflag CFLAGS_C99FSE -nostdinc |
| 340 | tryflag CFLAGS_C99FSE -ffreestanding \ |
| 341 | || tryflag CFLAGS_C99FSE -fno-builtin |
| 342 | tryflag CFLAGS_C99FSE -fexcess-precision=standard \ |
Rich Felker | 2121b8a | 2012-07-03 23:53:05 -0400 | [diff] [blame] | 343 | || { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; } |
Rich Felker | b4ccc3c | 2012-05-05 17:18:31 -0400 | [diff] [blame] | 344 | tryflag CFLAGS_C99FSE -frounding-math |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 345 | |
Rich Felker | 4a1f55e | 2013-08-01 17:12:23 -0400 | [diff] [blame] | 346 | # |
Rich Felker | 06ceee8 | 2013-08-27 17:33:47 -0400 | [diff] [blame] | 347 | # We may use the may_alias attribute if __GNUC__ is defined, so |
| 348 | # if the compiler defines __GNUC__ but does not provide it, |
| 349 | # it must be defined away as part of the CFLAGS. |
| 350 | # |
| 351 | printf "checking whether compiler needs attribute((may_alias)) suppression... " |
| 352 | cat > "$tmpc" <<EOF |
| 353 | typedef int |
| 354 | #ifdef __GNUC__ |
| 355 | __attribute__((__may_alias__)) |
| 356 | #endif |
| 357 | x; |
| 358 | EOF |
Rich Felker | e1d9989 | 2016-01-27 19:01:21 -0500 | [diff] [blame] | 359 | if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS \ |
Rich Felker | 06ceee8 | 2013-08-27 17:33:47 -0400 | [diff] [blame] | 360 | -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
| 361 | printf "no\n" |
| 362 | else |
| 363 | printf "yes\n" |
| 364 | CFLAGS_C99FSE="$CFLAGS_C99FSE -D__may_alias__=" |
| 365 | fi |
| 366 | |
| 367 | # |
Rich Felker | bc0c484 | 2015-10-23 00:01:01 -0400 | [diff] [blame] | 368 | # The GNU toolchain defaults to assuming unmarked files need an |
| 369 | # executable stack, potentially exposing vulnerabilities in programs |
| 370 | # linked with such object files. Fix this. |
| 371 | # |
| 372 | tryflag CFLAGS_C99FSE -Wa,--noexecstack |
| 373 | |
| 374 | # |
Rich Felker | 1ef849c | 2015-04-13 20:13:10 -0400 | [diff] [blame] | 375 | # Check for options to disable stack protector, which needs to be |
| 376 | # disabled for a few early-bootstrap translation units. If not found, |
| 377 | # this is not an error; we assume the toolchain does not do ssp. |
| 378 | # |
| 379 | tryflag CFLAGS_NOSSP -fno-stack-protector |
| 380 | |
| 381 | # |
Rich Felker | 4a1f55e | 2013-08-01 17:12:23 -0400 | [diff] [blame] | 382 | # Check for options that may be needed to prevent the compiler from |
| 383 | # generating self-referential versions of memcpy,, memmove, memcmp, |
| 384 | # and memset. Really, we should add a check to determine if this |
| 385 | # option is sufficient, and if not, add a macro to cripple these |
| 386 | # functions with volatile... |
| 387 | # |
| 388 | tryflag CFLAGS_MEMOPS -fno-tree-loop-distribute-patterns |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 389 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 390 | # |
Rich Felker | 4ad3588 | 2014-06-20 16:10:48 -0400 | [diff] [blame] | 391 | # Enable debugging if requessted. |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 392 | # |
Rich Felker | 4ad3588 | 2014-06-20 16:10:48 -0400 | [diff] [blame] | 393 | test "$debug" = yes && CFLAGS_AUTO=-g |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 394 | |
| 395 | # |
Alex Dowad | 35b3312 | 2015-07-10 15:03:24 +0200 | [diff] [blame] | 396 | # Preprocess asm files to add extra debugging information if debug is |
| 397 | # enabled, our assembler supports the needed directives, and the |
| 398 | # preprocessing script has been written for our architecture. |
| 399 | # |
| 400 | printf "checking whether we should preprocess assembly to add debugging information... " |
| 401 | if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" && |
| 402 | test -f "tools/add-cfi.$ARCH.awk" && |
| 403 | printf ".file 1 \"srcfile.s\"\n.line 1\n.cfi_startproc\n.cfi_endproc" | $CC -g -x assembler -c -o /dev/null 2>/dev/null - |
| 404 | then |
| 405 | ADD_CFI=yes |
| 406 | else |
| 407 | ADD_CFI=no |
| 408 | fi |
| 409 | printf "%s\n" "$ADD_CFI" |
| 410 | |
| 411 | # |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 412 | # Possibly add a -O option to CFLAGS and select modules to optimize with |
| 413 | # -O3 based on the status of --enable-optimize and provided CFLAGS. |
| 414 | # |
| 415 | printf "checking for optimization settings... " |
| 416 | case "x$optimize" in |
| 417 | xauto) |
| 418 | if fnmatch '-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then |
| 419 | printf "using provided CFLAGS\n" ;optimize=no |
| 420 | else |
| 421 | printf "using defaults\n" ; optimize=yes |
| 422 | fi |
| 423 | ;; |
| 424 | xsize|xnone) printf "minimize size\n" ; optimize=size ;; |
| 425 | xno|x) printf "disabled\n" ; optimize=no ;; |
| 426 | *) printf "custom\n" ;; |
| 427 | esac |
| 428 | |
| 429 | test "$optimize" = no || tryflag CFLAGS_AUTO -Os || tryflag CFLAGS_AUTO -O2 |
Rich Felker | 43d2531 | 2013-07-24 23:21:45 -0400 | [diff] [blame] | 430 | test "$optimize" = yes && optimize="internal,malloc,string" |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 431 | |
| 432 | if fnmatch 'no|size' "$optimize" ; then : |
| 433 | else |
| 434 | printf "components to be optimized for speed:" |
| 435 | while test "$optimize" ; do |
| 436 | case "$optimize" in |
| 437 | *,*) this=${optimize%%,*} optimize=${optimize#*,} ;; |
| 438 | *) this=$optimize optimize= |
| 439 | esac |
| 440 | printf " $this" |
| 441 | case "$this" in |
| 442 | */*.c) ;; |
| 443 | */*) this=$this*.c ;; |
| 444 | *) this=$this/*.c ;; |
| 445 | esac |
| 446 | OPTIMIZE_GLOBS="$OPTIMIZE_GLOBS $this" |
| 447 | done |
| 448 | OPTIMIZE_GLOBS=${OPTIMIZE_GLOBS# } |
| 449 | printf "\n" |
| 450 | fi |
| 451 | |
| 452 | # Always try -pipe |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 453 | tryflag CFLAGS_AUTO -pipe |
| 454 | |
| 455 | # |
Rich Felker | b439c05 | 2012-08-29 09:36:02 -0400 | [diff] [blame] | 456 | # If debugging is disabled, omit frame pointer. Modern GCC does this |
| 457 | # anyway on most archs even when debugging is enabled since the frame |
| 458 | # pointer is no longer needed for debugging. |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 459 | # |
| 460 | if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then : |
| 461 | else |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 462 | tryflag CFLAGS_AUTO -fomit-frame-pointer |
| 463 | fi |
| 464 | |
| 465 | # |
Rich Felker | b439c05 | 2012-08-29 09:36:02 -0400 | [diff] [blame] | 466 | # Modern GCC wants to put DWARF tables (used for debugging and |
| 467 | # unwinding) in the loaded part of the program where they are |
| 468 | # unstrippable. These options force them back to debug sections (and |
| 469 | # cause them not to get generated at all if debugging is off). |
| 470 | # |
| 471 | tryflag CFLAGS_AUTO -fno-unwind-tables |
| 472 | tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables |
| 473 | |
| 474 | # |
Rich Felker | 27c1ecc | 2015-11-04 13:24:11 -0500 | [diff] [blame] | 475 | # Attempt to put each function and each data object in its own |
| 476 | # section. This both allows additional size optimizations at link |
| 477 | # time and works around a dangerous class of compiler/assembler bugs |
| 478 | # whereby relative address expressions are constant-folded by the |
| 479 | # assembler even when one or more of the symbols involved is |
| 480 | # replaceable. See gas pr 18561 and gcc pr 66609, 68178, etc. |
| 481 | # |
| 482 | tryflag CFLAGS_AUTO -ffunction-sections |
| 483 | tryflag CFLAGS_AUTO -fdata-sections |
| 484 | |
| 485 | # |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 486 | # On x86, make sure we don't have incompatible instruction set |
| 487 | # extensions enabled by default. This is bad for making static binaries. |
| 488 | # We cheat and use i486 rather than i386 because i386 really does not |
| 489 | # work anyway (issues with atomic ops). |
Andre McCurdy | a6274a1 | 2015-04-21 10:34:05 -0700 | [diff] [blame] | 490 | # Some build environments pass -march and -mtune options via CC, so |
| 491 | # check both CC and CFLAGS. |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 492 | # |
| 493 | if test "$ARCH" = "i386" ; then |
Andre McCurdy | a6274a1 | 2015-04-21 10:34:05 -0700 | [diff] [blame] | 494 | fnmatch '-march=*|*\ -march=*' "$CC $CFLAGS" || tryldflag CFLAGS_AUTO -march=i486 |
| 495 | fnmatch '-mtune=*|*\ -mtune=*' "$CC $CFLAGS" || tryldflag CFLAGS_AUTO -mtune=generic |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 496 | fi |
| 497 | |
Rich Felker | 2384f27 | 2012-12-11 23:28:31 -0500 | [diff] [blame] | 498 | # |
| 499 | # Even with -std=c99, gcc accepts some constructs which are constraint |
| 500 | # violations. We want to treat these as errors regardless of whether |
| 501 | # other purely stylistic warnings are enabled -- especially implicit |
| 502 | # function declarations, which are a dangerous programming error. |
| 503 | # |
| 504 | tryflag CFLAGS_AUTO -Werror=implicit-function-declaration |
| 505 | tryflag CFLAGS_AUTO -Werror=implicit-int |
| 506 | tryflag CFLAGS_AUTO -Werror=pointer-sign |
| 507 | tryflag CFLAGS_AUTO -Werror=pointer-arith |
| 508 | |
Dmitry Golovin | 9d12a6a | 2017-06-09 17:10:47 +0300 | [diff] [blame] | 509 | # |
| 510 | # GCC ignores unused arguements by default, but Clang needs this extra |
| 511 | # parameter to stop printing warnings about LDFLAGS passed during |
| 512 | # compiling stage and CFLAGS passed during linking stage. |
| 513 | # |
| 514 | tryflag CFLAGS_AUTO -Qunused-arguments |
| 515 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 516 | if test "x$warnings" = xyes ; then |
| 517 | tryflag CFLAGS_AUTO -Wall |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 518 | tryflag CFLAGS_AUTO -Wno-parentheses |
| 519 | tryflag CFLAGS_AUTO -Wno-uninitialized |
| 520 | tryflag CFLAGS_AUTO -Wno-missing-braces |
| 521 | tryflag CFLAGS_AUTO -Wno-unused-value |
| 522 | tryflag CFLAGS_AUTO -Wno-unused-but-set-variable |
| 523 | tryflag CFLAGS_AUTO -Wno-unknown-pragmas |
rofl0r | adbeefb | 2014-01-08 03:11:46 +0100 | [diff] [blame] | 524 | tryflag CFLAGS_AUTO -Wno-pointer-to-int-cast |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 525 | fi |
| 526 | |
Rich Felker | 3aacb54 | 2015-04-22 22:11:48 -0400 | [diff] [blame] | 527 | if test "x$visibility" = xauto ; then |
Rich Felker | de2b67f | 2015-04-19 22:05:29 -0400 | [diff] [blame] | 528 | # This test checks toolchain support for several things: |
| 529 | # - the -include option |
| 530 | # - the attributes/pragmas used in vis.h |
| 531 | # - linking code that takes the address of protected symbols |
Rich Felker | f3a53f0 | 2015-09-29 02:44:05 +0000 | [diff] [blame] | 532 | # - gcc 3.x bug that wrongly claims declarations mismatch |
Rich Felker | de2b67f | 2015-04-19 22:05:29 -0400 | [diff] [blame] | 533 | printf "checking whether global visibility preinclude works... " |
Rich Felker | f3a53f0 | 2015-09-29 02:44:05 +0000 | [diff] [blame] | 534 | cat > "$tmpc" <<EOF |
| 535 | __attribute__((__visibility__("default"))) |
| 536 | extern struct a *const x; |
| 537 | typedef struct a b; |
| 538 | extern b *const x; |
| 539 | b *const x; |
| 540 | int (*fp)(void); |
| 541 | int foo(void) { } |
| 542 | int bar(void) { fp = foo; return foo(); } |
| 543 | EOF |
Rich Felker | 60ed988 | 2015-04-20 18:14:19 -0400 | [diff] [blame] | 544 | if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS \ |
Rich Felker | ce3e24e | 2016-01-20 19:43:37 +0000 | [diff] [blame] | 545 | -DSHARED -fPIC -I$srcdir/src/internal -include vis.h \ |
Rich Felker | de2b67f | 2015-04-19 22:05:29 -0400 | [diff] [blame] | 546 | -nostdlib -shared -Wl,-Bsymbolic-functions \ |
| 547 | -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
| 548 | visibility=yes |
| 549 | else |
| 550 | visibility=no |
| 551 | fi |
| 552 | printf "%s\n" "$visibility" |
| 553 | fi |
| 554 | |
Rich Felker | 3aacb54 | 2015-04-22 22:11:48 -0400 | [diff] [blame] | 555 | if test "x$visibility" = xyes ; then |
Rich Felker | 428462a | 2015-04-22 01:41:00 -0400 | [diff] [blame] | 556 | CFLAGS_AUTO="$CFLAGS_AUTO -include vis.h" |
Rich Felker | de2b67f | 2015-04-19 22:05:29 -0400 | [diff] [blame] | 557 | CFLAGS_AUTO="${CFLAGS_AUTO# }" |
| 558 | fi |
| 559 | |
Rich Felker | 1619127 | 2016-01-25 19:57:38 -0500 | [diff] [blame] | 560 | # Determine if the compiler produces position-independent code (PIC) |
| 561 | # by default. If so, we don't need to compile separate object files |
| 562 | # for libc.a and libc.so. |
| 563 | if trycppif __PIC__ "$CFLAGS_C99FSE $CPPFLAGS $CFLAGS" ; then |
| 564 | pic_default=yes |
| 565 | else |
| 566 | pic_default=no |
| 567 | fi |
| 568 | |
Rich Felker | 2efd38e | 2015-11-04 21:39:13 -0500 | [diff] [blame] | 569 | # Reduce space lost to padding for alignment purposes by sorting data |
| 570 | # objects according to their alignment reqirements. This approximates |
| 571 | # optimal packing. |
| 572 | tryldflag LDFLAGS_AUTO -Wl,--sort-section,alignment |
| 573 | tryldflag LDFLAGS_AUTO -Wl,--sort-common |
| 574 | |
Rich Felker | 6a851e3 | 2015-11-04 21:40:36 -0500 | [diff] [blame] | 575 | # When linking shared library, drop dummy weak definitions that were |
| 576 | # replaced by strong definitions from other translation units. |
| 577 | tryldflag LDFLAGS_AUTO -Wl,--gc-sections |
| 578 | |
Rich Felker | 0c5efde | 2012-06-06 22:00:08 -0400 | [diff] [blame] | 579 | # Some patched GCC builds have these defaults messed up... |
Rich Felker | 2bd05a4 | 2012-08-25 17:13:28 -0400 | [diff] [blame] | 580 | tryldflag LDFLAGS_AUTO -Wl,--hash-style=both |
Rich Felker | 08f70a3 | 2012-06-06 20:45:52 -0400 | [diff] [blame] | 581 | |
Rich Felker | 2462370 | 2015-09-22 15:45:40 +0000 | [diff] [blame] | 582 | # Prevent linking if there are undefined symbols; if any exist, |
| 583 | # libc.so will crash at runtime during relocation processing. |
| 584 | # The common way this can happen is failure to link the compiler |
| 585 | # runtime library; implementation error is also a possibility. |
| 586 | tryldflag LDFLAGS_AUTO -Wl,--no-undefined |
| 587 | |
Rich Felker | ea1e2c5 | 2015-11-07 20:23:49 -0500 | [diff] [blame] | 588 | # Avoid exporting symbols from compiler runtime libraries. They |
| 589 | # should be hidden anyway, but some toolchains including old gcc |
| 590 | # versions built without shared library support and pcc are broken. |
| 591 | tryldflag LDFLAGS_AUTO -Wl,--exclude-libs=ALL |
| 592 | |
Rich Felker | b941006 | 2018-04-16 20:12:12 -0400 | [diff] [blame] | 593 | # Public data symbols must be interposable to allow for copy |
| 594 | # relocations, but otherwise we want to bind symbols at libc link |
| 595 | # time to eliminate startup relocations and PLT overhead. Use |
| 596 | # --dynamic-list rather than -Bsymbolic-functions for greater |
| 597 | # control over what symbols are left unbound. |
| 598 | tryldflag LDFLAGS_AUTO -Wl,--dynamic-list="$srcdir/dynamic.list" |
Rich Felker | 498a100 | 2012-06-07 00:32:22 -0400 | [diff] [blame] | 599 | |
Rich Felker | 2c1cd23 | 2012-09-10 15:30:52 -0400 | [diff] [blame] | 600 | # Find compiler runtime library |
| 601 | test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh |
| 602 | test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt |
Matúš Olekšák | fcf24b9 | 2018-02-21 12:03:04 -0500 | [diff] [blame] | 603 | test -z "$LIBCC" && try_libcc=`$CC -print-libgcc-file-name 2>/dev/null` \ |
| 604 | && tryldflag LIBCC "$try_libcc" |
Rich Felker | cd31a1f | 2012-10-26 18:15:51 -0400 | [diff] [blame] | 605 | test -z "$LIBCC" && try_libcc=`$CC -print-file-name=libpcc.a 2>/dev/null` \ |
| 606 | && tryldflag LIBCC "$try_libcc" |
Rich Felker | 2c1cd23 | 2012-09-10 15:30:52 -0400 | [diff] [blame] | 607 | printf "using compiler runtime libraries: %s\n" "$LIBCC" |
Rich Felker | a1546e8 | 2012-07-12 14:24:10 -0400 | [diff] [blame] | 608 | |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 609 | # Figure out arch variants for archs with variants |
| 610 | SUBARCH= |
Rich Felker | 428462a | 2015-04-22 01:41:00 -0400 | [diff] [blame] | 611 | t="$CFLAGS_C99FSE $CPPFLAGS $CFLAGS" |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 612 | |
rofl0r | 8c82023 | 2014-03-19 22:31:00 +0100 | [diff] [blame] | 613 | if test "$ARCH" = "x86_64" ; then |
| 614 | trycppif __ILP32__ "$t" && ARCH=x32 |
| 615 | fi |
| 616 | |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 617 | if test "$ARCH" = "arm" ; then |
Rich Felker | 088c967 | 2016-12-19 21:53:33 -0500 | [diff] [blame] | 618 | if trycppif __thumb2__ "$t" ; then |
| 619 | tryflag CFLAGS_AUTO -Wa,-mimplicit-it=always |
| 620 | tryflag CFLAGS_AUTO -Wa,-mthumb |
| 621 | fi |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 622 | trycppif __ARMEB__ "$t" && SUBARCH=${SUBARCH}eb |
Rich Felker | 4918c2b | 2013-08-16 17:09:07 -0400 | [diff] [blame] | 623 | trycppif __ARM_PCS_VFP "$t" && SUBARCH=${SUBARCH}hf |
Rich Felker | 71c334f | 2016-02-19 01:20:07 +0000 | [diff] [blame] | 624 | # Versions of clang up until at least 3.8 have the wrong constraint codes |
| 625 | # for floating point operands to inline asm. Detect this so the affected |
| 626 | # source files can just disable the asm. |
| 627 | if test "$cc_family" = clang ; then |
| 628 | printf "checking whether clang's vfp asm constraints work... " |
| 629 | echo 'float f(float x) { __asm__("":"+t"(x)); return x; }' > "$tmpc" |
| 630 | if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
| 631 | printf "yes\n" |
| 632 | else |
| 633 | printf "no\n" |
| 634 | CFLAGS_AUTO="$CFLAGS_AUTO -DBROKEN_VFP_ASM" |
| 635 | CFLAGS_AUTO="${CFLAGS_AUTO# }" |
| 636 | fi |
| 637 | fi |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 638 | fi |
| 639 | |
Szabolcs Nagy | 01ef3dd | 2015-03-10 21:18:41 +0000 | [diff] [blame] | 640 | if test "$ARCH" = "aarch64" ; then |
| 641 | trycppif __AARCH64EB__ "$t" && SUBARCH=${SUBARCH}_be |
| 642 | fi |
| 643 | |
Szabolcs Nagy | e5bb165 | 2014-02-24 23:16:29 +0100 | [diff] [blame] | 644 | if test "$ARCH" = "mips" ; then |
Rich Felker | 6d99ad9 | 2016-04-03 10:42:37 +0000 | [diff] [blame] | 645 | trycppif "__mips_isa_rev >= 6" "$t" && SUBARCH=${SUBARCH}r6 |
Szabolcs Nagy | e5bb165 | 2014-02-24 23:16:29 +0100 | [diff] [blame] | 646 | trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el |
| 647 | trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf |
| 648 | fi |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 649 | |
Rich Felker | 8393357 | 2016-03-06 17:41:56 +0000 | [diff] [blame] | 650 | if test "$ARCH" = "mips64" ; then |
Rich Felker | 5972c4a | 2016-04-18 05:19:13 +0000 | [diff] [blame] | 651 | trycppif "_MIPS_SIM != _ABI64" "$t" && ARCH=mipsn32 |
Rich Felker | 6d99ad9 | 2016-04-03 10:42:37 +0000 | [diff] [blame] | 652 | trycppif "__mips_isa_rev >= 6" "$t" && SUBARCH=${SUBARCH}r6 |
Rich Felker | 8393357 | 2016-03-06 17:41:56 +0000 | [diff] [blame] | 653 | trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el |
| 654 | trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf |
| 655 | fi |
| 656 | |
Felix Fietkau | 5a92dd9 | 2016-01-25 13:20:52 +0100 | [diff] [blame] | 657 | if test "$ARCH" = "powerpc" ; then |
Rich Felker | 636a479 | 2016-03-06 17:11:29 -0500 | [diff] [blame] | 658 | trycppif "__NO_FPRS__ && !_SOFT_FLOAT" "$t" && fail \ |
| 659 | "$0: error: compiler's floating point configuration is unsupported" |
Felix Fietkau | 5a92dd9 | 2016-01-25 13:20:52 +0100 | [diff] [blame] | 660 | trycppif _SOFT_FLOAT "$t" && SUBARCH=${SUBARCH}-sf |
| 661 | fi |
| 662 | |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 663 | test "$ARCH" = "microblaze" && trycppif __MICROBLAZEEL__ "$t" \ |
| 664 | && SUBARCH=${SUBARCH}el |
| 665 | |
Bobby Bingham | c0ede9e | 2016-04-30 19:18:17 -0500 | [diff] [blame] | 666 | if test "$ARCH" = "powerpc64" ; then |
| 667 | trycppif "_CALL_ELF == 2" "$t" || fail "$0: error: unsupported powerpc64 ABI" |
| 668 | trycppif __LITTLE_ENDIAN__ "$t" && SUBARCH=${SUBARCH}le |
| 669 | trycppif _SOFT_FLOAT "$t" && fail "$0: error: soft-float not supported on powerpc64" |
| 670 | fi |
| 671 | |
Rich Felker | b1683a1 | 2014-02-27 23:18:42 -0500 | [diff] [blame] | 672 | if test "$ARCH" = "sh" ; then |
Rich Felker | 7978998 | 2015-10-15 17:21:07 -0400 | [diff] [blame] | 673 | tryflag CFLAGS_AUTO -Wa,--isa=any |
Rich Felker | b1683a1 | 2014-02-27 23:18:42 -0500 | [diff] [blame] | 674 | trycppif __BIG_ENDIAN__ "$t" && SUBARCH=${SUBARCH}eb |
Bobby Bingham | 23d6418 | 2014-04-27 21:13:59 -0500 | [diff] [blame] | 675 | if trycppif "__SH_FPU_ANY__ || __SH4__" "$t" ; then |
Rich Felker | b1683a1 | 2014-02-27 23:18:42 -0500 | [diff] [blame] | 676 | # Some sh configurations are broken and replace double with float |
| 677 | # rather than using softfloat when the fpu is present but only |
| 678 | # supports single precision. Reject them. |
| 679 | printf "checking whether compiler's double type is IEEE double... " |
Rich Felker | 946b9fa | 2014-02-27 23:55:04 -0500 | [diff] [blame] | 680 | echo 'typedef char dblcheck[(int)sizeof(double)-5];' > "$tmpc" |
Rich Felker | b1683a1 | 2014-02-27 23:18:42 -0500 | [diff] [blame] | 681 | if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
| 682 | printf "yes\n" |
| 683 | else |
| 684 | printf "no\n" |
| 685 | fail "$0: error: compiler's floating point configuration is unsupported" |
| 686 | fi |
| 687 | else |
| 688 | SUBARCH=${SUBARCH}-nofpu |
| 689 | fi |
Rich Felker | d4c82d0 | 2015-09-12 03:22:19 +0000 | [diff] [blame] | 690 | if trycppif __SH_FDPIC__ "$t" ; then |
| 691 | SUBARCH=${SUBARCH}-fdpic |
Rich Felker | d4c82d0 | 2015-09-12 03:22:19 +0000 | [diff] [blame] | 692 | fi |
Rich Felker | b1683a1 | 2014-02-27 23:18:42 -0500 | [diff] [blame] | 693 | fi |
Bobby Bingham | 3a3c813 | 2013-10-05 05:13:18 -0500 | [diff] [blame] | 694 | |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 695 | test "$SUBARCH" \ |
| 696 | && printf "configured for %s variant: %s\n" "$ARCH" "$ARCH$SUBARCH" |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 697 | |
Rich Felker | 90d7772 | 2013-08-11 03:27:35 -0400 | [diff] [blame] | 698 | case "$ARCH$SUBARCH" in |
| 699 | arm) ASMSUBARCH=el ;; |
| 700 | *) ASMSUBARCH=$SUBARCH ;; |
| 701 | esac |
| 702 | |
Rich Felker | 86cc54b | 2013-08-02 19:34:22 -0400 | [diff] [blame] | 703 | # |
| 704 | # Some archs (powerpc) have different possible long double formats |
| 705 | # that the compiler can be configured for. The logic for whether this |
| 706 | # is supported is in bits/float.h; in general, it is not. We need to |
| 707 | # check for mismatches here or code in printf, strotd, and scanf will |
| 708 | # be dangerously incorrect because it depends on (1) the macros being |
| 709 | # correct, and (2) IEEE semantics. |
| 710 | # |
| 711 | printf "checking whether compiler's long double definition matches float.h... " |
| 712 | echo '#include <float.h>' > "$tmpc" |
Szabolcs Nagy | 249b621 | 2017-09-17 15:35:55 +0000 | [diff] [blame] | 713 | echo '#define C(m,s) (m==LDBL_MANT_DIG && s==sizeof(long double))' >> "$tmpc" |
| 714 | echo 'typedef char ldcheck[(C(53,8)||C(64,12)||C(64,16)||C(113,16))*2-1];' >> "$tmpc" |
Rich Felker | efdf04c | 2016-01-27 19:31:15 -0500 | [diff] [blame] | 715 | if $CC $CFLAGS_C99FSE \ |
| 716 | -I$srcdir/arch/$ARCH -I$srcdir/arch/generic -I$srcdir/include \ |
| 717 | $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
Rich Felker | 86cc54b | 2013-08-02 19:34:22 -0400 | [diff] [blame] | 718 | printf "yes\n" |
| 719 | else |
| 720 | printf "no\n" |
| 721 | fail "$0: error: unsupported long double type" |
| 722 | fi |
| 723 | |
Rich Felker | 80fbaac | 2016-02-17 13:53:54 -0500 | [diff] [blame] | 724 | # |
| 725 | # Some build systems globally pass in broken CFLAGS like -ffast-math |
| 726 | # for all packages. On recent GCC we can detect this and error out |
| 727 | # early rather than producing a seriously-broken math library. |
| 728 | # |
Rich Felker | 5030e4a | 2016-02-18 04:09:33 +0000 | [diff] [blame] | 729 | if trycppif "__FAST_MATH__" \ |
Rich Felker | 80fbaac | 2016-02-17 13:53:54 -0500 | [diff] [blame] | 730 | "$CFLAGS_C99FSE $CPPFLAGS $CFLAGS" ; then |
| 731 | fail "$0: error: compiler has broken floating point; check CFLAGS" |
| 732 | fi |
| 733 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 734 | printf "creating config.mak... " |
| 735 | |
Rich Felker | 453f462 | 2013-08-16 18:19:47 -0400 | [diff] [blame] | 736 | cmdline=$(quote "$0") |
| 737 | for i ; do cmdline="$cmdline $(quote "$i")" ; done |
| 738 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 739 | exec 3>&1 1>config.mak |
| 740 | |
| 741 | |
| 742 | cat << EOF |
Rich Felker | 453f462 | 2013-08-16 18:19:47 -0400 | [diff] [blame] | 743 | # This version of config.mak was generated by: |
| 744 | # $cmdline |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 745 | # Any changes made here will be lost if configure is re-run |
| 746 | ARCH = $ARCH |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 747 | SUBARCH = $SUBARCH |
Rich Felker | 90d7772 | 2013-08-11 03:27:35 -0400 | [diff] [blame] | 748 | ASMSUBARCH = $ASMSUBARCH |
Petr Hosek | 2f853dd | 2015-11-18 12:07:32 -0800 | [diff] [blame] | 749 | srcdir = $srcdir |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 750 | prefix = $prefix |
| 751 | exec_prefix = $exec_prefix |
| 752 | bindir = $bindir |
| 753 | libdir = $libdir |
| 754 | includedir = $includedir |
| 755 | syslibdir = $syslibdir |
| 756 | CC = $CC |
Rich Felker | 4cd8b47 | 2015-11-02 16:58:14 -0500 | [diff] [blame] | 757 | CFLAGS = $CFLAGS |
| 758 | CFLAGS_AUTO = $CFLAGS_AUTO |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 759 | CFLAGS_C99FSE = $CFLAGS_C99FSE |
Rich Felker | 4a1f55e | 2013-08-01 17:12:23 -0400 | [diff] [blame] | 760 | CFLAGS_MEMOPS = $CFLAGS_MEMOPS |
Rich Felker | 1ef849c | 2015-04-13 20:13:10 -0400 | [diff] [blame] | 761 | CFLAGS_NOSSP = $CFLAGS_NOSSP |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 762 | CPPFLAGS = $CPPFLAGS |
Rich Felker | 4cd8b47 | 2015-11-02 16:58:14 -0500 | [diff] [blame] | 763 | LDFLAGS = $LDFLAGS |
| 764 | LDFLAGS_AUTO = $LDFLAGS_AUTO |
Rich Felker | 94e920d | 2012-08-14 22:50:16 -0400 | [diff] [blame] | 765 | CROSS_COMPILE = $CROSS_COMPILE |
Rich Felker | 2c1cd23 | 2012-09-10 15:30:52 -0400 | [diff] [blame] | 766 | LIBCC = $LIBCC |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 767 | OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 768 | ALL_TOOLS = $tools |
| 769 | TOOL_LIBS = $tool_libs |
Alex Dowad | 35b3312 | 2015-07-10 15:03:24 +0200 | [diff] [blame] | 770 | ADD_CFI = $ADD_CFI |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 771 | EOF |
| 772 | test "x$static" = xno && echo "STATIC_LIBS =" |
| 773 | test "x$shared" = xno && echo "SHARED_LIBS =" |
Shiz | b3cd7d1 | 2015-06-28 23:08:19 +0200 | [diff] [blame] | 774 | test "x$cc_family" = xgcc && echo 'WRAPCC_GCC = $(CC)' |
Shiz | fb58545 | 2015-06-28 23:08:21 +0200 | [diff] [blame] | 775 | test "x$cc_family" = xclang && echo 'WRAPCC_CLANG = $(CC)' |
Rich Felker | 1619127 | 2016-01-25 19:57:38 -0500 | [diff] [blame] | 776 | test "x$pic_default" = xyes && echo 'AOBJS = $(LOBJS)' |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 777 | exec 1>&3 3>&- |
| 778 | |
Petr Hosek | 2f853dd | 2015-11-18 12:07:32 -0800 | [diff] [blame] | 779 | test "$srcdir" = "." || ln -sf $srcdir/Makefile . |
| 780 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 781 | printf "done\n" |