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