configure 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #! /bin/sh
  2. usage () {
  3. cat <<EOF
  4. Usage: $0 [option]... [var=value]... [target]
  5. In order to set environment variables (like CXX), you have to specify them as
  6. var=value. See below for descriptions of some of them.
  7. Default values are specified in brackets.
  8. Configuration settings:
  9. --srcdir=dir source directory [auto detected]
  10. Installation directories:
  11. --prefix=prefix main installation prefix [/usr/local]
  12. --libdir=dir library files [prefix/lib]
  13. --includedir=dir include files [prefix/include]
  14. System types:
  15. --target=target configure to run on target [auto detected]
  16. --host=host same as target
  17. --build=build build system, used to detect cross compiling
  18. Optional features:
  19. --enable-debug build with debug symbols [no]
  20. --enable-warnings build with extensive warnings [yes]
  21. --enable-shared build shared library [yes]
  22. --enable-static build static library [no]
  23. --enable-threads build with multithreading [yes]
  24. Environment variables you may set:
  25. CXX C++ compiler [auto detected]
  26. CXXFLAGS C++ compiler flags [-O2 -pipe ...]
  27. CROSS_COMPILE prefix for cross compiler and tools [not set]
  28. These variables may be set to override detections made by configure.
  29. EOF
  30. exit 0
  31. }
  32. quote () {
  33. tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
  34. $1
  35. EOF
  36. printf %s\\n "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#"
  37. }
  38. echo () { printf "%s\n" "$*" ; }
  39. fail () { echo "$*" ; exit 1 ; }
  40. fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
  41. cmdexists () { type "$1" >/dev/null 2>&1 ; }
  42. trycxx () { test -z "$CXX" && cmdexists "$1" && CXX=$1 ; }
  43. stripdir () {
  44. while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
  45. }
  46. tryflag () {
  47. printf "checking whether compiler accepts %s... " "$2"
  48. echo "typedef int x;" > "$tsrc"
  49. if $CXX $CXXFLAGS_TRY $2 -c -o /dev/null "$tsrc" >/dev/null 2>&1 ; then
  50. printf "yes\n"
  51. eval "$1=\"\${$1} \$2\""
  52. eval "$1=\${$1# }"
  53. return 0
  54. else
  55. printf "no\n"
  56. return 1
  57. fi
  58. }
  59. CXXFLAGS_EXTRA=
  60. CXXFLAGS_AUTO=
  61. CXXFLAGS_TRY=
  62. CXX_PROG=
  63. LDFLAGS_AUTO=
  64. LDFLAGS_TRY=
  65. srcdir=
  66. prefix=/usr/local
  67. libdir='$(prefix)/lib'
  68. includedir='$(prefix)/include'
  69. debug=no
  70. warnings=yes
  71. shared=yes
  72. threads=yes
  73. for arg ; do
  74. case "$arg" in
  75. --help|-h) usage ;;
  76. --srcdir=*) srcdir=${arg#*=} ;;
  77. --prefix=*) prefix=${arg#*=} ;;
  78. --libdir=*) libdir=${arg#*=} ;;
  79. --includedir=*) includedir=${arg#*=} ;;
  80. --syslibdir=*) syslibdir=${arg#*=} ;;
  81. --enable-shared|--enable-shared=yes) shared=yes ;;
  82. --disable-shared|--enable-shared=no) shared=no ;;
  83. --enable-static|--enable-static=yes) shared=no ;;
  84. --disable-static|--enable-static=no) shared=yes ;;
  85. --enable-debug|--enable-debug=yes) debug=yes ;;
  86. --disable-debug|--enable-debug=no) debug=no ;;
  87. --enable-warnings|--enable-warnings=yes) warnings=yes ;;
  88. --disable-warnings|--enable-warnings=no) warnings=no ;;
  89. --enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;;
  90. --host=*|--target=*) target=${arg#*=} ;;
  91. --build=*) build=${arg#*=} ;;
  92. --enable-threads=*) threads=${arg#*=} ;;
  93. -* ) echo "$0: unknown option $arg" ;;
  94. CXX=*) CXX=${arg#*=} ;;
  95. CXXFLAGS=*) CXXFLAGS=${arg#*=} ;;
  96. LDFLAGS=*) LDFLAGS=${arg#*=} ;;
  97. CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;;
  98. *=*) ;;
  99. *) build=$arg ; target=$arg ;;
  100. esac
  101. done
  102. for i in srcdir prefix libdir includedir ; do
  103. stripdir $i
  104. done
  105. # See if we're building out of tree.
  106. if test -z "$srcdir" ; then
  107. srcdir="${0%/configure}"
  108. stripdir srcdir
  109. fi
  110. abs_builddir="$(pwd)" || fail "$0: cannot determine working directory"
  111. abs_srcdir="$(cd $srcdir && pwd)" || fail "$0: invalid source directory $srcdir"
  112. test "$abs_srcdir" = "$abs_builddir" && srcdir=.
  113. test "$srcdir" != "." -a -f Makefile -a ! -h Makefile && fail "$0: Makefile already exists in the working directory"
  114. # Generate a temporary directory.
  115. set -C
  116. tdir=$(mktemp -d "$(basename $0).XXXXXXX")
  117. set +C
  118. trap 'rm -rf "$tdir"' EXIT INT QUIT TERM HUP
  119. tsrc="$tdir/tx.cpp"
  120. texe="$tdir/tx"
  121. # For cross-compiling, set a default CROSS_COMPILE if it wasn't provided.
  122. test "$target" && \
  123. test "$target" != "$build" && \
  124. test -z "$CROSS_COMPILE" && \
  125. CROSS_COMPILE="$target-"
  126. # Set C++ compiler.
  127. printf "checking for C++ compiler..."
  128. trycxx ${CROSS_COMPILE}g++
  129. trycxx ${CROSS_COMPILE}clang++
  130. trycxx ${CROSS_COMPILE}icc
  131. trycxx ${CROSS_COMPILE}cxx
  132. printf "%s\n" "$CXX"
  133. test -n "$CXX" || { echo "$0: cannot find a C++ compiler" ; exit 1 ; }
  134. printf "checking whether C++ compiler works... "
  135. echo "typedef int x;" > "$tsrc"
  136. if output=$($CXX $CXXFLAGS -c -o /dev/null "$tsrc" 2>&1) ; then
  137. printf "yes\n"
  138. else
  139. printf "no; compiler output follows:\n%s\n" "$output"
  140. exit 1
  141. fi
  142. # Find out options to force errors on unknown compiler/linker flags.
  143. tryflag CXXFLAGS_TRY -Werror=unknown-warning-option
  144. tryflag CXXFLAGS_TRY -Werror=unused-command-line-argument
  145. tryflag CXXFLAGS_TRY -Werror=ignored-optimization-argument
  146. # Try to avoid executable stacks in GNU compilers.
  147. tryflag CXXFLAGS_AUTO -Wa,--noexecstack
  148. # See if the compiler accepts explicit standard versioning
  149. tryflag CXXFLAGS -std=c++11
  150. # Enable optimizations
  151. tryflag CXXFLAGS -O0
  152. # Disable stack checks.
  153. tryflag CXXFLAGS -fno-stack-protector
  154. # Disable exception stuff.
  155. tryflag CXXFLAGS_EXTRA -fno-exceptions
  156. # Enable debugging if needed.
  157. test "$debug" = yes && CXXFLAGS_AUTO=-g
  158. # Always try to use -pipe.
  159. tryflag CXXFLAGS_AUTO -pipe
  160. if test "x$warnings" = xyes ; then
  161. tryflag CXXFLAGS_AUTO -Wall
  162. tryflag CXXFLAGS_AUTO -Wno-parentheses
  163. tryflag CXXFLAGS_AUTO -Wno-uninitialized
  164. tryflag CXXFLAGS_AUTO -Wno-missing-braces
  165. tryflag CXXFLAGS_AUTO -Wno-unused-value
  166. tryflag CXXFLAGS_AUTO -Wno-unused-but-set-variable
  167. tryflag CXXFLAGS_AUTO -Wno-unknown-pragmas
  168. fi
  169. if test "x$threads" = xno ; then
  170. CXXFLAGS_AUTO="$CXXFLAGS_AUTO -DKP_NO_THREADS"
  171. fi
  172. if test "x$shared" = xno; then
  173. tryflag CXXFLAGS_AUTO -static
  174. tryflag CXXFLAGS_AUTO -static-libgcc
  175. fi
  176. printf "creating config.mak... "
  177. cmdline=$(quote "$0")
  178. for i ; do cmdline="$cmdline $(quote "$i")" ; done
  179. exec 3>&1 1>config.mak
  180. cat << EOF
  181. # This version of config.mak was generated by:
  182. # $cmdline
  183. # Any changes made here will be lost if configure is re-run
  184. srcdir = $srcdir
  185. prefix = $prefix
  186. libdir = $libdir
  187. includedir = $includedir
  188. CXX = $CXX
  189. CXXFLAGS += $CXXFLAGS
  190. CXXFLAGS_AUTO = $CXXFLAGS_AUTO
  191. CXXFLAGS_EXTRA = $CXXFLAGS_EXTRA
  192. LDFLAGS = $LDFLAGS
  193. LDFLAGS_AUTO = $LDFLAGS_AUTO
  194. CROSS_COMPILE = $CROSS_COMPILE
  195. EOF
  196. if test "x$shared" = xno ; then
  197. echo "DYNAMIC_OBJS = "
  198. echo 'UOBJS = $(OBJS)'
  199. echo 'KPLIB = $(STATIC_LIB)'
  200. echo "CXXFLAGS += -DKP_STATIC"
  201. else
  202. echo "STATIC_OBJS = "
  203. fi
  204. exec 1>&3 3>&-
  205. test "$srcdir" = "." || ln -sf $srcdir/GNUmakefile .
  206. printf "done\n"