bootstrap.sh 39 KB

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