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