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\" || \$6 ~ /$2/)"
  95. else
  96. opt_s="(\$6 == \"$2\" || \$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. ## MPC824x Systems
  232. #########################################################################
  233. LIST_824x="$(boards_by_cpu mpc824x)"
  234. #########################################################################
  235. ## MPC8260 Systems (includes 8250, 8255 etc.)
  236. #########################################################################
  237. LIST_8260="$(boards_by_cpu mpc8260)"
  238. #########################################################################
  239. ## MPC83xx Systems (includes 8349, etc.)
  240. #########################################################################
  241. LIST_83xx="$(boards_by_cpu mpc83xx)"
  242. #########################################################################
  243. ## MPC85xx Systems (includes 8540, 8560 etc.)
  244. #########################################################################
  245. LIST_85xx="$(boards_by_cpu mpc85xx)"
  246. #########################################################################
  247. ## MPC86xx Systems
  248. #########################################################################
  249. LIST_86xx="$(boards_by_cpu mpc86xx)"
  250. #########################################################################
  251. ## 74xx/7xx Systems
  252. #########################################################################
  253. LIST_74xx_7xx="$(boards_by_cpu 74xx_7xx)"
  254. #########################################################################
  255. ## PowerPC groups
  256. #########################################################################
  257. LIST_TSEC=" \
  258. ${LIST_83xx} \
  259. ${LIST_85xx} \
  260. ${LIST_86xx} \
  261. "
  262. LIST_powerpc=" \
  263. ${LIST_5xx} \
  264. ${LIST_512x} \
  265. ${LIST_5xxx} \
  266. ${LIST_8xx} \
  267. ${LIST_824x} \
  268. ${LIST_8260} \
  269. ${LIST_83xx} \
  270. ${LIST_85xx} \
  271. ${LIST_86xx} \
  272. ${LIST_4xx} \
  273. ${LIST_74xx_7xx}\
  274. "
  275. # Alias "ppc" -> "powerpc" to not break compatibility with older scripts
  276. # still using "ppc" instead of "powerpc"
  277. LIST_ppc=" \
  278. ${LIST_powerpc} \
  279. "
  280. #########################################################################
  281. ## StrongARM Systems
  282. #########################################################################
  283. LIST_SA="$(boards_by_cpu sa1100)"
  284. #########################################################################
  285. ## ARM7 Systems
  286. #########################################################################
  287. LIST_ARM7="$(boards_by_cpu arm720t)"
  288. #########################################################################
  289. ## ARM9 Systems
  290. #########################################################################
  291. LIST_ARM9="$(boards_by_cpu arm920t) \
  292. $(boards_by_cpu arm926ejs) \
  293. $(boards_by_cpu arm925t) \
  294. $(boards_by_cpu arm946es) \
  295. "
  296. #########################################################################
  297. ## ARM11 Systems
  298. #########################################################################
  299. LIST_ARM11="$(boards_by_cpu arm1136) \
  300. $(boards_by_cpu arm1176) \
  301. "
  302. #########################################################################
  303. ## ARMV7 Systems
  304. #########################################################################
  305. LIST_ARMV7="$(boards_by_cpu armv7)"
  306. #########################################################################
  307. ## AT91 Systems
  308. #########################################################################
  309. LIST_at91="$(boards_by_soc at91)"
  310. #########################################################################
  311. ## Xscale Systems
  312. #########################################################################
  313. LIST_pxa="$(boards_by_cpu pxa)"
  314. LIST_ixp="$(boards_by_cpu ixp)"
  315. #########################################################################
  316. ## SPEAr Systems
  317. #########################################################################
  318. LIST_spear="$(boards_by_soc spear)"
  319. #########################################################################
  320. ## ARM groups
  321. #########################################################################
  322. LIST_arm="$(boards_by_arch arm)"
  323. #########################################################################
  324. ## MIPS Systems (default = big endian)
  325. #########################################################################
  326. LIST_mips4kc=" \
  327. incaip \
  328. incaip_100MHz \
  329. incaip_133MHz \
  330. incaip_150MHz \
  331. qemu_mips \
  332. vct_platinum \
  333. vct_platinum_small \
  334. vct_platinum_onenand \
  335. vct_platinum_onenand_small \
  336. vct_platinumavc \
  337. vct_platinumavc_small \
  338. vct_platinumavc_onenand \
  339. vct_platinumavc_onenand_small \
  340. vct_premium \
  341. vct_premium_small \
  342. vct_premium_onenand \
  343. vct_premium_onenand_small \
  344. "
  345. LIST_au1xx0=" \
  346. dbau1000 \
  347. dbau1100 \
  348. dbau1500 \
  349. dbau1550 \
  350. "
  351. LIST_mips=" \
  352. ${LIST_mips4kc} \
  353. ${LIST_mips5kc} \
  354. ${LIST_au1xx0} \
  355. "
  356. #########################################################################
  357. ## MIPS Systems (little endian)
  358. #########################################################################
  359. LIST_au1xx0_el=" \
  360. dbau1550_el \
  361. pb1000 \
  362. "
  363. LIST_mips_el=" \
  364. ${LIST_au1xx0_el} \
  365. "
  366. #########################################################################
  367. ## OpenRISC Systems
  368. #########################################################################
  369. LIST_openrisc="$(boards_by_arch openrisc)"
  370. #########################################################################
  371. ## x86 Systems
  372. #########################################################################
  373. LIST_x86="$(boards_by_arch x86)"
  374. #########################################################################
  375. ## Nios-II Systems
  376. #########################################################################
  377. LIST_nios2="$(boards_by_arch nios2)"
  378. #########################################################################
  379. ## MicroBlaze Systems
  380. #########################################################################
  381. LIST_microblaze="$(boards_by_arch microblaze)"
  382. #########################################################################
  383. ## ColdFire Systems
  384. #########################################################################
  385. LIST_m68k="$(boards_by_arch m68k)"
  386. LIST_coldfire=${LIST_m68k}
  387. #########################################################################
  388. ## AVR32 Systems
  389. #########################################################################
  390. LIST_avr32="$(boards_by_arch avr32)"
  391. #########################################################################
  392. ## Blackfin Systems
  393. #########################################################################
  394. LIST_blackfin="$(boards_by_arch blackfin)"
  395. #########################################################################
  396. ## SH Systems
  397. #########################################################################
  398. LIST_sh2="$(boards_by_cpu sh2)"
  399. LIST_sh3="$(boards_by_cpu sh3)"
  400. LIST_sh4="$(boards_by_cpu sh4)"
  401. LIST_sh="$(boards_by_arch sh)"
  402. #########################################################################
  403. ## SPARC Systems
  404. #########################################################################
  405. LIST_sparc="$(boards_by_arch sparc)"
  406. #########################################################################
  407. ## NDS32 Systems
  408. #########################################################################
  409. LIST_nds32="$(boards_by_arch nds32)"
  410. #-----------------------------------------------------------------------
  411. get_target_location() {
  412. local target=$1
  413. local BOARD_NAME=""
  414. local CONFIG_NAME=""
  415. local board=""
  416. local vendor=""
  417. # Automatic mode
  418. local line=`egrep -i "^[[:space:]]*${target}[[:space:]]" boards.cfg`
  419. if [ -z "${line}" ] ; then echo "" ; return ; fi
  420. set ${line}
  421. # add default board name if needed
  422. [ $# = 3 ] && set ${line} ${1}
  423. CONFIG_NAME="${1%_config}"
  424. [ "${BOARD_NAME}" ] || BOARD_NAME="${1%_config}"
  425. if [ "$4" = "-" ] ; then
  426. board=${BOARD_NAME}
  427. else
  428. board="$4"
  429. fi
  430. [ $# -gt 4 ] && [ "$5" != "-" ] && vendor="$5"
  431. [ $# -gt 6 ] && [ "$7" != "-" ] && {
  432. tmp="${7%:*}"
  433. if [ "$tmp" ] ; then
  434. CONFIG_NAME="$tmp"
  435. fi
  436. }
  437. # Assign board directory to BOARDIR variable
  438. if [ -z "${vendor}" ] ; then
  439. BOARDDIR=${board}
  440. else
  441. BOARDDIR=${vendor}/${board}
  442. fi
  443. echo "${CONFIG_NAME}:${BOARDDIR}"
  444. }
  445. get_target_maintainers() {
  446. local name=`echo $1 | cut -d : -f 1`
  447. if ! grep -qsi "[[:blank:]]${name}[[:blank:]]" MAINTAINERS ; then
  448. echo ""
  449. return ;
  450. fi
  451. local line=`tac MAINTAINERS | grep -ni "[[:blank:]]${name}[[:blank:]]" | cut -d : -f 1`
  452. local mail=`tac MAINTAINERS | tail -n +${line} | \
  453. sed -n ":start /.*@.*/ { b mail } ; n ; b start ; :mail /.*@.*/ { p ; n ; b mail } ; q" | \
  454. sed "s/^.*<//;s/>.*$//"`
  455. echo "$mail"
  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