MAKEALL 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  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. # echo "Remaining arguments:"
  153. # for arg do echo '--> '"\`$arg'" ; done
  154. FILTER="\$1 !~ /^#/"
  155. [ "$opt_a" ] && FILTER="${FILTER} && $opt_a"
  156. [ "$opt_c" ] && FILTER="${FILTER} && $opt_c"
  157. [ "$opt_s" ] && FILTER="${FILTER} && $opt_s"
  158. [ "$opt_v" ] && FILTER="${FILTER} && $opt_v"
  159. [ "$opt_b" ] && FILTER="${FILTER} && $opt_b"
  160. if [ "$SELECTED" ] ; then
  161. SELECTED=$(awk '('"$FILTER"') { print $7 }' boards.cfg)
  162. # Make sure some boards from boards.cfg are actually found
  163. if [ -z "$SELECTED" ] ; then
  164. echo "Error: No boards selected, invalid arguments"
  165. exit 1
  166. fi
  167. fi
  168. #########################################################################
  169. # Print statistics when we exit
  170. trap exit 1 2 3 15
  171. trap print_stats 0
  172. # Determine number of CPU cores if no default was set
  173. : ${BUILD_NCPUS:="`getconf _NPROCESSORS_ONLN`"}
  174. if [ "$BUILD_NCPUS" -gt 1 ]
  175. then
  176. JOBS="-j $((BUILD_NCPUS + 1))"
  177. else
  178. JOBS=""
  179. fi
  180. if [ "${MAKEALL_LOGDIR}" ] ; then
  181. LOG_DIR=${MAKEALL_LOGDIR}
  182. else
  183. LOG_DIR="LOG"
  184. fi
  185. : ${BUILD_NBUILDS:=1}
  186. BUILD_MANY=0
  187. if [ "${BUILD_NBUILDS}" -gt 1 ] ; then
  188. BUILD_MANY=1
  189. : ${BUILD_DIR:=./build}
  190. mkdir -p "${BUILD_DIR}/ERR"
  191. find "${BUILD_DIR}/ERR/" -type f -exec rm -f {} +
  192. fi
  193. : ${BUILD_DIR:=.}
  194. OUTPUT_PREFIX="${BUILD_DIR}"
  195. [ -d ${LOG_DIR} ] || mkdir "${LOG_DIR}" || exit 1
  196. if [ "$CONTINUE" != 'y' -a "$REBUILD_ERRORS" != 'y' ] ; then
  197. find "${LOG_DIR}/" -type f -exec rm -f {} +
  198. fi
  199. LIST=""
  200. # Keep track of the number of builds and errors
  201. ERR_CNT=0
  202. ERR_LIST=""
  203. WRN_CNT=0
  204. WRN_LIST=""
  205. TOTAL_CNT=0
  206. SKIP_CNT=0
  207. CURRENT_CNT=0
  208. OLDEST_IDX=1
  209. RC=0
  210. # Helper funcs for parsing boards.cfg
  211. targets_by_field()
  212. {
  213. field=$1
  214. regexp=$2
  215. awk '($1 !~ /^#/ && $'"$field"' ~ /^'"$regexp"'$/) { print $7 }' \
  216. boards.cfg
  217. }
  218. targets_by_arch() { targets_by_field 2 "$@" ; }
  219. targets_by_cpu() { targets_by_field 3 "$@" ; targets_by_field 3 "$@:.*" ; }
  220. targets_by_soc() { targets_by_field 4 "$@" ; }
  221. #########################################################################
  222. ## MPC5xx Systems
  223. #########################################################################
  224. LIST_5xx="$(targets_by_cpu mpc5xx)"
  225. #########################################################################
  226. ## MPC5xxx Systems
  227. #########################################################################
  228. LIST_5xxx="$(targets_by_cpu mpc5xxx)"
  229. #########################################################################
  230. ## MPC512x Systems
  231. #########################################################################
  232. LIST_512x="$(targets_by_cpu mpc512x)"
  233. #########################################################################
  234. ## MPC8xx Systems
  235. #########################################################################
  236. LIST_8xx="$(targets_by_cpu mpc8xx)"
  237. #########################################################################
  238. ## PPC4xx Systems
  239. #########################################################################
  240. LIST_4xx="$(targets_by_cpu ppc4xx)"
  241. #########################################################################
  242. ## MPC824x Systems
  243. #########################################################################
  244. LIST_824x="$(targets_by_cpu mpc824x)"
  245. #########################################################################
  246. ## MPC8260 Systems (includes 8250, 8255 etc.)
  247. #########################################################################
  248. LIST_8260="$(targets_by_cpu mpc8260)"
  249. #########################################################################
  250. ## MPC83xx Systems (includes 8349, etc.)
  251. #########################################################################
  252. LIST_83xx="$(targets_by_cpu mpc83xx)"
  253. #########################################################################
  254. ## MPC85xx Systems (includes 8540, 8560 etc.)
  255. #########################################################################
  256. LIST_85xx="$(targets_by_cpu mpc85xx)"
  257. #########################################################################
  258. ## MPC86xx Systems
  259. #########################################################################
  260. LIST_86xx="$(targets_by_cpu mpc86xx)"
  261. #########################################################################
  262. ## 74xx/7xx Systems
  263. #########################################################################
  264. LIST_74xx_7xx="$(targets_by_cpu 74xx_7xx)"
  265. #########################################################################
  266. ## PowerPC groups
  267. #########################################################################
  268. LIST_TSEC=" \
  269. ${LIST_83xx} \
  270. ${LIST_85xx} \
  271. ${LIST_86xx} \
  272. "
  273. LIST_powerpc=" \
  274. ${LIST_5xx} \
  275. ${LIST_512x} \
  276. ${LIST_5xxx} \
  277. ${LIST_8xx} \
  278. ${LIST_824x} \
  279. ${LIST_8260} \
  280. ${LIST_83xx} \
  281. ${LIST_85xx} \
  282. ${LIST_86xx} \
  283. ${LIST_4xx} \
  284. ${LIST_74xx_7xx}\
  285. "
  286. # Alias "ppc" -> "powerpc" to not break compatibility with older scripts
  287. # still using "ppc" instead of "powerpc"
  288. LIST_ppc=" \
  289. ${LIST_powerpc} \
  290. "
  291. #########################################################################
  292. ## StrongARM Systems
  293. #########################################################################
  294. LIST_SA="$(targets_by_cpu sa1100)"
  295. #########################################################################
  296. ## ARM7 Systems
  297. #########################################################################
  298. LIST_ARM7="$(targets_by_cpu arm720t)"
  299. #########################################################################
  300. ## ARM9 Systems
  301. #########################################################################
  302. LIST_ARM9="$(targets_by_cpu arm920t) \
  303. $(targets_by_cpu arm926ejs) \
  304. $(targets_by_cpu arm946es) \
  305. "
  306. #########################################################################
  307. ## ARM11 Systems
  308. #########################################################################
  309. LIST_ARM11="$(targets_by_cpu arm1136) \
  310. $(targets_by_cpu arm1176) \
  311. "
  312. #########################################################################
  313. ## ARMV7 Systems
  314. #########################################################################
  315. LIST_ARMV7="$(targets_by_cpu armv7)"
  316. #########################################################################
  317. ## ARMV8 Systems
  318. #########################################################################
  319. LIST_ARMV8="$(targets_by_cpu armv8)"
  320. #########################################################################
  321. ## AT91 Systems
  322. #########################################################################
  323. LIST_at91="$(targets_by_soc at91)"
  324. #########################################################################
  325. ## Xscale Systems
  326. #########################################################################
  327. LIST_pxa="$(targets_by_cpu pxa)"
  328. #########################################################################
  329. ## SPEAr Systems
  330. #########################################################################
  331. LIST_spear="$(targets_by_soc spear)"
  332. #########################################################################
  333. ## ARM groups
  334. #########################################################################
  335. LIST_arm="$(targets_by_arch arm | \
  336. for ARMV8_TARGET in $LIST_ARMV8; \
  337. do sed "/$ARMV8_TARGET/d"; \
  338. done) \
  339. "
  340. #########################################################################
  341. ## MIPS Systems (default = big endian)
  342. #########################################################################
  343. LIST_mips4kc=" \
  344. incaip \
  345. incaip_100MHz \
  346. incaip_133MHz \
  347. incaip_150MHz \
  348. qemu_mips \
  349. vct_platinum \
  350. vct_platinum_small \
  351. vct_platinum_onenand \
  352. vct_platinum_onenand_small \
  353. vct_platinumavc \
  354. vct_platinumavc_small \
  355. vct_platinumavc_onenand \
  356. vct_platinumavc_onenand_small \
  357. vct_premium \
  358. vct_premium_small \
  359. vct_premium_onenand \
  360. vct_premium_onenand_small \
  361. "
  362. LIST_au1xx0=" \
  363. dbau1000 \
  364. dbau1100 \
  365. dbau1500 \
  366. dbau1550 \
  367. "
  368. LIST_mips=" \
  369. ${LIST_mips4kc} \
  370. ${LIST_mips5kc} \
  371. ${LIST_au1xx0} \
  372. "
  373. #########################################################################
  374. ## MIPS Systems (little endian)
  375. #########################################################################
  376. LIST_au1xx0_el=" \
  377. dbau1550_el \
  378. pb1000 \
  379. "
  380. LIST_mips_el=" \
  381. ${LIST_au1xx0_el} \
  382. "
  383. #########################################################################
  384. ## OpenRISC Systems
  385. #########################################################################
  386. LIST_openrisc="$(targets_by_arch openrisc)"
  387. #########################################################################
  388. ## x86 Systems
  389. #########################################################################
  390. LIST_x86="$(targets_by_arch x86)"
  391. #########################################################################
  392. ## Nios-II Systems
  393. #########################################################################
  394. LIST_nios2="$(targets_by_arch nios2)"
  395. #########################################################################
  396. ## MicroBlaze Systems
  397. #########################################################################
  398. LIST_microblaze="$(targets_by_arch microblaze)"
  399. #########################################################################
  400. ## ColdFire Systems
  401. #########################################################################
  402. LIST_m68k="$(targets_by_arch m68k)"
  403. LIST_coldfire=${LIST_m68k}
  404. #########################################################################
  405. ## AVR32 Systems
  406. #########################################################################
  407. LIST_avr32="$(targets_by_arch avr32)"
  408. #########################################################################
  409. ## Blackfin Systems
  410. #########################################################################
  411. LIST_blackfin="$(targets_by_arch blackfin)"
  412. #########################################################################
  413. ## SH Systems
  414. #########################################################################
  415. LIST_sh2="$(targets_by_cpu sh2)"
  416. LIST_sh3="$(targets_by_cpu sh3)"
  417. LIST_sh4="$(targets_by_cpu sh4)"
  418. LIST_sh="$(targets_by_arch sh)"
  419. #########################################################################
  420. ## SPARC Systems
  421. #########################################################################
  422. LIST_sparc="$(targets_by_arch sparc)"
  423. #########################################################################
  424. ## NDS32 Systems
  425. #########################################################################
  426. LIST_nds32="$(targets_by_arch nds32)"
  427. #########################################################################
  428. ## ARC Systems
  429. #########################################################################
  430. LIST_arc="$(targets_by_arch arc)"
  431. #-----------------------------------------------------------------------
  432. get_target_location() {
  433. local target=$1
  434. local BOARD_NAME=""
  435. local CONFIG_NAME=""
  436. local board=""
  437. local vendor=""
  438. # Automatic mode
  439. local line=`awk '\$7 == "'"$target"'" { print \$0 }' boards.cfg`
  440. if [ -z "${line}" ] ; then echo "" ; return ; fi
  441. set ${line}
  442. CONFIG_NAME="${7%_config}"
  443. [ "${BOARD_NAME}" ] || BOARD_NAME="${7%_config}"
  444. if [ $# -gt 5 ]; then
  445. if [ "$6" = "-" ] ; then
  446. board=${BOARD_NAME}
  447. else
  448. board="$6"
  449. fi
  450. fi
  451. [ $# -gt 4 ] && [ "$5" != "-" ] && vendor="$5"
  452. [ $# -gt 6 ] && [ "$8" != "-" ] && {
  453. tmp="${8%:*}"
  454. if [ "$tmp" ] ; then
  455. CONFIG_NAME="$tmp"
  456. fi
  457. }
  458. # Assign board directory to BOARDIR variable
  459. if [ "${vendor}" == "-" ] ; then
  460. BOARDDIR=${board}
  461. else
  462. BOARDDIR=${vendor}/${board}
  463. fi
  464. echo "${CONFIG_NAME}:${BOARDDIR}:${BOARD_NAME}"
  465. }
  466. get_target_maintainers() {
  467. local name=`echo $1 | cut -d : -f 3`
  468. local line=`awk '\$7 == "'"$target"'" { print \$0 }' boards.cfg`
  469. if [ -z "${line}" ]; then
  470. echo ""
  471. return ;
  472. fi
  473. local mails=`echo ${line} | cut -d ' ' -f 9- | sed -e 's/[^<]*<//' -e 's/>.*</ /' -e 's/>[^>]*$//'`
  474. [ "$mails" == "-" ] && mails=""
  475. echo "$mails"
  476. }
  477. get_target_arch() {
  478. local target=$1
  479. # Automatic mode
  480. local line=`awk '\$7 == "'"$target"'" { print \$0 }' boards.cfg`
  481. if [ -z "${line}" ] ; then echo "" ; return ; fi
  482. set ${line}
  483. echo "$2"
  484. }
  485. list_target() {
  486. if [ "$PRINT_MAINTS" != 'y' ] ; then
  487. echo "$1"
  488. return
  489. fi
  490. echo -n "$1:"
  491. local loc=`get_target_location $1`
  492. if [ -z "${loc}" ] ; then echo "ERROR" ; return ; fi
  493. local maintainers_result=`get_target_maintainers ${loc} | tr " " "\n"`
  494. if [ "$MAINTAINERS_ONLY" != 'y' ] ; then
  495. local dir=`echo ${loc} | cut -d ":" -f 2`
  496. local cfg=`echo ${loc} | cut -d ":" -f 1`
  497. local git_result=`git log --format=%aE board/${dir} \
  498. include/configs/${cfg}.h | grep "@"`
  499. local git_result_recent=`echo ${git_result} | tr " " "\n" | \
  500. head -n 3`
  501. local git_result_top=`echo ${git_result} | tr " " "\n" | \
  502. sort | uniq -c | sort -nr | head -n 3 | \
  503. sed "s/^ \+[0-9]\+ \+//"`
  504. echo -e "$git_result_recent\n$git_result_top\n$maintainers_result" | \
  505. sort -u | tr "\n" " " | sed "s/ $//" ;
  506. else
  507. echo -e "$maintainers_result" | sort -u | tr "\n" " " | \
  508. sed "s/ $//" ;
  509. fi
  510. echo ""
  511. }
  512. # Each finished build will have a file called ${donep}${n},
  513. # where n is the index of the build. Each build
  514. # we've already noted as finished will have ${skipp}${n}.
  515. # The code managing the build process will use this information
  516. # to ensure that only BUILD_NBUILDS builds are in flight at once
  517. donep="${LOG_DIR}/._done_"
  518. skipp="${LOG_DIR}/._skip_"
  519. build_target_killed() {
  520. echo "Aborted $target build."
  521. # Remove the logs for this board since it was aborted
  522. rm -f ${LOG_DIR}/$target.MAKELOG ${LOG_DIR}/$target.ERR
  523. exit
  524. }
  525. build_target() {
  526. target=$1
  527. build_idx=$2
  528. if [ "$ONLY_LIST" == 'y' ] ; then
  529. list_target ${target}
  530. return
  531. fi
  532. if [ $BUILD_MANY == 1 ] ; then
  533. output_dir="${OUTPUT_PREFIX}/${target}"
  534. mkdir -p "${output_dir}"
  535. trap build_target_killed TERM
  536. else
  537. output_dir="${OUTPUT_PREFIX}"
  538. fi
  539. target_arch=$(get_target_arch ${target})
  540. eval cross_toolchain=\$CROSS_COMPILE_`echo $target_arch | tr '[:lower:]' '[:upper:]'`
  541. if [ "${cross_toolchain}" ] ; then
  542. MAKE="make CROSS_COMPILE=${cross_toolchain}"
  543. elif [ "${CROSS_COMPILE}" ] ; then
  544. MAKE="make CROSS_COMPILE=${CROSS_COMPILE}"
  545. else
  546. MAKE=make
  547. fi
  548. if [ "${output_dir}" != "." ] ; then
  549. MAKE="${MAKE} O=${output_dir}"
  550. fi
  551. ${MAKE} distclean >/dev/null
  552. ${MAKE} -s ${target}_config
  553. ${MAKE} ${JOBS} ${CHECK} all \
  554. >${LOG_DIR}/$target.MAKELOG 2> ${LOG_DIR}/$target.ERR
  555. # Check for 'make' errors
  556. if [ ${PIPESTATUS[0]} -ne 0 ] ; then
  557. RC=1
  558. fi
  559. if [ $BUILD_MANY == 1 ] ; then
  560. trap - TERM
  561. ${MAKE} -s clean
  562. if [ -s ${LOG_DIR}/${target}.ERR ] ; then
  563. cp ${LOG_DIR}/${target}.ERR ${OUTPUT_PREFIX}/ERR/${target}
  564. else
  565. rm ${LOG_DIR}/${target}.ERR
  566. fi
  567. else
  568. if [ -s ${LOG_DIR}/${target}.ERR ] ; then
  569. if grep -iw error ${LOG_DIR}/${target}.ERR ; then
  570. : $(( ERR_CNT += 1 ))
  571. ERR_LIST="${ERR_LIST} $target"
  572. else
  573. : $(( WRN_CNT += 1 ))
  574. WRN_LIST="${WRN_LIST} $target"
  575. fi
  576. else
  577. rm ${LOG_DIR}/${target}.ERR
  578. fi
  579. fi
  580. OBJS=${output_dir}/u-boot
  581. if [ -e ${output_dir}/spl/u-boot-spl ]; then
  582. OBJS="${OBJS} ${output_dir}/spl/u-boot-spl"
  583. fi
  584. ${CROSS_COMPILE}size ${OBJS} | tee -a ${LOG_DIR}/$target.MAKELOG
  585. [ -e "${LOG_DIR}/${target}.ERR" ] && cat "${LOG_DIR}/${target}.ERR"
  586. touch "${donep}${build_idx}"
  587. }
  588. manage_builds() {
  589. search_idx=${OLDEST_IDX}
  590. if [ "$ONLY_LIST" == 'y' ] ; then return ; fi
  591. while true; do
  592. if [ -e "${donep}${search_idx}" ] ; then
  593. : $(( CURRENT_CNT-- ))
  594. [ ${OLDEST_IDX} -eq ${search_idx} ] &&
  595. : $(( OLDEST_IDX++ ))
  596. # Only want to count it once
  597. rm -f "${donep}${search_idx}"
  598. touch "${skipp}${search_idx}"
  599. elif [ -e "${skipp}${search_idx}" ] ; then
  600. [ ${OLDEST_IDX} -eq ${search_idx} ] &&
  601. : $(( OLDEST_IDX++ ))
  602. fi
  603. : $(( search_idx++ ))
  604. if [ ${search_idx} -gt ${TOTAL_CNT} ] ; then
  605. if [ ${CURRENT_CNT} -ge ${BUILD_NBUILDS} ] ; then
  606. search_idx=${OLDEST_IDX}
  607. sleep 1
  608. else
  609. break
  610. fi
  611. fi
  612. done
  613. }
  614. build_targets() {
  615. for t in "$@" ; do
  616. # If a LIST_xxx var exists, use it. But avoid variable
  617. # expansion in the eval when a board name contains certain
  618. # characters that the shell interprets.
  619. case ${t} in
  620. *[-+=]*) list= ;;
  621. *) list=$(eval echo '${LIST_'$t'}') ;;
  622. esac
  623. if [ -n "${list}" ] ; then
  624. build_targets ${list}
  625. else
  626. : $((TOTAL_CNT += 1))
  627. : $((CURRENT_CNT += 1))
  628. rm -f "${donep}${TOTAL_CNT}"
  629. rm -f "${skipp}${TOTAL_CNT}"
  630. if [ "$CONTINUE" = 'y' -a -e ${LOG_DIR}/$t.MAKELOG ] ; then
  631. : $((SKIP_CNT += 1))
  632. touch "${donep}${TOTAL_CNT}"
  633. elif [ "$REBUILD_ERRORS" = 'y' -a ! -e ${LOG_DIR}/$t.ERR ] ; then
  634. : $((SKIP_CNT += 1))
  635. touch "${donep}${TOTAL_CNT}"
  636. else
  637. if [ $BUILD_MANY == 1 ] ; then
  638. build_target ${t} ${TOTAL_CNT} &
  639. else
  640. CUR_TGT="${t}"
  641. build_target ${t} ${TOTAL_CNT}
  642. CUR_TGT=''
  643. fi
  644. fi
  645. fi
  646. # We maintain a running count of all the builds we have done.
  647. # Each finished build will have a file called ${donep}${n},
  648. # where n is the index of the build. Each build
  649. # we've already noted as finished will have ${skipp}${n}.
  650. # We track the current index via TOTAL_CNT, and the oldest
  651. # index. When we exceed the maximum number of parallel builds,
  652. # We look from oldest to current for builds that have completed,
  653. # and update the current count and oldest index as appropriate.
  654. # If we've gone through the entire list, wait a second, and
  655. # reprocess the entire list until we find a build that has
  656. # completed
  657. if [ ${CURRENT_CNT} -ge ${BUILD_NBUILDS} ] ; then
  658. manage_builds
  659. fi
  660. done
  661. }
  662. #-----------------------------------------------------------------------
  663. kill_children() {
  664. local OS=$(uname -s)
  665. local children=""
  666. case "${OS}" in
  667. "Darwin")
  668. # Mac OS X is known to have BSD style ps
  669. local pgid=$(ps -p $$ -o pgid | sed -e "/PGID/d")
  670. children=$(ps -g $pgid -o pid | sed -e "/PID\|$$\|$pgid/d")
  671. ;;
  672. *)
  673. # everything else tries the GNU style
  674. local pgid=$(ps -p $$ --no-headers -o "%r" | tr -d ' ')
  675. children=$(pgrep -g $pgid | sed -e "/$$\|$pgid/d")
  676. ;;
  677. esac
  678. kill $children 2> /dev/null
  679. wait $children 2> /dev/null
  680. exit
  681. }
  682. print_stats() {
  683. if [ "$ONLY_LIST" == 'y' ] ; then return ; fi
  684. # Only count boards that completed
  685. : $((TOTAL_CNT = `find ${skipp}* 2> /dev/null | wc -l`))
  686. rm -f ${donep}* ${skipp}*
  687. if [ $BUILD_MANY == 1 ] && [ -e "${OUTPUT_PREFIX}/ERR" ] ; then
  688. ERR_LIST=`grep -riwl error ${OUTPUT_PREFIX}/ERR/`
  689. ERR_LIST=`for f in $ERR_LIST ; do echo -n " $(basename $f)" ; done`
  690. ERR_CNT=`echo $ERR_LIST | wc -w | awk '{print $1}'`
  691. WRN_LIST=`grep -riwL error ${OUTPUT_PREFIX}/ERR/`
  692. WRN_LIST=`for f in $WRN_LIST ; do echo -n " $(basename $f)" ; done`
  693. WRN_CNT=`echo $WRN_LIST | wc -w | awk '{print $1}'`
  694. else
  695. # Remove the logs for any board that was interrupted
  696. rm -f ${LOG_DIR}/${CUR_TGT}.MAKELOG ${LOG_DIR}/${CUR_TGT}.ERR
  697. fi
  698. : $((TOTAL_CNT -= ${SKIP_CNT}))
  699. echo ""
  700. echo "--------------------- SUMMARY ----------------------------"
  701. if [ "$CONTINUE" = 'y' -o "$REBUILD_ERRORS" = 'y' ] ; then
  702. echo "Boards skipped: ${SKIP_CNT}"
  703. fi
  704. echo "Boards compiled: ${TOTAL_CNT}"
  705. if [ ${ERR_CNT} -gt 0 ] ; then
  706. echo "Boards with errors: ${ERR_CNT} (${ERR_LIST} )"
  707. fi
  708. if [ ${WRN_CNT} -gt 0 ] ; then
  709. echo "Boards with warnings but no errors: ${WRN_CNT} (${WRN_LIST} )"
  710. fi
  711. echo "----------------------------------------------------------"
  712. if [ $BUILD_MANY == 1 ] ; then
  713. kill_children
  714. fi
  715. exit $RC
  716. }
  717. #-----------------------------------------------------------------------
  718. # Build target groups selected by options, plus any command line args
  719. set -- ${SELECTED} "$@"
  720. # run PowerPC by default
  721. [ $# = 0 ] && set -- powerpc
  722. build_targets "$@"
  723. wait