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 | |
| 12 | Installation directories: |
| 13 | --prefix=PREFIX main installation prefix [/usr/local/musl] |
| 14 | --exec-prefix=EPREFIX installation prefix for executable files [PREFIX] |
| 15 | |
| 16 | Fine tuning of the installation directories: |
| 17 | --bindir=DIR user executables [EPREFIX/bin] |
| 18 | --libdir=DIR library files for the linker [PREFIX/lib] |
| 19 | --includedir=DIR include files for the C compiler [PREFIX/include] |
| 20 | --syslibdir=DIR location for the dynamic linker [/lib] |
| 21 | |
| 22 | System types: |
| 23 | --target=TARGET configure to run on target TARGET [detected] |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 24 | --host=HOST same as --target |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 25 | |
| 26 | Optional features: |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 27 | --enable-optimize=... optimize listed components for speed over size [auto] |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 28 | --enable-debug build with debugging information [disabled] |
| 29 | --enable-warnings build with recommended warnings flags [disabled] |
| 30 | --enable-gcc-wrapper build musl-gcc toolchain wrapper [auto] |
| 31 | --disable-shared inhibit building shared library [enabled] |
| 32 | --disable-static inhibit building static library [enabled] |
| 33 | |
| 34 | Some influential environment variables: |
| 35 | CC C compiler command [detected] |
| 36 | CFLAGS C compiler flags [-Os -pipe ...] |
Rich Felker | 94e920d | 2012-08-14 22:50:16 -0400 | [diff] [blame] | 37 | CROSS_COMPILE prefix for cross compiler and tools [none] |
Rich Felker | 2c1cd23 | 2012-09-10 15:30:52 -0400 | [diff] [blame] | 38 | LIBCC compiler runtime library [detected] |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 39 | |
| 40 | Use these variables to override the choices made by configure. |
| 41 | |
| 42 | EOF |
| 43 | exit 0 |
| 44 | } |
| 45 | |
| 46 | # Helper functions |
| 47 | |
Rich Felker | 453f462 | 2013-08-16 18:19:47 -0400 | [diff] [blame] | 48 | quote () { |
| 49 | tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; } |
| 50 | $1 |
| 51 | EOF |
Rich Felker | e449974 | 2013-08-20 13:51:46 -0400 | [diff] [blame] | 52 | 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] | 53 | } |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 54 | echo () { printf "%s\n" "$*" ; } |
| 55 | fail () { echo "$*" ; exit 1 ; } |
| 56 | fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; } |
| 57 | cmdexists () { type "$1" >/dev/null 2>&1 ; } |
| 58 | trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; } |
| 59 | |
Rich Felker | 3d9e3a3 | 2012-11-08 17:20:50 -0500 | [diff] [blame] | 60 | stripdir () { |
| 61 | while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 62 | } |
| 63 | |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 64 | trycppif () { |
| 65 | printf "checking preprocessor condition %s... " "$1" |
Rich Felker | df06578 | 2013-07-18 20:37:19 -0400 | [diff] [blame] | 66 | echo "typedef int x;" > "$tmpc" |
| 67 | echo "#if $1" >> "$tmpc" |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 68 | echo "#error yes" >> "$tmpc" |
| 69 | echo "#endif" >> "$tmpc" |
| 70 | if $CC $2 -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
| 71 | printf "false\n" |
| 72 | return 1 |
| 73 | else |
| 74 | printf "true\n" |
| 75 | return 0 |
| 76 | fi |
| 77 | } |
| 78 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 79 | tryflag () { |
| 80 | printf "checking whether compiler accepts %s... " "$2" |
| 81 | echo "typedef int x;" > "$tmpc" |
Rich Felker | cd31a1f | 2012-10-26 18:15:51 -0400 | [diff] [blame] | 82 | if $CC "$2" -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 83 | printf "yes\n" |
| 84 | eval "$1=\"\${$1} \$2\"" |
| 85 | eval "$1=\${$1# }" |
| 86 | return 0 |
| 87 | else |
| 88 | printf "no\n" |
| 89 | return 1 |
| 90 | fi |
| 91 | } |
| 92 | |
Rich Felker | 08f70a3 | 2012-06-06 20:45:52 -0400 | [diff] [blame] | 93 | tryldflag () { |
| 94 | printf "checking whether linker accepts %s... " "$2" |
Rich Felker | 67a0383 | 2012-06-07 00:23:58 -0400 | [diff] [blame] | 95 | echo "typedef int x;" > "$tmpc" |
Rich Felker | cd31a1f | 2012-10-26 18:15:51 -0400 | [diff] [blame] | 96 | if $CC -nostdlib -shared "$2" -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
Rich Felker | 08f70a3 | 2012-06-06 20:45:52 -0400 | [diff] [blame] | 97 | printf "yes\n" |
| 98 | eval "$1=\"\${$1} \$2\"" |
| 99 | eval "$1=\${$1# }" |
| 100 | return 0 |
| 101 | else |
| 102 | printf "no\n" |
| 103 | return 1 |
| 104 | fi |
| 105 | } |
| 106 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 107 | |
| 108 | |
| 109 | # Beginning of actual script |
| 110 | |
Rich Felker | 08f70a3 | 2012-06-06 20:45:52 -0400 | [diff] [blame] | 111 | CFLAGS_C99FSE= |
| 112 | CFLAGS_AUTO= |
Rich Felker | 4a1f55e | 2013-08-01 17:12:23 -0400 | [diff] [blame] | 113 | CFLAGS_MEMOPS= |
Rich Felker | 08f70a3 | 2012-06-06 20:45:52 -0400 | [diff] [blame] | 114 | LDFLAGS_AUTO= |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 115 | OPTIMIZE_GLOBS= |
Rich Felker | 3d9e3a3 | 2012-11-08 17:20:50 -0500 | [diff] [blame] | 116 | prefix=/usr/local/musl |
| 117 | exec_prefix='$(prefix)' |
| 118 | bindir='$(exec_prefix)/bin' |
| 119 | libdir='$(prefix)/lib' |
| 120 | includedir='$(prefix)/include' |
| 121 | syslibdir='/lib' |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 122 | target= |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 123 | optimize=auto |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 124 | debug=no |
Rich Felker | 3d9e3a3 | 2012-11-08 17:20:50 -0500 | [diff] [blame] | 125 | warnings=no |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 126 | shared=yes |
| 127 | static=yes |
| 128 | |
| 129 | for arg ; do |
| 130 | case "$arg" in |
| 131 | --help) usage ;; |
| 132 | --prefix=*) prefix=${arg#*=} ;; |
| 133 | --exec-prefix=*) exec_prefix=${arg#*=} ;; |
| 134 | --bindir=*) bindir=${arg#*=} ;; |
| 135 | --libdir=*) libdir=${arg#*=} ;; |
| 136 | --includedir=*) includedir=${arg#*=} ;; |
| 137 | --syslibdir=*) syslibdir=${arg#*=} ;; |
| 138 | --enable-shared|--enable-shared=yes) shared=yes ;; |
| 139 | --disable-shared|--enable-shared=no) shared=no ;; |
| 140 | --enable-static|--enable-static=yes) static=yes ;; |
| 141 | --disable-static|--enable-static=no) static=no ;; |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 142 | --enable-optimize) optimize=yes ;; |
| 143 | --enable-optimize=*) optimize=${arg#*=} ;; |
| 144 | --disable-optimize) optimize=no ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 145 | --enable-debug|--enable-debug=yes) debug=yes ;; |
| 146 | --disable-debug|--enable-debug=no) debug=no ;; |
| 147 | --enable-warnings|--enable-warnings=yes) warnings=yes ;; |
| 148 | --disable-warnings|--enable-warnings=no) warnings=no ;; |
| 149 | --enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ;; |
| 150 | --disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;; |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 151 | --enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;; |
| 152 | --host=*|--target=*) target=${arg#*=} ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 153 | -* ) echo "$0: unknown option $arg" ;; |
| 154 | CC=*) CC=${arg#*=} ;; |
| 155 | CFLAGS=*) CFLAGS=${arg#*=} ;; |
| 156 | CPPFLAGS=*) CPPFLAGS=${arg#*=} ;; |
| 157 | LDFLAGS=*) LDFLAGS=${arg#*=} ;; |
Rich Felker | 94e920d | 2012-08-14 22:50:16 -0400 | [diff] [blame] | 158 | CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;; |
Rich Felker | 2c1cd23 | 2012-09-10 15:30:52 -0400 | [diff] [blame] | 159 | LIBCC=*) LIBCC=${arg#*=} ;; |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 160 | *=*) ;; |
| 161 | *) target=$arg ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 162 | esac |
| 163 | done |
| 164 | |
Rich Felker | 3d9e3a3 | 2012-11-08 17:20:50 -0500 | [diff] [blame] | 165 | for i in prefix exec_prefix bindir libdir includedir syslibdir ; do |
| 166 | stripdir $i |
| 167 | done |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 168 | |
| 169 | # |
| 170 | # Get a temp filename we can use |
| 171 | # |
| 172 | i=0 |
| 173 | set -C |
| 174 | while : ; do i=$(($i+1)) |
| 175 | tmpc="./conf$$-$PPID-$i.c" |
Rich Felker | 6c0cba8 | 2012-11-18 23:15:47 -0500 | [diff] [blame] | 176 | 2>|/dev/null > "$tmpc" && break |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 177 | test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc" |
| 178 | done |
| 179 | set +C |
| 180 | trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP |
| 181 | |
| 182 | # |
| 183 | # Find a C compiler to use |
| 184 | # |
| 185 | printf "checking for C compiler... " |
Rich Felker | 94e920d | 2012-08-14 22:50:16 -0400 | [diff] [blame] | 186 | trycc ${CROSS_COMPILE}gcc |
| 187 | trycc ${CROSS_COMPILE}c99 |
| 188 | trycc ${CROSS_COMPILE}cc |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 189 | printf "%s\n" "$CC" |
| 190 | test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; } |
| 191 | |
Rich Felker | 8945667 | 2014-05-12 14:22:57 -0400 | [diff] [blame] | 192 | printf "checking whether C compiler works... " |
| 193 | echo "typedef int x;" > "$tmpc" |
| 194 | if output=$($CC $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" 2>&1) ; then |
| 195 | printf "yes\n" |
| 196 | else |
| 197 | printf "no; compiler output follows:\n%s\n" "$output" |
| 198 | exit 1 |
| 199 | fi |
| 200 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 201 | # |
| 202 | # Only build musl-gcc wrapper if toolchain does not already target musl |
| 203 | # |
| 204 | if test -z "$wrapper" ; then |
| 205 | printf "checking whether compiler is gcc... " |
Rich Felker | 01e5a1b | 2012-10-18 23:02:53 -0400 | [diff] [blame] | 206 | if fnmatch '*gcc\ version*' "$($CC -v 2>&1)" ; then |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 207 | echo yes |
| 208 | printf "checking whether to build musl-gcc wrapper... " |
| 209 | wrapper=yes |
| 210 | while read line ; do |
| 211 | case "$line" in */ld-musl-*) wrapper=no ;; esac |
| 212 | done <<EOF |
| 213 | $($CC -dumpspecs) |
| 214 | EOF |
| 215 | echo $wrapper |
| 216 | else |
| 217 | echo no |
| 218 | fi |
| 219 | fi |
| 220 | |
| 221 | |
| 222 | |
| 223 | # |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 224 | # Find the target architecture |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 225 | # |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 226 | printf "checking target system type... " |
Rich Felker | 01e5a1b | 2012-10-18 23:02:53 -0400 | [diff] [blame] | 227 | test -n "$target" || target=$($CC -dumpmachine 2>/dev/null) || target=unknown |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 228 | printf "%s\n" "$target" |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 229 | |
| 230 | # |
| 231 | # Convert to just ARCH |
| 232 | # |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 233 | case "$target" in |
Rich Felker | 0b8f0c5 | 2014-02-28 13:12:40 -0500 | [diff] [blame] | 234 | # Catch these early to simplify matching for 32-bit archs |
| 235 | mips64*|powerpc64*) fail "$0: unsupported target \"$target\"" ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 236 | arm*) ARCH=arm ;; |
| 237 | i?86*) ARCH=i386 ;; |
Rich Felker | f162c06 | 2014-03-17 17:38:22 -0400 | [diff] [blame] | 238 | x86_64-x32*|x32*|x86_64*x32) ARCH=x32 ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 239 | x86_64*) ARCH=x86_64 ;; |
Rich Felker | 0b8f0c5 | 2014-02-28 13:12:40 -0500 | [diff] [blame] | 240 | mips*) ARCH=mips ;; |
| 241 | microblaze*) ARCH=microblaze ;; |
| 242 | powerpc*) ARCH=powerpc ;; |
| 243 | sh[1-9bel-]*|sh|superh*) ARCH=sh ;; |
Rich Felker | 278883d | 2012-06-03 16:22:13 -0400 | [diff] [blame] | 244 | unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;; |
| 245 | *) fail "$0: unknown or unsupported target \"$target\"" ;; |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 246 | esac |
| 247 | |
| 248 | # |
| 249 | # Try to get a conforming C99 freestanding environment |
| 250 | # |
| 251 | tryflag CFLAGS_C99FSE -std=c99 |
| 252 | tryflag CFLAGS_C99FSE -nostdinc |
| 253 | tryflag CFLAGS_C99FSE -ffreestanding \ |
| 254 | || tryflag CFLAGS_C99FSE -fno-builtin |
| 255 | tryflag CFLAGS_C99FSE -fexcess-precision=standard \ |
Rich Felker | 2121b8a | 2012-07-03 23:53:05 -0400 | [diff] [blame] | 256 | || { test "$ARCH" = i386 && tryflag CFLAGS_C99FSE -ffloat-store ; } |
Rich Felker | b4ccc3c | 2012-05-05 17:18:31 -0400 | [diff] [blame] | 257 | tryflag CFLAGS_C99FSE -frounding-math |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 258 | |
Rich Felker | 4a1f55e | 2013-08-01 17:12:23 -0400 | [diff] [blame] | 259 | # |
Rich Felker | 06ceee8 | 2013-08-27 17:33:47 -0400 | [diff] [blame] | 260 | # We may use the may_alias attribute if __GNUC__ is defined, so |
| 261 | # if the compiler defines __GNUC__ but does not provide it, |
| 262 | # it must be defined away as part of the CFLAGS. |
| 263 | # |
| 264 | printf "checking whether compiler needs attribute((may_alias)) suppression... " |
| 265 | cat > "$tmpc" <<EOF |
| 266 | typedef int |
| 267 | #ifdef __GNUC__ |
| 268 | __attribute__((__may_alias__)) |
| 269 | #endif |
| 270 | x; |
| 271 | EOF |
| 272 | if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \ |
| 273 | -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
| 274 | printf "no\n" |
| 275 | else |
| 276 | printf "yes\n" |
| 277 | CFLAGS_C99FSE="$CFLAGS_C99FSE -D__may_alias__=" |
| 278 | fi |
| 279 | |
| 280 | # |
Rich Felker | 4a1f55e | 2013-08-01 17:12:23 -0400 | [diff] [blame] | 281 | # Check for options that may be needed to prevent the compiler from |
| 282 | # generating self-referential versions of memcpy,, memmove, memcmp, |
| 283 | # and memset. Really, we should add a check to determine if this |
| 284 | # option is sufficient, and if not, add a macro to cripple these |
| 285 | # functions with volatile... |
| 286 | # |
| 287 | tryflag CFLAGS_MEMOPS -fno-tree-loop-distribute-patterns |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 288 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 289 | # |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 290 | # If debugging is explicitly enabled, don't auto-enable optimizations |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 291 | # |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 292 | if test "$debug" = yes ; then |
| 293 | CFLAGS_AUTO=-g |
| 294 | test "$optimize" = auto && optimize=no |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 295 | fi |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 296 | |
| 297 | # |
| 298 | # Possibly add a -O option to CFLAGS and select modules to optimize with |
| 299 | # -O3 based on the status of --enable-optimize and provided CFLAGS. |
| 300 | # |
| 301 | printf "checking for optimization settings... " |
| 302 | case "x$optimize" in |
| 303 | xauto) |
| 304 | if fnmatch '-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then |
| 305 | printf "using provided CFLAGS\n" ;optimize=no |
| 306 | else |
| 307 | printf "using defaults\n" ; optimize=yes |
| 308 | fi |
| 309 | ;; |
| 310 | xsize|xnone) printf "minimize size\n" ; optimize=size ;; |
| 311 | xno|x) printf "disabled\n" ; optimize=no ;; |
| 312 | *) printf "custom\n" ;; |
| 313 | esac |
| 314 | |
| 315 | test "$optimize" = no || tryflag CFLAGS_AUTO -Os || tryflag CFLAGS_AUTO -O2 |
Rich Felker | 43d2531 | 2013-07-24 23:21:45 -0400 | [diff] [blame] | 316 | test "$optimize" = yes && optimize="internal,malloc,string" |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 317 | |
| 318 | if fnmatch 'no|size' "$optimize" ; then : |
| 319 | else |
| 320 | printf "components to be optimized for speed:" |
| 321 | while test "$optimize" ; do |
| 322 | case "$optimize" in |
| 323 | *,*) this=${optimize%%,*} optimize=${optimize#*,} ;; |
| 324 | *) this=$optimize optimize= |
| 325 | esac |
| 326 | printf " $this" |
| 327 | case "$this" in |
| 328 | */*.c) ;; |
| 329 | */*) this=$this*.c ;; |
| 330 | *) this=$this/*.c ;; |
| 331 | esac |
| 332 | OPTIMIZE_GLOBS="$OPTIMIZE_GLOBS $this" |
| 333 | done |
| 334 | OPTIMIZE_GLOBS=${OPTIMIZE_GLOBS# } |
| 335 | printf "\n" |
| 336 | fi |
| 337 | |
| 338 | # Always try -pipe |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 339 | tryflag CFLAGS_AUTO -pipe |
| 340 | |
| 341 | # |
Rich Felker | b439c05 | 2012-08-29 09:36:02 -0400 | [diff] [blame] | 342 | # If debugging is disabled, omit frame pointer. Modern GCC does this |
| 343 | # anyway on most archs even when debugging is enabled since the frame |
| 344 | # pointer is no longer needed for debugging. |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 345 | # |
| 346 | if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then : |
| 347 | else |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 348 | tryflag CFLAGS_AUTO -fomit-frame-pointer |
| 349 | fi |
| 350 | |
| 351 | # |
Rich Felker | b439c05 | 2012-08-29 09:36:02 -0400 | [diff] [blame] | 352 | # Modern GCC wants to put DWARF tables (used for debugging and |
| 353 | # unwinding) in the loaded part of the program where they are |
| 354 | # unstrippable. These options force them back to debug sections (and |
| 355 | # cause them not to get generated at all if debugging is off). |
| 356 | # |
| 357 | tryflag CFLAGS_AUTO -fno-unwind-tables |
| 358 | tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables |
| 359 | |
| 360 | # |
Rich Felker | adefe83 | 2012-10-03 11:49:58 -0400 | [diff] [blame] | 361 | # The GNU toolchain defaults to assuming unmarked files need an |
| 362 | # executable stack, potentially exposing vulnerabilities in programs |
| 363 | # linked with such object files. Fix this. |
| 364 | # |
| 365 | tryflag CFLAGS_AUTO -Wa,--noexecstack |
| 366 | |
| 367 | # |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 368 | # On x86, make sure we don't have incompatible instruction set |
| 369 | # extensions enabled by default. This is bad for making static binaries. |
| 370 | # We cheat and use i486 rather than i386 because i386 really does not |
| 371 | # work anyway (issues with atomic ops). |
| 372 | # |
| 373 | if test "$ARCH" = "i386" ; then |
Rich Felker | 80a4545 | 2012-10-25 14:52:12 -0400 | [diff] [blame] | 374 | fnmatch '-march=*|*\ -march=*' "$CFLAGS" || tryldflag CFLAGS_AUTO -march=i486 |
| 375 | fnmatch '-mtune=*|*\ -mtune=*' "$CFLAGS" || tryldflag CFLAGS_AUTO -mtune=generic |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 376 | fi |
| 377 | |
Rich Felker | 2384f27 | 2012-12-11 23:28:31 -0500 | [diff] [blame] | 378 | # |
| 379 | # Even with -std=c99, gcc accepts some constructs which are constraint |
| 380 | # violations. We want to treat these as errors regardless of whether |
| 381 | # other purely stylistic warnings are enabled -- especially implicit |
| 382 | # function declarations, which are a dangerous programming error. |
| 383 | # |
| 384 | tryflag CFLAGS_AUTO -Werror=implicit-function-declaration |
| 385 | tryflag CFLAGS_AUTO -Werror=implicit-int |
| 386 | tryflag CFLAGS_AUTO -Werror=pointer-sign |
| 387 | tryflag CFLAGS_AUTO -Werror=pointer-arith |
| 388 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 389 | if test "x$warnings" = xyes ; then |
| 390 | tryflag CFLAGS_AUTO -Wall |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 391 | tryflag CFLAGS_AUTO -Wno-parentheses |
| 392 | tryflag CFLAGS_AUTO -Wno-uninitialized |
| 393 | tryflag CFLAGS_AUTO -Wno-missing-braces |
| 394 | tryflag CFLAGS_AUTO -Wno-unused-value |
| 395 | tryflag CFLAGS_AUTO -Wno-unused-but-set-variable |
| 396 | tryflag CFLAGS_AUTO -Wno-unknown-pragmas |
rofl0r | adbeefb | 2014-01-08 03:11:46 +0100 | [diff] [blame] | 397 | tryflag CFLAGS_AUTO -Wno-pointer-to-int-cast |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 398 | fi |
| 399 | |
Rich Felker | 0c5efde | 2012-06-06 22:00:08 -0400 | [diff] [blame] | 400 | # Some patched GCC builds have these defaults messed up... |
| 401 | tryflag CFLAGS_AUTO -fno-stack-protector |
Rich Felker | 2bd05a4 | 2012-08-25 17:13:28 -0400 | [diff] [blame] | 402 | tryldflag LDFLAGS_AUTO -Wl,--hash-style=both |
Rich Felker | 08f70a3 | 2012-06-06 20:45:52 -0400 | [diff] [blame] | 403 | |
Rich Felker | 498a100 | 2012-06-07 00:32:22 -0400 | [diff] [blame] | 404 | # Disable dynamic linking if ld is broken and can't do -Bsymbolic-functions |
| 405 | LDFLAGS_DUMMY= |
| 406 | tryldflag LDFLAGS_DUMMY -Wl,-Bsymbolic-functions || { |
| 407 | printf "warning: disabling dynamic linking support\n" |
| 408 | shared=no |
| 409 | } |
| 410 | |
Rich Felker | 2c1cd23 | 2012-09-10 15:30:52 -0400 | [diff] [blame] | 411 | # Find compiler runtime library |
| 412 | test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh |
| 413 | test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt |
Rich Felker | cd31a1f | 2012-10-26 18:15:51 -0400 | [diff] [blame] | 414 | test -z "$LIBCC" && try_libcc=`$CC -print-file-name=libpcc.a 2>/dev/null` \ |
| 415 | && tryldflag LIBCC "$try_libcc" |
Rich Felker | 2c1cd23 | 2012-09-10 15:30:52 -0400 | [diff] [blame] | 416 | printf "using compiler runtime libraries: %s\n" "$LIBCC" |
Rich Felker | a1546e8 | 2012-07-12 14:24:10 -0400 | [diff] [blame] | 417 | |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 418 | # Figure out arch variants for archs with variants |
| 419 | SUBARCH= |
| 420 | t="$CFLAGS_C99FSE $CPPFLAGS $CFLAGS_AUTO $CFLAGS" |
| 421 | |
rofl0r | 8c82023 | 2014-03-19 22:31:00 +0100 | [diff] [blame] | 422 | if test "$ARCH" = "x86_64" ; then |
| 423 | trycppif __ILP32__ "$t" && ARCH=x32 |
| 424 | fi |
| 425 | |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 426 | if test "$ARCH" = "arm" ; then |
| 427 | trycppif __ARMEB__ "$t" && SUBARCH=${SUBARCH}eb |
Rich Felker | 4918c2b | 2013-08-16 17:09:07 -0400 | [diff] [blame] | 428 | trycppif __ARM_PCS_VFP "$t" && SUBARCH=${SUBARCH}hf |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 429 | fi |
| 430 | |
Szabolcs Nagy | e5bb165 | 2014-02-24 23:16:29 +0100 | [diff] [blame] | 431 | if test "$ARCH" = "mips" ; then |
| 432 | trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el |
| 433 | trycppif __mips_soft_float "$t" && SUBARCH=${SUBARCH}-sf |
| 434 | fi |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 435 | |
| 436 | test "$ARCH" = "microblaze" && trycppif __MICROBLAZEEL__ "$t" \ |
| 437 | && SUBARCH=${SUBARCH}el |
| 438 | |
Rich Felker | b1683a1 | 2014-02-27 23:18:42 -0500 | [diff] [blame] | 439 | if test "$ARCH" = "sh" ; then |
| 440 | trycppif __BIG_ENDIAN__ "$t" && SUBARCH=${SUBARCH}eb |
Bobby Bingham | 23d6418 | 2014-04-27 21:13:59 -0500 | [diff] [blame] | 441 | if trycppif "__SH_FPU_ANY__ || __SH4__" "$t" ; then |
Rich Felker | b1683a1 | 2014-02-27 23:18:42 -0500 | [diff] [blame] | 442 | # Some sh configurations are broken and replace double with float |
| 443 | # rather than using softfloat when the fpu is present but only |
| 444 | # supports single precision. Reject them. |
| 445 | printf "checking whether compiler's double type is IEEE double... " |
Rich Felker | 946b9fa | 2014-02-27 23:55:04 -0500 | [diff] [blame] | 446 | echo 'typedef char dblcheck[(int)sizeof(double)-5];' > "$tmpc" |
Rich Felker | b1683a1 | 2014-02-27 23:18:42 -0500 | [diff] [blame] | 447 | if $CC $CFLAGS_C99FSE $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
| 448 | printf "yes\n" |
| 449 | else |
| 450 | printf "no\n" |
| 451 | fail "$0: error: compiler's floating point configuration is unsupported" |
| 452 | fi |
| 453 | else |
| 454 | SUBARCH=${SUBARCH}-nofpu |
| 455 | fi |
| 456 | fi |
Bobby Bingham | 3a3c813 | 2013-10-05 05:13:18 -0500 | [diff] [blame] | 457 | |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 458 | test "$SUBARCH" \ |
| 459 | && printf "configured for %s variant: %s\n" "$ARCH" "$ARCH$SUBARCH" |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 460 | |
Rich Felker | 90d7772 | 2013-08-11 03:27:35 -0400 | [diff] [blame] | 461 | case "$ARCH$SUBARCH" in |
| 462 | arm) ASMSUBARCH=el ;; |
| 463 | *) ASMSUBARCH=$SUBARCH ;; |
| 464 | esac |
| 465 | |
Rich Felker | 86cc54b | 2013-08-02 19:34:22 -0400 | [diff] [blame] | 466 | # |
| 467 | # Some archs (powerpc) have different possible long double formats |
| 468 | # that the compiler can be configured for. The logic for whether this |
| 469 | # is supported is in bits/float.h; in general, it is not. We need to |
| 470 | # check for mismatches here or code in printf, strotd, and scanf will |
| 471 | # be dangerously incorrect because it depends on (1) the macros being |
| 472 | # correct, and (2) IEEE semantics. |
| 473 | # |
| 474 | printf "checking whether compiler's long double definition matches float.h... " |
| 475 | echo '#include <float.h>' > "$tmpc" |
| 476 | echo '#if LDBL_MANT_DIG == 53' >> "$tmpc" |
| 477 | echo 'typedef char ldcheck[9-(int)sizeof(long double)];' >> "$tmpc" |
| 478 | echo '#endif' >> "$tmpc" |
| 479 | if $CC $CFLAGS_C99FSE -I./arch/$ARCH -I./include $CPPFLAGS $CFLAGS \ |
| 480 | -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then |
| 481 | printf "yes\n" |
| 482 | else |
| 483 | printf "no\n" |
| 484 | fail "$0: error: unsupported long double type" |
| 485 | fi |
| 486 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 487 | printf "creating config.mak... " |
| 488 | |
Rich Felker | 453f462 | 2013-08-16 18:19:47 -0400 | [diff] [blame] | 489 | cmdline=$(quote "$0") |
| 490 | for i ; do cmdline="$cmdline $(quote "$i")" ; done |
| 491 | |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 492 | exec 3>&1 1>config.mak |
| 493 | |
| 494 | |
| 495 | cat << EOF |
Rich Felker | 453f462 | 2013-08-16 18:19:47 -0400 | [diff] [blame] | 496 | # This version of config.mak was generated by: |
| 497 | # $cmdline |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 498 | # Any changes made here will be lost if configure is re-run |
| 499 | ARCH = $ARCH |
Rich Felker | 3e7f186 | 2013-07-18 20:30:58 -0400 | [diff] [blame] | 500 | SUBARCH = $SUBARCH |
Rich Felker | 90d7772 | 2013-08-11 03:27:35 -0400 | [diff] [blame] | 501 | ASMSUBARCH = $ASMSUBARCH |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 502 | prefix = $prefix |
| 503 | exec_prefix = $exec_prefix |
| 504 | bindir = $bindir |
| 505 | libdir = $libdir |
| 506 | includedir = $includedir |
| 507 | syslibdir = $syslibdir |
| 508 | CC = $CC |
| 509 | CFLAGS= $CFLAGS_AUTO $CFLAGS |
| 510 | CFLAGS_C99FSE = $CFLAGS_C99FSE |
Rich Felker | 4a1f55e | 2013-08-01 17:12:23 -0400 | [diff] [blame] | 511 | CFLAGS_MEMOPS = $CFLAGS_MEMOPS |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 512 | CPPFLAGS = $CPPFLAGS |
Rich Felker | 08f70a3 | 2012-06-06 20:45:52 -0400 | [diff] [blame] | 513 | LDFLAGS = $LDFLAGS_AUTO $LDFLAGS |
Rich Felker | 94e920d | 2012-08-14 22:50:16 -0400 | [diff] [blame] | 514 | CROSS_COMPILE = $CROSS_COMPILE |
Rich Felker | 2c1cd23 | 2012-09-10 15:30:52 -0400 | [diff] [blame] | 515 | LIBCC = $LIBCC |
Rich Felker | a80847d | 2013-07-22 21:22:04 -0400 | [diff] [blame] | 516 | OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS |
Rich Felker | 64d2f8e | 2012-05-04 23:24:51 -0400 | [diff] [blame] | 517 | EOF |
| 518 | test "x$static" = xno && echo "STATIC_LIBS =" |
| 519 | test "x$shared" = xno && echo "SHARED_LIBS =" |
| 520 | test "x$wrapper" = xno && echo "ALL_TOOLS =" |
| 521 | test "x$wrapper" = xno && echo "TOOL_LIBS =" |
| 522 | exec 1>&3 3>&- |
| 523 | |
| 524 | printf "done\n" |