2
0

bootstrap.sh 13 KB

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