MAKEALL 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  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%)} || \$6 == \"$2\" || \$6 ~ /$2/)"
  97. else
  98. opt_s="(\$6 == \"$2\" || \$6 ~ /$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 $1 }' 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 $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. ## 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 arm925t) \
  296. $(boards_by_cpu arm946es) \
  297. "
  298. #########################################################################
  299. ## ARM11 Systems
  300. #########################################################################
  301. LIST_ARM11="$(boards_by_cpu arm1136) \
  302. $(boards_by_cpu arm1176) \
  303. "
  304. #########################################################################
  305. ## ARMV7 Systems
  306. #########################################################################
  307. LIST_ARMV7="$(boards_by_cpu armv7)"
  308. #########################################################################
  309. ## AT91 Systems
  310. #########################################################################
  311. LIST_at91="$(boards_by_soc at91)"
  312. #########################################################################
  313. ## Xscale Systems
  314. #########################################################################
  315. LIST_pxa="$(boards_by_cpu pxa)"
  316. LIST_ixp="$(boards_by_cpu ixp)"
  317. #########################################################################
  318. ## SPEAr Systems
  319. #########################################################################
  320. LIST_spear="$(boards_by_soc spear)"
  321. #########################################################################
  322. ## ARM groups
  323. #########################################################################
  324. LIST_arm="$(boards_by_arch arm)"
  325. #########################################################################
  326. ## MIPS Systems (default = big endian)
  327. #########################################################################
  328. LIST_mips4kc=" \
  329. incaip \
  330. incaip_100MHz \
  331. incaip_133MHz \
  332. incaip_150MHz \
  333. qemu_mips \
  334. vct_platinum \
  335. vct_platinum_small \
  336. vct_platinum_onenand \
  337. vct_platinum_onenand_small \
  338. vct_platinumavc \
  339. vct_platinumavc_small \
  340. vct_platinumavc_onenand \
  341. vct_platinumavc_onenand_small \
  342. vct_premium \
  343. vct_premium_small \
  344. vct_premium_onenand \
  345. vct_premium_onenand_small \
  346. "
  347. LIST_au1xx0=" \
  348. dbau1000 \
  349. dbau1100 \
  350. dbau1500 \
  351. dbau1550 \
  352. "
  353. LIST_mips=" \
  354. ${LIST_mips4kc} \
  355. ${LIST_mips5kc} \
  356. ${LIST_au1xx0} \
  357. "
  358. #########################################################################
  359. ## MIPS Systems (little endian)
  360. #########################################################################
  361. LIST_au1xx0_el=" \
  362. dbau1550_el \
  363. pb1000 \
  364. "
  365. LIST_mips_el=" \
  366. ${LIST_au1xx0_el} \
  367. "
  368. #########################################################################
  369. ## OpenRISC Systems
  370. #########################################################################
  371. LIST_openrisc="$(boards_by_arch openrisc)"
  372. #########################################################################
  373. ## x86 Systems
  374. #########################################################################
  375. LIST_x86="$(boards_by_arch x86)"
  376. #########################################################################
  377. ## Nios-II Systems
  378. #########################################################################
  379. LIST_nios2="$(boards_by_arch nios2)"
  380. #########################################################################
  381. ## MicroBlaze Systems
  382. #########################################################################
  383. LIST_microblaze="$(boards_by_arch microblaze)"
  384. #########################################################################
  385. ## ColdFire Systems
  386. #########################################################################
  387. LIST_m68k="$(boards_by_arch m68k)"
  388. LIST_coldfire=${LIST_m68k}
  389. #########################################################################
  390. ## AVR32 Systems
  391. #########################################################################
  392. LIST_avr32="$(boards_by_arch avr32)"
  393. #########################################################################
  394. ## Blackfin Systems
  395. #########################################################################
  396. LIST_blackfin="$(boards_by_arch blackfin)"
  397. #########################################################################
  398. ## SH Systems
  399. #########################################################################
  400. LIST_sh2="$(boards_by_cpu sh2)"
  401. LIST_sh3="$(boards_by_cpu sh3)"
  402. LIST_sh4="$(boards_by_cpu sh4)"
  403. LIST_sh="$(boards_by_arch sh)"
  404. #########################################################################
  405. ## SPARC Systems
  406. #########################################################################
  407. LIST_sparc="$(boards_by_arch sparc)"
  408. #########################################################################
  409. ## NDS32 Systems
  410. #########################################################################
  411. LIST_nds32="$(boards_by_arch nds32)"
  412. #-----------------------------------------------------------------------
  413. get_target_location() {
  414. local target=$1
  415. local BOARD_NAME=""
  416. local CONFIG_NAME=""
  417. local board=""
  418. local vendor=""
  419. # Automatic mode
  420. local line=`egrep -i "^[[:space:]]*${target}[[:space:]]" boards.cfg`
  421. if [ -z "${line}" ] ; then echo "" ; return ; fi
  422. set ${line}
  423. # add default board name if needed
  424. [ $# = 3 ] && set ${line} ${1}
  425. CONFIG_NAME="${1%_config}"
  426. [ "${BOARD_NAME}" ] || BOARD_NAME="${1%_config}"
  427. if [ "$4" = "-" ] ; then
  428. board=${BOARD_NAME}
  429. else
  430. board="$4"
  431. fi
  432. [ $# -gt 4 ] && [ "$5" != "-" ] && vendor="$5"
  433. [ $# -gt 6 ] && [ "$7" != "-" ] && {
  434. tmp="${7%:*}"
  435. if [ "$tmp" ] ; then
  436. CONFIG_NAME="$tmp"
  437. fi
  438. }
  439. # Assign board directory to BOARDIR variable
  440. if [ -z "${vendor}" ] ; then
  441. BOARDDIR=${board}
  442. else
  443. BOARDDIR=${vendor}/${board}
  444. fi
  445. echo "${CONFIG_NAME}:${BOARDDIR}"
  446. }
  447. get_target_maintainers() {
  448. local name=`echo $1 | cut -d : -f 1`
  449. if ! grep -qsi "[[:blank:]]${name}[[:blank:]]" MAINTAINERS ; then
  450. echo ""
  451. return ;
  452. fi
  453. local line=`tac MAINTAINERS | grep -ni "[[:blank:]]${name}[[:blank:]]" | cut -d : -f 1`
  454. local mail=`tac MAINTAINERS | tail -n +${line} | \
  455. sed -n ":start /.*@.*/ { b mail } ; n ; b start ; :mail /.*@.*/ { p ; n ; b mail } ; q" | \
  456. sed "s/^.*<//;s/>.*$//"`
  457. echo "$mail"
  458. }
  459. get_target_arch() {
  460. local target=$1
  461. # Automatic mode
  462. local line=`egrep -i "^[[:space:]]*${target}[[:space:]]" boards.cfg`
  463. if [ -z "${line}" ] ; then echo "" ; return ; fi
  464. set ${line}
  465. echo "$2"
  466. }
  467. list_target() {
  468. if [ "$PRINT_MAINTS" != 'y' ] ; then
  469. echo "$1"
  470. return
  471. fi
  472. echo -n "$1:"
  473. local loc=`get_target_location $1`
  474. if [ -z "${loc}" ] ; then echo "ERROR" ; return ; fi
  475. local maintainers_result=`get_target_maintainers ${loc} | tr " " "\n"`
  476. if [ "$MAINTAINERS_ONLY" != 'y' ] ; then
  477. local dir=`echo ${loc} | cut -d ":" -f 2`
  478. local cfg=`echo ${loc} | cut -d ":" -f 1`
  479. local git_result=`git log --format=%aE board/${dir} \
  480. include/configs/${cfg}.h | grep "@"`
  481. local git_result_recent=`echo ${git_result} | tr " " "\n" | \
  482. head -n 3`
  483. local git_result_top=`echo ${git_result} | tr " " "\n" | \
  484. sort | uniq -c | sort -nr | head -n 3 | \
  485. sed "s/^ \+[0-9]\+ \+//"`
  486. echo -e "$git_result_recent\n$git_result_top\n$maintainers_result" | \
  487. sort -u | tr "\n" " " | sed "s/ $//" ;
  488. else
  489. echo -e "$maintainers_result" | sort -u | tr "\n" " " | \
  490. sed "s/ $//" ;
  491. fi
  492. echo ""
  493. }
  494. # Each finished build will have a file called ${donep}${n},
  495. # where n is the index of the build. Each build
  496. # we've already noted as finished will have ${skipp}${n}.
  497. # The code managing the build process will use this information
  498. # to ensure that only BUILD_NBUILDS builds are in flight at once
  499. donep="${LOG_DIR}/._done_"
  500. skipp="${LOG_DIR}/._skip_"
  501. build_target_killed() {
  502. echo "Aborted $target build."
  503. # Remove the logs for this board since it was aborted
  504. rm -f ${LOG_DIR}/$target.MAKELOG ${LOG_DIR}/$target.ERR
  505. exit
  506. }
  507. build_target() {
  508. target=$1
  509. build_idx=$2
  510. if [ "$ONLY_LIST" == 'y' ] ; then
  511. list_target ${target}
  512. return
  513. fi
  514. if [ $BUILD_MANY == 1 ] ; then
  515. output_dir="${OUTPUT_PREFIX}/${target}"
  516. mkdir -p "${output_dir}"
  517. trap build_target_killed TERM
  518. else
  519. output_dir="${OUTPUT_PREFIX}"
  520. fi
  521. export BUILD_DIR="${output_dir}"
  522. target_arch=$(get_target_arch ${target})
  523. eval cross_toolchain=\$CROSS_COMPILE_`echo $target_arch | tr '[:lower:]' '[:upper:]'`
  524. if [ "${cross_toolchain}" ] ; then
  525. MAKE="make CROSS_COMPILE=${cross_toolchain}"
  526. elif [ "${CROSS_COMPILE}" ] ; then
  527. MAKE="make CROSS_COMPILE=${CROSS_COMPILE}"
  528. else
  529. MAKE=make
  530. fi
  531. ${MAKE} distclean >/dev/null
  532. ${MAKE} -s ${target}_config
  533. ${MAKE} ${JOBS} ${CHECK} all \
  534. >${LOG_DIR}/$target.MAKELOG 2> ${LOG_DIR}/$target.ERR
  535. # Check for 'make' errors
  536. if [ ${PIPESTATUS[0]} -ne 0 ] ; then
  537. RC=1
  538. fi
  539. if [ $BUILD_MANY == 1 ] ; then
  540. trap - TERM
  541. ${MAKE} -s tidy
  542. if [ -s ${LOG_DIR}/${target}.ERR ] ; then
  543. cp ${LOG_DIR}/${target}.ERR ${OUTPUT_PREFIX}/ERR/${target}
  544. else
  545. rm ${LOG_DIR}/${target}.ERR
  546. fi
  547. else
  548. if [ -s ${LOG_DIR}/${target}.ERR ] ; then
  549. if grep -iw error ${LOG_DIR}/${target}.ERR ; then
  550. : $(( ERR_CNT += 1 ))
  551. ERR_LIST="${ERR_LIST} $target"
  552. else
  553. : $(( WRN_CNT += 1 ))
  554. WRN_LIST="${WRN_LIST} $target"
  555. fi
  556. else
  557. rm ${LOG_DIR}/${target}.ERR
  558. fi
  559. fi
  560. OBJS=${output_dir}/u-boot
  561. if [ -e ${output_dir}/spl/u-boot-spl ]; then
  562. OBJS="${OBJS} ${output_dir}/spl/u-boot-spl"
  563. fi
  564. ${CROSS_COMPILE}size ${OBJS} | tee -a ${LOG_DIR}/$target.MAKELOG
  565. [ -e "${LOG_DIR}/${target}.ERR" ] && cat "${LOG_DIR}/${target}.ERR"
  566. touch "${donep}${build_idx}"
  567. }
  568. manage_builds() {
  569. search_idx=${OLDEST_IDX}
  570. if [ "$ONLY_LIST" == 'y' ] ; then return ; fi
  571. while true; do
  572. if [ -e "${donep}${search_idx}" ] ; then
  573. : $(( CURRENT_CNT-- ))
  574. [ ${OLDEST_IDX} -eq ${search_idx} ] &&
  575. : $(( OLDEST_IDX++ ))
  576. # Only want to count it once
  577. rm -f "${donep}${search_idx}"
  578. touch "${skipp}${search_idx}"
  579. elif [ -e "${skipp}${search_idx}" ] ; then
  580. [ ${OLDEST_IDX} -eq ${search_idx} ] &&
  581. : $(( OLDEST_IDX++ ))
  582. fi
  583. : $(( search_idx++ ))
  584. if [ ${search_idx} -gt ${TOTAL_CNT} ] ; then
  585. if [ ${CURRENT_CNT} -ge ${BUILD_NBUILDS} ] ; then
  586. search_idx=${OLDEST_IDX}
  587. sleep 1
  588. else
  589. break
  590. fi
  591. fi
  592. done
  593. }
  594. build_targets() {
  595. for t in "$@" ; do
  596. # If a LIST_xxx var exists, use it. But avoid variable
  597. # expansion in the eval when a board name contains certain
  598. # characters that the shell interprets.
  599. case ${t} in
  600. *[-+=]*) list= ;;
  601. *) list=$(eval echo '${LIST_'$t'}') ;;
  602. esac
  603. if [ -n "${list}" ] ; then
  604. build_targets ${list}
  605. else
  606. : $((TOTAL_CNT += 1))
  607. : $((CURRENT_CNT += 1))
  608. rm -f "${donep}${TOTAL_CNT}"
  609. rm -f "${skipp}${TOTAL_CNT}"
  610. if [ "$CONTINUE" = 'y' -a -e ${LOG_DIR}/$t.MAKELOG ] ; then
  611. : $((SKIP_CNT += 1))
  612. touch "${donep}${TOTAL_CNT}"
  613. elif [ "$REBUILD_ERRORS" = 'y' -a ! -e ${LOG_DIR}/$t.ERR ] ; then
  614. : $((SKIP_CNT += 1))
  615. touch "${donep}${TOTAL_CNT}"
  616. else
  617. if [ $BUILD_MANY == 1 ] ; then
  618. build_target ${t} ${TOTAL_CNT} &
  619. else
  620. CUR_TGT="${t}"
  621. build_target ${t} ${TOTAL_CNT}
  622. CUR_TGT=''
  623. fi
  624. fi
  625. fi
  626. # We maintain a running count of all the builds we have done.
  627. # Each finished build will have a file called ${donep}${n},
  628. # where n is the index of the build. Each build
  629. # we've already noted as finished will have ${skipp}${n}.
  630. # We track the current index via TOTAL_CNT, and the oldest
  631. # index. When we exceed the maximum number of parallel builds,
  632. # We look from oldest to current for builds that have completed,
  633. # and update the current count and oldest index as appropriate.
  634. # If we've gone through the entire list, wait a second, and
  635. # reprocess the entire list until we find a build that has
  636. # completed
  637. if [ ${CURRENT_CNT} -ge ${BUILD_NBUILDS} ] ; then
  638. manage_builds
  639. fi
  640. done
  641. }
  642. #-----------------------------------------------------------------------
  643. kill_children() {
  644. local OS=$(uname -s)
  645. local children=""
  646. case "${OS}" in
  647. "Darwin")
  648. # Mac OS X is known to have BSD style ps
  649. local pgid=$(ps -p $$ -o pgid | sed -e "/PGID/d")
  650. children=$(ps -g $pgid -o pid | sed -e "/PID\|$$\|$pgid/d")
  651. ;;
  652. *)
  653. # everything else tries the GNU style
  654. local pgid=$(ps -p $$ --no-headers -o "%r" | tr -d ' ')
  655. children=$(pgrep -g $pgid | sed -e "/$$\|$pgid/d")
  656. ;;
  657. esac
  658. kill $children 2> /dev/null
  659. wait $children 2> /dev/null
  660. exit
  661. }
  662. print_stats() {
  663. if [ "$ONLY_LIST" == 'y' ] ; then return ; fi
  664. # Only count boards that completed
  665. : $((TOTAL_CNT = `find ${skipp}* 2> /dev/null | wc -l`))
  666. rm -f ${donep}* ${skipp}*
  667. if [ $BUILD_MANY == 1 ] && [ -e "${OUTPUT_PREFIX}/ERR" ] ; then
  668. ERR_LIST=`grep -riwl error ${OUTPUT_PREFIX}/ERR/`
  669. ERR_LIST=`for f in $ERR_LIST ; do echo -n " $(basename $f)" ; done`
  670. ERR_CNT=`echo $ERR_LIST | wc -w | awk '{print $1}'`
  671. WRN_LIST=`grep -riwL error ${OUTPUT_PREFIX}/ERR/`
  672. WRN_LIST=`for f in $WRN_LIST ; do echo -n " $(basename $f)" ; done`
  673. WRN_CNT=`echo $WRN_LIST | wc -w | awk '{print $1}'`
  674. else
  675. # Remove the logs for any board that was interrupted
  676. rm -f ${LOG_DIR}/${CUR_TGT}.MAKELOG ${LOG_DIR}/${CUR_TGT}.ERR
  677. fi
  678. : $((TOTAL_CNT -= ${SKIP_CNT}))
  679. echo ""
  680. echo "--------------------- SUMMARY ----------------------------"
  681. if [ "$CONTINUE" = 'y' -o "$REBUILD_ERRORS" = 'y' ] ; then
  682. echo "Boards skipped: ${SKIP_CNT}"
  683. fi
  684. echo "Boards compiled: ${TOTAL_CNT}"
  685. if [ ${ERR_CNT} -gt 0 ] ; then
  686. echo "Boards with errors: ${ERR_CNT} (${ERR_LIST} )"
  687. fi
  688. if [ ${WRN_CNT} -gt 0 ] ; then
  689. echo "Boards with warnings but no errors: ${WRN_CNT} (${WRN_LIST} )"
  690. fi
  691. echo "----------------------------------------------------------"
  692. if [ $BUILD_MANY == 1 ] ; then
  693. kill_children
  694. fi
  695. exit $RC
  696. }
  697. #-----------------------------------------------------------------------
  698. # Build target groups selected by options, plus any command line args
  699. set -- ${SELECTED} "$@"
  700. # run PowerPC by default
  701. [ $# = 0 ] && set -- powerpc
  702. build_targets "$@"
  703. wait