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