MAKEALL 22 KB

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