2 ################################################################################
5 # Description: Perform building in parallel
6 # Author: Andrew@DeFaria.com
7 # Created: Mon Jun 2 11:19:46 PDT 2003
9 # Modification: 6/2/2003 AD: Added code to handle new cards (if present)
10 # 6/11/2003 AD: Added -nomonitor option to pop up monitor windows
11 # (default). Added -sequential option to build sequentially
12 # instead of parallel per card. Default off. Added -wait option
13 # to wait for all jobs to complete. Default off.
14 # 6/17/2003 AD: Changed 2310_onu to onu2310 as the card directory
17 # (c) Copyright 2001-2003, Andrew@DeFaria.com, all rights reserved.
19 ################################################################################
20 # Set me to command name
23 # Source /etc/site_parms
24 if [ -f /etc/site_parms ]; then
27 echo "$me: WARNING: /etc/site_parms does not exist!"
31 adm_base="$SITE_TOOLS_PATH/adm"
34 adm_fpath=${adm_fpath:-$adm_base/functions}
40 make="$SITE_TOOLS_PATH/bin/smake"
42 # Get cards definition
43 . $SITE_TOOLS_PATH/adm/etc/cards
45 # Positioning for geometry parameter
51 # Because of a problem with the make system we must stagger the parallel
52 # makes to avoid collisions with .d dependency files. Here we set the
53 # sleep interval between builds.
54 declare -i sleep_interval=${sleep_interval:-35}
57 if [ ! -z "$1" ]; then
60 display "Usage: $me: [-cle|an | -clo|bber] [-n|omonitor] [-w|ait] [-s|equential]"
61 display "\t [-q|uiet] [-t|ee <filename>] [-v|erbose] [-d|ebug] [-u|sage]"
62 display "\t [card...]"
65 display "\t-clean:\t\tPerform make clean before building"
66 display "\t-clobber:\tPerform make clobber before building"
67 display "\t-nomonitor:\tDo not put up monitor windows"
68 display "\t-wait:\t\tWait for all builds to complete before"
69 display "\t\t\treturning to the shell"
70 display "\t-sequential:\tPerform builds sequentially (not parallel by card)"
71 display "\t-quiet:\t\tBe quiet"
72 display "\t-tee:\t\tAppend build.log to <filename>"
73 display "\t-verbose:\tTurn on verbose mode"
74 display "\t-debug:\t\tTurn on debug mode"
75 display "\t-usage:\t\tDisplay usage"
76 display "\t<card>\t\tBuild only for these individual card(s)"
90 while [ $# -ge 1 ]; do
129 if [ $# -le 1 ]; then
130 usage "Tee filename is mmissing"
138 cards_passed_in="$cards_passed_in $(echo $1 | tr [:upper:] [:lower:])"
144 # Check to see if they specified both clean AND clobber!
145 if [ $clean = "yes" -a $clobber = "yes" ]; then
146 usage "Cannot specify both clean and clobber!"
149 # If cards were passed in, make sure that they are all on the list
150 # and replace the standard definition of cards:
151 if [ ! -z "$cards_passed_in" ]; then
152 for card_passed_in in $cards_passed_in; do
155 for card in $cards; do
156 if [[ $card_passed_in = $card ]]; then
157 # If we match then set flag and break out of this for loop
163 # If we've fallen through with no match then we error out
164 if [[ $match = "no" ]]; then
165 error "The card specified, $card_passed_in, is an unknown card!" 10
170 cards="$cards_passed_in"
173 # Check if we are in a view and if we are in the build area
174 view=$(cleartool pwv -short)
176 if [[ $view = "** NONE **" ]]; then
177 error "Not in a view!" 1
180 # Check to see if we are in the proper build directory
181 current_dir=$(basename $(pwd))
183 if [ "$current_dir" != "build" ]; then
184 error "Not in $view's build directory!" 2
188 if [ $clean = "yes" ]; then
189 verbose "Cleaning up..."
190 if [ $quiet = "yes" ]; then
191 if [ -z "$teefile" ]; then
192 $make clean > /dev/null 2>&1
194 $make clean >> $teefile
197 if [ -z "$teefile" ]; then
200 $make clean 2>&1 | tee -a $teefile
205 # Clobber if requested
206 if [ $clobber = "yes" ]; then
207 verbose "Clobbering old build..."
208 if [ $quiet = "yes" ]; then
209 if [ -z "$teefile" ]; then
210 $make clobber > /dev/null 2>&1
212 $make clobber >> $teefile
215 if [ -z "$teefile" ]; then
218 $make clobber 2>&1 | tee -a $teefile
223 declare -i build_status=0
224 declare -i overall_status=0
226 # Now perform a build for each card
227 for card in $cards; do
228 # Check to see if card's build directory is present
229 if [ "$card" = "scc" ]; then
235 if [ -d "$card_dirname" ]; then
236 if [ "$quiet" = "no" -a -z "$teefile" ]; then
237 echo -n "Starting build job for $card..."
240 # Clear out build log file
241 rm -f $card.build.log
244 if [ "$sequential" = "yes" ]; then
245 if [ ! -z "$teefile" ]; then
246 $make $card.sf 2>&1 | tee -a $teefile > $card.build.log
247 # Note: Need to grab the status of make from the PIPESTATUS
248 # array, otherwise the return status of a pipe is the
249 # same as the status of the last command in the pipe,
250 # in this case the tee! For a pipe, ${PIPESTATUS[0]}
251 # is the return status of the first command in the pipe,
252 # ${PIPESTATUS[1]} is the status of the second command
254 build_status=${PIPESTATUS[0]}
255 let overall_status=overall_status+build_status
257 $make $card.sf > $card.build.log 2>&1
259 let overall_status=overall_status+build_status
262 $make $card.sf > $card.build.log 2>&1 &
264 if [ "$monitor" = "yes" ]; then
265 # Put up a monitor window
267 -title "Monitoring build of $card - type Control-C to close window" \
268 -geometry 80x10+$xpos+$ypos \
269 -e tail -f $card.build.log &
271 # Adjust positions and index
276 # Sleep to avoid .d dependency file collisions
277 if [ "$quiet" = "no" ]; then
278 echo " Sleeping for $sleep_interval seconds..."
280 sleep $sleep_interval
282 # This disown is required or else when this script exits it will send
283 # SIGHUPs to all jobs stated from this script.
289 if [ "$wait" = "yes" ]; then