move post-build ops from nightly.sh to tools/postbuild/Makefile
[unleashed.git] / tools / nightly.sh
blob0890a745bee4010b3f615f879cc2fede59da4c47
1 #!/bin/ksh -p
2 # vim: noet sw=8 ts=8
4 # CDDL HEADER START
6 # The contents of this file are subject to the terms of the
7 # Common Development and Distribution License (the "License").
8 # You may not use this file except in compliance with the License.
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
21 # CDDL HEADER END
25 # Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
26 # Copyright 2008, 2010, Richard Lowe
27 # Copyright 2011 Nexenta Systems, Inc. All rights reserved.
28 # Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
29 # Copyright 2014 Garrett D'Amore <garrett@damore.org>
30 # Copyright 2018 Joyent, Inc.
32 # Based on the nightly script from the integration folks,
33 # Mostly modified and owned by mike_s.
34 # Changes also by kjc, dmk.
36 # -i on the command line, means fast options, so when it's on the
37 # command line (only), check builds are skipped no matter what
38 # the setting of their individual flags are in NIGHTLY_OPTIONS.
40 # OPTHOME may be set in the environment to override /opt
44 # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
45 # under certain circumstances, which can really screw things up; unset it.
47 unset CDPATH
49 # Get the absolute path of the nightly script that the user invoked. This
50 # may be a relative path, and we need to do this before changing directory.
51 nightly_path=`whence $0`
53 function fatal_error
55 print -u2 "nightly: $*"
56 exit 1
60 # Function to do a DEBUG and non-DEBUG build. Needed because we might
61 # need to do another for the source build, and since we only deliver DEBUG or
62 # non-DEBUG packages.
64 # usage: normal_build
66 function normal_build {
68 typeset orig_p_FLAG="$p_FLAG"
70 if [ "$D_FLAG" = "n" ]; then
71 set_non_debug_build_flags
72 build "non-DEBUG"
73 else
74 set_debug_build_flags
75 build "DEBUG"
78 p_FLAG="$orig_p_FLAG"
82 # usage: run_hook HOOKNAME ARGS...
84 # If variable "$HOOKNAME" is defined, insert a section header into
85 # our logs and then run the command with ARGS
87 function run_hook {
88 HOOKNAME=$1
89 eval HOOKCMD=\$$HOOKNAME
90 shift
92 if [ -n "$HOOKCMD" ]; then
94 echo "\n==== Running $HOOKNAME command: $HOOKCMD ====\n"
95 ( $HOOKCMD "$@" 2>&1 )
96 if [ "$?" -ne 0 ]; then
97 # Let exit status propagate up
98 touch $TMPDIR/abort
102 if [ -f $TMPDIR/abort ]; then
103 build_ok=n
104 echo "\nAborting at request of $HOOKNAME"
105 exit 1
110 # Return library search directive as function of given root.
111 function myldlibs {
112 echo "-L$1/lib -L$1/usr/lib"
115 # Return header search directive as function of given root.
116 function myheaders {
117 echo "-I$1/usr/include"
121 # Function to do the build, including package generation.
122 # usage: build LABEL
123 # - LABEL is used to tag build output.
125 function build {
126 LABEL=$1
127 INSTALLOG=install-${MACH}
129 export ROOT
131 export ENVLDLIBS1=`myldlibs $ROOT`
132 export ENVCPPFLAGS1=`myheaders $ROOT`
134 this_build_ok=y
136 echo "\n==== bmake -C include all install\n" >&2
138 # Before we build anything via dmake, we need to install
139 # bmake-ified headers and libs to the proto area
141 if ! make -j$DMAKE_MAX_JOBS -C $SRCTOP/include all DESTDIR=$ROOT; then
142 build_ok=n
143 this_build_ok=n
144 fatal_error "cannot install headers"
146 if ! make -j$DMAKE_MAX_JOBS -C $SRCTOP/include install DESTDIR=$ROOT; then
147 build_ok=n
148 this_build_ok=n
149 fatal_error "cannot install headers"
151 echo "\n==== bmake -C lib build\n" >&2
152 if ! make -j$DMAKE_MAX_JOBS -C $SRCTOP/lib build DESTDIR=$ROOT; then
153 build_ok=n
154 this_build_ok=n
155 fatal_error "cannot install libraries"
159 # Build the legacy part of the source
161 echo "\n==== Building legacy source at `date` ($LABEL) ====\n"
163 cd $SRC
164 echo "\n==== dmake install ====\n" >&2
165 if ! /bin/time $MAKE -e install; then
166 build_ok=n
167 this_build_ok=n
171 # Build the new part of the source
173 echo "\n==== bmake build ====\n" >&2
174 if ! /bin/time env -i PATH=${GNUC_ROOT}/bin:/usr/bin \
175 SRCTOP=$SRCTOP \
176 make -C $SRCTOP -j $DMAKE_MAX_JOBS VERBOSE=yes build DESTDIR=$ROOT; then
177 build_ok=n
178 this_build_ok=n
181 echo "\n==== Ended OS-Net source build at `date` ($LABEL) ====\n"
183 if [ "$this_build_ok" = "y" ]; then
184 make -C ${SRCTOP}/tools/postbuild clean obj
185 if ! make -j$DMAKE_MAX_JOBS -C ${SRCTOP}/tools/postbuild; then
186 build_extras_ok=n
187 this_build_ok=n
193 # Build and install the onbld tools.
195 # usage: build_tools DESTROOT
197 # returns non-zero status if the build was successful.
199 function build_tools {
200 DESTROOT=$1
202 INSTALLOG=install-${MACH}
204 echo "\n==== Building tools at `date` ====\n" \
206 rm -f ${TOOLS}/${INSTALLOG}.out
207 cd ${TOOLS}
208 if ! $MAKE TOOLS_PROTO=${DESTROOT} -e install; then
209 return 1
211 return 0
215 # Set up to use locally installed tools.
217 # usage: use_tools TOOLSROOT
219 function use_tools {
220 TOOLSROOT=$1
223 # If we're not building ON workspace, then the TOOLSROOT
224 # settings here are clearly ignored by the workspace
225 # makefiles, prepending nonexistent directories to PATH is
226 # harmless, and we clearly do not wish to override
227 # ONBLD_TOOLS.
229 # If we're building an ON workspace, then the prepended PATH
230 # elements should supercede the preexisting ONBLD_TOOLS paths,
231 # and we want to override ONBLD_TOOLS to catch the tools that
232 # don't have specific path env vars here.
234 # So the only conditional behavior is overriding ONBLD_TOOLS,
235 # and we check for "an ON workspace" by looking for
236 # ${TOOLSROOT}/opt/onbld.
239 STABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/stabs
240 export STABS
241 CTFSTABS=${TOOLSROOT}/opt/onbld/bin/${MACH}/ctfstabs
242 export CTFSTABS
243 GENOFFSETS=${TOOLSROOT}/opt/onbld/bin/genoffsets
244 export GENOFFSETS
247 PATH="${TOOLSROOT}/opt/onbld/bin/${MACH}:${PATH}"
248 PATH="${TOOLSROOT}/opt/onbld/bin:${PATH}"
249 export PATH
251 if [ -d "${TOOLSROOT}/opt/onbld" ]; then
252 ONBLD_TOOLS=${TOOLSROOT}/opt/onbld
253 export ONBLD_TOOLS
256 echo "\n==== New environment settings. ====\n"
257 echo "STABS=${STABS}"
258 echo "CTFSTABS=${CTFSTABS}"
259 echo "PATH=${PATH}"
260 echo "ONBLD_TOOLS=${ONBLD_TOOLS}"
264 # wrapper over wsdiff.
265 # usage: do_wsdiff LABEL OLDPROTO NEWPROTO
267 function do_wsdiff {
268 label=$1
269 oldproto=$2
270 newproto=$3
272 wsdiff="wsdiff -t"
274 echo "\n==== Getting object changes since last build at `date`" \
275 "($label) ====\n" >&2
276 $wsdiff -s -r ${TMPDIR}/wsdiff.results $oldproto $newproto >&2
277 echo "\n==== Object changes determined at `date` ($label) ====\n" >&2
281 # Functions for setting build flags (DEBUG/non-DEBUG). Keep them
282 # together.
285 function set_non_debug_build_flags {
286 export RELEASE_BUILD ; RELEASE_BUILD=
287 unset EXTRA_OPTIONS
288 unset EXTRA_CFLAGS
291 function set_debug_build_flags {
292 unset RELEASE_BUILD
293 unset EXTRA_OPTIONS
294 unset EXTRA_CFLAGS
298 MACH=`uname -p`
300 if [ "$OPTHOME" = "" ]; then
301 OPTHOME=/opt
302 export OPTHOME
305 USAGE='Usage: nightly [-in] [-V VERS ] [env_file]
307 Where:
308 -i Fast incremental options (no clobber, check)
309 -V VERS set the build version string to VERS
311 <env_file> file in Bourne shell syntax that sets and exports
312 variables that configure the operation of this script and many of
313 the scripts this one calls.
315 non-DEBUG is the default build type. Build options can be set in the
316 NIGHTLY_OPTIONS variable in the <env_file> as follows:
318 -A check for ABI differences in .so files
319 -C check for cstyle/hdrchk errors
320 -D do a build with DEBUG on
321 -G gate keeper default group of options (-au)
322 -I integration engineer default group of options (-ampu)
323 -M do not run pmodes (safe file permission checker)
324 -N do not run protocmp
325 -R default group of options for building a release (-mp)
326 -U update proto area in the parent
327 -V VERS set the build version string to VERS
328 -i do an incremental build (no "make clobber")
329 -m send mail to $MAILTO at end of build
330 -p create packages
331 -r check ELF runtime attributes in the proto area
332 -u update proto_list_$MACH and friends in the parent workspace
333 -w report on differences between previous and current proto areas
336 # A log file will be generated under the name $LOGFILE
337 # for partially completed build and log.`date '+%F'`
338 # in the same directory for fully completed builds.
341 # default values for low-level FLAGS; G I R are group FLAGS
342 A_FLAG=n
343 C_FLAG=n
344 D_FLAG=n
345 i_FLAG=n; i_CMD_LINE_FLAG=n
346 M_FLAG=n
347 m_FLAG=n
348 N_FLAG=n
349 p_FLAG=n
350 r_FLAG=n
351 V_FLAG=n
352 w_FLAG=n
353 W_FLAG=n
355 build_ok=y
356 build_extras_ok=y
359 # examine arguments
362 OPTIND=1
363 while getopts +iV:W FLAG
365 case $FLAG in
366 i ) i_FLAG=y; i_CMD_LINE_FLAG=y
368 V ) V_FLAG=y
369 V_ARG="$OPTARG"
371 W ) W_FLAG=y
373 \? ) echo "$USAGE"
374 exit 1
376 esac
377 done
379 # correct argument count after options
380 shift `expr $OPTIND - 1`
382 # test that the path to the environment-setting file was given
383 if [ $# -ne 1 ]; then
384 envfile=$(dirname $0)/env.sh
385 else
386 envfile=$1
390 # force locale to C
391 LANG=C; export LANG
392 LC_ALL=C; export LC_ALL
393 LC_COLLATE=C; export LC_COLLATE
394 LC_CTYPE=C; export LC_CTYPE
395 LC_MESSAGES=C; export LC_MESSAGES
396 LC_MONETARY=C; export LC_MONETARY
397 LC_NUMERIC=C; export LC_NUMERIC
398 LC_TIME=C; export LC_TIME
400 # clear environment variables we know to be bad for the build
401 unset LD_OPTIONS
402 unset LD_AUDIT LD_AUDIT_32 LD_AUDIT_64
403 unset LD_BIND_NOW LD_BIND_NOW_32 LD_BIND_NOW_64
404 unset LD_BREADTH LD_BREADTH_32 LD_BREADTH_64
405 unset LD_CONFIG LD_CONFIG_32 LD_CONFIG_64
406 unset LD_DEBUG LD_DEBUG_32 LD_DEBUG_64
407 unset LD_DEMANGLE LD_DEMANGLE_32 LD_DEMANGLE_64
408 unset LD_FLAGS LD_FLAGS_32 LD_FLAGS_64
409 unset LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64
410 unset LD_LOADFLTR LD_LOADFLTR_32 LD_LOADFLTR_64
411 unset LD_NOAUDIT LD_NOAUDIT_32 LD_NOAUDIT_64
412 unset LD_NOAUXFLTR LD_NOAUXFLTR_32 LD_NOAUXFLTR_64
413 unset LD_NOCONFIG LD_NOCONFIG_32 LD_NOCONFIG_64
414 unset LD_NODIRCONFIG LD_NODIRCONFIG_32 LD_NODIRCONFIG_64
415 unset LD_NODIRECT LD_NODIRECT_32 LD_NODIRECT_64
416 unset LD_NOLAZYLOAD LD_NOLAZYLOAD_32 LD_NOLAZYLOAD_64
417 unset LD_NOOBJALTER LD_NOOBJALTER_32 LD_NOOBJALTER_64
418 unset LD_NOVERSION LD_NOVERSION_32 LD_NOVERSION_64
419 unset LD_ORIGIN LD_ORIGIN_32 LD_ORIGIN_64
420 unset LD_PRELOAD LD_PRELOAD_32 LD_PRELOAD_64
421 unset LD_PROFILE LD_PROFILE_32 LD_PROFILE_64
423 unset CONFIG
424 unset GROUP
425 unset OWNER
426 unset REMOTE
427 unset ENV
428 unset ARCH
429 unset CLASSPATH
430 unset NAME
433 # To get ONBLD_TOOLS from the environment, it must come from the env file.
434 # If it comes interactively, it is generally TOOLS_PROTO, which will be
435 # clobbered before the compiler version checks, which will therefore fail.
437 unset ONBLD_TOOLS
440 # Setup environmental variables
442 if [ -f $envfile ]; then
443 . $envfile
444 else
445 echo "Cannot find env file $envfile"
446 exit 1
449 # Check if we have sufficient data to continue...
450 [[ -n "$SRCTOP" ]] || \
451 fatal_error "Error: Variable SRCTOP not set."
452 [[ -d "${SRCTOP}" ]] || \
453 fatal_error "Error: ${SRCTOP} is not a directory."
454 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || \
455 fatal_error "Error: ${SRCTOP}/usr/src/Makefile not found."
458 # place ourselves in a new task, respecting BUILD_PROJECT if set.
460 if [ -z "$BUILD_PROJECT" ]; then
461 /usr/bin/newtask -c $$
462 else
463 /usr/bin/newtask -c $$ -p $BUILD_PROJECT
466 ps -o taskid= -p $$ | read build_taskid
467 ps -o project= -p $$ | read build_project
470 # See if NIGHTLY_OPTIONS is set
472 if [ "$NIGHTLY_OPTIONS" = "" ]; then
473 NIGHTLY_OPTIONS="-aBm"
477 # Note: changes to the option letters here should also be applied to the
478 # bldenv script. `d' is listed for backward compatibility.
480 NIGHTLY_OPTIONS=-${NIGHTLY_OPTIONS#-}
481 OPTIND=1
482 while getopts +ABCDdfGIiMmNpRrwW FLAG $NIGHTLY_OPTIONS
484 case $FLAG in
485 A ) A_FLAG=y
487 B ) D_FLAG=y
488 ;; # old version of D
489 C ) C_FLAG=y
491 D ) D_FLAG=y
493 G ) ;;
494 I ) m_FLAG=y
495 p_FLAG=y
497 i ) i_FLAG=y
499 M ) M_FLAG=y
501 m ) m_FLAG=y
503 N ) N_FLAG=y
505 p ) p_FLAG=y
507 R ) m_FLAG=y
508 p_FLAG=y
510 r ) r_FLAG=y
512 w ) w_FLAG=y
514 W ) W_FLAG=y
516 \? ) echo "$USAGE"
517 exit 1
519 esac
520 done
522 if [ -z "$MAILTO" -o "$MAILTO" = "nobody" ]; then
523 MAILTO=`/usr/bin/id -un`
524 export MAILTO
527 PATH="$OPTHOME/onbld/bin:$OPTHOME/onbld/bin/${MACH}:/usr/bin"
528 PATH="$PATH:/usr/bin:/usr/sbin:/usr/ucb"
529 PATH="$PATH:/usr/openwin/bin:/usr/sfw/bin:/opt/sfw/bin:.:$OPTHOME/SUNWspro/bin"
530 export PATH
532 # roots of source trees, both relative to $SRC and absolute.
533 relsrcdirs="."
534 abssrcdirs="$SRC"
536 PROTOCMPTERSE="protocmp.terse -gu"
537 POUND_SIGN="#"
538 # have we set RELEASE_DATE in our env file?
539 if [ -z "$RELEASE_DATE" ]; then
540 RELEASE_DATE=$(LC_ALL=C date +"%B %Y")
542 BUILD_DATE=$(LC_ALL=C date +%Y-%b-%d)
543 BASEWSDIR=$(basename $SRCTOP)
545 # we export POUND_SIGN and RELEASE_DATE to speed up the build process
546 # by avoiding repeated shell invocations to evaluate Makefile.master
547 # definitions.
548 export POUND_SIGN RELEASE_DATE
550 maketype="distributed"
551 if [[ -z "$MAKE" ]]; then
552 MAKE=dmake
553 elif [[ ! -x "$MAKE" ]]; then
554 echo "\$MAKE is set to garbage in the environment"
555 exit 1
557 export PATH
558 export MAKE
560 hostname=$(uname -n)
561 if [[ $DMAKE_MAX_JOBS != +([0-9]) || $DMAKE_MAX_JOBS -eq 0 ]]
562 then
563 maxjobs=
564 if [[ -f $HOME/.make.machines ]]
565 then
566 # Note: there is a hard tab and space character in the []s
567 # below.
568 egrep -i "^[ ]*$hostname[ \.]" \
569 $HOME/.make.machines | read host jobs
570 maxjobs=${jobs##*=}
573 if [[ $maxjobs != +([0-9]) || $maxjobs -eq 0 ]]
574 then
575 # default
576 maxjobs=4
579 export DMAKE_MAX_JOBS=$maxjobs
582 DMAKE_MODE=parallel;
583 export DMAKE_MODE
584 DMAKE_OUTPUT_MODE=TXT2;
585 export DMAKE_OUTPUT_MODE
587 if [ -z "${ROOT}" ]; then
588 echo "ROOT must be set."
589 exit 1
593 # if -V flag was given, reset VERSION to V_ARG
595 if [ "$V_FLAG" = "y" ]; then
596 VERSION=$V_ARG
599 TMPDIR="/tmp/nightly.tmpdir.$$"
600 export TMPDIR
601 rm -rf ${TMPDIR}
602 mkdir -p $TMPDIR || exit 1
604 # Tools should only be built non-DEBUG. Keep track of the tools proto
605 # area path relative to $TOOLS, because the latter changes in an
606 # export build.
608 # TOOLS_PROTO is included below for builds other than usr/src/tools
609 # that look for this location. For usr/src/tools, this will be
610 # overridden on the $MAKE command line in build_tools().
612 TOOLS=${SRC}/tools
613 TOOLS_PROTO_REL=proto/root_${MACH}-nd
614 TOOLS_PROTO=${TOOLS}/${TOOLS_PROTO_REL}; export TOOLS_PROTO
616 unset CFLAGS LD_LIBRARY_PATH LDFLAGS
618 # create directories that are automatically removed if the nightly script
619 # fails to start correctly
620 function newdir {
621 dir=$1
622 toadd=
623 while [ ! -d $dir ]; do
624 toadd="$dir $toadd"
625 dir=`dirname $dir`
626 done
627 torm=
628 newlist=
629 for dir in $toadd; do
630 if mkdir $dir; then
631 newlist="$dir $newlist"
632 torm="$dir $torm"
633 else
634 [ -z "$torm" ] || rmdir $torm
635 return 1
637 done
638 newdirlist="$newlist $newdirlist"
639 return 0
641 newdirlist=
643 [ -d $SRCTOP ] || newdir $SRCTOP || exit 1
645 # since this script assumes the build is from full source, it nullifies
646 # variables likely to have been set by a "ws" script; nullification
647 # confines the search space for headers and libraries to the proto area
648 # built from this immediate source.
649 ENVLDLIBS1=
650 ENVLDLIBS2=
651 ENVLDLIBS3=
652 ENVCPPFLAGS1=
653 ENVCPPFLAGS2=
654 ENVCPPFLAGS3=
655 ENVCPPFLAGS4=
657 export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 \
658 ENVLDLIBS1 ENVLDLIBS2
661 # Juggle the logs and optionally send mail on completion.
664 function logshuffle {
665 LLOG="$ATLOG/log.`date '+%F.%H:%M'`"
666 if [ -f $LLOG -o -d $LLOG ]; then
667 LLOG=$LLOG.$$
670 rm -f "$ATLOG/latest" 2>/dev/null
671 mkdir $LLOG
672 export LLOG
674 if [ "$build_ok" = "y" ]; then
675 mv $ATLOG/proto_list_${MACH} $LLOG
677 if [ -f $ATLOG/proto_list_tools_${MACH} ]; then
678 mv $ATLOG/proto_list_tools_${MACH} $LLOG
681 if [ -f $TMPDIR/wsdiff.results ]; then
682 mv $TMPDIR/wsdiff.results $LLOG
685 if [ -f $TMPDIR/wsdiff-nd.results ]; then
686 mv $TMPDIR/wsdiff-nd.results $LLOG
690 kill $TEE
691 case "$build_ok" in
693 state=Completed
696 state=Interrupted
699 state=Failed
701 esac
703 if [[ $state != "Interrupted" && $build_extras_ok != "y" ]]; then
704 state=Failed
707 NIGHTLY_STATUS=$state
708 export NIGHTLY_STATUS
710 run_hook POST_NIGHTLY $state
711 run_hook SYS_POST_NIGHTLY $state
713 echo "Subject: Nightly ${MACH} Build of `basename ${SRCTOP}` ${state}." \
714 > ${LLOG}/mail_msg
715 cat $build_time_file $mail_msg_file \
716 >> ${LLOG}/mail_msg
717 if [ "$m_FLAG" = "y" ]; then
718 /usr/bin/mail ${MAILTO} < ${LLOG}/mail_msg
721 mv $LOGFILE $LLOG
723 ln -s "$LLOG" "$ATLOG/latest"
727 # Remove the temporary files on any exit
729 function cleanup {
730 logshuffle
732 set -- $newdirlist
733 while [ $# -gt 0 ]; do
734 rmdir $1
735 shift; shift
736 done
737 rm -rf $TMPDIR
740 function cleanup_signal {
741 build_ok=i
742 # this will trigger cleanup(), above.
743 exit 1
746 trap cleanup 0
747 trap cleanup_signal 1 2 3 15
749 newdirlist=
752 # Create mail_msg_file
754 mail_msg_file="${TMPDIR}/mail_msg"
755 touch $mail_msg_file
756 build_time_file="${TMPDIR}/build_time"
758 mkdir -p "$ATLOG"
760 # Move old LOGFILE aside
762 if [ -f $LOGFILE ]; then
763 mv -f $LOGFILE ${LOGFILE}-
766 mkfifo ${TMPDIR}/err.fifo ${TMPDIR}/out.fifo
767 tee $mail_msg_file < ${TMPDIR}/err.fifo >> $LOGFILE &
768 TEE=$!
769 tee ${TMPDIR}/stdout.txt < ${TMPDIR}/out.fifo >> $LOGFILE &
770 TEE="$TEE $!"
771 exec > ${TMPDIR}/out.fifo
772 exec 2> ${TMPDIR}/err.fifo
775 # Build OsNet source
777 START_DATE=`date`
778 SECONDS=0
779 echo "\n==== Nightly $maketype build started: $START_DATE ====" | \
780 tee -a $build_time_file
782 run_hook SYS_PRE_NIGHTLY
783 run_hook PRE_NIGHTLY
785 echo "\n==== list of environment variables ====\n"
788 echo "Building $VERSION
789 on $(uname -srv)" >&2
791 if [[ ! -f $SRC/Makefile ]]; then
792 build_ok=n
793 echo "\nUnable to find \"Makefile\" in $SRC." >&2
794 exit 1
797 # Save the current proto area if we're comparing against the last build
798 if [ "$w_FLAG" = "y" -a -d "$ROOT" ]; then
799 if [ -d "$ROOT.prev" ]; then
800 rm -rf $ROOT.prev
802 mv $ROOT $ROOT.prev
805 # Safeguards
806 [[ -n "${SRCTOP}" ]] || fatal_error "Error: Variable SRCTOP not set."
807 [[ -d "${SRCTOP}" ]] || fatal_error "Error: ${SRCTOP} is not a directory."
808 [[ -f "${SRCTOP}/usr/src/Makefile" ]] || fatal_error "Error: ${SRCTOP}/usr/src/Makefile not found."
811 # Generate the cfgparam files
813 # We have to do this before running *any* make commands.
815 make gen-config || fatal_error "gen-config failed"
818 # Decide whether to clobber
820 if [ "$i_FLAG" = "n" -a -d "$SRC" ]; then
821 echo "\n==== Make clobber at `date` ====\n"
822 echo "\n==== clobber / cleandir ===="
824 cd $SRC
825 # remove old clobber file
826 rm -f $SRC/clobber.out
827 rm -f $SRC/clobber-${MACH}.out
829 # Remove all .make.state* files, just in case we are restarting
830 # the build after having interrupted a previous 'make clobber'.
831 find . \( -name SCCS -o -name .hg -o -name .svn -o -name .git \
832 -o -name 'interfaces.*' \) -prune \
833 -o -name '.make.*' -print | xargs rm -f
834 if ! $MAKE -ek clobber; then
835 build_extras_ok=n
838 echo "\n==== Make tools clobber at `date` ====\n"
839 cd ${TOOLS}
840 rm -f ${TOOLS}/clobber-${MACH}.out
842 if ! $MAKE TOOLS_PROTO=$TOOLS_PROTO -ek clobber; then
843 build_extras_ok=n
845 rm -rf ${TOOLS_PROTO}
846 mkdir -p ${TOOLS_PROTO}
848 typeset roots=$ROOT
849 echo "\n\nClearing $roots"
850 rm -rf $roots
852 # Get back to a clean workspace as much as possible to catch
853 # problems that only occur on fresh workspaces.
854 # Remove all .make.state* files, libraries, and .o's that may
855 # have been omitted from clobber. A couple of libraries are
856 # under source code control, so leave them alone.
857 # We should probably blow away temporary directories too.
858 cd $SRC
859 find $relsrcdirs \( -name SCCS -o -name .hg -o -name .svn \
860 -o -name .git -o -name 'interfaces.*' \) -prune -o \
861 \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
862 -name '*.o' \) -print | \
863 grep -v 'tools/ctf/dwarf/.*/libdwarf' | xargs rm -f
864 make -C $SRCTOP cleandir
865 else
866 echo "\n==== No clobber at `date` ====\n"
870 # Build and use the workspace's tools if requested
872 set_non_debug_build_flags
874 build_tools ${TOOLS_PROTO}
875 if (( $? != 0 )); then
876 build_ok=n
877 else
878 use_tools $TOOLS_PROTO
881 normal_build
883 ORIG_SRC=$SRC
885 if [ "$build_ok" = "y" ]; then
886 echo "\n==== Creating protolist system file at `date` ====" \
887 protolist $ROOT > $ATLOG/proto_list_${MACH}
888 echo "==== protolist system file created at `date` ====\n" \
890 if [ "$N_FLAG" != "y" ]; then
894 for f in $f1; do
895 if [ -f "$f" ]; then
896 E1="$E1 -e $f"
898 done
902 if [ -d "$SRC/pkg" ]; then
903 f2="$f2 exceptions/packaging"
906 for f in $f2; do
907 if [ -f "$f" ]; then
908 E2="$E2 -e $f"
910 done
914 echo "\n==== Find core files ====\n" >&2
916 find $abssrcdirs -name core -a -type f -exec file {} \; >&2
918 # Verify that the usual lists of files, such as exception lists,
919 # contain only valid references to files. If the build has failed,
920 # then don't check the proto area.
921 CHECK_PATHS=${CHECK_PATHS:-y}
922 if [ "$CHECK_PATHS" = y -a "$N_FLAG" != y ]; then
923 echo "\n==== Check lists of files ====\n" >&2
924 arg=-b
925 [ "$build_ok" = y ] && arg=
926 checkpaths $arg $ROOT > $TMPDIR/check-paths.out 2>&1
927 if [[ -s $TMPDIR/check-paths.out ]]; then
928 cat $TMPDIR/check-paths.out >&2
929 build_extras_ok=n
933 if [ "$M_FLAG" != "y" -a "$build_ok" = y ]; then
934 echo "\n==== Impact on file permissions ====\n" >&2
936 abspkg=
937 for d in $abssrcdirs; do
938 if [ -d "$d/pkg" ]; then
939 abspkg="$abspkg $d"
941 done
943 if [ -n "$abspkg" ]; then
944 for d in "$abspkg"; do
945 ( cd $d/pkg ; $MAKE -e pmodes ) >&2
946 done
950 if [ "$w_FLAG" = "y" -a "$build_ok" = "y" ]; then
951 if [[ "$D_FLAG" = y ]]; then
952 do_wsdiff DEBUG $ROOT.prev $ROOT
953 else
954 do_wsdiff non-DEBUG $ROOT.prev $ROOT
958 END_DATE=`date`
959 echo "==== Nightly $maketype build completed: $END_DATE ====" | \
960 tee -a $build_time_file
962 typeset -i10 hours
963 typeset -Z2 minutes
964 typeset -Z2 seconds
966 elapsed_time=$SECONDS
967 hours=$(( elapsed_time / 3600 ))
968 minutes=$(( elapsed_time / 60 % 60 ))
969 seconds=$((elapsed_time % 60 ))
971 echo "Total build time ${hours}:${minutes}:${seconds}" |
972 tee -a $build_time_file
975 # All done save for the sweeping up.
976 # (whichever exit we hit here will trigger the "cleanup" trap which
977 # optionally sends mail on completion).
979 if [[ "$build_ok" == "y" ]]; then
980 if [[ "$W_FLAG" == "y" || "$build_extras_ok" == "y" ]]; then
981 exit 0
985 exit 1