bootstrap.sh 39 KB

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