bootstrap.sh 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870
  1. #!/bin/bash
  2. #
  3. # Copyright (C) 2012-2013 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. warn "$@: command not found"
  46. #if $DEBUG; then
  47. echo ""
  48. echo "Stack trace:"
  49. local frame=0
  50. while caller $frame; do
  51. ((frame++));
  52. done
  53. echo ""
  54. #fi
  55. return 127
  56. }
  57. function error ()
  58. {
  59. echo "$BASH_SOURCE:$BASH_LINENO: $@" >&2
  60. }
  61. function die ()
  62. {
  63. echo "$BASH_SOURCE:$BASH_LINENO: $@" >&2
  64. exit 1;
  65. }
  66. function warn ()
  67. {
  68. echo "$BASH_SOURCE:$BASH_LINENO: $@"
  69. #echo "$BASH_SOURCE:$BASH_LINENO: $@" >&1
  70. }
  71. function nassert ()
  72. {
  73. local param_name=\$"$1"
  74. local param_value=`eval "expr \"$param_name\" "`
  75. if [ -n "$param_value" ]; then
  76. echo "$bash_source:$bash_lineno: assert($param_name) had value of "$param_value"" >&2
  77. exit 1
  78. fi
  79. }
  80. function assert ()
  81. {
  82. local param_name=\$"$1"
  83. local param_value=`eval "expr \"$param_name\" "`
  84. if [ -z "$param_value" ]; then
  85. echo "$bash_source:$bash_lineno: assert($param_name)" >&2
  86. exit 1
  87. fi
  88. }
  89. function assert_file ()
  90. {
  91. if [ ! -f "$1" ]; then
  92. echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
  93. exit 1;
  94. fi
  95. }
  96. function assert_no_file ()
  97. {
  98. if [ -f "$1" ]; then
  99. echo "$BASH_SOURCE:$BASH_LINENO: assert($1) file exists: $2" >&2
  100. exit 1;
  101. fi
  102. }
  103. function assert_no_directory ()
  104. {
  105. if [ -d "$1" ]; then
  106. echo "$BASH_SOURCE:$BASH_LINENO: assert($1) directory exists: $2" >&2
  107. exit 1;
  108. fi
  109. }
  110. function assert_exec_file ()
  111. {
  112. if [ ! -f "$1" ]; then
  113. echo "$BASH_SOURCE:$BASH_LINENO: assert($1) does not exist: $2" >&2
  114. exit 1;
  115. fi
  116. if [ ! -x "$1" ]; then
  117. echo "$BASH_SOURCE:$BASH_LINENO: assert($1) exists but is not executable: $2" >&2
  118. exit 1;
  119. fi
  120. }
  121. function command_exists ()
  122. {
  123. type "$1" &> /dev/null ;
  124. }
  125. function rebuild_host_os ()
  126. {
  127. HOST_OS="${UNAME_MACHINE_ARCH}-${VENDOR}-${VENDOR_DISTRIBUTION}-${VENDOR_RELEASE}-${UNAME_KERNEL}-${UNAME_KERNEL_RELEASE}"
  128. if [ -z "$1" ]; then
  129. if $VERBOSE; then
  130. echo "HOST_OS=$HOST_OS"
  131. fi
  132. fi
  133. }
  134. # Validate the distribution name, or toss an erro
  135. # values: darwin,fedora,rhel,ubuntu,debian,opensuse
  136. function set_VENDOR_DISTRIBUTION ()
  137. {
  138. local dist=`echo "$1" | tr '[A-Z]' '[a-z]'`
  139. case "$dist" in
  140. darwin)
  141. VENDOR_DISTRIBUTION='darwin'
  142. ;;
  143. fedora)
  144. VENDOR_DISTRIBUTION='fedora'
  145. ;;
  146. rhel)
  147. VENDOR_DISTRIBUTION='rhel'
  148. ;;
  149. debian)
  150. VENDOR_DISTRIBUTION='debian'
  151. ;;
  152. ubuntu)
  153. VENDOR_DISTRIBUTION='ubuntu'
  154. ;;
  155. suse)
  156. VENDOR_DISTRIBUTION='opensuse'
  157. ;;
  158. opensuse)
  159. VENDOR_DISTRIBUTION='opensuse'
  160. ;;
  161. *)
  162. die "attempt to set an invalid VENDOR_DISTRIBUTION=$dist"
  163. ;;
  164. esac
  165. }
  166. # Validate a Vendor's release name/number
  167. function set_VENDOR_RELEASE ()
  168. {
  169. local release=`echo "$1" | tr '[A-Z]' '[a-z]'`
  170. if $DEBUG; then
  171. echo "VENDOR_DISTRIBUTION:$VENDOR_DISTRIBUTION"
  172. echo "VENDOR_RELEASE:$release"
  173. fi
  174. case $VENDOR_DISTRIBUTION in
  175. darwin)
  176. case $release in
  177. 10.6*)
  178. VENDOR_RELEASE='snow_leopard'
  179. ;;
  180. 10.7*)
  181. VENDOR_RELEASE='mountain'
  182. ;;
  183. mountain)
  184. VENDOR_RELEASE='mountain'
  185. ;;
  186. 10.8.*)
  187. echo "mountain_lion"
  188. VENDOR_RELEASE='mountain_lion'
  189. ;;
  190. *)
  191. echo $VENDOR_RELEASE
  192. VENDOR_RELEASE='unknown'
  193. ;;
  194. esac
  195. ;;
  196. fedora)
  197. VENDOR_RELEASE="$release"
  198. if [[ "x$VENDOR_RELEASE" == '18' ]]; then
  199. VENDOR_RELEASE='sphericalcow'
  200. fi
  201. ;;
  202. rhel)
  203. VENDOR_RELEASE="$release"
  204. ;;
  205. debian)
  206. VENDOR_RELEASE="$release"
  207. ;;
  208. ubuntu)
  209. VENDOR_RELEASE="$release"
  210. if [[ "x$VENDOR_RELEASE" == 'x12.04' ]]; then
  211. VENDOR_RELEASE="precise"
  212. elif [[ "x$VENDOR_RELEASE" == 'x12.10' ]]; then
  213. VENDOR_RELEASE="quantal"
  214. elif [[ "x$VENDOR_RELEASE" == 'x13.04' ]]; then
  215. VENDOR_RELEASE="raring"
  216. fi
  217. ;;
  218. opensuse)
  219. VENDOR_RELEASE="$release"
  220. ;;
  221. unknown)
  222. die "attempt to set VENDOR_RELEASE without setting VENDOR_DISTRIBUTION"
  223. ;;
  224. *)
  225. die "attempt to set with an invalid VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
  226. ;;
  227. esac
  228. }
  229. # Valid values are: apple, redhat, centos, canonical, oracle, suse
  230. function set_VENDOR ()
  231. {
  232. local vendor=`echo "$1" | tr '[A-Z]' '[a-z]'`
  233. case $vendor in
  234. apple)
  235. VENDOR='apple'
  236. ;;
  237. redhat)
  238. VENDOR='redhat'
  239. ;;
  240. fedora)
  241. VENDOR='redhat'
  242. ;;
  243. redhat-release-server-*)
  244. VENDOR='redhat'
  245. ;;
  246. enterprise-release-*)
  247. VENDOR='oracle'
  248. ;;
  249. centos)
  250. VENDOR='centos'
  251. ;;
  252. canonical)
  253. VENDOR='canonical'
  254. ;;
  255. ubuntu)
  256. VENDOR='canonical'
  257. ;;
  258. debian)
  259. VENDOR='debian'
  260. ;;
  261. opensuse)
  262. VENDOR='suse'
  263. ;;
  264. suse)
  265. VENDOR='suse'
  266. ;;
  267. *)
  268. die "An attempt was made to set an invalid VENDOR=$_vendor"
  269. ;;
  270. esac
  271. set_VENDOR_DISTRIBUTION $2
  272. set_VENDOR_RELEASE $3
  273. # Set which vendor/versions we trust for autoreconf
  274. case $VENDOR_DISTRIBUTION in
  275. fedora)
  276. if [[ "x$VENDOR_RELEASE" == 'x18' ]]; then
  277. AUTORECONF_REBUILD_HOST=true
  278. elif [[ "x$VENDOR_RELEASE" == 'xsphericalcow' ]]; then
  279. AUTORECONF_REBUILD_HOST=true
  280. elif [[ "x$VENDOR_RELEASE" == 'x19' ]]; then
  281. AUTORECONF_REBUILD_HOST=true
  282. fi
  283. ;;
  284. canonical)
  285. if [[ "x$VENDOR_RELEASE" == 'xprecise' ]]; then
  286. AUTORECONF_REBUILD_HOST=true
  287. elif [[ "x$VENDOR_RELEASE" == 'xquantal' ]]; then
  288. AUTORECONF_REBUILD_HOST=true
  289. fi
  290. ;;
  291. esac
  292. }
  293. function determine_target_platform ()
  294. {
  295. UNAME_MACHINE_ARCH=`(uname -m) 2>/dev/null` || UNAME_MACHINE_ARCH=unknown
  296. UNAME_KERNEL=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
  297. UNAME_KERNEL_RELEASE=`(uname -r) 2>/dev/null` || UNAME_KERNEL_RELEASE=unknown
  298. if [[ -x '/usr/bin/sw_vers' ]]; then
  299. local _VERSION=`/usr/bin/sw_vers -productVersion`
  300. set_VENDOR 'apple' 'darwin' $_VERSION
  301. elif [[ $(uname) == 'Darwin' ]]; then
  302. set_VENDOR 'apple' 'darwin' 'mountain'
  303. elif [[ -f '/etc/fedora-release' ]]; then
  304. local fedora_version=`cat /etc/fedora-release | awk ' { print $3 } '`
  305. set_VENDOR 'redhat' 'fedora' $fedora_version
  306. elif [[ -f '/etc/centos-release' ]]; then
  307. local centos_version=`cat /etc/centos-release | awk ' { print $7 } '`
  308. set_VENDOR 'centos' 'rhel' $centos_version
  309. elif [[ -f '/etc/SuSE-release' ]]; then
  310. local suse_distribution=`head -1 /etc/SuSE-release | awk ' { print $1 } '`
  311. local suse_version=`head -1 /etc/SuSE-release | awk ' { print $2 } '`
  312. set_VENDOR 'suse' $suse_distribution $suse_version
  313. elif [[ -f '/etc/redhat-release' ]]; then
  314. local rhel_version=`cat /etc/redhat-release | awk ' { print $7 } '`
  315. local _vendor=`rpm -qf /etc/redhat-release`
  316. set_VENDOR $_vendor 'rhel' $rhel_version
  317. elif [[ -f '/etc/os-release' ]]; then
  318. source '/etc/os-release'
  319. set_VENDOR $ID $ID $VERSION_ID
  320. elif [[ -x '/usr/bin/lsb_release' ]]; then
  321. local _ID=`/usr/bin/lsb_release -s -i`
  322. local _VERSION=`/usr/bin/lsb_release -s -r`
  323. set_VENDOR $_ID $_ID $_VERSION_ID
  324. elif [[ -f '/etc/lsb-release' ]]; then
  325. source '/etc/lsb-release'
  326. set_VENDOR 'canonical' $DISTRIB_ID $DISTRIB_CODENAME
  327. fi
  328. rebuild_host_os
  329. }
  330. function run_configure ()
  331. {
  332. # We will run autoreconf if we are required
  333. run_autoreconf_if_required
  334. # We always begin at the root of our build
  335. if [ ! popd ]; then
  336. die "Programmer error, we entered run_configure with a stacked directory"
  337. fi
  338. if ! command_exists "$CONFIGURE"; then
  339. die "$CONFIGURE does not exist"
  340. fi
  341. local BUILD_DIR="$1"
  342. if [[ -n "$BUILD_DIR" ]]; then
  343. rm -r -f $BUILD_DIR
  344. mkdir -p $BUILD_DIR
  345. safe_pushd $BUILD_DIR
  346. fi
  347. # Arguments for configure
  348. local BUILD_CONFIGURE_ARG=
  349. # If ENV DEBUG is set we enable both debug and asssert, otherwise we see if this is a VCS checkout and if so enable assert
  350. # Set ENV ASSERT in order to enable assert.
  351. # If we are doing a valgrind run, we always compile with assert disabled
  352. if $valgrind_run; then
  353. BUILD_CONFIGURE_ARG+= '--enable-assert=no'
  354. else
  355. if $DEBUG; then
  356. BUILD_CONFIGURE_ARG+=' --enable-debug --enable-assert'
  357. elif [[ -n "$VCS_CHECKOUT" ]]; then
  358. BUILD_CONFIGURE_ARG+=' --enable-assert'
  359. fi
  360. fi
  361. if [[ -n "$CONFIGURE_ARG" ]]; then
  362. BUILD_CONFIGURE_ARG+=" $CONFIGURE_ARG"
  363. fi
  364. if [[ -n "$PREFIX_ARG" ]]; then
  365. BUILD_CONFIGURE_ARG+=" $PREFIX_ARG"
  366. fi
  367. ret=1;
  368. # If we are executing on OSX use CLANG, otherwise only use it if we find it in the ENV
  369. case $HOST_OS in
  370. *-darwin-*)
  371. CC=clang CXX=clang++ $top_srcdir/configure $BUILD_CONFIGURE_ARG || die "Cannot execute CC=clang CXX=clang++ configure $BUILD_CONFIGURE_ARG"
  372. ret=$?
  373. ;;
  374. rhel-5*)
  375. command_exists 'gcc44' || die "Could not locate gcc44"
  376. CC=gcc44 CXX=gcc44 $top_srcdir/configure $BUILD_CONFIGURE_ARG || die "Cannot execute CC=gcc44 CXX=gcc44 configure $BUILD_CONFIGURE_ARG"
  377. ret=$?
  378. ;;
  379. *)
  380. $CONFIGURE $BUILD_CONFIGURE_ARG
  381. ret=$?
  382. ;;
  383. esac
  384. if [ $ret -ne 0 ]; then
  385. die "Could not execute $CONFIGURE $BUILD_CONFIGURE_ARG"
  386. fi
  387. if [ ! -f 'Makefile' ]; then
  388. die "Programmer error, configure was run but no Makefile existed after $CONFIGURE was run"
  389. fi
  390. }
  391. function setup_gdb_command () {
  392. GDB_TMPFILE=$(mktemp /tmp/gdb.XXXXXXXXXX)
  393. echo 'set logging overwrite on' > $GDB_TMPFILE
  394. echo 'set logging on' >> $GDB_TMPFILE
  395. echo 'set environment LIBTEST_IN_GDB=1' >> $GDB_TMPFILE
  396. echo 'run' >> $GDB_TMPFILE
  397. echo 'thread apply all bt' >> $GDB_TMPFILE
  398. echo 'quit' >> $GDB_TMPFILE
  399. GDB_COMMAND="gdb -f -batch -x $GDB_TMPFILE"
  400. }
  401. function setup_valgrind_command () {
  402. VALGRIND_PROGRAM=`type -p valgrind`
  403. if [[ -n "$VALGRIND_PROGRAM" ]]; then
  404. VALGRIND_COMMAND="$VALGRIND_PROGRAM --error-exitcode=1 --leak-check=yes --malloc-fill=A5 --free-fill=DE --xml=yes --xml-file=\"valgrind-%p.xml\""
  405. fi
  406. }
  407. function save_BUILD ()
  408. {
  409. if [[ -n "$OLD_CONFIGURE" ]]; then
  410. die "OLD_CONFIGURE($OLD_CONFIGURE) was set on push, programmer error!"
  411. fi
  412. if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
  413. die "OLD_CONFIGURE_ARG($OLD_CONFIGURE_ARG) was set on push, programmer error!"
  414. fi
  415. if [[ -n "$OLD_PREFIX" ]]; then
  416. die "OLD_PREFIX($OLD_PREFIX) was set on push, programmer error!"
  417. fi
  418. if [[ -n "$OLD_MAKE" ]]; then
  419. die "OLD_MAKE($OLD_MAKE) was set on push, programmer error!"
  420. fi
  421. if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
  422. die "OLD_TESTS_ENVIRONMENT($OLD_TESTS_ENVIRONMENT) was set on push, programmer error!"
  423. fi
  424. if [[ -n "$CONFIGURE" ]]; then
  425. OLD_CONFIGURE=$CONFIGURE
  426. fi
  427. if [[ -n "$CONFIGURE_ARG" ]]; then
  428. OLD_CONFIGURE_ARG=$CONFIGURE_ARG
  429. fi
  430. if [[ -n "$MAKE" ]]; then
  431. OLD_MAKE=$MAKE
  432. fi
  433. if [[ -n "$TESTS_ENVIRONMENT" ]]; then
  434. OLD_TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT
  435. fi
  436. }
  437. function restore_BUILD ()
  438. {
  439. if [[ -n "$OLD_CONFIGURE" ]]; then
  440. CONFIGURE=$OLD_CONFIGURE
  441. fi
  442. if [[ -n "$OLD_CONFIGURE_ARG" ]]; then
  443. CONFIGURE_ARG=$OLD_CONFIGURE_ARG
  444. fi
  445. if [[ -n "$OLD_PREFIX" ]]; then
  446. PREFIX_ARG=$OLD_PREFIX
  447. fi
  448. if [[ -n "$OLD_MAKE" ]]; then
  449. MAKE=$OLD_MAKE
  450. fi
  451. if [[ -n "$OLD_TESTS_ENVIRONMENT" ]]; then
  452. TESTS_ENVIRONMENT=$OLD_TESTS_ENVIRONMENT
  453. fi
  454. OLD_CONFIGURE=
  455. OLD_CONFIGURE_ARG=
  456. OLD_PREFIX=
  457. OLD_MAKE=
  458. OLD_TESTS_ENVIRONMENT=
  459. export -n CC CXX
  460. }
  461. function safe_pushd ()
  462. {
  463. pushd $1 &> /dev/null ;
  464. if [ -n "$BUILD_DIR" ]; then
  465. if $VERBOSE; then
  466. echo "BUILD_DIR=$BUILD_DIR"
  467. fi
  468. fi
  469. }
  470. function safe_popd ()
  471. {
  472. local directory_to_delete=`pwd`
  473. popd &> /dev/null ;
  474. if [ $? -eq 0 ]; then
  475. if [[ "$top_srcdir" == "$directory_to_delete" ]]; then
  476. die "We almost deleted top_srcdir($top_srcdir), programmer error"
  477. fi
  478. rm -r -f "$directory_to_delete"
  479. fi
  480. }
  481. function make_valgrind ()
  482. {
  483. # If the env VALGRIND_COMMAND is set then we assume it is valid
  484. local valgrind_was_set=false
  485. if [[ -z "$VALGRIND_COMMAND" ]]; then
  486. setup_valgrind_command
  487. if [[ -n "$VALGRIND_COMMAND" ]]; then
  488. valgrind_was_set=true
  489. fi
  490. else
  491. valgrind_was_set=true
  492. fi
  493. # If valgrind_was_set is set to no we bail
  494. if ! $valgrind_was_set; then
  495. echo 'valgrind was not present'
  496. return 1
  497. fi
  498. save_BUILD
  499. valgrind_run=true
  500. # If we are required to run configure, do so now
  501. run_configure
  502. # If we don't have a configure, then most likely we will be missing libtool
  503. assert_file 'configure'
  504. if [[ -x 'libtool' ]]; then
  505. TESTS_ENVIRONMENT="./libtool --mode=execute $VALGRIND_COMMAND"
  506. else
  507. TESTS_ENVIRONMENT="$VALGRIND_COMMAND"
  508. fi
  509. make_target 'all'
  510. make_target 'check'
  511. ret=$?
  512. # If we aren't going to error, we will clean up our environment
  513. if [ "$ret" -eq 0 ]; then
  514. make 'distclean'
  515. fi
  516. valgrind_run=false
  517. restore_BUILD
  518. if [ "$ret" -ne 0 ]; then
  519. return 1
  520. fi
  521. }
  522. function make_install_system ()
  523. {
  524. local INSTALL_LOCATION=$(mktemp -d /tmp/XXXXXXXXXX)
  525. save_BUILD
  526. PREFIX_ARG="--prefix=$INSTALL_LOCATION"
  527. if [ ! -d $INSTALL_LOCATION ] ; then
  528. die "ASSERT temp directory not found '$INSTALL_LOCATION'"
  529. fi
  530. run_configure #install_buid_dir
  531. make_target 'install'
  532. make_target 'installcheck'
  533. make_target 'uninstall'
  534. rm -r -f $INSTALL_LOCATION
  535. make 'distclean'
  536. if [ -f 'Makefile' ]; then
  537. die "ASSERT Makefile should not exist"
  538. fi
  539. restore_BUILD
  540. safe_popd
  541. }
  542. function make_darwin_malloc ()
  543. {
  544. run_configure_if_required
  545. old_MallocGuardEdges=$MallocGuardEdges
  546. MallocGuardEdges=1
  547. old_MallocErrorAbort=$MallocErrorAbort
  548. MallocErrorAbort=1
  549. old_MallocScribble=$MallocScribble
  550. MallocScribble=1
  551. make_check
  552. MallocGuardEdges=$old_MallocGuardEdges
  553. MallocErrorAbort=$old_MallocErrorAbort
  554. MallocScribble=$old_MallocScribble
  555. }
  556. # This will reset our environment, and make sure built files are available.
  557. function make_for_snapshot ()
  558. {
  559. # Lets make sure we have a clean environment
  560. assert_no_file 'Makefile'
  561. assert_no_file 'configure'
  562. assert_no_directory 'autom4te.cache'
  563. run_configure
  564. make_target 'all'
  565. make_target 'distclean'
  566. # We should have a configure, but no Makefile at the end of this exercise
  567. assert_no_file 'Makefile'
  568. assert_exec_file 'configure'
  569. }
  570. function check_mingw ()
  571. {
  572. command_exists 'mingw64-configure'
  573. ret=$?
  574. if [ "$ret" -ne 0 ]; then
  575. return 1
  576. fi
  577. command_exists 'mingw64-make'
  578. ret=$?
  579. if [ "$ret" -ne 0 ]; then
  580. return 1
  581. fi
  582. return 0
  583. }
  584. function check_clang ()
  585. {
  586. command_exists 'clang'
  587. ret=$?
  588. if [ "$ret" -ne 0 ]; then
  589. return 1
  590. fi
  591. return 0
  592. }
  593. function check_clang_analyzer ()
  594. {
  595. command_exists 'scan-build'
  596. ret=$?
  597. if [ "$ret" -ne 0 ]; then
  598. return 1
  599. fi
  600. return 0
  601. }
  602. function make_skeleton ()
  603. {
  604. run_configure
  605. ret=$?
  606. if [ $ret -eq 0 ]; then
  607. assert_file 'Makefile'
  608. make_target 'all' 'warn'
  609. ret=$?
  610. if [ $ret -ne 0 ]; then
  611. warn "$MAKE failed"
  612. else
  613. if [[ -n "$DISPLAY" ]]; then
  614. if command_exists 'wine'; then
  615. TESTS_ENVIRONMENT='wine'
  616. fi
  617. fi
  618. if [[ -n "$TESTS_ENVIRONMENT" ]]; then
  619. make_target 'check' 'warn' || warn "$MAKE check failed"
  620. ret=$?
  621. fi
  622. fi
  623. if $jenkins_build_environment; then
  624. make_target 'clean' 'warn'
  625. fi
  626. fi
  627. return $ret
  628. }
  629. function make_for_mingw ()
  630. {
  631. if ! check_mingw; then
  632. return 1
  633. fi
  634. # Make sure it is clean
  635. if [ -f Makefile -o -f configure ]; then
  636. make_maintainer_clean
  637. fi
  638. run_autoreconf
  639. save_BUILD
  640. CONFIGURE='mingw64-configure'
  641. MAKE='mingw64-make'
  642. CONFIGURE_ARGS='--enable-static --disable-shared'
  643. make_skeleton
  644. ret=$?
  645. restore_BUILD
  646. return $ret
  647. }
  648. function make_for_clang ()
  649. {
  650. if ! check_clang; then
  651. return 1
  652. fi
  653. # Make sure it is clean
  654. if [ -f Makefile -o -f configure ]; then
  655. make_maintainer_clean
  656. fi
  657. run_autoreconf
  658. save_BUILD
  659. CC=clang CXX=clang++
  660. export CC CXX
  661. make_skeleton
  662. ret=$?
  663. make_target 'check'
  664. restore_BUILD
  665. return $ret
  666. }
  667. function make_for_clang_analyzer ()
  668. {
  669. if ! check_clang; then
  670. return 1
  671. fi
  672. if ! check_clang_analyzer; then
  673. die 'clang-analyzer was not found'
  674. fi
  675. # Make sure it is clean
  676. if [ -f Makefile -o -f configure ]; then
  677. make_maintainer_clean
  678. fi
  679. run_autoreconf
  680. save_BUILD
  681. CC=clang CXX=clang++
  682. export CC CXX
  683. CONFIGURE_ARGS='--enable-debug'
  684. make_skeleton
  685. ret=$?
  686. make_target 'clean' 'warn'
  687. scan-build -o clang-html make -j4 -k
  688. restore_BUILD
  689. return $ret
  690. }
  691. # If we are locally testing, we should make sure the environment is setup correctly
  692. function check_for_jenkins ()
  693. {
  694. if ! $jenkins_build_environment; then
  695. echo "Not inside of jenkins, simulating environment"
  696. if [ -f 'configure' ]; then
  697. make_maintainer_clean
  698. fi
  699. if $BOOTSTRAP_SNAPSHOT; then
  700. make_for_snapshot
  701. fi
  702. fi
  703. }
  704. function make_universe ()
  705. {
  706. make_for_snapshot
  707. make_valgrind
  708. make_gdb
  709. make_rpm
  710. make_for_clang
  711. make_for_clang_analyzer
  712. if [ check_mingw -eq 0 ]; then
  713. make_for_mingw
  714. fi
  715. make_distcheck
  716. make_install_system
  717. }
  718. function check_snapshot ()
  719. {
  720. if [ -n "$BOOTSTRAP_SNAPSHOT_CHECK" ]; then
  721. assert_file "$BOOTSTRAP_SNAPSHOT_CHECK" 'snapshot check failed'
  722. fi
  723. }
  724. function make_for_continuus_integration ()
  725. {
  726. # Setup the environment if we are local
  727. check_for_jenkins
  728. # No matter then evironment, we should not have a Makefile at this point
  729. assert_no_file 'Makefile'
  730. # Platforms which require bootstrap should have some setup done before we hit this stage.
  731. # If we are building locally, skip this step, unless we are just testing locally.
  732. if $BOOTSTRAP_SNAPSHOT; then
  733. if $BOOTSTRAP_SNAPSHOT; then
  734. assert_file 'configure'
  735. fi
  736. check_snapshot
  737. else
  738. # If we didn't require a snapshot, then we should not have a configure
  739. assert_no_file 'configure'
  740. run_autoreconf
  741. fi
  742. assert_no_file 'Makefile' 'Programmer error, Makefile existed where build state should have been clean'
  743. case $HOST_OS in
  744. *)
  745. make_jenkins_default
  746. ;;
  747. esac
  748. make_maintainer_clean
  749. safe_popd
  750. }
  751. # The point to this test is to test bootstrap.sh itself
  752. function self_test ()
  753. {
  754. # We start off with a clean env
  755. make_maintainer_clean
  756. eval "./bootstrap.sh jenkins" || die "failed 'jenkins'"
  757. eval "./bootstrap.sh all" || die "failed 'all'"
  758. eval "./bootstrap.sh gdb" || die "failed 'gdb'"
  759. eval "./bootstrap.sh maintainer-clean" || die "failed 'maintainer-clean'"
  760. }
  761. function make_install_html ()
  762. {
  763. run_configure_if_required
  764. assert_file 'configure'
  765. make_target 'install-html'
  766. }
  767. function make_gdb ()
  768. {
  769. save_BUILD
  770. if command_exists 'gdb'; then
  771. run_configure_if_required
  772. # Set ENV GDB_COMMAND
  773. if [[ -z "$GDB_COMMAND" ]]; then
  774. setup_gdb_command
  775. fi
  776. # If we don't have a configure, then most likely we will be missing libtool
  777. assert_file 'configure'
  778. if [[ -f 'libtool' ]]; then
  779. TESTS_ENVIRONMENT="./libtool --mode=execute $GDB_COMMAND"
  780. else
  781. TESTS_ENVIRONMENT="$GDB_COMMAND"
  782. fi
  783. make_target 'check'
  784. if [ -f 'gdb.txt' ]; then
  785. rm 'gdb.txt'
  786. fi
  787. if [ -f '.gdb_history' ]; then
  788. rm '.gdb_history'
  789. fi
  790. if $jenkins_build_environment; then
  791. make_target 'clean'
  792. fi
  793. else
  794. echo 'gdb was not present'
  795. return 1
  796. fi
  797. restore_BUILD
  798. }
  799. # $1 target to compile
  800. # $2 to die, or not to die, based on contents
  801. function make_target ()
  802. {
  803. if [ -z "$1" ]; then
  804. die "Programmer error, no target provided for make"
  805. fi
  806. if [ ! -f 'Makefile' ]; then
  807. die "Programmer error, make was called before configure"
  808. run_configure
  809. fi
  810. if [ -n "$TESTS_ENVIRONMENT" ]; then
  811. if $VERBOSE; then
  812. echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
  813. fi
  814. fi
  815. if [ -z "$MAKE" ]; then
  816. die "MAKE was not set"
  817. fi
  818. # $2 represents error or warn
  819. run $MAKE $1
  820. ret=$?
  821. if [ $ret -ne 0 ]; then
  822. if [ -n "$2" ]; then
  823. warn "Failed to execute $MAKE $1: $ret"
  824. elif [ $ret -eq 2 ]; then
  825. die "Failed to execute $MAKE $1"
  826. else
  827. die "Failed to execute $MAKE $1: $ret"
  828. fi
  829. fi
  830. return $ret
  831. }
  832. function make_distcheck ()
  833. {
  834. make_target 'distcheck'
  835. }
  836. function make_rpm ()
  837. {
  838. if command_exists 'rpmbuild'; then
  839. if [ -f 'rpm.am' -o -d 'rpm' ]; then
  840. run_configure_if_required
  841. make_target 'rpm'
  842. if $jenkins_build_environment; then
  843. make_target 'clean'
  844. fi
  845. fi
  846. fi
  847. }
  848. function make_maintainer_clean ()
  849. {
  850. run_configure_if_required
  851. make_target 'maintainer-clean' 'no_error'
  852. # Lets make sure we really cleaned up the environment
  853. assert_no_file 'Makefile'
  854. assert_no_file 'configure'
  855. assert_no_directory 'autom4te.cache'
  856. }
  857. function make_check ()
  858. {
  859. make_target 'check'
  860. }
  861. function make_jenkins_default ()
  862. {
  863. run_configure
  864. make_target 'all'
  865. }
  866. function make_default ()
  867. {
  868. run_configure_if_required
  869. make_target 'all'
  870. }
  871. function run_configure_if_required ()
  872. {
  873. run_autoreconf_if_required
  874. if [ ! -f 'Makefile' ]; then
  875. run_configure
  876. fi
  877. assert_file 'Makefile' 'configure did not produce a Makefile'
  878. }
  879. function run_make_maintainer_clean_if_possible ()
  880. {
  881. if [ -f 'Makefile' ]; then
  882. make_maintainer_clean
  883. fi
  884. }
  885. function run_autoreconf_if_required ()
  886. {
  887. if [ ! -x 'configure' ]; then
  888. run_autoreconf
  889. fi
  890. assert_exec_file 'configure'
  891. bash -n configure
  892. }
  893. function run_autoreconf ()
  894. {
  895. if [[ -z "$AUTORECONF" ]]; then
  896. die "Programmer error, tried to call run_autoreconf () but AUTORECONF was not set"
  897. fi
  898. if test $use_libtool = 1; then
  899. assert $BOOTSTRAP_LIBTOOLIZE
  900. run $BOOTSTRAP_LIBTOOLIZE '--copy' '--install' '--force' || die "Cannot execute $BOOTSTRAP_LIBTOOLIZE"
  901. fi
  902. run $AUTORECONF $AUTORECONF_ARGS || die "Cannot execute $AUTORECONF"
  903. eval 'bash -n configure' || die "autoreconf generated a malformed configure"
  904. }
  905. function run ()
  906. {
  907. if $VERBOSE; then
  908. echo "\`$@' $ARGS"
  909. fi
  910. if [ -z "$1" ]; then
  911. return 127;
  912. fi
  913. eval $@ $ARGS
  914. }
  915. function parse_command_line_options ()
  916. {
  917. local SHORTOPTS=':apcmt:dvh'
  918. nassert MAKE_TARGET
  919. while getopts "$SHORTOPTS" opt; do
  920. case $opt in
  921. a) #--autoreconf
  922. AUTORECONF_OPTION=true
  923. MAKE_TARGET='autoreconf'
  924. ;;
  925. p) #--print-env
  926. PRINT_SETUP_OPTION=true
  927. ;;
  928. c) # --configure
  929. CONFIGURE_OPTION=true
  930. MAKE_TARGET='configure'
  931. ;;
  932. m) # maintainer-clean
  933. CLEAN_OPTION=true
  934. MAKE_TARGET='clean_op'
  935. ;;
  936. t) # target
  937. TARGET_OPTION=true
  938. TARGET_OPTION_ARG="$OPTARG"
  939. MAKE_TARGET="$OPTARG"
  940. ;;
  941. d) # debug
  942. DEBUG_OPTION=true
  943. enable_debug
  944. ;;
  945. h) # help
  946. echo "bootstrap.sh [options] optional_target ..."
  947. echo " -a # Just run autoreconf";
  948. echo " -p # Print ENV";
  949. echo " -c # Just run configure";
  950. echo " -m # Just run maintainer-clean";
  951. echo " -t # Make target";
  952. echo " -d # Enable debug";
  953. echo " -h # Show help";
  954. echo " -v # Be more verbose in output";
  955. exit
  956. ;;
  957. v) # verbose
  958. VERBOSE_OPTION=true
  959. VERBOSE=true
  960. ;;
  961. :)
  962. echo "Option -$OPTARG requires an argument." >&2
  963. exit 1
  964. ;;
  965. *)
  966. echo "$0: error - unrecognized option $1" 1>&2
  967. exit 1
  968. ;;
  969. esac
  970. done
  971. shift $((OPTIND-1))
  972. if [ -n "$1" ]; then
  973. MAKE_TARGET="$@"
  974. fi
  975. }
  976. function determine_vcs ()
  977. {
  978. if [[ -d '.git' ]]; then
  979. VCS_CHECKOUT=git
  980. elif [[ -d '.bzr' ]]; then
  981. VCS_CHECKOUT=bzr
  982. elif [[ -d '.svn' ]]; then
  983. VCS_CHECKOUT=svn
  984. elif [[ -d '.hg' ]]; then
  985. VCS_CHECKOUT=hg
  986. else
  987. VCS_CHECKOUT=
  988. fi
  989. if [[ -n "$VCS_CHECKOUT" ]]; then
  990. VERBOSE=true
  991. fi
  992. }
  993. function require_libtoolise ()
  994. {
  995. use_libtool=0
  996. grep '^[ ]*A[CM]_PROG_LIBTOOL' configure.ac >/dev/null \
  997. && use_libtool=1
  998. grep '^[ ]*LT_INIT' configure.ac >/dev/null \
  999. && use_libtool=1
  1000. }
  1001. function autoreconf_setup ()
  1002. {
  1003. # Set ENV MAKE in order to override "make"
  1004. if [[ -z "$MAKE" ]]; then
  1005. if command_exists 'gmake'; then
  1006. MAKE=`type -p gmake`
  1007. else
  1008. if command_exists 'make'; then
  1009. MAKE=`type -p make`
  1010. fi
  1011. fi
  1012. if [ "$VCS_CHECKOUT" ]; then
  1013. if $DEBUG; then
  1014. MAKE="$MAKE --warn-undefined-variables"
  1015. fi
  1016. fi
  1017. if $DEBUG; then
  1018. MAKE="$MAKE -d"
  1019. fi
  1020. fi
  1021. if [[ -z "$GNU_BUILD_FLAGS" ]]; then
  1022. GNU_BUILD_FLAGS="--install --force"
  1023. fi
  1024. if $VERBOSE; then
  1025. GNU_BUILD_FLAGS="$GNU_BUILD_FLAGS --verbose"
  1026. fi
  1027. if [ -z "$ACLOCAL_PATH" ]; then
  1028. ACLOCAL_PATH="/usr/local/share/aclocal $ACLOCAL_PATH"
  1029. fi
  1030. if [[ -z "$WARNINGS" ]]; then
  1031. if [[ -n "$VCS_CHECKOUT" ]]; then
  1032. WARNINGS="all,error"
  1033. else
  1034. WARNINGS="all"
  1035. fi
  1036. fi
  1037. if test $use_libtool = 1; then
  1038. if [[ -n "$LIBTOOLIZE" ]]; then
  1039. BOOTSTRAP_LIBTOOLIZE=`type -p $LIBTOOLIZE`
  1040. if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
  1041. echo "Couldn't find user supplied libtoolize, it is required"
  1042. return 1
  1043. fi
  1044. else
  1045. # If we are using OSX, we first check to see glibtoolize is available
  1046. if [[ "$VENDOR_DISTRIBUTION" == "darwin" ]]; then
  1047. BOOTSTRAP_LIBTOOLIZE=`type -p glibtoolize`
  1048. if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
  1049. echo "Couldn't find glibtoolize, it is required on OSX"
  1050. return 1
  1051. fi
  1052. else
  1053. BOOTSTRAP_LIBTOOLIZE=`type -p libtoolize`
  1054. if [[ -z "$BOOTSTRAP_LIBTOOLIZE" ]]; then
  1055. echo "Couldn't find libtoolize, it is required"
  1056. return 1
  1057. fi
  1058. fi
  1059. fi
  1060. if $VERBOSE; then
  1061. LIBTOOLIZE_OPTIONS="--verbose $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
  1062. fi
  1063. if $DEBUG; then
  1064. LIBTOOLIZE_OPTIONS="--debug $BOOTSTRAP_LIBTOOLIZE_OPTIONS"
  1065. fi
  1066. # Here we set LIBTOOLIZE to true since we are going to invoke it via BOOTSTRAP_LIBTOOLIZE
  1067. LIBTOOLIZE=true
  1068. fi
  1069. # Test the ENV AUTOMAKE if it exists
  1070. if [[ -n "$AUTOMAKE" ]]; then
  1071. run $AUTOMAKE '--help' &> /dev/null || die "Failed to run AUTOMAKE:$AUTOMAKE"
  1072. fi
  1073. # Test the ENV AUTOCONF if it exists
  1074. if [[ -n "$AUTOCONF" ]]; then
  1075. run $AUTOCONF '--help' &> /dev/null || die "Failed to run AUTOCONF:$AUTOCONF"
  1076. fi
  1077. # Test the ENV AUTOHEADER if it exists
  1078. if [[ -n "$AUTOHEADER" ]]; then
  1079. run $AUTOHEADER '--help' &> /dev/null || die "Failed to run AUTOHEADER:$AUTOHEADER"
  1080. fi
  1081. # Test the ENV AUTOM4TE if it exists
  1082. if [[ -n "$AUTOM4TE" ]]; then
  1083. run $AUTOM4TE '--help' &> /dev/null || die "Failed to run AUTOM4TE:$AUTOM4TE"
  1084. fi
  1085. # Test the ENV AUTOHEADER if it exists, if not we add one and add --install
  1086. if [[ -z "$ACLOCAL" ]]; then
  1087. ACLOCAL="aclocal --install"
  1088. fi
  1089. run $ACLOCAL '--help' &> /dev/null || die "Failed to run ACLOCAL:$ACLOCAL"
  1090. if [[ -z "$AUTORECONF" ]]; then
  1091. AUTORECONF=`type -p autoreconf`
  1092. if [[ -z "$AUTORECONF" ]]; then
  1093. die "Couldn't find autoreconf"
  1094. fi
  1095. if [[ -n "$GNU_BUILD_FLAGS" ]]; then
  1096. AUTORECONF_ARGS="$GNU_BUILD_FLAGS"
  1097. fi
  1098. fi
  1099. run $AUTORECONF '--help' &> /dev/null || die "Failed to run AUTORECONF:$AUTORECONF"
  1100. }
  1101. function print_setup ()
  1102. {
  1103. saved_debug_status=$DEBUG
  1104. if $DEBUG; then
  1105. disable_debug
  1106. fi
  1107. echo '----------------------------------------------'
  1108. echo 'BOOTSTRAP ENV'
  1109. echo "AUTORECONF=$AUTORECONF"
  1110. echo "HOST_OS=$HOST_OS"
  1111. echo "VENDOR=$VENDOR"
  1112. echo "VENDOR_DISTRIBUTION=$VENDOR_DISTRIBUTION"
  1113. echo "VENDOR_RELEASE=$VENDOR_RELEASE"
  1114. echo "getopt()"
  1115. if $AUTORECONF_OPTION; then
  1116. echo "--autoreconf"
  1117. fi
  1118. if $CLEAN_OPTION; then
  1119. echo "--clean"
  1120. fi
  1121. if $CONFIGURE_OPTION; then
  1122. echo "--configure"
  1123. fi
  1124. if $DEBUG_OPTION; then
  1125. echo "--debug"
  1126. fi
  1127. if $PRINT_SETUP_OPTION; then
  1128. echo "--print-env"
  1129. fi
  1130. if $TARGET_OPTION; then
  1131. echo "--target=$TARGET_OPTION_ARG"
  1132. fi
  1133. if $VERBOSE_OPTION; then
  1134. echo "--verbose"
  1135. fi
  1136. if [[ -n "$MAKE" ]]; then
  1137. echo "MAKE=$MAKE"
  1138. fi
  1139. if [[ -n "$MAKE_TARGET" ]]; then
  1140. echo "MAKE_TARGET=$MAKE_TARGET"
  1141. fi
  1142. if [[ -n "$PREFIX" ]]; then
  1143. echo "PREFIX=$PREFIX"
  1144. fi
  1145. if [[ -n "$TESTS_ENVIRONMENT" ]]; then
  1146. echo "TESTS_ENVIRONMENT=$TESTS_ENVIRONMENT"
  1147. fi
  1148. if [[ -n "$VCS_CHECKOUT" ]]; then
  1149. echo "VCS_CHECKOUT=$VCS_CHECKOUT"
  1150. fi
  1151. if $VERBOSE; then
  1152. echo "VERBOSE=true"
  1153. fi
  1154. if $DEBUG; then
  1155. echo "DEBUG=true"
  1156. fi
  1157. if [[ -n "$WARNINGS" ]]; then
  1158. echo "WARNINGS=$WARNINGS"
  1159. fi
  1160. echo '----------------------------------------------'
  1161. if $saved_debug_status; then
  1162. enable_debug
  1163. fi
  1164. }
  1165. function make_clean_option ()
  1166. {
  1167. run_configure_if_required
  1168. make_maintainer_clean
  1169. if [[ "$VCS_CHECKOUT" == 'git' ]]; then
  1170. run "$VCS_CHECKOUT" status --ignored
  1171. elif [[ -n "$VCS_CHECKOUT" ]]; then
  1172. run "$VCS_CHECKOUT" status
  1173. fi
  1174. }
  1175. function make_for_autoreconf ()
  1176. {
  1177. if [ -f 'Makefile' ]; then
  1178. make_maintainer_clean
  1179. fi
  1180. run_autoreconf
  1181. assert_no_file 'Makefile'
  1182. }
  1183. function check_make_target()
  1184. {
  1185. case $1 in
  1186. 'self')
  1187. ;;
  1188. 'rpm')
  1189. ;;
  1190. 'gdb')
  1191. ;;
  1192. 'clean_op')
  1193. ;;
  1194. 'autoreconf')
  1195. ;;
  1196. 'install-system')
  1197. ;;
  1198. 'configure')
  1199. ;;
  1200. 'distcheck')
  1201. ;;
  1202. 'check')
  1203. ;;
  1204. 'snapshot')
  1205. ;;
  1206. 'mingw')
  1207. ;;
  1208. 'universe')
  1209. ;;
  1210. 'valgrind')
  1211. ;;
  1212. 'jenkins')
  1213. ;;
  1214. 'distclean')
  1215. ;;
  1216. 'maintainer-clean')
  1217. ;;
  1218. 'install')
  1219. ;;
  1220. 'all')
  1221. ;;
  1222. 'make_default')
  1223. ;;
  1224. 'clang')
  1225. ;;
  1226. 'clang-analyzer')
  1227. ;;
  1228. test-*)
  1229. ;;
  1230. valgrind-*)
  1231. ;;
  1232. gdb-*)
  1233. ;;
  1234. 'dist')
  1235. ;;
  1236. *)
  1237. echo "Matched default"
  1238. return 1
  1239. ;;
  1240. esac
  1241. return 0
  1242. }
  1243. function bootstrap ()
  1244. {
  1245. determine_target_platform
  1246. determine_vcs
  1247. # Set up whatever we need to do to use autoreconf later
  1248. require_libtoolise
  1249. if ! autoreconf_setup; then
  1250. return 1
  1251. fi
  1252. if [ -z "$MAKE_TARGET" ]; then
  1253. MAKE_TARGET="make_default"
  1254. fi
  1255. if $PRINT_SETUP_OPTION -o $DEBUG; then
  1256. echo
  1257. print_setup
  1258. echo
  1259. # Exit if all we were looking for were the currently used options
  1260. if $PRINT_SETUP_OPTION; then
  1261. exit
  1262. fi
  1263. fi
  1264. # Use OLD_TESTS_ENVIRONMENT for tracking the state of the variable
  1265. local OLD_TESTS_ENVIRONMENT=
  1266. # Set ENV PREFIX in order to set --prefix for ./configure
  1267. if [[ -n "$PREFIX" ]]; then
  1268. PREFIX_ARG="--prefix=$PREFIX"
  1269. fi
  1270. # We should always have a target by this point
  1271. assert MAKE_TARGET
  1272. local MAKE_TARGET_ARRAY=($MAKE_TARGET)
  1273. for target in "${MAKE_TARGET_ARRAY[@]}"
  1274. do
  1275. # If we are running inside of Jenkins, we want to only run some of the possible tests
  1276. if $jenkins_build_environment; then
  1277. check_make_target $target
  1278. ret=$?
  1279. if [ $ret -ne 0 ]; then
  1280. die "Unknown MAKE_TARGET option: $target"
  1281. fi
  1282. fi
  1283. local snapshot_run=false
  1284. local valgrind_run=false
  1285. case $target in
  1286. 'self')
  1287. self_test
  1288. ;;
  1289. 'gdb')
  1290. make_gdb
  1291. ;;
  1292. 'install-html')
  1293. make_install_html
  1294. ;;
  1295. 'clean_op')
  1296. make_clean_option
  1297. ;;
  1298. 'autoreconf')
  1299. make_for_autoreconf
  1300. ;;
  1301. 'install-system')
  1302. make_install_system
  1303. ;;
  1304. 'configure')
  1305. run_configure
  1306. ;;
  1307. 'make_default')
  1308. make_default
  1309. ;;
  1310. 'clang')
  1311. if ! check_clang; then
  1312. die "clang was not found"
  1313. fi
  1314. if ! make_for_clang; then
  1315. die "Failed to build clang: $?"
  1316. fi
  1317. ;;
  1318. 'clang-analyzer')
  1319. if ! check_clang_analyzer; then
  1320. die "clang-analyzer was not found"
  1321. fi
  1322. if ! check_clang; then
  1323. die "clang was not found"
  1324. fi
  1325. if ! make_for_clang_analyzer; then
  1326. die "Failed to build clang-analyzer: $?"
  1327. fi
  1328. ;;
  1329. 'mingw')
  1330. if ! check_mingw; then
  1331. die "mingw was not found"
  1332. fi
  1333. if ! make_for_mingw; then
  1334. die "Failed to build mingw: $?"
  1335. fi
  1336. ;;
  1337. 'snapshot')
  1338. make_for_snapshot
  1339. snapshot_run=true
  1340. check_snapshot
  1341. ;;
  1342. 'rpm')
  1343. make_rpm
  1344. ;;
  1345. 'darwin_malloc')
  1346. make_darwin_malloc
  1347. ;;
  1348. 'valgrind')
  1349. make_maintainer_clean
  1350. make_valgrind
  1351. ;;
  1352. 'universe')
  1353. make_universe
  1354. ;;
  1355. 'jenkins')
  1356. make_for_continuus_integration
  1357. ;;
  1358. *)
  1359. run_configure_if_required
  1360. make_target "$target"
  1361. ;;
  1362. esac
  1363. if $jenkins_build_environment; then
  1364. if ! $snapshot_run; then
  1365. run_make_maintainer_clean_if_possible
  1366. fi
  1367. fi
  1368. done
  1369. }
  1370. function main ()
  1371. {
  1372. # Variables we export
  1373. declare -x VCS_CHECKOUT=
  1374. # Variables we control globally
  1375. local MAKE_TARGET=
  1376. local CONFIGURE=
  1377. # Options for getopt
  1378. local AUTORECONF_OPTION=false
  1379. local CLEAN_OPTION=false
  1380. local CONFIGURE_OPTION=false
  1381. local DEBUG_OPTION=false
  1382. local PRINT_SETUP_OPTION=false
  1383. local TARGET_OPTION=false
  1384. local TARGET_OPTION_ARG=
  1385. local VERBOSE_OPTION=false
  1386. local OLD_CONFIGURE=
  1387. local OLD_CONFIGURE_ARG=
  1388. local OLD_PREFIX=
  1389. local OLD_MAKE=
  1390. local OLD_TESTS_ENVIRONMENT=
  1391. # If we call autoreconf on the platform or not
  1392. local AUTORECONF_REBUILD_HOST=false
  1393. local AUTORECONF_REBUILD=false
  1394. local -r top_srcdir=`pwd`
  1395. # Default configure
  1396. if [ -z "$CONFIGURE" ]; then
  1397. CONFIGURE="$top_srcdir/configure"
  1398. fi
  1399. # Variables for determine_target_platform () and rebuild_host_os ()
  1400. # UNAME_MACHINE_ARCH= uname -m
  1401. # VENDOR= apple, redhat, centos, canonical
  1402. # VENDOR_RELEASE=
  1403. # RHEL{rhel,Tikanga,Santiago}
  1404. # Ubuntu{ubuntu,Lucid,Maverick,Natty,Oneiric,Precise,Quantal}
  1405. # Fedora{fedora,Verne,Beefy}
  1406. # OSX{osx,lion,snow,mountain}
  1407. # VENDOR_DISTRIBUTION= darwin,fedora,rhel,ubuntu
  1408. # UNAME_KERNEL= Linux, Darwin,...
  1409. # UNAME_KERNEL_RELEASE= Linux, Darwin,...
  1410. local UNAME_MACHINE_ARCH=unknown
  1411. local VENDOR=unknown
  1412. local VENDOR_RELEASE=unknown
  1413. local VENDOR_DISTRIBUTION=unknown
  1414. local UNAME_KERNEL=unknown
  1415. local UNAME_KERNEL_RELEASE=unknown
  1416. local HOST_OS=
  1417. rebuild_host_os no_output
  1418. parse_command_line_options $@
  1419. # If we are running under Jenkins we predetermine what tests we will run against
  1420. # This MAKE_TARGET can be overridden by parse_command_line_options based MAKE_TARGET changes.
  1421. # We don't want Jenkins overriding other variables, so we NULL them.
  1422. if [ -z "$MAKE_TARGET" ]; then
  1423. if $jenkins_build_environment; then
  1424. if [[ -n "$label" ]]; then
  1425. check_make_target $label
  1426. if [ $? -eq 0 ]; then
  1427. MAKE_TARGET="$label"
  1428. fi
  1429. fi
  1430. if [[ -n "$LABEL" ]]; then
  1431. check_make_target $LABEL
  1432. if [ $? -eq 0 ]; then
  1433. MAKE_TARGET="$LABEL"
  1434. fi
  1435. fi
  1436. if [ -z "$MAKE_TARGET" ]; then
  1437. MAKE_TARGET='jenkins'
  1438. fi
  1439. fi
  1440. fi
  1441. bootstrap
  1442. jobs -l
  1443. wait
  1444. exit 0
  1445. }
  1446. function set_branch ()
  1447. {
  1448. if [ -z "$BRANCH" ]; then
  1449. if [ -z "$CI_PROJECT_TEAM" ]; then
  1450. die "Variable CI_PROJECT_TEAM has not been set"
  1451. fi
  1452. if [ -z "$PROJECT" ]; then
  1453. die "Variable PROJECT has not been set"
  1454. fi
  1455. if [ -z "$BUILD_TAG" ]; then
  1456. die "Variable BUILD_TAG has not been set"
  1457. fi
  1458. BRANCH="lp:~$CI_PROJECT_TEAM/$PROJECT/$BUILD_TAG"
  1459. export BRANCH
  1460. fi
  1461. if [ -z "$BRANCH" ]; then
  1462. die "Missing values required to build BRANCH variable."
  1463. fi
  1464. }
  1465. function merge ()
  1466. {
  1467. if [ -z "$VCS_CHECKOUT" ]; then
  1468. die "Merges require VCS_CHECKOUT."
  1469. fi
  1470. set_branch
  1471. if [[ "$VCS_CHECKOUT" == 'bzr' ]]; then
  1472. if test -n "$BRANCH_TO_MERGE"; then
  1473. bzr merge $BRANCH_TO_MERGE
  1474. bzr commit --message="Merge $BRANCH_TO_MERGE Build: $BUILD_TAG" --unchanged
  1475. fi
  1476. bzr push "$BRANCH"
  1477. elif [[ -n "$VCS_CHECKOUT" ]]; then
  1478. die "Merge attempt occured, current VCS setup does not support this"
  1479. fi
  1480. }
  1481. function enable_debug ()
  1482. {
  1483. if ! $DEBUG; then
  1484. local caller_loc=`caller`
  1485. if [ -n $1 ]; then
  1486. echo "$caller_loc Enabling debug: $1"
  1487. else
  1488. echo "$caller_loc Enabling debug"
  1489. fi
  1490. set -x
  1491. DEBUG=true
  1492. fi
  1493. }
  1494. function usage ()
  1495. {
  1496. cat << EOF
  1497. Usage: $program_name [OPTION]..
  1498. Bootstrap this package from the checked-out sources, and optionally walk through CI run.
  1499. Options:
  1500. EOF
  1501. }
  1502. function disable_debug ()
  1503. {
  1504. set +x
  1505. DEBUG=true
  1506. }
  1507. # Script begins here
  1508. program_name=$0
  1509. env_debug_enabled=false
  1510. if [[ -n "$JENKINS_HOME" ]]; then
  1511. declare -r jenkins_build_environment=true
  1512. else
  1513. declare -r jenkins_build_environment=false
  1514. fi
  1515. export ACLOCAL
  1516. export AUTOCONF
  1517. export AUTOHEADER
  1518. export AUTOM4TE
  1519. export AUTOMAKE
  1520. export AUTORECONF
  1521. export CONFIGURE_ARG
  1522. export DEBUG
  1523. export GNU_BUILD_FLAGS
  1524. export LIBTOOLIZE
  1525. export LIBTOOLIZE_OPTIONS
  1526. export MAKE
  1527. export PREFIX_ARG
  1528. export TESTS_ENVIRONMENT
  1529. export VERBOSE
  1530. export WARNINGS
  1531. case $OSTYPE in
  1532. darwin*)
  1533. export MallocGuardEdges
  1534. export MallocErrorAbort
  1535. export MallocScribble
  1536. ;;
  1537. esac
  1538. # We check for DEBUG twice, once before we source the config file, and once afterward
  1539. env_debug_enabled=false
  1540. if [[ -n "$DEBUG" ]]; then
  1541. env_debug_enabled=true
  1542. enable_debug
  1543. print_setup
  1544. fi
  1545. # Variables which only can be set by .bootstrap
  1546. BOOTSTRAP_SNAPSHOT=false
  1547. BOOTSTRAP_SNAPSHOT_CHECK=
  1548. if [ -f '.bootstrap' ]; then
  1549. source '.bootstrap'
  1550. fi
  1551. if $env_debug_enabled; then
  1552. enable_debug
  1553. else
  1554. if [[ -n "$DEBUG" ]]; then
  1555. enable_debug "Enabling DEBUG from '.bootstrap'"
  1556. print_setup
  1557. fi
  1558. fi
  1559. # We do this in order to protect the case where DEBUG
  1560. if ! $env_debug_enabled; then
  1561. DEBUG=false
  1562. fi
  1563. main $@