MAKEALL 23 KB

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