configure 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. --max-finalizers=N maximum number of pending finalizers
  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. srcdir=
  63. prefix=/usr/local
  64. libdir='$(prefix)/lib'
  65. includedir='$(prefix)/include'
  66. debug=no
  67. warnings=yes
  68. shared=yes
  69. static=no
  70. maxfins=1000
  71. for arg ; do
  72. case "$arg" in
  73. --help|-h) usage ;;
  74. --srcdir=*) srcdir=${arg#*=} ;;
  75. --prefix=*) prefix=${arg#*=} ;;
  76. --libdir=*) libdir=${arg#*=} ;;
  77. --includedir=*) includedir=${arg#*=} ;;
  78. --syslibdir=*) syslibdir=${arg#*=} ;;
  79. --enable-shared|--enable-shared=yes) shared=yes ;;
  80. --disable-shared|--enable-shared=no) shared=no ;;
  81. --enable-static|--enable-static=yes) static=yes ;;
  82. --disable-static|--enable-static=no) static=no ;;
  83. --enable-debug|--enable-debug=yes) debug=yes ;;
  84. --disable-debug|--enable-debug=no) debug=no ;;
  85. --enable-warnings|--enable-warnings=yes) warnings=yes ;;
  86. --disable-warnings|--enable-warnings=no) warnings=no ;;
  87. --enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;;
  88. --host=*|--target=*) target=${arg#*=} ;;
  89. --build=*) build=${arg#*=} ;;
  90. --max-finalizers=*) maxfins=${arg#*=} ;;
  91. -* ) fail "$0: unknown option '$arg'" ;;
  92. CXX=*) CXX=${arg#*=} ;;
  93. CXXFLAGS=*) CXXFLAGS=${arg#*=} ;;
  94. LDFLAGS=*) LDFLAGS=${arg#*=} ;;
  95. CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;;
  96. *=*) ;;
  97. *) build=$arg ; target=$arg ;;
  98. esac
  99. done
  100. for i in srcdir prefix libdir includedir ; do
  101. stripdir $i
  102. done
  103. # See if we're building out of tree.
  104. if test -z "$srcdir" ; then
  105. srcdir="${0%/configure}"
  106. stripdir srcdir
  107. fi
  108. abs_builddir="$(pwd)" || fail "$0: cannot determine working directory"
  109. abs_srcdir="$(cd $srcdir && pwd)" || fail "$0: invalid source directory $srcdir"
  110. test "$abs_srcdir" = "$abs_builddir" && srcdir=.
  111. test "$srcdir" != "." -a -f Makefile -a ! -h Makefile && fail "$0: Makefile already exists in the working directory"
  112. # Generate a temporary directory.
  113. set -C
  114. tdir=$(mktemp -d "$(basename $0).XXXXXXX")
  115. set +C
  116. trap 'rm -rf "$tdir"' EXIT INT QUIT TERM HUP
  117. tsrc="$tdir/tx.cpp"
  118. texe="$tdir/texe"
  119. # For cross-compiling, set a default CROSS_COMPILE if it wasn't provided.
  120. test "$target" && \
  121. test "$target" != "$build" && \
  122. test -z "$CROSS_COMPILE" && \
  123. CROSS_COMPILE="$target-"
  124. # Set C++ compiler.
  125. printf "checking for C++ compiler..."
  126. trycxx ${CROSS_COMPILE}g++
  127. trycxx ${CROSS_COMPILE}clang++
  128. trycxx ${CROSS_COMPILE}icc
  129. trycxx ${CROSS_COMPILE}cxx
  130. printf "%s\n" "$CXX"
  131. test -n "$CXX" || { echo "$0: cannot find a C++ compiler" ; exit 1 ; }
  132. printf "checking whether C++ compiler works... "
  133. echo "typedef int x;" > "$tsrc"
  134. if output=$($CXX $CXXFLAGS -c -o /dev/null "$tsrc" 2>&1) ; then
  135. printf "yes\n"
  136. else
  137. printf "no; compiler output follows:\n%s\n" "$output"
  138. exit 1
  139. fi
  140. # Find out options to force errors on unknown compiler/linker flags.
  141. tryflag CXXFLAGS_TRY -Werror=unknown-warning-option
  142. tryflag CXXFLAGS_TRY -Werror=unused-command-line-argument
  143. tryflag CXXFLAGS_TRY -Werror=ignored-optimization-argument
  144. # Try to avoid executable stacks in GNU compilers.
  145. tryflag CXXFLAGS_EXTRA -Wa,--noexecstack
  146. # See if the compiler accepts explicit standard versioning
  147. tryflag CXXFLAGS -std=c++11
  148. # Enable optimizations
  149. tryflag CXXFLAGS -O2
  150. # Enable debugging if needed.
  151. test "x$debug" = xyes && tryflag CXXFLAGS_AUTO -g
  152. # Always try to use -pipe.
  153. tryflag CXXFLAGS_AUTO -pipe
  154. # See if we can link against pthreads with a compiler switch.
  155. tryflag CXXFLAGS_AUTO -pthread
  156. if test "x$warnings" = xyes ; then
  157. tryflag CXXFLAGS_AUTO -Wall
  158. tryflag CXXFLAGS_AUTO -Wno-parentheses
  159. tryflag CXXFLAGS_AUTO -Wno-uninitialized
  160. tryflag CXXFLAGS_AUTO -Wno-missing-braces
  161. tryflag CXXFLAGS_AUTO -Wno-unused-value
  162. tryflag CXXFLAGS_AUTO -Wno-unused-but-set-variable
  163. tryflag CXXFLAGS_AUTO -Wno-unknown-pragmas
  164. fi
  165. case $maxfins in
  166. ''|*[!0-9]*) fail "--max-finalizers must be an integer" ;;
  167. *) ;;
  168. esac
  169. # generate version file
  170. version=$(cat $srcdir/VERSION)
  171. major=$(echo $version | cut -d. -f1)
  172. minor=$(echo $version | cut -d. -f2)
  173. echo "const int MAJOR = $major; const int MINOR = $minor;" > $srcdir/version.hpp
  174. printf "creating config.mak... "
  175. cmdline=$(quote "$0")
  176. for i ; do cmdline="$cmdline $(quote "$i")" ; done
  177. exec 3>&1 1>config.mak
  178. cat << EOF
  179. # This version of config.mak was generated by:
  180. # $cmdline
  181. # Any changes made here will be lost if configure is re-run
  182. srcdir = $srcdir
  183. prefix = $prefix
  184. libdir = $libdir
  185. includedir = $includedir
  186. CXX = $CXX
  187. CXXFLAGS = $CXXFLAGS -DXRCU_MAX_FINS=$maxfins
  188. CXXFLAGS_AUTO = $CXXFLAGS_AUTO
  189. CXXFLAGS_EXTRA = $CXXFLAGS_EXTRA
  190. LDFLAGS = $LDFLAGS
  191. CROSS_COMPILE = $CROSS_COMPILE
  192. EOF
  193. test "x$static" = xno && echo "STATIC_LIBS ="
  194. test "x$shared" = xno && echo "SHARED_LIBS ="
  195. test "x$shared" = xno && echo 'TEST_OBJS = $(OBJS)'
  196. exec 1>&3 3>&-
  197. test "$srcdir" = "." || ln -sf $srcdir/Makefile .
  198. printf "done\n"