bootstrap.sh 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324
  1. #!/bin/bash
  2. #
  3. # Copyright (C) 2012 Brian Aker
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. #
  10. # * Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. #
  13. # * Redistributions in binary form must reproduce the above
  14. # copyright notice, this list of conditions and the following disclaimer
  15. # in the documentation and/or other materials provided with the
  16. # distribution.
  17. #
  18. # * The names of its contributors may not be used to endorse or
  19. # promote products derived from this software without specific prior
  20. # written permission.
  21. #
  22. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. # Environment Variables that will influence the build:
  34. # AUTOMAKE
  35. # AUTORECONF
  36. # LIBTOOLIZE
  37. # MAKE
  38. # PREFIX
  39. # TESTS_ENVIRONMENT
  40. # VERBOSE
  41. # WARNINGS
  42. #
  43. command_not_found_handle ()
  44. {
  45. echo "Command not found: '$@'"
  46. exit 127
  47. }
  48. function die ()
  49. {
  50. echo "$BASH_SOURCE:$BASH_LINENO: $@" >&2
  51. exit 1;
  52. }
  53. function nassert ()
  54. {
  55. local param_name=\$"$1"
  56. local param_value=`eval "expr \"$param_name\" "`
  57. if [ -n "$param_value" ]; then
  58. echo "$bash_source:$bash_lineno: assert($param_name) had value of "$param_value"" >&2
  59. exit 1
  60. fi
  61. }
  62. function assert ()
  63. {
  64. local param_name=\$"$1"
  65. local param_value=`eval "expr \"$param_name\" "`
  66. if [ -z "$param_value" ]; then
  67. echo "$bash_source:$bash_lineno: assert($param_name)" >&2
  68. exit 1
  69. fi
  70. }
  71. assert_file ()
  72. {
  73. if [ ! -f "$1" ]; then
  74. echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
  75. exit 1;
  76. fi
  77. }
  78. assert_no_file ()
  79. {
  80. if [ -f "$1" ]; then
  81. echo "$BASH_SOURCE:$BASH_LINENO: assert($1) file exists: $2" >&2
  82. exit 1;
  83. fi
  84. }
  85. assert_exec_file ()
  86. {
  87. if [ ! -f "$1" ]; then
  88. echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
  89. exit 1;
  90. fi
  91. if [ ! -x "$1" ]; then
  92. echo "$BASH_SOURCE:$BASH_LINENO: assert($1) exists but is not executable: $2" >&2
  93. exit 1;
  94. fi
  95. }
  96. command_exists ()
  97. {
  98. type "$1" &> /dev/null ;
  99. }
  100. rebuild_host_os ()
  101. {
  102. HOST_OS="${UNAME_MACHINE_ARCH}-${VENDOR}-${VENDOR_DISTRIBUTION}-${VENDOR_RELEASE}-${UNAME_KERNEL}-${UNAME_KERNEL_RELEASE}"
  103. if [ -z "$1" ]; then
  104. if $VERBOSE; then
  105. echo "HOST_OS=$HOST_OS"
  106. fi
  107. fi
  108. }
  109. # Valid values are: darwin,fedora,rhel,ubuntu
  110. set_VENDOR_DISTRIBUTION ()
  111. {
  112. local dist=`echo "$1" | tr '[A-Z]' '[a-z]'`
  113. case "$dist" in
  114. darwin)
  115. VENDOR_DISTRIBUTION='darwin'
  116. ;;
  117. fedora)
  118. VENDOR_DISTRIBUTION='fedora'
  119. ;;
  120. rhel)
  121. VENDOR_DISTRIBUTION='rhel'
  122. ;;
  123. ubuntu)
  124. VENDOR_DISTRIBUTION='ubuntu'
  125. ;;
  126. opensuse)
  127. VENDOR_DISTRIBUTION='opensuse'
  128. ;;
  129. *)
  130. die "attempt to set an invalid VENDOR_DISTRIBUTION=$dist"
  131. ;;
  132. esac
  133. }
  134. set_VENDOR_RELEASE ()
  135. {
  136. local release=`echo "$1" | tr '[A-Z]' '[a-z]'`
  137. case "$VENDOR_DISTRIBUTION" in
  138. darwin)
  139. VENDOR_RELEASE='mountain'
  140. ;;
  141. fedora)
  142. VENDOR_RELEASE="$release"
  143. ;;
  144. rhel)
  145. VENDOR_RELEASE="$release"
  146. ;;
  147. ubuntu)
  148. VENDOR_RELEASE="$release"
  149. ;;
  150. opensuse)
  151. VENDOR_RELEASE="$release"
  152. ;;
  153. unknown)
  154. die "attempt to set VENDOR_RELEASE without setting VENDOR_DISTRIBUTION"
  155. ;;
  156. *)
  157. die "attempt to set with an invalid VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
  158. ;;
  159. esac
  160. }
  161. # Valid values are: apple, redhat, centos, canonical
  162. set_VENDOR ()
  163. {
  164. local vendor=`echo "$1" | tr '[A-Z]' '[a-z]'`
  165. case $vendor in
  166. apple)
  167. VENDOR='apple'
  168. ;;
  169. redhat)
  170. VENDOR='redhat'
  171. ;;
  172. centos)
  173. VENDOR='centos'
  174. ;;
  175. canonical)
  176. VENDOR='canonical'
  177. ;;
  178. suse)
  179. VENDOR='suse'
  180. ;;
  181. *)
  182. die "An attempt was made to set an invalid VENDOR=$_vendor"
  183. ;;
  184. esac
  185. set_VENDOR_DISTRIBUTION $2
  186. set_VENDOR_RELEASE $3
  187. }
  188. determine_target_platform ()
  189. {
  190. UNAME_MACHINE_ARCH=`(uname -m) 2>/dev/null` || UNAME_MACHINE_ARCH=unknown
  191. UNAME_KERNEL=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
  192. UNAME_KERNEL_RELEASE=`(uname -r) 2>/dev/null` || UNAME_KERNEL_RELEASE=unknown
  193. if [[ $(uname) == 'Darwin' ]]; then
  194. set_VENDOR 'apple' 'darwin' 'mountain'
  195. elif [[ -f '/etc/fedora-release' ]]; then
  196. local fedora_version=`cat /etc/fedora-release | awk ' { print $3 } '`
  197. set_VENDOR 'redhat' 'fedora' $fedora_version
  198. if [[ "x$VENDOR_RELEASE" == 'x17' ]]; then
  199. AUTORECONF_REBUILD_HOST=true
  200. fi
  201. elif [[ -f '/etc/centos-release' ]]; then
  202. local centos_version=`cat /etc/centos-release | awk ' { print $7 } '`
  203. set_VENDOR 'centos' 'rhel' $centos_version
  204. elif [[ -f '/etc/SuSE-release' ]]; then
  205. local suse_distribution=`head -1 /etc/SuSE-release | awk ' { print $1 } '`
  206. local suse_version=`head -1 /etc/SuSE-release | awk ' { print $2 } '`
  207. set_VENDOR 'suse' $suse_distribution $suse_version
  208. elif [[ -f '/etc/redhat-release' ]]; then
  209. local rhel_version=`cat /etc/redhat-release | awk ' { print $7 } '`
  210. set_VENDOR 'redhat' 'rhel' $rhel_version
  211. elif [[ -f '/etc/lsb-release' ]]; then
  212. local debian_DISTRIB_ID=`cat /etc/lsb-release | grep DISTRIB_ID | awk -F= ' { print $2 } '`
  213. local debian_version=`cat /etc/lsb-release | grep DISTRIB_CODENAME | awk -F= ' { print $2 } '`
  214. set_VENDOR 'canonical' $debian_DISTRIB_ID $debian_version
  215. if [[ "x$VENDOR_RELEASE" == 'xprecise' ]]; then
  216. AUTORECONF_REBUILD_HOST=true
  217. fi
  218. fi
  219. rebuild_host_os
  220. }
  221. run_configure ()
  222. {
  223. # We will run autoreconf if we are required
  224. run_autoreconf_if_required
  225. # We always begin at the root of our build
  226. if [ ! popd ]; then
  227. die "Programmer error, we entered run_configure with a stacked directory"
  228. fi
  229. local BUILD_DIR="$1"
  230. if [[ -n "$BUILD_DIR" ]]; then
  231. rm -r -f $BUILD_DIR
  232. mkdir -p $BUILD_DIR
  233. safe_pushd $BUILD_DIR
  234. fi
  235. # Arguments for configure
  236. local CONFIGURE_ARG=
  237. # Set ENV DEBUG in order to enable debugging
  238. if $DEBUG; then
  239. CONFIGURE_ARG='--enable-debug'
  240. fi
  241. # Set ENV ASSERT in order to enable assert
  242. if [[ -n "$ASSERT" ]]; then
  243. local ASSERT_ARG=
  244. ASSERT_ARG='--enable-assert'
  245. CONFIGURE_ARG="$ASSERT_ARG $CONFIGURE_ARG"
  246. fi
  247. # If we are executing on OSX use CLANG, otherwise only use it if we find it in the ENV
  248. case $HOST_OS in
  249. *-darwin-*)
  250. CC=clang CXX=clang++ $top_srcdir/configure $CONFIGURE_ARG || die "Cannot execute CC=clang CXX=clang++ configure $CONFIGURE_ARG $PREFIX_ARG"
  251. ;;
  252. rhel-5*)
  253. command_exists gcc44 || die "Could not locate gcc44"
  254. CC=gcc44 CXX=gcc44 $top_srcdir/configure $CONFIGURE_ARG $PREFIX_ARG || die "Cannot execute CC=gcc44 CXX=gcc44 configure $CONFIGURE_ARG $PREFIX_ARG"
  255. ;;
  256. *)
  257. $top_srcdir/configure $CONFIGURE_ARG $PREFIX_ARG || die "Cannot execute configure $CONFIGURE_ARG $PREFIX_ARG"
  258. ;;
  259. esac
  260. if [ ! -f 'Makefile' ]; then
  261. die "Programmer error, configure was run but no Makefile existed afterward"
  262. fi
  263. }
  264. setup_gdb_command () {
  265. GDB_TMPFILE=$(mktemp /tmp/gdb.XXXXXXXXXX)
  266. echo 'set logging overwrite on' > $GDB_TMPFILE
  267. echo 'set logging on' >> $GDB_TMPFILE
  268. echo 'set environment LIBTEST_IN_GDB=1' >> $GDB_TMPFILE
  269. echo 'run' >> $GDB_TMPFILE
  270. echo 'thread apply all bt' >> $GDB_TMPFILE
  271. echo 'quit' >> $GDB_TMPFILE
  272. GDB_COMMAND="gdb -f -batch -x $GDB_TMPFILE"
  273. }
  274. setup_valgrind_command () {
  275. VALGRIND_PROGRAM=`type -p valgrind`
  276. if [[ -n "$VALGRIND_PROGRAM" ]]; then
  277. VALGRIND_COMMAND="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --show-reachable=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE"
  278. fi
  279. }
  280. push_PREFIX_ARG ()
  281. {
  282. if [[ -n "$PREFIX_ARG" ]]; then
  283. OLD_PREFIX_ARG=$PREFIX_ARG
  284. PREFIX_ARG=
  285. fi
  286. if [[ -n "$1" ]]; then
  287. PREFIX_ARG="--prefix=$1"
  288. fi
  289. }
  290. pop_PREFIX_ARG ()
  291. {
  292. if [[ -n "$OLD_PREFIX_ARG" ]]; then
  293. PREFIX_ARG=$OLD_TESTS_ENVIRONMENT
  294. OLD_PREFIX_ARG=
  295. else
  296. PREFIX_ARG=
  297. fi
  298. }
  299. push_TESTS_ENVIRONMENT ()
  300. {
  301. if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
  302. die "OLD_TESTS_ENVIRONMENT was set on push, programmer error!"
  303. fi
  304. if [[ -n "$TESTS_ENVIRONMENT" ]]; then
  305. OLD_TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT
  306. TESTS_ENVIRONMENT=
  307. fi
  308. }
  309. pop_TESTS_ENVIRONMENT ()
  310. {
  311. TESTS_ENVIRONMENT=
  312. if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
  313. TESTS_ENVIRONMENT=$OLD_TESTS_ENVIRONMENT
  314. OLD_TESTS_ENVIRONMENT=
  315. fi
  316. }
  317. function safe_pushd ()
  318. {
  319. pushd $1 &> /dev/null ;
  320. if $VERBOSE -a test -n "$BUILD_DIR"; then
  321. echo "BUILD_DIR=$BUILD_DIR"
  322. fi
  323. }
  324. function safe_popd ()
  325. {
  326. local directory_to_delete=`pwd`
  327. popd &> /dev/null ;
  328. if [ $? -eq 0 ]; then
  329. if [[ "$top_srcdir" == "$directory_to_delete" ]]; then
  330. die "We almost deleted top_srcdir($top_srcdir), programmer error"
  331. fi
  332. rm -r -f "$directory_to_delete"
  333. fi
  334. }
  335. function make_valgrind ()
  336. {
  337. if [[ "$VENDOR_DISTRIBUTION" == 'darwin' ]]; then
  338. make_darwin_malloc
  339. return
  340. fi
  341. # If the env VALGRIND_COMMAND is set then we assume it is valid
  342. local valgrind_was_set=false
  343. if [[ -z "$VALGRIND_COMMAND" ]]; then
  344. setup_valgrind_command
  345. if [[ -n "$VALGRIND_COMMAND" ]]; then
  346. valgrind_was_set=true
  347. fi
  348. else
  349. valgrind_was_set=true
  350. fi
  351. # If valgrind_was_set is set to no we bail
  352. if ! $valgrind_was_set; then
  353. echo 'valgrind was not present'
  354. return 1
  355. fi
  356. # If we are required to run configure, do so now
  357. run_configure_if_required
  358. push_TESTS_ENVIRONMENT
  359. # If we don't have a configure, then most likely we will be missing libtool
  360. assert_file 'configure'
  361. if [[ -f 'libtool' ]]; then
  362. TESTS_ENVIRONMENT="./libtool --mode=execute $VALGRIND_COMMAND"
  363. else
  364. TESTS_ENVIRONMENT="$VALGRIND_COMMAND"
  365. fi
  366. make_target 'check' || return 1
  367. pop_TESTS_ENVIRONMENT
  368. }
  369. function make_install_system ()
  370. {
  371. local INSTALL_LOCATION=$(mktemp -d /tmp/XXXXXXXXXX)
  372. push_PREFIX_ARG $INSTALL_LOCATION
  373. if [ ! -d $INSTALL_LOCATION ] ; then
  374. die "ASSERT temp directory not found '$INSTALL_LOCATION'"
  375. fi
  376. run_configure #install_buid_dir
  377. push_TESTS_ENVIRONMENT
  378. make_target 'install'
  379. make_target 'installcheck'
  380. make_target 'uninstall'
  381. pop_TESTS_ENVIRONMENT
  382. pop_PREFIX_ARG
  383. rm -r -f $INSTALL_LOCATION
  384. make 'distclean'
  385. if [ -f 'Makefile' ]; then
  386. die "ASSERT Makefile should not exist"
  387. fi
  388. safe_popd
  389. }
  390. function make_darwin_malloc ()
  391. {
  392. run_configure_if_required
  393. old_MallocGuardEdges=$MallocGuardEdges
  394. MallocGuardEdges=1
  395. old_MallocErrorAbort=$MallocErrorAbort
  396. MallocErrorAbort=1
  397. old_MallocScribble=$MallocScribble
  398. MallocScribble=1
  399. make_check
  400. MallocGuardEdges=$old_MallocGuardEdges
  401. MallocErrorAbort=$old_MallocErrorAbort
  402. MallocScribble=$old_MallocScribble
  403. }
  404. function snapshot_check ()
  405. {
  406. if [ ! -f "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
  407. make_for_snapshot
  408. fi
  409. if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
  410. assert_file "$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
  411. fi
  412. }
  413. # This will reset our environment, and make sure built files are available.
  414. function make_for_snapshot ()
  415. {
  416. # Make sure it is clean
  417. make_maintainer_clean
  418. run_configure
  419. make_target 'dist'
  420. make_target 'distclean'
  421. # We should have a configure, but no Makefile at the end of this exercise
  422. assert_no_file 'Makefile'
  423. assert_exec_file 'configure'
  424. snapshot_check
  425. }
  426. function make_for_mingw32 ()
  427. {
  428. # Make sure it is clean
  429. if [ -f Makefile -o -f configure ]; then
  430. make_maintainer_clean
  431. fi
  432. assert_no_file 'Makefile'
  433. if command_exists mingw32-configure; then
  434. run_autoreconf
  435. mingw32-configure || die 'mingw32-configure failed'
  436. assert_file 'Makefile'
  437. if command_exists mingw32-make; then
  438. mingw32-make || die 'mingw32-make failed'
  439. fi
  440. fi
  441. }
  442. # If we are locally testing, we should make sure the environment is setup correctly
  443. function check_for_jenkins ()
  444. {
  445. if ! $jenkins_build_environment; then
  446. echo "Not inside of jenkins"
  447. if [ -f 'configure' ]; then
  448. make_maintainer_clean
  449. fi
  450. if $BOOTSTRAP_SNAPSHOT; then
  451. make_for_snapshot
  452. fi
  453. fi
  454. }
  455. function make_universe ()
  456. {
  457. make_for_snapshot
  458. make_valgrind
  459. make_gdb
  460. make_rpm
  461. make_for_mingw32
  462. make_distcheck
  463. make_install_system
  464. }
  465. function make_for_continuus_integration ()
  466. {
  467. # Setup the environment if we are local
  468. check_for_jenkins
  469. # No matter then evironment, we should not have a Makefile at this point
  470. assert_no_file 'Makefile'
  471. # Platforms which require bootstrap should have some setup done before we hit this stage.
  472. # If we are building locally, skip this step, unless we are just testing locally.
  473. if $BOOTSTRAP_SNAPSHOT; then
  474. snapshot_check
  475. else
  476. # If we didn't require a snapshot, then we should not have a configure
  477. assert_no_file 'configure'
  478. run_autoreconf
  479. fi
  480. assert_no_file 'Makefile' 'Programmer error, Makefile existed where build state should have been clean'
  481. case $HOST_OS in
  482. *-fedora-*)
  483. run_configure
  484. assert_exec_file 'configure'
  485. assert_file 'Makefile'
  486. # make rpm includes "make distcheck"
  487. if [[ -f rpm.am ]]; then
  488. make_rpm
  489. elif [[ -d rpm ]]; then
  490. make_rpm
  491. else
  492. make_distcheck
  493. fi
  494. assert_exec_file 'configure'
  495. assert_file 'Makefile'
  496. make_install_system
  497. ;;
  498. *-precise-*)
  499. run_configure
  500. assert_exec_file 'configure'
  501. assert_file 'Makefile'
  502. make_distcheck
  503. assert_exec_file 'configure'
  504. assert_file 'Makefile'
  505. make_valgrind
  506. assert_exec_file 'configure'
  507. assert_file 'Makefile'
  508. make_install_system
  509. ;;
  510. *)
  511. make_jenkins_default
  512. ;;
  513. esac
  514. make_maintainer_clean
  515. safe_popd
  516. }
  517. # The point to this test is to test bootstrap.sh itself
  518. function self_test ()
  519. {
  520. # We start off with a clean env
  521. make_maintainer_clean
  522. eval "./bootstrap.sh jenkins" || die "failed 'jenkins'"
  523. eval "./bootstrap.sh all" || die "failed 'all'"
  524. eval "./bootstrap.sh gdb" || die "failed 'gdb'"
  525. eval "./bootstrap.sh maintainer-clean" || die "failed 'maintainer-clean'"
  526. }
  527. function make_gdb ()
  528. {
  529. run_configure_if_required
  530. if command_exists gdb; then
  531. push_TESTS_ENVIRONMENT
  532. # Set ENV GDB_COMMAND
  533. if [[ -z "$GDB_COMMAND" ]]; then
  534. setup_gdb_command
  535. fi
  536. # If we don't have a configure, then most likely we will be missing libtool
  537. assert_file 'configure'
  538. if [[ -f 'libtool' ]]; then
  539. TESTS_ENVIRONMENT="./libtool --mode=execute $GDB_COMMAND"
  540. else
  541. TESTS_ENVIRONMENT="$GDB_COMMAND"
  542. fi
  543. make_target check
  544. if [ -f 'gdb.txt' ]; then
  545. rm 'gdb.txt'
  546. fi
  547. pop_TESTS_ENVIRONMENT
  548. if [ -f '.gdb_history' ]; then
  549. rm '.gdb_history'
  550. fi
  551. else
  552. echo 'gdb was not present'
  553. return 1
  554. fi
  555. }
  556. # $1 target to compile
  557. # $2 to die, or not to die, based on contents
  558. function make_target ()
  559. {
  560. if [[ -z "$1" ]]; then
  561. die "Programmer error, no target provided for make"
  562. fi
  563. if [ ! -f 'Makefile' ]; then
  564. die "Programmer error, make was called before configure"
  565. run_configure
  566. fi
  567. if [ -n "$TESTS_ENVIRONMENT" -a $VERBOSE ]; then
  568. echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
  569. fi
  570. if [[ -z "$MAKE" ]]; then
  571. die "MAKE was not set"
  572. fi
  573. if [[ -n "$2" ]]; then
  574. run $MAKE $1 || return 1
  575. else
  576. run $MAKE $1 || die "Cannot execute $MAKE $1"
  577. fi
  578. }
  579. function make_distcheck ()
  580. {
  581. make_target 'distcheck'
  582. }
  583. function make_rpm ()
  584. {
  585. if [ -f 'rpm.am' -o -d 'rpm' ]; then
  586. run_configure_if_required
  587. make_target 'rpm'
  588. fi
  589. }
  590. function make_maintainer_clean ()
  591. {
  592. run_configure_if_required
  593. make_target 'maintainer-clean' 'no_error'
  594. }
  595. function make_check ()
  596. {
  597. make_target 'check'
  598. }
  599. function make_jenkins_default ()
  600. {
  601. run_configure
  602. make_target 'all'
  603. }
  604. function make_default ()
  605. {
  606. run_configure_if_required
  607. make_target 'all'
  608. }
  609. function run_configure_if_required ()
  610. {
  611. run_autoreconf_if_required
  612. if [ ! -f 'Makefile' ]; then
  613. run_configure
  614. fi
  615. assert_file 'Makefile' 'configure did not produce a Makefile'
  616. }
  617. function run_autoreconf_if_required ()
  618. {
  619. if [ ! -x 'configure' ]; then
  620. run_autoreconf
  621. fi
  622. assert_exec_file 'configure'
  623. }
  624. function run_autoreconf ()
  625. {
  626. if [[ -z "$AUTORECONF" ]]; then
  627. die "Programmer error, tried to call run_autoreconf () but AUTORECONF was not set"
  628. fi
  629. run $AUTORECONF || die "Cannot execute $AUTORECONF"
  630. eval 'bash -n configure' || die "autoreconf generated a malformed configure"
  631. }
  632. function run ()
  633. {
  634. if $VERBOSE; then
  635. echo "\`$@' $ARGS"
  636. fi
  637. eval $@ $ARGS
  638. }
  639. parse_command_line_options ()
  640. {
  641. local SHORTOPTS=':apcmt:dvh'
  642. nassert MAKE_TARGET
  643. while getopts "$SHORTOPTS" opt; do
  644. case $opt in
  645. a) #--autoreconf
  646. AUTORECONF_OPTION=true
  647. MAKE_TARGET='autoreconf'
  648. ;;
  649. p) #--print-env
  650. PRINT_SETUP_OPTION=true
  651. ;;
  652. c) # --configure
  653. CONFIGURE_OPTION=true
  654. MAKE_TARGET='configure'
  655. ;;
  656. m) # maintainer-clean
  657. CLEAN_OPTION=true
  658. MAKE_TARGET='clean_op'
  659. ;;
  660. t) # target
  661. TARGET_OPTION=true
  662. TARGET_OPTION_ARG="$OPTARG"
  663. MAKE_TARGET="$OPTARG"
  664. ;;
  665. d) # debug
  666. DEBUG_OPTION=true
  667. enable_debug
  668. ;;
  669. h) # help
  670. echo "bootstrap.sh [options] optional_target ..."
  671. exit
  672. ;;
  673. v) # verbose
  674. VERBOSE_OPTION=true
  675. VERBOSE=true
  676. ;;
  677. :)
  678. echo "Option -$OPTARG requires an argument." >&2
  679. exit 1
  680. ;;
  681. *)
  682. echo "$0: error - unrecognized option $1" 1>&2
  683. exit 1
  684. ;;
  685. esac
  686. done
  687. shift $((OPTIND-1))
  688. if [ -n "$1" ]; then
  689. MAKE_TARGET="$@"
  690. fi
  691. }
  692. determine_vcs ()
  693. {
  694. if [[ -d '.git' ]]; then
  695. VCS_CHECKOUT=git
  696. elif [[ -d '.bzr' ]]; then
  697. VCS_CHECKOUT=bzr
  698. elif [[ -d '.svn' ]]; then
  699. VCS_CHECKOUT=svn
  700. elif [[ -d '.hg' ]]; then
  701. VCS_CHECKOUT=hg
  702. fi
  703. if [[ -n "$VCS_CHECKOUT" ]]; then
  704. VERBOSE=true
  705. fi
  706. }
  707. autoreconf_setup ()
  708. {
  709. # Set ENV MAKE in order to override "make"
  710. if [[ -z "$MAKE" ]]; then
  711. if command_exists gmake; then
  712. MAKE=`type -p gmake`
  713. else
  714. if command_exists make; then
  715. MAKE=`type -p make`
  716. fi
  717. fi
  718. if [ "$VCS_CHECKOUT" ]; then
  719. if $DEBUG; then
  720. MAKE="$MAKE --warn-undefined-variables"
  721. fi
  722. fi
  723. if $DEBUG; then
  724. MAKE="$MAKE -d"
  725. fi
  726. fi
  727. if [[ -z "$GNU_BUILD_FLAGS" ]]; then
  728. GNU_BUILD_FLAGS="--install --force"
  729. fi
  730. if $VERBOSE; then
  731. GNU_BUILD_FLAGS="$GNU_BUILD_FLAGS --verbose"
  732. fi
  733. if [ -z "$ACLOCAL_PATH" ]; then
  734. ACLOCAL_PATH="/usr/local/share/aclocal $ACLOCAL_PATH"
  735. fi
  736. if [[ -z "$WARNINGS" ]]; then
  737. if [[ -n "$VCS_CHECKOUT" ]]; then
  738. WARNINGS="all,error"
  739. else
  740. WARNINGS="all"
  741. fi
  742. fi
  743. if [[ -z "$LIBTOOLIZE" ]]; then
  744. # If we are using OSX, we first check to see glibtoolize is available
  745. if [[ "$VENDOR_DISTRIBUTION" == "darwin" ]]; then
  746. LIBTOOLIZE=`type -p glibtoolize`
  747. if [[ -z "$LIBTOOLIZE" ]]; then
  748. echo "Couldn't find glibtoolize, it is required on OSX"
  749. fi
  750. fi
  751. fi
  752. # Test the ENV AUTOMAKE if it exists
  753. if [[ -n "$AUTOMAKE" ]]; then
  754. run $AUTOMAKE '--help' &> /dev/null || die "Failed to run AUTOMAKE:$AUTOMAKE"
  755. fi
  756. # Test the ENV AUTOCONF if it exists
  757. if [[ -n "$AUTOCONF" ]]; then
  758. run $AUTOCONF '--help' &> /dev/null || die "Failed to run AUTOCONF:$AUTOCONF"
  759. fi
  760. # Test the ENV AUTOHEADER if it exists
  761. if [[ -n "$AUTOHEADER" ]]; then
  762. run $AUTOHEADER '--help' &> /dev/null || die "Failed to run AUTOHEADER:$AUTOHEADER"
  763. fi
  764. # Test the ENV AUTOM4TE if it exists
  765. if [[ -n "$AUTOM4TE" ]]; then
  766. run $AUTOM4TE '--help' &> /dev/null || die "Failed to run AUTOM4TE:$AUTOM4TE"
  767. fi
  768. if [[ -z "$AUTORECONF" ]]; then
  769. AUTORECONF=`type -p autoreconf`
  770. if [[ -z "$AUTORECONF" ]]; then
  771. die "Couldn't find autoreconf"
  772. fi
  773. if [[ -n "$GNU_BUILD_FLAGS" ]]; then
  774. AUTORECONF="$AUTORECONF $GNU_BUILD_FLAGS"
  775. fi
  776. fi
  777. run $AUTORECONF '--help' &> /dev/null || die "Failed to run AUTORECONF:$AUTORECONF"
  778. }
  779. print_setup ()
  780. {
  781. saved_debug_status=$DEBUG
  782. if $DEBUG; then
  783. disable_debug
  784. fi
  785. echo '----------------------------------------------'
  786. echo 'BOOTSTRAP ENV'
  787. echo "AUTORECONF=$AUTORECONF"
  788. echo "HOST_OS=$HOST_OS"
  789. echo "getopt()"
  790. if $AUTORECONF_OPTION; then
  791. echo "--autoreconf"
  792. fi
  793. if $CLEAN_OPTION; then
  794. echo "--clean"
  795. fi
  796. if $CONFIGURE_OPTION; then
  797. echo "--configure"
  798. fi
  799. if $DEBUG_OPTION; then
  800. echo "--debug"
  801. fi
  802. if $PRINT_SETUP_OPTION; then
  803. echo "--print-env"
  804. fi
  805. if $TARGET_OPTION; then
  806. echo "--target=$TARGET_OPTION_ARG"
  807. fi
  808. if $VERBOSE_OPTION; then
  809. echo "--verbose"
  810. fi
  811. if [[ -n "$MAKE" ]]; then
  812. echo "MAKE=$MAKE"
  813. fi
  814. if [[ -n "$MAKE_TARGET" ]]; then
  815. echo "MAKE_TARGET=$MAKE_TARGET"
  816. fi
  817. if [[ -n "$PREFIX" ]]; then
  818. echo "PREFIX=$PREFIX"
  819. fi
  820. if [[ -n "$TESTS_ENVIRONMENT" ]]; then
  821. echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
  822. fi
  823. if [[ -n "$VCS_CHECKOUT" ]]; then
  824. echo "VCS_CHECKOUT=$VCS_CHECKOUT"
  825. fi
  826. if $VERBOSE; then
  827. echo "VERBOSE=true"
  828. fi
  829. if $DEBUG; then
  830. echo "DEBUG=true"
  831. fi
  832. if [[ -n "$WARNINGS" ]]; then
  833. echo "WARNINGS=$WARNINGS"
  834. fi
  835. echo '----------------------------------------------'
  836. if $saved_debug_status; then
  837. enable_debug
  838. fi
  839. }
  840. make_clean_option ()
  841. {
  842. run_configure_if_required
  843. make_maintainer_clean
  844. if [[ "$VCS_CHECKOUT" == 'git' ]]; then
  845. run "$VCS_CHECKOUT" status --ignored
  846. elif [[ -n "$VCS_CHECKOUT" ]]; then
  847. run "$VCS_CHECKOUT" status
  848. fi
  849. }
  850. make_for_autoreconf ()
  851. {
  852. if [ -f 'Makefile' ]; then
  853. make_maintainer_clean
  854. fi
  855. run_autoreconf
  856. assert_no_file 'Makefile'
  857. }
  858. check_make_target()
  859. {
  860. case $1 in
  861. 'self')
  862. ;;
  863. 'rpm')
  864. ;;
  865. 'gdb')
  866. ;;
  867. 'clean_op')
  868. ;;
  869. 'autoreconf')
  870. ;;
  871. 'install-system')
  872. ;;
  873. 'configure')
  874. ;;
  875. 'distcheck')
  876. ;;
  877. 'check')
  878. ;;
  879. 'snapshot')
  880. ;;
  881. 'mingw')
  882. ;;
  883. 'universe')
  884. ;;
  885. 'valgrind')
  886. ;;
  887. 'jenkins')
  888. ;;
  889. 'distclean')
  890. ;;
  891. 'maintainer-clean')
  892. ;;
  893. 'install')
  894. ;;
  895. 'all')
  896. ;;
  897. 'test-*')
  898. ;;
  899. 'valgrind-*')
  900. ;;
  901. 'gdb-*')
  902. ;;
  903. 'dist')
  904. ;;
  905. *)
  906. die "Unknown MAKE_TARGET option: $1"
  907. ;;
  908. esac
  909. }
  910. function bootstrap ()
  911. {
  912. determine_target_platform
  913. determine_vcs
  914. # Set up whatever we need to do to use autoreconf later
  915. autoreconf_setup
  916. if [ -z "$MAKE_TARGET" ]; then
  917. MAKE_TARGET="make_default"
  918. fi
  919. if $PRINT_SETUP_OPTION -o $DEBUG; then
  920. echo
  921. print_setup
  922. echo
  923. # Exit if all we were looking for were the currently used options
  924. if $PRINT_SETUP_OPTION; then
  925. exit
  926. fi
  927. fi
  928. # Use OLD_TESTS_ENVIRONMENT for tracking the state of the variable
  929. local OLD_TESTS_ENVIRONMENT=
  930. # Set ENV PREFIX in order to set --prefix for ./configure
  931. if [[ -n "$PREFIX" ]]; then
  932. push_PREFIX_ARG $PREFIX
  933. fi
  934. # We should always have a target by this point
  935. assert MAKE_TARGET
  936. local MAKE_TARGET_ARRAY=($MAKE_TARGET)
  937. for target in "${MAKE_TARGET_ARRAY[@]}"
  938. do
  939. # If we are running inside of Jenkins, we want to only run some of the possible tests
  940. if $jenkins_build_environment; then
  941. check_make_target $target
  942. fi
  943. case $target in
  944. 'self')
  945. self_test
  946. ;;
  947. 'gdb')
  948. make_gdb
  949. ;;
  950. 'clean_op')
  951. make_clean_option
  952. ;;
  953. 'autoreconf')
  954. make_for_autoreconf
  955. ;;
  956. 'install-system')
  957. make_install_system
  958. ;;
  959. 'configure')
  960. run_configure
  961. ;;
  962. 'default')
  963. make
  964. run_configure
  965. ;;
  966. 'mingw')
  967. make_for_mingw32
  968. ;;
  969. 'snapshot')
  970. make_for_snapshot
  971. ;;
  972. 'rpm')
  973. make_rpm
  974. ;;
  975. 'valgrind')
  976. make_valgrind
  977. ;;
  978. 'universe')
  979. make_universe
  980. ;;
  981. 'jenkins')
  982. make_for_continuus_integration
  983. ;;
  984. *)
  985. run_configure_if_required
  986. make_target "$target"
  987. ;;
  988. esac
  989. done
  990. }
  991. main ()
  992. {
  993. # Variables we export
  994. declare -x VCS_CHECKOUT=
  995. # Variables we control globally
  996. local MAKE_TARGET=
  997. # Options for getopt
  998. local AUTORECONF_OPTION=false
  999. local CLEAN_OPTION=false
  1000. local CONFIGURE_OPTION=false
  1001. local DEBUG_OPTION=false
  1002. local PRINT_SETUP_OPTION=false
  1003. local TARGET_OPTION=false
  1004. local TARGET_OPTION_ARG=
  1005. local VERBOSE_OPTION=false
  1006. # If we call autoreconf on the platform or not
  1007. local AUTORECONF_REBUILD_HOST=false
  1008. local AUTORECONF_REBUILD=false
  1009. local -r top_srcdir=`pwd`
  1010. # Variables for determine_target_platform () and rebuild_host_os ()
  1011. # UNAME_MACHINE_ARCH= uname -m
  1012. # VENDOR= apple, redhat, centos, canonical
  1013. # VENDOR_RELEASE=
  1014. # RHEL{rhel,Tikanga,Santiago}
  1015. # Ubuntu{ubuntu,Lucid,Maverick,Natty,Oneiric,Precise,Quantal}
  1016. # Fedora{fedora,Verne,Beefy}
  1017. # OSX{osx,lion,snow,mountain}
  1018. # VENDOR_DISTRIBUTION= darwin,fedora,rhel,ubuntu
  1019. # UNAME_KERNEL= Linux, Darwin,...
  1020. # UNAME_KERNEL_RELEASE= Linux, Darwin,...
  1021. local UNAME_MACHINE_ARCH=unknown
  1022. local VENDOR=unknown
  1023. local VENDOR_RELEASE=unknown
  1024. local VENDOR_DISTRIBUTION=unknown
  1025. local UNAME_KERNEL=unknown
  1026. local UNAME_KERNEL_RELEASE=unknown
  1027. local HOST_OS=
  1028. rebuild_host_os no_output
  1029. parse_command_line_options $@
  1030. # If we are running under Jenkins we predetermine what tests we will run against
  1031. # This MAKE_TARGET can be overridden by parse_command_line_options based MAKE_TARGET changes.
  1032. # We don't want Jenkins overriding other variables, so we NULL them.
  1033. if [ -z "$MAKE_TARGET" -a $jenkins_build_environment ]; then
  1034. MAKE_TARGET='jenkins'
  1035. fi
  1036. bootstrap
  1037. jobs -l
  1038. wait
  1039. exit 0
  1040. }
  1041. enable_debug ()
  1042. {
  1043. if ! $DEBUG; then
  1044. local caller_loc=`caller`
  1045. if [ -n $1 ]; then
  1046. echo "$caller_loc Enabling debug: $1"
  1047. else
  1048. echo "$caller_loc Enabling debug"
  1049. fi
  1050. set -x
  1051. DEBUG=true
  1052. fi
  1053. }
  1054. disable_debug ()
  1055. {
  1056. set +x
  1057. DEBUG=true
  1058. }
  1059. # Script begins here
  1060. env_debug_enabled=false
  1061. if [[ -n "$JENKINS_HOME" ]]; then
  1062. declare -r jenkins_build_environment=true
  1063. else
  1064. declare -r jenkins_build_environment=false
  1065. fi
  1066. export AUTOCONF
  1067. export AUTOHEADER
  1068. export AUTOM4TE
  1069. export AUTOMAKE
  1070. export AUTORECONF
  1071. export DEBUG
  1072. export GNU_BUILD_FLAGS
  1073. export MAKE
  1074. export TESTS_ENVIRONMENT
  1075. export VERBOSE
  1076. export WARNINGS
  1077. case $OSTYPE in
  1078. darwin*)
  1079. export MallocGuardEdges
  1080. export MallocErrorAbort
  1081. export MallocScribble
  1082. ;;
  1083. esac
  1084. # We check for DEBUG twice, once before we source the config file, and once afterward
  1085. env_debug_enabled=false
  1086. if [[ -n "$DEBUG" ]]; then
  1087. env_debug_enabled=true
  1088. enable_debug
  1089. print_setup
  1090. fi
  1091. # Variables which only can be set by .bootstrap
  1092. BOOTSTRAP_SNAPSHOT=false
  1093. BOOTSTRAP_SNAPSHOT_CHECK=
  1094. if [ -f '.bootstrap' ]; then
  1095. source '.bootstrap'
  1096. fi
  1097. if $env_debug_enabled; then
  1098. enable_debug
  1099. else
  1100. if [[ -n "$DEBUG" ]]; then
  1101. enable_debug "Enabling DEBUG from '.bootstrap'"
  1102. print_setup
  1103. fi
  1104. fi
  1105. # We do this in order to protect the case where DEBUG
  1106. if ! $env_debug_enabled; then
  1107. DEBUG=false
  1108. fi
  1109. main $@