bootstrap.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. #!/bin/sh
  2. ##### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*-
  3. ##### bootstrap FreeSWITCH and FreeSWITCH libraries
  4. echo "bootstrap: checking installation..."
  5. BGJOB=false
  6. VERBOSE=false
  7. BASEDIR=`pwd`;
  8. LIBDIR=${BASEDIR}/libs;
  9. SUBDIRS="apr \
  10. libzrtp ilbc iksemel libdingaling libsndfile sofia-sip \
  11. speex srtp freetdm spandsp libg722_1 unimrcp tiff-4.0.2 broadvoice silk libcodec2 \
  12. fs";
  13. while getopts 'jhd:v' o; do
  14. case "$o" in
  15. j) BGJOB=true;;
  16. d) SUBDIRS="$OPTARG";;
  17. v) VERBOSE=true;;
  18. h) echo "Usage: $0 <options>"
  19. echo " Options:"
  20. echo " -d 'library1 library2'"
  21. echo " => Bootstrap only specified subdirectories"
  22. echo " -j => Run Jobs in Background"
  23. exit;;
  24. esac
  25. done
  26. ex() {
  27. test $VERBOSE && echo "bootstrap: $@" >&2
  28. $@
  29. }
  30. setup_modules() {
  31. if [ ! -f modules.conf ]; then
  32. cp build/modules.conf.in modules.conf
  33. fi
  34. }
  35. setup_gnu() {
  36. # keep automake from making us magically GPL, and to stop
  37. # complaining about missing files.
  38. cp -f docs/COPYING .
  39. cp -f docs/AUTHORS .
  40. cp -f docs/ChangeLog .
  41. touch NEWS
  42. touch README
  43. }
  44. check_ac_ver() {
  45. # autoconf 2.59 or newer
  46. ac_version=`${AUTOCONF:-autoconf} --version 2>/dev/null|sed -e 's/^[^0-9]*//;s/[a-z]* *$//;s/[- ].*//g;q'`
  47. if test -z "$ac_version"; then
  48. echo "bootstrap: autoconf not found."
  49. echo " You need autoconf version 2.59 or newer installed"
  50. echo " to build FreeSWITCH from source."
  51. exit 1
  52. fi
  53. if test `uname -s` = "OpenBSD" && test "$ac_version" = "2.62"; then
  54. echo "Autoconf 2.62 is broken on OpenBSD, please try another version"
  55. exit 1
  56. fi
  57. IFS=_; set $ac_version; IFS=' '
  58. ac_version=$1
  59. IFS=.; set $ac_version; IFS=' '
  60. if test "$1" = "2" -a "$2" -lt "59" || test "$1" -lt "2"; then
  61. echo "bootstrap: autoconf version $ac_version found."
  62. echo " You need autoconf version 2.59 or newer installed"
  63. echo " to build FreeSWITCH from source."
  64. exit 1
  65. else
  66. echo "bootstrap: autoconf version $ac_version (ok)"
  67. fi
  68. }
  69. check_am_ver() {
  70. # automake 1.7 or newer
  71. am_version=`${AUTOMAKE:-automake} --version 2>/dev/null|sed -e 's/^[^0-9]*//;s/[a-z]* *$//;s/[- ].*//g;q'`
  72. if test -z "$am_version"; then
  73. echo "bootstrap: automake not found."
  74. echo " You need automake version 1.7 or newer installed"
  75. echo " to build FreeSWITCH from source."
  76. exit 1
  77. fi
  78. IFS=_; set $am_version; IFS=' '
  79. am_version=$1
  80. IFS=.; set $am_version; IFS=' '
  81. if test "$1" = "1" -a "$2" -lt "7"; then
  82. echo "bootstrap: automake version $am_version found."
  83. echo " You need automake version 1.7 or newer installed"
  84. echo " to build FreeSWITCH from source."
  85. exit 1
  86. else
  87. echo "bootstrap: automake version $am_version (ok)"
  88. fi
  89. }
  90. check_acl_ver() {
  91. # aclocal 1.7 or newer
  92. acl_version=`${ACLOCAL:-aclocal} --version 2>/dev/null|sed -e 's/^[^0-9]*//;s/[a-z]* *$//;s/[- ].*//g;q'`
  93. if test -z "$acl_version"; then
  94. echo "bootstrap: aclocal not found."
  95. echo " You need aclocal version 1.7 or newer installed"
  96. echo " to build FreeSWITCH from source."
  97. exit 1
  98. fi
  99. IFS=_; set $acl_version; IFS=' '
  100. acl_version=$1
  101. IFS=.; set $acl_version; IFS=' '
  102. if test "$1" = "1" -a "$2" -lt "7"; then
  103. echo "bootstrap: aclocal version $acl_version found."
  104. echo " You need aclocal version 1.7 or newer installed"
  105. echo " to build FreeSWITCH from source."
  106. exit 1
  107. else
  108. echo "bootstrap: aclocal version $acl_version (ok)"
  109. fi
  110. }
  111. check_lt_ver() {
  112. # Sample libtool --version outputs:
  113. # ltmain.sh (GNU libtool) 1.3.3 (1.385.2.181 1999/07/02 15:49:11)
  114. # ltmain.sh (GNU libtool 1.1361 2004/01/02 23:10:52) 1.5a
  115. # output is multiline from 1.5 onwards
  116. # Require libtool 1.4 or newer
  117. libtool=${LIBTOOL:-`${LIBDIR}/apr/build/PrintPath glibtool libtool libtool22 libtool15 libtool14`}
  118. lt_pversion=`$libtool --version 2>/dev/null|sed -e 's/([^)]*)//g;s/^[^0-9]*//;s/[- ].*//g;q'`
  119. if test -z "$lt_pversion"; then
  120. echo "bootstrap: libtool not found."
  121. echo " You need libtool version 1.5.14 or newer to build FreeSWITCH from source."
  122. exit 1
  123. fi
  124. lt_version=`echo $lt_pversion|sed -e 's/\([a-z]*\)$/.\1/'`
  125. IFS=.; set $lt_version; IFS=' '
  126. lt_status="good"
  127. if test -z "$1"; then a=0 ; else a=$1;fi
  128. if test -z "$2"; then b=0 ; else b=$2;fi
  129. if test -z "$3"; then c=0 ; else c=$3;fi
  130. lt_major=$a
  131. if test "$a" -eq "2"; then
  132. lt_status="good"
  133. elif test "$a" -lt "2"; then
  134. if test "$b" -lt "5" -o "$b" = "5" -a "$c" -lt "14" ; then
  135. lt_status="bad"
  136. fi
  137. else
  138. lt_status="bad"
  139. fi
  140. if test $lt_status = "good"; then
  141. echo "bootstrap: libtool version $lt_pversion (ok)"
  142. else
  143. echo "bootstrap: libtool version $lt_pversion found."
  144. echo " You need libtool version 1.5.14 or newer to build FreeSWITCH from source."
  145. exit 1
  146. fi
  147. }
  148. check_libtoolize() {
  149. # check libtoolize availability
  150. if [ -n "${LIBTOOL}" ]; then
  151. libtoolize=${LIBTOOLIZE:-`dirname "${libtool}"`/libtoolize}
  152. else
  153. libtoolize=${LIBTOOLIZE:-`${LIBDIR}/apr/build/PrintPath glibtoolize libtoolize libtoolize22 libtoolize15 libtoolize14`}
  154. fi
  155. if [ "x$libtoolize" = "x" ]; then
  156. echo "libtoolize not found in path"
  157. exit 1
  158. fi
  159. if [ ! -x "$libtoolize" ]; then
  160. echo "$libtoolize does not exist or is not executable"
  161. exit 1
  162. fi
  163. # compare libtool and libtoolize version
  164. ltl_pversion=`$libtoolize --version 2>/dev/null|sed -e 's/([^)]*)//g;s/^[^0-9]*//;s/[- ].*//g;q'`
  165. ltl_version=`echo $ltl_pversion|sed -e 's/\([a-z]*\)$/.\1/'`
  166. IFS=.; set $ltl_version; IFS=' '
  167. if [ "x${lt_version}" != "x${ltl_version}" ]; then
  168. echo "$libtool and $libtoolize have different versions"
  169. exit 1
  170. fi
  171. }
  172. check_make() {
  173. #
  174. # Check to make sure we have GNU Make installed
  175. #
  176. make=`which make`
  177. if [ -x "$make" ]; then
  178. make_version=`$make --version | grep GNU`
  179. if [ $? -ne 0 ]; then
  180. make=`which gmake`
  181. if [ -x "$make" ]; then
  182. make_version=`$make --version | grep GNU`
  183. if [ $? -ne 0 ]; then
  184. echo "GNU Make does not exist or is not executable"
  185. exit 1;
  186. fi
  187. fi
  188. fi
  189. fi
  190. }
  191. check_awk() {
  192. # TODO: Building with mawk on at least Debian squeeze is know to
  193. # work, but mawk is believed to fail on some systems. If we can
  194. # replicate this, we need a particular behavior that we can test
  195. # here to verify whether we have an acceptable awk.
  196. :
  197. }
  198. print_autotools_vers() {
  199. #
  200. # Info output
  201. #
  202. echo "Bootstrapping using:"
  203. echo " autoconf : ${AUTOCONF:-`which autoconf`}"
  204. echo " automake : ${AUTOMAKE:-`which automake`}"
  205. echo " aclocal : ${ACLOCAL:-`which aclocal`}"
  206. echo " libtool : ${libtool} (${lt_version})"
  207. echo " libtoolize: ${libtoolize}"
  208. echo " make : ${make} (${make_version})"
  209. echo " awk : ${awk} (${awk_version})"
  210. echo
  211. }
  212. bootstrap_apr() {
  213. echo "Entering directory ${LIBDIR}/apr"
  214. cd ${LIBDIR}/apr
  215. # Licensed to the Apache Software Foundation (ASF) under one or more
  216. # contributor license agreements. See the NOTICE file distributed with
  217. # this work for additional information regarding copyright ownership.
  218. # The ASF licenses this file to You under the Apache License, Version 2.0
  219. # (the "License"); you may not use this file except in compliance with
  220. # the License. You may obtain a copy of the License at
  221. #
  222. # http://www.apache.org/licenses/LICENSE-2.0
  223. #
  224. # Unless required by applicable law or agreed to in writing, software
  225. # distributed under the License is distributed on an "AS IS" BASIS,
  226. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  227. # See the License for the specific language governing permissions and
  228. # limitations under the License.
  229. #
  230. #
  231. # bootstrap: Build the support scripts needed to compile from a
  232. # checked-out version of the source code.
  233. # Create the libtool helper files
  234. #
  235. # Note: we copy (rather than link) them to simplify distribution.
  236. # Note: APR supplies its own config.guess and config.sub -- we do not
  237. # rely on libtool's versions
  238. #
  239. echo "Copying libtool helper files ..."
  240. # Remove any libtool files so one can switch between libtool 1.3
  241. # and libtool 1.4 by simply rerunning the bootstrap script.
  242. (cd build ; rm -f ltconfig ltmain.sh libtool.m4)
  243. if ${libtoolize} -n --install >/dev/null 2>&1 ; then
  244. $libtoolize --force --copy --install
  245. else
  246. $libtoolize --force --copy
  247. fi
  248. if [ -f libtool.m4 ]; then
  249. ltfile=`pwd`/libtool.m4
  250. else
  251. if [ $lt_major -eq 2 ]; then
  252. ltfindcmd="`sed -n \"/aclocaldir=/{s/.*=/echo /p;q;}\" < $libtoolize`"
  253. ltfile=${LIBTOOL_M4-`eval "$ltfindcmd"`/libtool.m4}
  254. else
  255. ltfindcmd="`sed -n \"/=[^\\\`]/p;/libtool_m4=/{s/.*=/echo /p;q;}\" \
  256. < $libtoolize`"
  257. ltfile=${LIBTOOL_M4-`eval "$ltfindcmd"`}
  258. fi
  259. # Expecting the code above to be very portable, but just in case...
  260. if [ -z "$ltfile" -o ! -f "$ltfile" ]; then
  261. ltpath=`dirname $libtoolize`
  262. ltfile=`cd $ltpath/../share/aclocal ; pwd`/libtool.m4
  263. fi
  264. fi
  265. if [ ! -f $ltfile ]; then
  266. echo "$ltfile not found"
  267. exit 1
  268. fi
  269. echo "bootstrap: Using libtool.m4 at ${ltfile}."
  270. cat $ltfile | sed -e 's/LIBTOOL=\(.*\)top_build/LIBTOOL=\1apr_build/' > build/libtool.m4
  271. # libtool.m4 from 1.6 requires ltsugar.m4
  272. if [ -f ltsugar.m4 ]; then
  273. rm -f build/ltsugar.m4
  274. mv ltsugar.m4 build/ltsugar.m4
  275. fi
  276. # Clean up any leftovers
  277. rm -f aclocal.m4 libtool.m4
  278. # fix for FreeBSD (at least):
  279. # libtool.m4 is in share/aclocal, while e.g. aclocal19 only looks in share/aclocal19
  280. # get aclocal's default directory and include the libtool.m4 directory via -I if
  281. # it's in a different location
  282. aclocal_dir="`${ACLOCAL:-aclocal} --print-ac-dir`"
  283. if [ -n "${aclocal_dir}" -a -n "${ltfile}" -a "`dirname ${ltfile}`" != "${aclocal_dir}" ] ; then
  284. ACLOCAL_OPTS="-I `dirname ${ltfile}`"
  285. fi
  286. ### run aclocal
  287. echo "Re-creating aclocal.m4 ..."
  288. ${ACLOCAL:-aclocal} ${ACLOCAL_OPTS}
  289. ### do some work to toss config.cache?
  290. rm -rf config.cache
  291. echo "Creating configure ..."
  292. ${AUTOCONF:-autoconf}
  293. #
  294. # Generate the autoconf header
  295. #
  296. echo "Creating include/arch/unix/apr_private.h.in ..."
  297. ${AUTOHEADER:-autoheader}
  298. # Remove autoconf 2.5x's cache directory
  299. rm -rf autom4te*.cache
  300. echo "Entering directory ${LIBDIR}/apr-util"
  301. cd ${LIBDIR}/apr-util
  302. ./buildconf
  303. }
  304. bootstrap_libzrtp() {
  305. (cd ${LIBDIR}/libzrtp && ./bootstrap.sh)
  306. }
  307. # Libs automake automation function
  308. libbootstrap() {
  309. i=$1
  310. if [ -d ${LIBDIR}/${i} ]; then
  311. echo "Entering directory ${LIBDIR}/${i}"
  312. ex cd ${LIBDIR}/${i}
  313. ex rm -f aclocal.m4
  314. CFFILE=
  315. if [ -f ${LIBDIR}/${i}/configure.in ]; then
  316. CFFILE="${LIBDIR}/${i}/configure.in"
  317. else
  318. if [ -f ${LIBDIR}/${i}/configure.ac ]; then
  319. CFFILE="${LIBDIR}/${i}/configure.ac"
  320. fi
  321. fi
  322. if [ ! -z ${CFFILE} ]; then
  323. LTTEST=`grep "AC_PROG_LIBTOOL" ${CFFILE}`
  324. LTTEST2=`grep "AM_PROG_LIBTOOL" ${CFFILE}`
  325. AMTEST=`grep "AM_INIT_AUTOMAKE" ${CFFILE}`
  326. AMTEST2=`grep "AC_PROG_INSTALL" ${CFFILE}`
  327. AHTEST=`grep "AC_CONFIG_HEADERS" ${CFFILE}`
  328. AXTEST=`grep "ACX_LIBTOOL_C_ONLY" ${CFFILE}`
  329. echo "Creating aclocal.m4"
  330. ex ${ACLOCAL:-aclocal} ${ACLOCAL_OPTS} ${ACLOCAL_FLAGS}
  331. # only run if AC_PROG_LIBTOOL is in configure.in/configure.ac
  332. if [ ! -z "${LTTEST}" -o "${LTTEST2}" -o "${AXTEST}" ]; then
  333. echo "Running libtoolize..."
  334. if ${libtoolize} -n --install >/dev/null 2>&1; then
  335. ex $libtoolize --force --copy --install
  336. else
  337. ex $libtoolize --force --copy
  338. fi
  339. fi
  340. echo "Creating configure"
  341. ex ${AUTOCONF:-autoconf}
  342. # only run if AC_CONFIG_HEADERS is found in configure.in/configure.ac
  343. if [ ! -z "${AHTEST}" ]; then
  344. echo "Running autoheader..."
  345. ex ${AUTOHEADER:-autoheader};
  346. fi
  347. # run if AM_INIT_AUTOMAKE / AC_PROG_INSTALL is in configure.in/configure.ac
  348. if [ ! -z "${AMTEST}" -o "${AMTEST2}" ]; then
  349. echo "Creating Makefile.in"
  350. ex ${AUTOMAKE:-automake} --no-force --add-missing --copy;
  351. fi
  352. ex rm -rf autom4te*.cache
  353. fi
  354. else
  355. echo "Skipping directory ${LIBDIR}/${i}"
  356. fi
  357. }
  358. bootstrap_fs() {
  359. cd ${BASEDIR}
  360. rm -f aclocal.m4
  361. ${ACLOCAL:-aclocal} ${ACLOCAL_OPTS}
  362. $libtoolize --copy --automake
  363. ${AUTOCONF:-autoconf}
  364. ${AUTOHEADER:-autoheader}
  365. ${AUTOMAKE:-automake} --no-force --add-missing --copy
  366. rm -rf autom4te*.cache
  367. }
  368. bootstrap_libs_pre() {
  369. case "$1" in
  370. *) return 0;;
  371. esac
  372. }
  373. bootstrap_libs_post() {
  374. case "$1" in
  375. *) return 0;;
  376. esac
  377. }
  378. bootstrap_libs() {
  379. for i in ${SUBDIRS}; do
  380. case "$i" in
  381. apr|fs|libzrtp)
  382. ${BGJOB} && wait
  383. bootstrap_$i
  384. continue
  385. ;;
  386. esac
  387. bootstrap_libs_pre ${i}
  388. if ! ${BGJOB}; then
  389. libbootstrap ${i} ; bootstrap_libs_post ${i}
  390. else
  391. (libbootstrap ${i} ; bootstrap_libs_post ${i}) &
  392. fi
  393. done
  394. ${BGJOB} && wait
  395. }
  396. run() {
  397. setup_modules
  398. setup_gnu
  399. check_make
  400. check_awk
  401. check_ac_ver
  402. check_am_ver
  403. check_acl_ver
  404. check_lt_ver
  405. check_libtoolize
  406. print_autotools_vers
  407. bootstrap_libs
  408. return 0
  409. }
  410. run