MAKEALL 23 KB

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