configure 21 KB

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