configure 23 KB

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