configure 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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-wxpages build with W+X pages [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_AUTO=
  60. CXXFLAGS_TRY=
  61. CXXFLAGS_ZERO=
  62. CXXFLAGS_COMMON=
  63. srcdir=
  64. prefix=/usr/local
  65. libdir='$(prefix)/lib'
  66. includedir='$(prefix)/include'
  67. debug=no
  68. warnings=yes
  69. shared=yes
  70. static=no
  71. wxpages=yes
  72. for arg ; do
  73. case "$arg" in
  74. --help|-h) usage ;;
  75. --srcdir=*) srcdir=${arg#*=} ;;
  76. --prefix=*) prefix=${arg#*=} ;;
  77. --libdir=*) libdir=${arg#*=} ;;
  78. --includedir=*) includedir=${arg#*=} ;;
  79. --syslibdir=*) syslibdir=${arg#*=} ;;
  80. --enable-shared|--enable-shared=yes) shared=yes ;;
  81. --disable-shared|--enable-shared=no) shared=no ;;
  82. --enable-static|--enable-static=yes) static=yes ;;
  83. --disable-static|--enable-static=no) static=no ;;
  84. --enable-debug|--enable-debug=yes) debug=yes ;;
  85. --disable-debug|--enable-debug=no) debug=no ;;
  86. --enable-warnings|--enable-warnings=yes) warnings=yes ;;
  87. --disable-warnings|--enable-warnings=no) warnings=no ;;
  88. --enable-wxpages|--enable-wxpages=yes) wxpages=yes ;;
  89. --disable-wxpages|--enable-wxpages=no) wxpages=no ;;
  90. --enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;;
  91. --host=*|--target=*) target=${arg#*=} ;;
  92. --build=*) build=${arg#*=} ;;
  93. -* ) fail "$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/texe"
  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. testcxx () {
  143. printf "checking whether $1... "
  144. echo "$2" > "$tsrc"
  145. echo "int main () { $3 return (0); }" >> "$tsrc"
  146. if $($CXX -static $tsrc -o $texe >/dev/null 2>&1) ; then
  147. "./$texe"
  148. if [ $? -eq 0 ]; then
  149. printf "yes\n"
  150. return 0
  151. fi
  152. fi
  153. printf "no\n"
  154. return 1
  155. }
  156. # Find out options to force errors on unknown compiler/linker flags.
  157. tryflag CXXFLAGS_TRY -Werror=unknown-warning-option
  158. tryflag CXXFLAGS_TRY -Werror=unused-command-line-argument
  159. tryflag CXXFLAGS_TRY -Werror=ignored-optimization-argument
  160. # See if the compiler accepts explicit standard versioning
  161. tryflag CXXFLAGS_COMMON -std=c++11
  162. # Enable optimizations
  163. tryflag CXXFLAGS_COMMON -O2
  164. # Disable stack protection
  165. tryflag CXXFLAGS_COMMON -fno-stack-protector
  166. # Enable debugging if needed.
  167. test "x$debug" = xyes && tryflag CXXFLAGS_AUTO -g
  168. # Always try to use -pipe.
  169. tryflag CXXFLAGS_AUTO -pipe
  170. # Enable specific flags for compilation of dangerous modules
  171. tryflag CXXFLAGS_ZERO -fno-omit-frame-pointer
  172. if test "x$warnings" = xyes ; then
  173. tryflag CXXFLAGS_AUTO -Wall
  174. tryflag CXXFLAGS_AUTO -Wno-parentheses
  175. tryflag CXXFLAGS_AUTO -Wno-uninitialized
  176. tryflag CXXFLAGS_AUTO -Wno-missing-braces
  177. tryflag CXXFLAGS_AUTO -Wno-unused-value
  178. tryflag CXXFLAGS_AUTO -Wno-unused-but-set-variable
  179. tryflag CXXFLAGS_AUTO -Wno-unknown-pragmas
  180. fi
  181. if testcxx "long double is the same as double" "" "return (sizeof (long double) != sizeof (double));" ; then
  182. CXXFLAGS="$CXXFLAGS -DCXXCALL_LONG_DOUBLE_ALIASED"
  183. fi
  184. # generate version file
  185. version=$(cat $srcdir/VERSION)
  186. major=$(echo $version | cut -d. -f1)
  187. minor=$(echo $version | cut -d. -f2)
  188. echo "const int MAJOR = $major; const int MINOR = $minor;" > $srcdir/version.hpp
  189. if test "x$wxpages" = xno ; then
  190. CXXFLAGS_COMMON="$CXXFLAGS_COMMON -DCXXCALL_DISABLE_WXPAGES"
  191. fi
  192. printf "creating config.mak... "
  193. cmdline=$(quote "$0")
  194. for i ; do cmdline="$cmdline $(quote "$i")" ; done
  195. exec 3>&1 1>config.mak
  196. cat << EOF
  197. # This version of config.mak was generated by:
  198. # $cmdline
  199. # Any changes made here will be lost if configure is re-run
  200. srcdir = $srcdir
  201. prefix = $prefix
  202. libdir = $libdir
  203. includedir = $includedir
  204. CXX = $CXX
  205. CXXFLAGS = $CXXFLAGS_COMMON $CXXFLAGS
  206. CXXFLAGS_AUTO = $CXXFLAGS_AUTO
  207. CXXFLAGS_ZERO = $CXXFLAGS_COMMON $CXXFLAGS_ZERO
  208. LDFLAGS = $LDFLAGS
  209. CROSS_COMPILE = $CROSS_COMPILE
  210. EOF
  211. test "x$static" = xno && echo "STATIC_LIBS ="
  212. test "x$shared" = xno && echo "SHARED_LIBS ="
  213. test "x$shared" = xno && echo 'TEST_OBJS = $(OBJS)'
  214. exec 1>&3 3>&-
  215. test "$srcdir" = "." || ln -sf $srcdir/Makefile .
  216. printf "done\n"