configure 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/bin/sh
  2. # Copyright (C) 2006,2008 G.P. Halkes
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License version 3, as
  5. # published by the Free Software Foundation.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. # Set zsh to emulate sh (otherwise all kinds of eval's wont work)
  15. [ -n "${ZSH_VERSION}" ] && emulate sh
  16. #==============================
  17. # Functions
  18. #==============================
  19. error() {
  20. echo "$@"
  21. exit 1
  22. }
  23. check() {
  24. if "$@" ; then
  25. :
  26. else
  27. error "Error executing $@. Aborting."
  28. fi
  29. }
  30. check_message() {
  31. printf "$@"
  32. echo "----------------------------------">> ../config.log
  33. echo "$@" >> ../config.log
  34. }
  35. check_message_result() {
  36. echo "$@"
  37. echo "$@" >> ../config.log
  38. }
  39. checkConfig() {
  40. check_message "Checking for $1... "
  41. shift
  42. echo "Running '${MAKE} $@ test'" >> ../config.log
  43. rm -rf test >/dev/null 2>&1
  44. ${MAKE} "$@" test >> ../config.log 2>&1 && check_message_result "yes" && { createConfig .. "$@" ; rm -rf Makefile test >/dev/null 2>&1 ; exit 0 ; }
  45. check_message_result "no"
  46. rm -rf test >/dev/null 2>&1
  47. }
  48. createConfig() {
  49. DIRECTORY="$1"
  50. shift
  51. if [ -z "${DIRECTORY}" ] ; then
  52. DIRECTORY=.
  53. fi
  54. (
  55. if [ -n "${PREFIX}" ] ; then
  56. ESCAPED_PREFIX=`echo "${PREFIX}" | sed 's/\//\\\\\//g'`
  57. echo "s/^prefix=.*/prefix=${ESCAPED_PREFIX}/g"
  58. fi
  59. if [ -n "${CFLAGS}" ] ; then
  60. ESCAPED_CFLAGS=`echo "${CFLAGS}" | sed 's/\//\\\\\//g'`
  61. echo "s/^CFLAGS=.*/CFLAGS=${ESCAPED_CFLAGS}/g"
  62. fi
  63. for SETTING in "$@"
  64. do
  65. NAME=`echo "${SETTING}" | sed 's/=.*/=/g'`
  66. ESCAPED_SETTING=`echo "${SETTING}" | sed 's/\//\\\\\//g'`
  67. echo "s/^${NAME}.*/${ESCAPED_SETTING}/g"
  68. done
  69. [ -z "${CC}" ] || echo "/^\\.POSIX:/a\\
  70. CC=${CC}"
  71. [ -z "${LDFLAGS}" ] || echo "/^\\.POSIX:/a\\
  72. LDFLAGS=${LDFLAGS}"
  73. [ -z "${LDLIBS}" ] || echo "/^\\.POSIX:/a\\
  74. LDLIBS=${LDLIBS}"
  75. ) > sedscript
  76. cat "${DIRECTORY}/Makefile.in" | sed -f sedscript > "${DIRECTORY}/Makefile"
  77. rm -rf sedscript >/dev/null 2>&1
  78. true
  79. }
  80. #==============================
  81. # Setup
  82. #==============================
  83. for PARAM
  84. do
  85. case "${PARAM}" in
  86. -h|--help)
  87. cat <<EOF
  88. Usage: configure [--prefix=<dir>] [<var>=<value>]
  89. --prefix=<dir> Prefix for installation [/usr/local]
  90. Environment variables that tune build:
  91. MAKE Make program to use [make]
  92. CC C-compiler to use (default determined by make)
  93. CFLAGS C-compiler flags to use [-O2]
  94. LDFLAGS Linker flags to use (default determined by make)
  95. LDLIBS Extra libraries to link
  96. PREFIX See --prefix=<dir>
  97. Note: Environment variables may also be specified as parameters.
  98. EOF
  99. exit 0
  100. ;;
  101. --prefix=*)
  102. PREFIX=`echo "${PARAM}" | sed 's/^--prefix=//'`
  103. ;;
  104. -*=*)
  105. error "Error on commandline: ${PARAM}"
  106. ;;
  107. *=*)
  108. name=`echo "${PARAM}" | sed 's/=.*//'`
  109. value=`echo "${PARAM}" | sed 's/^[^=]*=//'`
  110. eval "${name}"="\"${value}\""
  111. ;;
  112. *)
  113. error "Error on commandline: ${PARAM}"
  114. ;;
  115. esac
  116. done
  117. check cd config
  118. if [ -z "${MAKE}" ] ; then
  119. MAKE=make
  120. fi
  121. echo "Configuration test log created at `date`" > ../config.log
  122. echo "-- configure called with $0 $@" >> ../config.log
  123. unset SETTINGS
  124. [ -z "${LDLIBS}" ] || SETTINGS="LDLIBS=${LDLIBS} ${SETTINGS}"
  125. [ -z "${LDFLAGS}" ] || SETTINGS="LDFLAGS=${LDFLAGS} ${SETTINGS}"
  126. [ -z "${CFLAGS}" ] || SETTINGS="CFLAGS=${CFLAGS} ${SETTINGS}"
  127. [ -z "${CC}" ] || SETTINGS="CC=${CC} ${SETTINGS}"
  128. [ -n "${SETTINGS}" ] && check_message_result "Using settings ${SETTINGS}"
  129. createConfig .
  130. check_message "Checking for working make (${MAKE})... "
  131. rm -rf test >/dev/null 2>&1
  132. echo "Running '${MAKE} test'" >> ../config.log
  133. ${MAKE} test >> ../config.log 2>&1 || error "${MAKE} failed on sanity check. See config.log."
  134. check_message_result "yes"
  135. #==============================
  136. # Regex testing
  137. #==============================
  138. checkConfig "POSIX regex" REGEX=POSIX
  139. checkConfig "POSIX regex in -lregex" REGEX=POSIX REGEXLIBS=-lregex
  140. checkConfig "old POSIX regex" REGEX=OLDPOSIX
  141. checkConfig "old POSIX regex in -lregex" REGEX=OLDPOSIX REGEXLIBS=-lregex
  142. checkConfig "PCRE POSIX compatiblity API" REGEX=PCRE REGEXLIBS=-lpcreposix
  143. check_message_result "Regex support disabled"
  144. createConfig .. REGEX=