MAKEALL 23 KB

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