bootstrap.sh 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. #!/bin/sh
  2. ##### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*-
  3. ##### bootstrap FreeSWITCH and FreeSWITCH libraries
  4. . $(dirname $0)/scripts/ci/build-requirements.sh
  5. echo "bootstrap: checking installation..."
  6. BGJOB=false
  7. VERBOSE=false
  8. BASEDIR=`pwd`;
  9. LIBDIR=${BASEDIR}/libs;
  10. SUBDIRS="apr libzrtp iksemel libdingaling srtp unimrcp fs";
  11. while getopts 'jhd:v' o; do
  12. case "$o" in
  13. j) BGJOB=true;;
  14. d) SUBDIRS="$OPTARG";;
  15. v) VERBOSE=true;;
  16. h) echo "Usage: $0 <options>"
  17. echo " Options:"
  18. echo " -d 'library1 library2'"
  19. echo " => Bootstrap only specified subdirectories"
  20. echo " -j => Run Jobs in Background"
  21. exit;;
  22. esac
  23. done
  24. ex() {
  25. test $VERBOSE && echo "bootstrap: $@" >&2
  26. $@
  27. }
  28. setup_modules() {
  29. if [ ! -f modules.conf ]; then
  30. cp build/modules.conf.in modules.conf
  31. fi
  32. }
  33. setup_gnu() {
  34. # keep automake from making us magically GPL, and to stop
  35. # complaining about missing files.
  36. cp -f docs/COPYING .
  37. cp -f docs/AUTHORS .
  38. cp -f docs/ChangeLog .
  39. touch NEWS
  40. touch README
  41. }
  42. print_autotools_vers() {
  43. #
  44. # Info output
  45. #
  46. echo "Bootstrapping using:"
  47. echo " autoconf : ${AUTOCONF:-`which autoconf`}"
  48. echo " automake : ${AUTOMAKE:-`which automake`}"
  49. echo " aclocal : ${ACLOCAL:-`which aclocal`}"
  50. echo " libtool : ${libtool} (${lt_version})"
  51. echo " libtoolize: ${libtoolize}"
  52. echo " make : ${make} (${make_version})"
  53. echo " awk : ${awk} (${awk_version})"
  54. echo
  55. }
  56. bootstrap_apr() {
  57. echo "Entering directory ${LIBDIR}/apr"
  58. cd ${LIBDIR}/apr
  59. # Licensed to the Apache Software Foundation (ASF) under one or more
  60. # contributor license agreements. See the NOTICE file distributed with
  61. # this work for additional information regarding copyright ownership.
  62. # The ASF licenses this file to You under the Apache License, Version 2.0
  63. # (the "License"); you may not use this file except in compliance with
  64. # the License. You may obtain a copy of the License at
  65. #
  66. # http://www.apache.org/licenses/LICENSE-2.0
  67. #
  68. # Unless required by applicable law or agreed to in writing, software
  69. # distributed under the License is distributed on an "AS IS" BASIS,
  70. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  71. # See the License for the specific language governing permissions and
  72. # limitations under the License.
  73. #
  74. #
  75. # bootstrap: Build the support scripts needed to compile from a
  76. # checked-out version of the source code.
  77. # Create the libtool helper files
  78. #
  79. # Note: we copy (rather than link) them to simplify distribution.
  80. # Note: APR supplies its own config.guess and config.sub -- we do not
  81. # rely on libtool's versions
  82. #
  83. echo "Copying libtool helper files ..."
  84. # Remove any libtool files so one can switch between libtool 1.3
  85. # and libtool 1.4 by simply rerunning the bootstrap script.
  86. (cd build ; rm -f ltconfig ltmain.sh libtool.m4)
  87. if ${libtoolize} -n --install >/dev/null 2>&1 ; then
  88. $libtoolize --force --copy --install
  89. else
  90. $libtoolize --force --copy
  91. fi
  92. if [ -f libtool.m4 ]; then
  93. ltfile=`pwd`/libtool.m4
  94. else
  95. if [ $lt_major -eq 2 ]; then
  96. ltfindcmd="`sed -n \"/aclocaldir=/{s/.*=/echo /p;q;}\" < $libtoolize`"
  97. ltfile=${LIBTOOL_M4-`eval "$ltfindcmd"`/libtool.m4}
  98. else
  99. ltfindcmd="`sed -n \"/=[^\\\`]/p;/libtool_m4=/{s/.*=/echo /p;q;}\" \
  100. < $libtoolize`"
  101. ltfile=${LIBTOOL_M4-`eval "$ltfindcmd"`}
  102. fi
  103. # Expecting the code above to be very portable, but just in case...
  104. if [ -z "$ltfile" -o ! -f "$ltfile" ]; then
  105. ltpath=`dirname $libtoolize`
  106. ltfile=`cd $ltpath/../share/aclocal ; pwd`/libtool.m4
  107. fi
  108. fi
  109. if [ ! -f $ltfile ]; then
  110. echo "$ltfile not found"
  111. exit 1
  112. fi
  113. echo "bootstrap: Using libtool.m4 at ${ltfile}."
  114. cat $ltfile | sed -e 's/LIBTOOL=\(.*\)top_build/LIBTOOL=\1apr_build/' > build/libtool.m4
  115. # libtool.m4 from 1.6 requires ltsugar.m4
  116. if [ -f ltsugar.m4 ]; then
  117. rm -f build/ltsugar.m4
  118. mv ltsugar.m4 build/ltsugar.m4
  119. fi
  120. # Clean up any leftovers
  121. rm -f aclocal.m4 libtool.m4
  122. # fix for FreeBSD (at least):
  123. # libtool.m4 is in share/aclocal, while e.g. aclocal19 only looks in share/aclocal19
  124. # get aclocal's default directory and include the libtool.m4 directory via -I if
  125. # it's in a different location
  126. aclocal_dir="`${ACLOCAL:-aclocal} --print-ac-dir`"
  127. if [ -n "${aclocal_dir}" -a -n "${ltfile}" -a "`dirname ${ltfile}`" != "${aclocal_dir}" ] ; then
  128. ACLOCAL_OPTS="-I `dirname ${ltfile}`"
  129. fi
  130. ### run aclocal
  131. echo "Re-creating aclocal.m4 ..."
  132. ${ACLOCAL:-aclocal} ${ACLOCAL_OPTS}
  133. ### do some work to toss config.cache?
  134. rm -rf config.cache
  135. echo "Creating configure ..."
  136. ${AUTOCONF:-autoconf}
  137. #
  138. # Generate the autoconf header
  139. #
  140. echo "Creating include/arch/unix/apr_private.h.in ..."
  141. ${AUTOHEADER:-autoheader}
  142. # Remove autoconf 2.5x's cache directory
  143. rm -rf autom4te*.cache
  144. echo "Entering directory ${LIBDIR}/apr-util"
  145. cd ${LIBDIR}/apr-util
  146. ./buildconf
  147. }
  148. bootstrap_libzrtp() {
  149. (cd ${LIBDIR}/libzrtp && ./bootstrap.sh)
  150. }
  151. # Libs automake automation function
  152. libbootstrap() {
  153. i=$1
  154. if [ -d ${LIBDIR}/${i} ]; then
  155. echo "Entering directory ${LIBDIR}/${i}"
  156. ex cd ${LIBDIR}/${i}
  157. ex rm -f aclocal.m4
  158. CFFILE=
  159. if [ -f ${LIBDIR}/${i}/configure.in ]; then
  160. CFFILE="${LIBDIR}/${i}/configure.in"
  161. else
  162. if [ -f ${LIBDIR}/${i}/configure.ac ]; then
  163. CFFILE="${LIBDIR}/${i}/configure.ac"
  164. fi
  165. fi
  166. if [ ! -z ${CFFILE} ]; then
  167. LTTEST=`grep "AC_PROG_LIBTOOL" ${CFFILE}`
  168. LTTEST2=`grep "AM_PROG_LIBTOOL" ${CFFILE}`
  169. AMTEST=`grep "AM_INIT_AUTOMAKE" ${CFFILE}`
  170. AMTEST2=`grep "AC_PROG_INSTALL" ${CFFILE}`
  171. AHTEST=`grep "AC_CONFIG_HEADERS" ${CFFILE}`
  172. AXTEST=`grep "ACX_LIBTOOL_C_ONLY" ${CFFILE}`
  173. echo "Creating aclocal.m4"
  174. ex ${ACLOCAL:-aclocal} ${ACLOCAL_OPTS} ${ACLOCAL_FLAGS}
  175. # only run if AC_PROG_LIBTOOL is in configure.in/configure.ac
  176. if [ ! -z "${LTTEST}" -o "${LTTEST2}" -o "${AXTEST}" ]; then
  177. echo "Running libtoolize..."
  178. if ${libtoolize} -n --install >/dev/null 2>&1; then
  179. ex $libtoolize --force --copy --install
  180. else
  181. ex $libtoolize --force --copy
  182. fi
  183. fi
  184. echo "Creating configure"
  185. ex ${AUTOCONF:-autoconf}
  186. # only run if AC_CONFIG_HEADERS is found in configure.in/configure.ac
  187. if [ ! -z "${AHTEST}" ]; then
  188. echo "Running autoheader..."
  189. ex ${AUTOHEADER:-autoheader};
  190. fi
  191. # run if AM_INIT_AUTOMAKE / AC_PROG_INSTALL is in configure.in/configure.ac
  192. if [ ! -z "${AMTEST}" -o "${AMTEST2}" ]; then
  193. echo "Creating Makefile.in"
  194. ex ${AUTOMAKE:-automake} --no-force --add-missing --copy;
  195. fi
  196. ex rm -rf autom4te*.cache
  197. fi
  198. else
  199. echo "Skipping directory ${LIBDIR}/${i}"
  200. fi
  201. }
  202. bootstrap_fs() {
  203. cd ${BASEDIR}
  204. rm -f aclocal.m4
  205. ${ACLOCAL:-aclocal} ${ACLOCAL_OPTS}
  206. $libtoolize --copy --automake
  207. ${AUTOCONF:-autoconf}
  208. ${AUTOHEADER:-autoheader}
  209. ${AUTOMAKE:-automake} --no-force --add-missing --copy
  210. rm -rf autom4te*.cache
  211. }
  212. bootstrap_libs_pre() {
  213. case "$1" in
  214. *) return 0;;
  215. esac
  216. }
  217. bootstrap_libs_post() {
  218. case "$1" in
  219. *) return 0;;
  220. esac
  221. }
  222. bootstrap_libs() {
  223. for i in ${SUBDIRS}; do
  224. case "$i" in
  225. apr|fs|libzrtp)
  226. ${BGJOB} && wait
  227. bootstrap_$i
  228. continue
  229. ;;
  230. esac
  231. bootstrap_libs_pre ${i}
  232. if ! ${BGJOB}; then
  233. libbootstrap ${i} ; bootstrap_libs_post ${i}
  234. else
  235. (libbootstrap ${i} ; bootstrap_libs_post ${i}) &
  236. fi
  237. done
  238. ${BGJOB} && wait
  239. }
  240. run() {
  241. setup_modules
  242. setup_gnu
  243. check_make
  244. check_awk
  245. check_ac_ver
  246. check_am_ver
  247. check_acl_ver
  248. check_lt_ver
  249. check_libtoolize
  250. print_autotools_vers
  251. bootstrap_libs
  252. return 0
  253. }
  254. run