1
0

configure 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. Installation directories:
  9. --prefix=PREFIX main installation prefix [/usr/local/musl]
  10. --exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
  11. Fine tuning of the installation directories:
  12. --bindir=DIR user executables [EPREFIX/bin]
  13. --libdir=DIR library files for the linker [PREFIX/lib]
  14. --includedir=DIR include files for the C compiler [PREFIX/include]
  15. --syslibdir=DIR location for the dynamic linker [/lib]
  16. System types:
  17. --target=TARGET configure to run on target TARGET [detected]
  18. --host=HOST same as --target
  19. Optional features:
  20. --enable-debug build with debugging information [disabled]
  21. --enable-warnings build with recommended warnings flags [disabled]
  22. --enable-gcc-wrapper build musl-gcc toolchain wrapper [auto]
  23. --disable-shared inhibit building shared library [enabled]
  24. --disable-static inhibit building static library [enabled]
  25. Some influential environment variables:
  26. CC C compiler command [detected]
  27. CFLAGS C compiler flags [-Os -pipe ...]
  28. Use these variables to override the choices made by configure.
  29. EOF
  30. exit 0
  31. }
  32. # Helper functions
  33. echo () { printf "%s\n" "$*" ; }
  34. fail () { echo "$*" ; exit 1 ; }
  35. fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
  36. cmdexists () { type "$1" >/dev/null 2>&1 ; }
  37. trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
  38. setdir () {
  39. if eval "test -z \"\${$1}\"" ; then eval "$1=\$2"
  40. else eval "fnmatch '*/' \"\${$1}\"" && eval "$1=\${$1%/}" ; fi
  41. }
  42. tryflag () {
  43. printf "checking whether compiler accepts %s... " "$2"
  44. echo "typedef int x;" > "$tmpc"
  45. if "$CC" "$2" -c -o /dev/null "$tmpc" 2>/dev/null ; then
  46. printf "yes\n"
  47. eval "$1=\"\${$1} \$2\""
  48. eval "$1=\${$1# }"
  49. return 0
  50. else
  51. printf "no\n"
  52. return 1
  53. fi
  54. }
  55. # Beginning of actual script
  56. prefix=
  57. exec_prefix=
  58. bindir=
  59. libdir=
  60. includedir=
  61. syslibdir=
  62. target=
  63. debug=no
  64. warnings=
  65. shared=yes
  66. static=yes
  67. for arg ; do
  68. case "$arg" in
  69. --help) usage ;;
  70. --prefix=*) prefix=${arg#*=} ;;
  71. --exec-prefix=*) exec_prefix=${arg#*=} ;;
  72. --bindir=*) bindir=${arg#*=} ;;
  73. --libdir=*) libdir=${arg#*=} ;;
  74. --includedir=*) includedir=${arg#*=} ;;
  75. --syslibdir=*) syslibdir=${arg#*=} ;;
  76. --enable-shared|--enable-shared=yes) shared=yes ;;
  77. --disable-shared|--enable-shared=no) shared=no ;;
  78. --enable-static|--enable-static=yes) static=yes ;;
  79. --disable-static|--enable-static=no) static=no ;;
  80. --enable-debug|--enable-debug=yes) debug=yes ;;
  81. --disable-debug|--enable-debug=no) debug=no ;;
  82. --enable-warnings|--enable-warnings=yes) warnings=yes ;;
  83. --disable-warnings|--enable-warnings=no) warnings=no ;;
  84. --enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ;;
  85. --disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;;
  86. --enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
  87. --host=*|--target=*) target=${arg#*=} ;;
  88. -* ) echo "$0: unknown option $arg" ;;
  89. CC=*) CC=${arg#*=} ;;
  90. CFLAGS=*) CFLAGS=${arg#*=} ;;
  91. CPPFLAGS=*) CPPFLAGS=${arg#*=} ;;
  92. LDFLAGS=*) LDFLAGS=${arg#*=} ;;
  93. *=*) ;;
  94. *) target=$arg ;;
  95. esac
  96. done
  97. setdir prefix /usr/local/musl
  98. setdir exec_prefix '$(prefix)'
  99. setdir bindir '$(exec_prefix)/bin'
  100. setdir libdir '$(prefix)/lib'
  101. setdir includedir '$(prefix)/include'
  102. setdir syslibdir '/lib'
  103. #
  104. # Get a temp filename we can use
  105. #
  106. i=0
  107. set -C
  108. while : ; do i=$(($i+1))
  109. tmpc="./conf$$-$PPID-$i.c"
  110. 2>/dev/null > "$tmpc" && break
  111. test "$i" -gt 50 && fail "$0: cannot create temporary file $tmpc"
  112. done
  113. set +C
  114. trap 'rm "$tmpc"' EXIT INT QUIT TERM HUP
  115. #
  116. # Find a C compiler to use
  117. #
  118. printf "checking for C compiler... "
  119. trycc gcc
  120. trycc c99
  121. trycc cc
  122. printf "%s\n" "$CC"
  123. test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
  124. #
  125. # Only build musl-gcc wrapper if toolchain does not already target musl
  126. #
  127. if test -z "$wrapper" ; then
  128. printf "checking whether compiler is gcc... "
  129. if fnmatch '*gcc\ version*' "$("$CC" -v 2>&1)" ; then
  130. echo yes
  131. printf "checking whether to build musl-gcc wrapper... "
  132. wrapper=yes
  133. while read line ; do
  134. case "$line" in */ld-musl-*) wrapper=no ;; esac
  135. done <<EOF
  136. $($CC -dumpspecs)
  137. EOF
  138. echo $wrapper
  139. else
  140. echo no
  141. fi
  142. fi
  143. #
  144. # Find the target architecture
  145. #
  146. printf "checking target system type... "
  147. test -n "$target" || target=$("$CC" -dumpmachine 2>/dev/null) || target=unknown
  148. printf "%s\n" "$target"
  149. #
  150. # Convert to just ARCH
  151. #
  152. case "$target" in
  153. arm*) ARCH=arm ;;
  154. i?86*) ARCH=i386 ;;
  155. x86_64*) ARCH=x86_64 ;;
  156. unknown) fail "$0: unable to detect target arch; try $0 --target=..." ;;
  157. *) fail "$0: unknown or unsupported target \"$target\"" ;;
  158. esac
  159. #
  160. # Try to get a conforming C99 freestanding environment
  161. #
  162. tryflag CFLAGS_C99FSE -std=c99
  163. tryflag CFLAGS_C99FSE -nostdinc
  164. tryflag CFLAGS_C99FSE -ffreestanding \
  165. || tryflag CFLAGS_C99FSE -fno-builtin
  166. tryflag CFLAGS_C99FSE -fexcess-precision=standard \
  167. || tryflag CFLAGS_C99FSE -ffloat-store
  168. tryflag CFLAGS_C99FSE -frounding-math
  169. #
  170. # Setup basic default CFLAGS: debug, optimization, and -pipe
  171. #
  172. if fnmatch '-O*|*\ -O*' "$CFLAGS_AUTO $CFLAGS" ; then :
  173. else
  174. tryflag CFLAGS_AUTO -Os || tryflag CFLAGS_AUTO -O2
  175. fi
  176. test "x$debug" = xyes && CFLAGS_AUTO="-g"
  177. tryflag CFLAGS_AUTO -pipe
  178. #
  179. # If debugging is disabled, omit bloated DWARF2 unwind tables & frame ptr
  180. #
  181. if fnmatch '-g*|*\ -g*' "$CFLAGS_AUTO $CFLAGS" ; then :
  182. else
  183. tryflag CFLAGS_AUTO -fno-unwind-tables
  184. tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
  185. tryflag CFLAGS_AUTO -fomit-frame-pointer
  186. fi
  187. #
  188. # Some optimization levels add bloated alignment that hurt performance
  189. #
  190. tryflag CFLAGS_AUTO -falign-functions=1
  191. tryflag CFLAGS_AUTO -falign-labels=1
  192. tryflag CFLAGS_AUTO -falign-loops=1
  193. tryflag CFLAGS_AUTO -falign-jumps=1
  194. #
  195. # On x86, make sure we don't have incompatible instruction set
  196. # extensions enabled by default. This is bad for making static binaries.
  197. # We cheat and use i486 rather than i386 because i386 really does not
  198. # work anyway (issues with atomic ops).
  199. #
  200. if test "$ARCH" = "i386" ; then
  201. fnmatch '-march=*|*\ -march=*' "$CFLAGS" || tryflag CFLAGS_AUTO -march=i486
  202. fnmatch '-mtune=*|*\ -mtune=*' "$CFLAGS" || tryflag CFLAGS_AUTO -mtune=generic
  203. fi
  204. if test "x$warnings" = xyes ; then
  205. tryflag CFLAGS_AUTO -Wall
  206. tryflag CFLAGS_AUTO -Wpointer-arith
  207. tryflag CFLAGS_AUTO -Wcast-align
  208. tryflag CFLAGS_AUTO -Wno-parentheses
  209. tryflag CFLAGS_AUTO -Wno-uninitialized
  210. tryflag CFLAGS_AUTO -Wno-missing-braces
  211. tryflag CFLAGS_AUTO -Wno-unused-value
  212. tryflag CFLAGS_AUTO -Wno-unused-but-set-variable
  213. tryflag CFLAGS_AUTO -Wno-unknown-pragmas
  214. fi
  215. printf "creating config.mak... "
  216. exec 3>&1 1>config.mak
  217. cat << EOF
  218. # This version of config.mak was generated by configure
  219. # Any changes made here will be lost if configure is re-run
  220. ARCH = $ARCH
  221. prefix = $prefix
  222. exec_prefix = $exec_prefix
  223. bindir = $bindir
  224. libdir = $libdir
  225. includedir = $includedir
  226. syslibdir = $syslibdir
  227. CC = $CC
  228. CFLAGS= $CFLAGS_AUTO $CFLAGS
  229. CFLAGS_C99FSE = $CFLAGS_C99FSE
  230. CPPFLAGS = $CPPFLAGS
  231. LDFLAGS = $LDFLAGS
  232. EOF
  233. test "x$static" = xno && echo "STATIC_LIBS ="
  234. test "x$shared" = xno && echo "SHARED_LIBS ="
  235. test "x$wrapper" = xno && echo "ALL_TOOLS ="
  236. test "x$wrapper" = xno && echo "TOOL_LIBS ="
  237. exec 1>&3 3>&-
  238. printf "done\n"