MAKEALL 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  1. #!/bin/bash
  2. # Tool mainly for U-Boot Quality Assurance: build one or more board
  3. # configurations with minimal verbosity, showing only warnings and
  4. # errors.
  5. #
  6. # SPDX-License-Identifier: GPL-2.0+
  7. usage()
  8. {
  9. # if exiting with 0, write to stdout, else write to stderr
  10. local ret=${1:-0}
  11. [ "${ret}" -eq 1 ] && exec 1>&2
  12. cat <<-EOF
  13. Usage: MAKEALL [options] [--] [boards-to-build]
  14. Options:
  15. -a ARCH, --arch ARCH Build all boards with arch ARCH
  16. -c CPU, --cpu CPU Build all boards with cpu CPU
  17. -v VENDOR, --vendor VENDOR Build all boards with vendor VENDOR
  18. -s SOC, --soc SOC Build all boards with soc SOC
  19. -b BOARD, --board BOARD Build all boards with board name BOARD
  20. -l, --list List all targets to be built
  21. -m, --maintainers List all targets and maintainer email
  22. -M, --mails List all targets and all affilated emails
  23. -C, --check Enable build checking
  24. -n, --continue Continue (skip boards already built)
  25. -r, --rebuild-errors Rebuild any boards that errored
  26. -h, --help This help output
  27. Selections by these options are logically ANDed; if the same option
  28. is used repeatedly, such selections are ORed. So "-v FOO -v BAR"
  29. will select all configurations where the vendor is either FOO or
  30. BAR. Any additional arguments specified on the command line are
  31. always build additionally. See the boards.cfg file for more info.
  32. If no boards are specified, then the default is "powerpc".
  33. Environment variables:
  34. BUILD_NCPUS number of parallel make jobs (default: auto)
  35. CROSS_COMPILE cross-compiler toolchain prefix (default: "")
  36. CROSS_COMPILE_<ARCH> cross-compiler toolchain prefix for
  37. architecture "ARCH". Substitute "ARCH" for any
  38. supported architecture (default: "")
  39. MAKEALL_LOGDIR output all logs to here (default: ./LOG/)
  40. BUILD_DIR output build directory (default: ./)
  41. BUILD_NBUILDS number of parallel targets (default: 1)
  42. Examples:
  43. - build all Power Architecture boards:
  44. MAKEALL -a powerpc
  45. MAKEALL --arch powerpc
  46. MAKEALL powerpc
  47. - build all PowerPC boards manufactured by vendor "esd":
  48. MAKEALL -a powerpc -v esd
  49. - build all PowerPC boards manufactured either by "keymile" or "siemens":
  50. MAKEALL -a powerpc -v keymile -v siemens
  51. - build all Freescale boards with MPC83xx CPUs, plus all 4xx boards:
  52. MAKEALL -c mpc83xx -v freescale 4xx
  53. EOF
  54. exit ${ret}
  55. }
  56. deprecation() {
  57. echo "** Note: MAKEALL is deprecated - please use buildman instead"
  58. echo "** See tools/buildman/README for details"
  59. echo
  60. }
  61. deprecation
  62. SHORT_OPTS="ha:c:v:s:b:lmMCnr"
  63. LONG_OPTS="help,arch:,cpu:,vendor:,soc:,board:,list,maintainers,mails,check,continue,rebuild-errors"
  64. # Option processing based on util-linux-2.13/getopt-parse.bash
  65. # Note that we use `"$@"' to let each command-line parameter expand to a
  66. # separate word. The quotes around `$@' are essential!
  67. # We need TEMP as the `eval set --' would nuke the return value of
  68. # getopt.
  69. TEMP=`getopt -o ${SHORT_OPTS} --long ${LONG_OPTS} \
  70. -n 'MAKEALL' -- "$@"`
  71. [ $? != 0 ] && usage 1
  72. # Note the quotes around `$TEMP': they are essential!
  73. eval set -- "$TEMP"
  74. SELECTED=''
  75. ONLY_LIST=''
  76. PRINT_MAINTS=''
  77. MAINTAINERS_ONLY=''
  78. CONTINUE=''
  79. REBUILD_ERRORS=''
  80. while true ; do
  81. case "$1" in
  82. -a|--arch)
  83. # echo "Option ARCH: argument \`$2'"
  84. if [ "$opt_a" ] ; then
  85. opt_a="${opt_a%)} || \$2 == \"$2\")"
  86. else
  87. opt_a="(\$2 == \"$2\")"
  88. fi
  89. SELECTED='y'
  90. shift 2 ;;
  91. -c|--cpu)
  92. # echo "Option CPU: argument \`$2'"
  93. if [ "$opt_c" ] ; then
  94. opt_c="${opt_c%)} || \$3 == \"$2\" || \$3 ~ /$2:/)"
  95. else
  96. opt_c="(\$3 == \"$2\" || \$3 ~ /$2:/)"
  97. fi
  98. SELECTED='y'
  99. shift 2 ;;
  100. -s|--soc)
  101. # echo "Option SoC: argument \`$2'"
  102. if [ "$opt_s" ] ; then
  103. opt_s="${opt_s%)} || \$4 == \"$2\" || \$4 ~ /$2/)"
  104. else
  105. opt_s="(\$4 == \"$2\" || \$4 ~ /$2/)"
  106. fi
  107. SELECTED='y'
  108. shift 2 ;;
  109. -v|--vendor)
  110. # echo "Option VENDOR: argument \`$2'"
  111. if [ "$opt_v" ] ; then
  112. opt_v="${opt_v%)} || \$5 == \"$2\")"
  113. else
  114. opt_v="(\$5 == \"$2\")"
  115. fi
  116. SELECTED='y'
  117. shift 2 ;;
  118. -b|--board)
  119. # echo "Option BOARD: argument \`$2'"
  120. if [ "$opt_b" ] ; then
  121. opt_b="${opt_b%)} || \$6 == \"$2\" || \$7 == \"$2\")"
  122. else
  123. # We need to check the 7th field too
  124. # for boards whose 6th field is "-"
  125. opt_b="(\$6 == \"$2\" || \$7 == \"$2\")"
  126. fi
  127. SELECTED='y'
  128. shift 2 ;;
  129. -C|--check)
  130. CHECK='C=1'
  131. shift ;;
  132. -n|--continue)
  133. CONTINUE='y'
  134. shift ;;
  135. -r|--rebuild-errors)
  136. REBUILD_ERRORS='y'
  137. shift ;;
  138. -l|--list)
  139. ONLY_LIST='y'
  140. shift ;;
  141. -m|--maintainers)
  142. ONLY_LIST='y'
  143. PRINT_MAINTS='y'
  144. MAINTAINERS_ONLY='y'
  145. shift ;;
  146. -M|--mails)
  147. ONLY_LIST='y'
  148. PRINT_MAINTS='y'
  149. shift ;;
  150. -h|--help)
  151. usage ;;
  152. --)
  153. shift ; break ;;
  154. *)
  155. echo "Internal error!" >&2 ; exit 1 ;;
  156. esac
  157. done
  158. GNU_MAKE=$(scripts/show-gnu-make) || {
  159. echo "GNU Make not found" >&2
  160. exit 1
  161. }
  162. # echo "Remaining arguments:"
  163. # for arg do echo '--> '"\`$arg'" ; done
  164. tools/genboardscfg.py || {
  165. echo "Failed to generate boards.cfg" >&2
  166. exit 1
  167. }
  168. FILTER="\$1 !~ /^#/"
  169. [ "$opt_a" ] && FILTER="${FILTER} && $opt_a"
  170. [ "$opt_c" ] && FILTER="${FILTER} && $opt_c"
  171. [ "$opt_s" ] && FILTER="${FILTER} && $opt_s"
  172. [ "$opt_v" ] && FILTER="${FILTER} && $opt_v"
  173. [ "$opt_b" ] && FILTER="${FILTER} && $opt_b"
  174. if [ "$SELECTED" ] ; then
  175. SELECTED=$(awk '('"$FILTER"') { print $7 }' boards.cfg)
  176. # Make sure some boards from boards.cfg are actually found
  177. if [ -z "$SELECTED" ] ; then
  178. echo "Error: No boards selected, invalid arguments"
  179. exit 1
  180. fi
  181. fi
  182. #########################################################################
  183. # Print statistics when we exit
  184. trap exit 1 2 3 15
  185. trap print_stats 0
  186. # Determine number of CPU cores if no default was set
  187. : ${BUILD_NCPUS:="`getconf _NPROCESSORS_ONLN`"}
  188. if [ "$BUILD_NCPUS" -gt 1 ]
  189. then
  190. JOBS="-j $((BUILD_NCPUS + 1))"
  191. else
  192. JOBS=""
  193. fi
  194. if [ "${MAKEALL_LOGDIR}" ] ; then
  195. LOG_DIR=${MAKEALL_LOGDIR}
  196. else
  197. LOG_DIR="LOG"
  198. fi
  199. : ${BUILD_NBUILDS:=1}
  200. BUILD_MANY=0
  201. if [ "${BUILD_NBUILDS}" -gt 1 ] ; then
  202. BUILD_MANY=1
  203. : ${BUILD_DIR:=./build}
  204. mkdir -p "${BUILD_DIR}/ERR"
  205. find "${BUILD_DIR}/ERR/" -type f -exec rm -f {} +
  206. fi
  207. : ${BUILD_DIR:=.}
  208. OUTPUT_PREFIX="${BUILD_DIR}"
  209. [ -d ${LOG_DIR} ] || mkdir "${LOG_DIR}" || exit 1
  210. if [ "$CONTINUE" != 'y' -a "$REBUILD_ERRORS" != 'y' ] ; then
  211. find "${LOG_DIR}/" -type f -exec rm -f {} +
  212. fi
  213. LIST=""
  214. # Keep track of the number of builds and errors
  215. ERR_CNT=0
  216. ERR_LIST=""
  217. WRN_CNT=0
  218. WRN_LIST=""
  219. TOTAL_CNT=0
  220. SKIP_CNT=0
  221. CURRENT_CNT=0
  222. OLDEST_IDX=1
  223. RC=0
  224. # Helper funcs for parsing boards.cfg
  225. targets_by_field()
  226. {
  227. field=$1
  228. regexp=$2
  229. awk '($1 !~ /^#/ && $'"$field"' ~ /^'"$regexp"'$/) { print $7 }' \
  230. boards.cfg
  231. }
  232. targets_by_arch() { targets_by_field 2 "$@" ; }
  233. targets_by_cpu() { targets_by_field 3 "$@" ; targets_by_field 3 "$@:.*" ; }
  234. targets_by_soc() { targets_by_field 4 "$@" ; }
  235. #########################################################################
  236. ## MPC5xx Systems
  237. #########################################################################
  238. LIST_5xx="$(targets_by_cpu mpc5xx)"
  239. #########################################################################
  240. ## MPC5xxx Systems
  241. #########################################################################
  242. LIST_5xxx="$(targets_by_cpu mpc5xxx)"
  243. #########################################################################
  244. ## MPC512x Systems
  245. #########################################################################
  246. LIST_512x="$(targets_by_cpu mpc512x)"
  247. #########################################################################
  248. ## MPC8xx Systems
  249. #########################################################################
  250. LIST_8xx="$(targets_by_cpu mpc8xx)"
  251. #########################################################################
  252. ## PPC4xx Systems
  253. #########################################################################
  254. LIST_4xx="$(targets_by_cpu ppc4xx)"
  255. #########################################################################
  256. ## MPC8260 Systems (includes 8250, 8255 etc.)
  257. #########################################################################
  258. LIST_8260="$(targets_by_cpu mpc8260)"
  259. #########################################################################
  260. ## MPC83xx Systems (includes 8349, etc.)
  261. #########################################################################
  262. LIST_83xx="$(targets_by_cpu mpc83xx)"
  263. #########################################################################
  264. ## MPC85xx Systems (includes 8540, 8560 etc.)
  265. #########################################################################
  266. LIST_85xx="$(targets_by_cpu mpc85xx)"
  267. #########################################################################
  268. ## MPC86xx Systems
  269. #########################################################################
  270. LIST_86xx="$(targets_by_cpu mpc86xx)"
  271. #########################################################################
  272. ## PowerPC groups
  273. #########################################################################
  274. LIST_TSEC=" \
  275. ${LIST_83xx} \
  276. ${LIST_85xx} \
  277. ${LIST_86xx} \
  278. "
  279. LIST_powerpc=" \
  280. ${LIST_5xx} \
  281. ${LIST_512x} \
  282. ${LIST_5xxx} \
  283. ${LIST_8xx} \
  284. ${LIST_824x} \
  285. ${LIST_8260} \
  286. ${LIST_83xx} \
  287. ${LIST_85xx} \
  288. ${LIST_86xx} \
  289. ${LIST_4xx} \
  290. "
  291. # Alias "ppc" -> "powerpc" to not break compatibility with older scripts
  292. # still using "ppc" instead of "powerpc"
  293. LIST_ppc=" \
  294. ${LIST_powerpc} \
  295. "
  296. #########################################################################
  297. ## StrongARM Systems
  298. #########################################################################
  299. LIST_SA="$(targets_by_cpu sa1100)"
  300. #########################################################################
  301. ## ARM7 Systems
  302. #########################################################################
  303. LIST_ARM7="$(targets_by_cpu arm720t)"
  304. #########################################################################
  305. ## ARM9 Systems
  306. #########################################################################
  307. LIST_ARM9="$(targets_by_cpu arm920t) \
  308. $(targets_by_cpu arm926ejs) \
  309. $(targets_by_cpu arm946es) \
  310. "
  311. #########################################################################
  312. ## ARM11 Systems
  313. #########################################################################
  314. LIST_ARM11="$(targets_by_cpu arm1136) \
  315. $(targets_by_cpu arm1176) \
  316. "
  317. #########################################################################
  318. ## ARMV7 Systems
  319. #########################################################################
  320. LIST_ARMV7="$(targets_by_cpu armv7)"
  321. #########################################################################
  322. ## ARMV8 Systems
  323. #########################################################################
  324. LIST_ARMV8="$(targets_by_cpu armv8)"
  325. #########################################################################
  326. ## AT91 Systems
  327. #########################################################################
  328. LIST_at91="$(targets_by_soc at91)"
  329. #########################################################################
  330. ## Xscale Systems
  331. #########################################################################
  332. LIST_pxa="$(targets_by_cpu pxa)"
  333. #########################################################################
  334. ## SPEAr Systems
  335. #########################################################################
  336. LIST_spear="$(targets_by_soc spear)"
  337. #########################################################################
  338. ## ARM groups
  339. #########################################################################
  340. LIST_arm="$(targets_by_arch arm | \
  341. for ARMV8_TARGET in $LIST_ARMV8; \
  342. do sed "/$ARMV8_TARGET/d"; \
  343. done) \
  344. "
  345. #########################################################################
  346. ## MIPS Systems (default = big endian)
  347. #########################################################################
  348. LIST_mips="$(targets_by_arch mips)"
  349. #########################################################################
  350. ## OpenRISC Systems
  351. #########################################################################
  352. LIST_openrisc="$(targets_by_arch openrisc)"
  353. #########################################################################
  354. ## x86 Systems
  355. #########################################################################
  356. LIST_x86="$(targets_by_arch x86)"
  357. #########################################################################
  358. ## Nios-II Systems
  359. #########################################################################
  360. LIST_nios2="$(targets_by_arch nios2)"
  361. #########################################################################
  362. ## MicroBlaze Systems
  363. #########################################################################
  364. LIST_microblaze="$(targets_by_arch microblaze)"
  365. #########################################################################
  366. ## ColdFire Systems
  367. #########################################################################
  368. LIST_m68k="$(targets_by_arch m68k)"
  369. LIST_coldfire=${LIST_m68k}
  370. #########################################################################
  371. ## AVR32 Systems
  372. #########################################################################
  373. LIST_avr32="$(targets_by_arch avr32)"
  374. #########################################################################
  375. ## Blackfin Systems
  376. #########################################################################
  377. LIST_blackfin="$(targets_by_arch blackfin)"
  378. #########################################################################
  379. ## SH Systems
  380. #########################################################################
  381. LIST_sh2="$(targets_by_cpu sh2)"
  382. LIST_sh3="$(targets_by_cpu sh3)"
  383. LIST_sh4="$(targets_by_cpu sh4)"
  384. LIST_sh="$(targets_by_arch sh)"
  385. #########################################################################
  386. ## SPARC Systems
  387. #########################################################################
  388. LIST_sparc="$(targets_by_arch sparc)"
  389. #########################################################################
  390. ## NDS32 Systems
  391. #########################################################################
  392. LIST_nds32="$(targets_by_arch nds32)"
  393. #########################################################################
  394. ## ARC Systems
  395. #########################################################################
  396. LIST_arc="$(targets_by_arch arc)"
  397. #-----------------------------------------------------------------------
  398. get_target_location() {
  399. local target=$1
  400. local BOARD_NAME=""
  401. local CONFIG_NAME=""
  402. local board=""
  403. local vendor=""
  404. # Automatic mode
  405. local line=`awk '\$7 == "'"$target"'" { print \$0 }' boards.cfg`
  406. if [ -z "${line}" ] ; then echo "" ; return ; fi
  407. set ${line}
  408. CONFIG_NAME="${7%_defconfig}"
  409. [ "${BOARD_NAME}" ] || BOARD_NAME="${7%_defconfig}"
  410. if [ $# -gt 5 ]; then
  411. if [ "$6" = "-" ] ; then
  412. board=${BOARD_NAME}
  413. else
  414. board="$6"
  415. fi
  416. fi
  417. [ $# -gt 4 ] && [ "$5" != "-" ] && vendor="$5"
  418. [ $# -gt 6 ] && [ "$8" != "-" ] && {
  419. tmp="${8%:*}"
  420. if [ "$tmp" ] ; then
  421. CONFIG_NAME="$tmp"
  422. fi
  423. }
  424. # Assign board directory to BOARDIR variable
  425. if [ "${vendor}" == "-" ] ; then
  426. BOARDDIR=${board}
  427. else
  428. BOARDDIR=${vendor}/${board}
  429. fi
  430. echo "${CONFIG_NAME}:${BOARDDIR}:${BOARD_NAME}"
  431. }
  432. get_target_maintainers() {
  433. local name=`echo $1 | cut -d : -f 3`
  434. local line=`awk '\$7 == "'"$target"'" { print \$0 }' boards.cfg`
  435. if [ -z "${line}" ]; then
  436. echo ""
  437. return ;
  438. fi
  439. local mails=`echo ${line} | cut -d ' ' -f 9- | sed -e 's/[^<]*<//' -e 's/>.*</ /' -e 's/>[^>]*$//'`
  440. [ "$mails" == "-" ] && mails=""
  441. echo "$mails"
  442. }
  443. get_target_arch() {
  444. local target=$1
  445. awk '$7 == "'$target'" { print $2 }' boards.cfg
  446. }
  447. list_target() {
  448. if [ "$PRINT_MAINTS" != 'y' ] ; then
  449. echo "$1"
  450. return
  451. fi
  452. echo -n "$1:"
  453. local loc=`get_target_location $1`
  454. if [ -z "${loc}" ] ; then echo "ERROR" ; return ; fi
  455. local maintainers_result=`get_target_maintainers ${loc} | tr " " "\n"`
  456. if [ "$MAINTAINERS_ONLY" != 'y' ] ; then
  457. local dir=`echo ${loc} | cut -d ":" -f 2`
  458. local cfg=`echo ${loc} | cut -d ":" -f 1`
  459. local git_result=`git log --format=%aE board/${dir} \
  460. include/configs/${cfg}.h | grep "@"`
  461. local git_result_recent=`echo ${git_result} | tr " " "\n" | \
  462. head -n 3`
  463. local git_result_top=`echo ${git_result} | tr " " "\n" | \
  464. sort | uniq -c | sort -nr | head -n 3 | \
  465. sed "s/^ \+[0-9]\+ \+//"`
  466. echo -e "$git_result_recent\n$git_result_top\n$maintainers_result" | \
  467. sort -u | tr "\n" " " | sed "s/ $//" ;
  468. else
  469. echo -e "$maintainers_result" | sort -u | tr "\n" " " | \
  470. sed "s/ $//" ;
  471. fi
  472. echo ""
  473. }
  474. # Each finished build will have a file called ${donep}${n},
  475. # where n is the index of the build. Each build
  476. # we've already noted as finished will have ${skipp}${n}.
  477. # The code managing the build process will use this information
  478. # to ensure that only BUILD_NBUILDS builds are in flight at once
  479. donep="${LOG_DIR}/._done_"
  480. skipp="${LOG_DIR}/._skip_"
  481. build_target_killed() {
  482. echo "Aborted $target build."
  483. # Remove the logs for this board since it was aborted
  484. rm -f ${LOG_DIR}/$target.MAKELOG ${LOG_DIR}/$target.ERR
  485. exit
  486. }
  487. build_target() {
  488. target=$1
  489. build_idx=$2
  490. if [ "$ONLY_LIST" == 'y' ] ; then
  491. list_target ${target}
  492. return
  493. fi
  494. if [ $BUILD_MANY == 1 ] ; then
  495. output_dir="${OUTPUT_PREFIX}/${target}"
  496. mkdir -p "${output_dir}"
  497. trap build_target_killed TERM
  498. else
  499. output_dir="${OUTPUT_PREFIX}"
  500. fi
  501. target_arch=$(get_target_arch ${target})
  502. eval cross_toolchain=\$CROSS_COMPILE_`echo $target_arch | tr '[:lower:]' '[:upper:]'`
  503. if [ "${cross_toolchain}" ] ; then
  504. MAKE="$GNU_MAKE CROSS_COMPILE=${cross_toolchain}"
  505. elif [ "${CROSS_COMPILE}" ] ; then
  506. MAKE="$GNU_MAKE CROSS_COMPILE=${CROSS_COMPILE}"
  507. else
  508. MAKE=$GNU_MAKE
  509. fi
  510. if [ "${output_dir}" != "." ] ; then
  511. MAKE="${MAKE} O=${output_dir}"
  512. fi
  513. ${MAKE} mrproper >/dev/null
  514. echo "Building ${target} board..."
  515. ${MAKE} -s ${target}_defconfig >/dev/null
  516. ${MAKE} ${JOBS} ${CHECK} all \
  517. >${LOG_DIR}/$target.MAKELOG 2> ${LOG_DIR}/$target.ERR
  518. # Check for 'make' errors
  519. if [ ${PIPESTATUS[0]} -ne 0 ] ; then
  520. RC=1
  521. fi
  522. OBJS=${output_dir}/u-boot
  523. if [ -e ${output_dir}/spl/u-boot-spl ]; then
  524. OBJS="${OBJS} ${output_dir}/spl/u-boot-spl"
  525. fi
  526. ${CROSS_COMPILE}size ${OBJS} | tee -a ${LOG_DIR}/$target.MAKELOG
  527. if [ $BUILD_MANY == 1 ] ; then
  528. trap - TERM
  529. ${MAKE} -s clean
  530. if [ -s ${LOG_DIR}/${target}.ERR ] ; then
  531. cp ${LOG_DIR}/${target}.ERR ${OUTPUT_PREFIX}/ERR/${target}
  532. else
  533. rm ${LOG_DIR}/${target}.ERR
  534. fi
  535. else
  536. if [ -s ${LOG_DIR}/${target}.ERR ] ; then
  537. if grep -iw error ${LOG_DIR}/${target}.ERR ; then
  538. : $(( ERR_CNT += 1 ))
  539. ERR_LIST="${ERR_LIST} $target"
  540. else
  541. : $(( WRN_CNT += 1 ))
  542. WRN_LIST="${WRN_LIST} $target"
  543. fi
  544. else
  545. rm ${LOG_DIR}/${target}.ERR
  546. fi
  547. fi
  548. [ -e "${LOG_DIR}/${target}.ERR" ] && cat "${LOG_DIR}/${target}.ERR"
  549. touch "${donep}${build_idx}"
  550. }
  551. manage_builds() {
  552. search_idx=${OLDEST_IDX}
  553. if [ "$ONLY_LIST" == 'y' ] ; then return ; fi
  554. while true; do
  555. if [ -e "${donep}${search_idx}" ] ; then
  556. : $(( CURRENT_CNT-- ))
  557. [ ${OLDEST_IDX} -eq ${search_idx} ] &&
  558. : $(( OLDEST_IDX++ ))
  559. # Only want to count it once
  560. rm -f "${donep}${search_idx}"
  561. touch "${skipp}${search_idx}"
  562. elif [ -e "${skipp}${search_idx}" ] ; then
  563. [ ${OLDEST_IDX} -eq ${search_idx} ] &&
  564. : $(( OLDEST_IDX++ ))
  565. fi
  566. : $(( search_idx++ ))
  567. if [ ${search_idx} -gt ${TOTAL_CNT} ] ; then
  568. if [ ${CURRENT_CNT} -ge ${BUILD_NBUILDS} ] ; then
  569. search_idx=${OLDEST_IDX}
  570. sleep 1
  571. else
  572. break
  573. fi
  574. fi
  575. done
  576. }
  577. build_targets() {
  578. for t in "$@" ; do
  579. # If a LIST_xxx var exists, use it. But avoid variable
  580. # expansion in the eval when a board name contains certain
  581. # characters that the shell interprets.
  582. case ${t} in
  583. *[-+=]*) list= ;;
  584. *) list=$(eval echo '${LIST_'$t'}') ;;
  585. esac
  586. if [ -n "${list}" ] ; then
  587. build_targets ${list}
  588. else
  589. : $((TOTAL_CNT += 1))
  590. : $((CURRENT_CNT += 1))
  591. rm -f "${donep}${TOTAL_CNT}"
  592. rm -f "${skipp}${TOTAL_CNT}"
  593. if [ "$CONTINUE" = 'y' -a -e ${LOG_DIR}/$t.MAKELOG ] ; then
  594. : $((SKIP_CNT += 1))
  595. touch "${donep}${TOTAL_CNT}"
  596. elif [ "$REBUILD_ERRORS" = 'y' -a ! -e ${LOG_DIR}/$t.ERR ] ; then
  597. : $((SKIP_CNT += 1))
  598. touch "${donep}${TOTAL_CNT}"
  599. else
  600. if [ $BUILD_MANY == 1 ] ; then
  601. build_target ${t} ${TOTAL_CNT} &
  602. else
  603. CUR_TGT="${t}"
  604. build_target ${t} ${TOTAL_CNT}
  605. CUR_TGT=''
  606. fi
  607. fi
  608. fi
  609. # We maintain a running count of all the builds we have done.
  610. # Each finished build will have a file called ${donep}${n},
  611. # where n is the index of the build. Each build
  612. # we've already noted as finished will have ${skipp}${n}.
  613. # We track the current index via TOTAL_CNT, and the oldest
  614. # index. When we exceed the maximum number of parallel builds,
  615. # We look from oldest to current for builds that have completed,
  616. # and update the current count and oldest index as appropriate.
  617. # If we've gone through the entire list, wait a second, and
  618. # reprocess the entire list until we find a build that has
  619. # completed
  620. if [ ${CURRENT_CNT} -ge ${BUILD_NBUILDS} ] ; then
  621. manage_builds
  622. fi
  623. done
  624. }
  625. #-----------------------------------------------------------------------
  626. kill_children() {
  627. local OS=$(uname -s)
  628. local children=""
  629. case "${OS}" in
  630. "Darwin")
  631. # Mac OS X is known to have BSD style ps
  632. local pgid=$(ps -p $$ -o pgid | sed -e "/PGID/d")
  633. children=$(ps -g $pgid -o pid | sed -e "/PID\|$$\|$pgid/d")
  634. ;;
  635. *)
  636. # everything else tries the GNU style
  637. local pgid=$(ps -p $$ --no-headers -o "%r" | tr -d ' ')
  638. children=$(pgrep -g $pgid | sed -e "/$$\|$pgid/d")
  639. ;;
  640. esac
  641. kill $children 2> /dev/null
  642. wait $children 2> /dev/null
  643. exit
  644. }
  645. print_stats() {
  646. if [ "$ONLY_LIST" == 'y' ] ; then return ; fi
  647. # Only count boards that completed
  648. : $((TOTAL_CNT = `find ${skipp}* 2> /dev/null | wc -l`))
  649. rm -f ${donep}* ${skipp}*
  650. if [ $BUILD_MANY == 1 ] && [ -e "${OUTPUT_PREFIX}/ERR" ] ; then
  651. ERR_LIST=`grep -riwl error ${OUTPUT_PREFIX}/ERR/`
  652. ERR_LIST=`for f in $ERR_LIST ; do echo -n " $(basename $f)" ; done`
  653. ERR_CNT=`echo $ERR_LIST | wc -w | awk '{print $1}'`
  654. WRN_LIST=`grep -riwL error ${OUTPUT_PREFIX}/ERR/`
  655. WRN_LIST=`for f in $WRN_LIST ; do echo -n " $(basename $f)" ; done`
  656. WRN_CNT=`echo $WRN_LIST | wc -w | awk '{print $1}'`
  657. else
  658. # Remove the logs for any board that was interrupted
  659. rm -f ${LOG_DIR}/${CUR_TGT}.MAKELOG ${LOG_DIR}/${CUR_TGT}.ERR
  660. fi
  661. : $((TOTAL_CNT -= ${SKIP_CNT}))
  662. echo ""
  663. echo "--------------------- SUMMARY ----------------------------"
  664. if [ "$CONTINUE" = 'y' -o "$REBUILD_ERRORS" = 'y' ] ; then
  665. echo "Boards skipped: ${SKIP_CNT}"
  666. fi
  667. echo "Boards compiled: ${TOTAL_CNT}"
  668. if [ ${ERR_CNT} -gt 0 ] ; then
  669. echo "Boards with errors: ${ERR_CNT} (${ERR_LIST} )"
  670. fi
  671. if [ ${WRN_CNT} -gt 0 ] ; then
  672. echo "Boards with warnings but no errors: ${WRN_CNT} (${WRN_LIST} )"
  673. fi
  674. echo "----------------------------------------------------------"
  675. if [ $BUILD_MANY == 1 ] ; then
  676. kill_children
  677. fi
  678. deprecation
  679. exit $RC
  680. }
  681. #-----------------------------------------------------------------------
  682. # Build target groups selected by options, plus any command line args
  683. set -- ${SELECTED} "$@"
  684. # run PowerPC by default
  685. [ $# = 0 ] && set -- powerpc
  686. build_targets "$@"
  687. wait