1 #!/bin/ksh
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 #
  29 # This script can be used to build the ON component of the source product.
  30 # It should _not_ be used by developers, since it does not work with
  31 # workspaces, or do many of the features that 'nightly' uses to help you
  32 # (like detection errors and warnings, and send mail on completion).
  33 # 'nightly' (and other tools we use) lives in usr/src/tools.
  34 #
  35 # examine arguments. Source customers probably use no arguments, which just
  36 # builds in usr/src from the current directory. They might want to use
  37 # the -B flag, but the others are for use internally for testing the
  38 # compressed cpio archives we deliver to the folks who build the source product.
  39 #
  40 
  41 #
  42 # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout
  43 # under certain circumstances, which can really screw things up; unset it.
  44 #
  45 unset CDPATH
  46 
  47 USAGE='build_osnet [-B dir] [-E export_archive ] [-C crypt_archive ]
  48         [ -H binary_archive ] [-D] [-P]
  49 
  50 where:
  51     -B dir              - set build directory
  52     -E export_archive   - create build directory from export_archive
  53     -C crypt_archive    - extract crypt_archive on top of build area
  54     -H binary_archive   - extract binary_archive on top of build area
  55     -D                  - do a DEBUG build
  56     -P                  - do not copy packages to /pkgs
  57 '
  58 
  59 BUILDAREA=`pwd`
  60 EXPORT_CPIO=
  61 CRYPT_CPIO=
  62 BINARY_CPIO=
  63 DEBUGFLAG="n"
  64 PKGCPFLAG="y"
  65 
  66 OPTIND=1
  67 while getopts B:E:C:H:DP FLAG
  68 do
  69         case $FLAG in
  70           B )   BUILDAREA="$OPTARG"
  71                 ;;
  72           E )   EXPORT_CPIO="$OPTARG"
  73                 ;;
  74           C )   CRYPT_CPIO="$OPTARG"
  75                 ;;
  76           H )   BINARY_CPIO="$OPTARG"
  77                 ;;
  78           D )   DEBUGFLAG="y"
  79                 ;;
  80           P )   PKGCPFLAG="n"
  81                 ;;
  82          \? )   echo "$USAGE"
  83                 exit 1
  84                 ;;
  85         esac
  86 done
  87 
  88 
  89 # extract source
  90 
  91 # verify you are root
  92 /usr/bin/id | grep root >/dev/null 2>&1
  93 if [ "$?" != "0" ]; then
  94         echo \"$0\" must be run as root.
  95         exit 1
  96 fi
  97 
  98 if [ ! -z "${EXPORT_CPIO}" -a ! -f "${EXPORT_CPIO}" ]; then
  99         echo "${EXPORT_CPIO} does not exist - aborting."
 100         exit 1
 101 fi
 102 
 103 if [ -z "${BUILDAREA}" ]; then
 104         echo "BUILDAREA must be set - aborting."
 105         exit 1
 106 fi
 107 
 108 if [ -z "${SPRO_ROOT}" ]; then
 109         echo
 110         echo "SPRO_ROOT is not set - defaulting to /opt/SUNWspro."
 111         echo "If your compilers are located at a different location,"
 112         echo "you will need to set the SPRO_ROOT variable before"
 113         echo "you execute this script."
 114         echo
 115         SPRO_ROOT=/opt/SUNWspro;        export SPRO_ROOT
 116 fi
 117 
 118 if [ -z "${JAVA_ROOT}" ]; then
 119         echo "JAVA_ROOT is not set - defaulting to /usr/java."
 120         JAVA_ROOT=/usr/java;            export JAVA_ROOT
 121 fi
 122 
 123 # in case you use dmake. Note that dmake on ON has only been
 124 # tested in parallel make mode.
 125 if [ -z "${DMAKE_MAX_JOBS}" ]; then
 126         DMAKE_MAX_JOBS=4;
 127         export DMAKE_MAX_JOBS
 128 fi
 129 DMAKE_MODE=parallel; export DMAKE_MODE
 130 
 131 ################################################################
 132 # Uncomment the line below to change to a parallel make using
 133 # dmake. Be sure to put a "#" in front of the other make line.
 134 # dmake can help create builds much faster, though if
 135 # you have problems you should go back to serial make.
 136 ################################################################
 137 #MAKE=dmake;                            export MAKE
 138 MAKE=/usr/ccs/bin/make;                         export MAKE
 139 
 140 #
 141 # force locale to C
 142 LC_COLLATE=C;   export LC_COLLATE
 143 LC_CTYPE=C;     export LC_CTYPE
 144 LC_MESSAGES=C;  export LC_MESSAGES
 145 LC_MONETARY=C;  export LC_MONETARY
 146 LC_NUMERIC=C;   export LC_NUMERIC
 147 LC_TIME=C;      export LC_TIME
 148 
 149 # clear environment variables we know to be bad for the build
 150 unset LD_OPTIONS LD_LIBRARY_PATH LD_AUDIT LD_BIND_NOW LD_BREADTH LD_CONFIG
 151 unset LD_DEBUG LD_FLAGS LD_LIBRARY_PATH_64 LD_NOVERSION LD_ORIGIN
 152 unset LD_LOADFLTR LD_NOAUXFLTR LD_NOCONFIG LD_NODIRCONFIG LD_NOOBJALTER
 153 unset LD_PRELOAD LD_PROFILE
 154 unset CONFIG
 155 unset GROUP
 156 unset OWNER
 157 unset REMOTE
 158 unset ENV
 159 unset ARCH
 160 unset CLASSPATH 
 161 
 162 # set magic variables
 163 
 164 MACH=`uname -p`;                        export MACH
 165 ROOT="${BUILDAREA}/proto/root_${MACH}"; export ROOT
 166 SRC="${BUILDAREA}/usr/src";             export SRC
 167 TOOLS_PROTO="${SRC}/tools/proto/root_${MACH}-nd";       export TOOLS_PROTO
 168 PKGARCHIVE="${BUILDAREA}/packages/${MACH}";     export PKGARCHIVE
 169 UT_NO_USAGE_TRACKING="1";               export UT_NO_USAGE_TRACKING
 170 RPCGEN=/usr/bin/rpcgen;                 export RPCGEN
 171 TMPDIR=/tmp;                            export TMPDIR
 172 ONBLD_ROOT=/tmp/opt/onbld;              export ONBLD_ROOT
 173 STABS=${ONBLD_ROOT}/bin/sparc/stabs;    export STABS
 174 CTFSTABS=${ONBLD_ROOT}/bin/${MACH}/ctfstabs;     export CTFSTABS
 175 CTFCONVERT=${ONBLD_ROOT}/bin/${MACH}/ctfconvert; export CTFCONVERT
 176 CTFCVTPTBL=${ONBLD_ROOT}/bin/ctfcvtptbl;         export CTFCVTPTBL
 177 CTFFINDMOD=${ONBLD_ROOT}/bin/ctffindmod;         export CTFFINDMOD
 178 CTFMERGE=${ONBLD_ROOT}/bin/${MACH}/ctfmerge;     export CTFMERGE
 179 ENVLDLIBS1=
 180 ENVLDLIBS2=
 181 ENVLDLIBS3=
 182 ENVCPPFLAGS1=
 183 ENVCPPFLAGS2=
 184 ENVCPPFLAGS3=
 185 ENVCPPFLAGS4=
 186 export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4
 187 unset RELEASE RELEASE_DATE
 188 
 189 ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
 190 ENVCPPFLAGS1="-I$ROOT/usr/include"
 191 
 192 export ENVLDLIBS1 ENVLDLIBS2
 193 
 194 export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
 195 export RELEASE_BUILD ; RELEASE_BUILD=
 196 unset EXTRA_OPTIONS
 197 unset EXTRA_CFLAGS
 198 
 199 if [ "${DEBUGFLAG}" = "y" ]; then
 200         unset RELEASE_BUILD
 201 fi
 202 
 203 unset CFLAGS LD_LIBRARY_PATH LD_OPTIONS
 204 
 205 PATH="/opt/SUNWspro/bin:/usr/ccs/bin:/usr/bin:/usr/sbin"
 206 export PATH
 207 
 208 if [ -z "${ROOT}" ]; then
 209         echo "ROOT must be set - aborting."
 210         exit 1
 211 fi
 212 
 213 if [ -z "${PKGARCHIVE}" ]; then
 214         echo "PKGARCHIVE must be set - aborting."
 215         exit 1
 216 fi
 217 
 218 if [ -d "${BUILDAREA}" ]; then
 219         if [ -z "${EXPORT_CPIO}" ]; then
 220                 # clobber doesn't work on the free source product,
 221                 # since it will destroy the preinstalled object modules
 222                 # so we just comment it out for now
 223                 echo "\n==== Not clobbering in ${BUILDAREA} ====\n"
 224                 #echo "\n==== Clobbering in ${BUILDAREA} ====\n"
 225                 #cd $SRC
 226                 #rm -f clobber.out
 227                 #/bin/time ${MAKE} -e clobber | tee -a clobber.out
 228                 #find . -name SCCS -prune -o \
 229                 #    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
 230                 #    -name '*.o' \) \
 231                 #    -exec rm -f {} \;
 232 
 233         else
 234                 echo "\n==== Removing ${BUILDAREA} ====\n"
 235                 sleep 15
 236                 rm -rf ${BUILDAREA}
 237         fi
 238 fi
 239 
 240 if [ -d "${ROOT}" ]; then
 241         echo "\n==== Removing ${ROOT} ====\n"
 242         sleep 15
 243         rm -rf ${ROOT}
 244 fi
 245 
 246 if [ -d "${PKGARCHIVE}" ]; then
 247         echo "\n==== Removing ${PKGARCHIVE} ====\n"
 248         sleep 15
 249         rm -rf ${PKGARCHIVE}
 250 fi
 251 
 252 mkdir -p ${BUILDAREA}
 253 
 254 cd ${BUILDAREA}
 255 
 256 if [ ! -z "${EXPORT_CPIO}" ]; then
 257         echo "\n==== Extracting export source ====\n"
 258         zcat ${EXPORT_CPIO} | cpio -idmucB
 259 fi
 260 
 261 # hack
 262 if [ -d usr/src/cmd/sendmail ]; then
 263         VERSION="Source"
 264 else
 265         VERSION="MODIFIED_SOURCE_PRODUCT"
 266 fi
 267 
 268 if [ ! -z "${CRYPT_CPIO}" -a -f "${CRYPT_CPIO}" ]; then
 269         echo "\n==== Extracting crypt source ====\n"
 270         zcat ${CRYPT_CPIO} | cpio -idmucB
 271         VERSION="Source:Crypt"
 272         echo "\n==== Performing crypt build ====\n"
 273 elif [ ! -z "${BINARY_CPIO}" -a -f "${BINARY_CPIO}" ]; then
 274         echo "\n==== Extracting binary modules ====\n"
 275         zcat ${BINARY_CPIO} | cpio -idmucB
 276         VERSION="MODIFIED_SOURCE_PRODUCT"
 277         echo "\n==== Performing hybrid build ====\n"
 278 else
 279         VERSION="Source:Export"
 280         echo "\n==== Performing export build ====\n"
 281 fi
 282 export VERSION
 283 
 284 echo "\n==== Disk space used (Source) ====\n"
 285 
 286 cd ${BUILDAREA}
 287 /usr/bin/du -s -k usr
 288 
 289 mkdir -p ${ROOT}
 290 mkdir -p ${PKGARCHIVE}
 291 
 292 echo "\n==== Building osnet tools ====\n"
 293 rm -rf /tmp/opt
 294 cd $SRC/tools;
 295 rm -f install.out
 296 export BUILD_TOOLS=/tmp/opt
 297 /bin/time env TOOLS_PROTO=/tmp ${MAKE} -e install | tee -a install.out
 298 PATH="${ONBLD_ROOT}/bin:${ONBLD_ROOT}/bin/${MACH}:$PATH"
 299 export PATH
 300 
 301 echo "\n==== Build environment ====\n"
 302 env
 303 
 304 if [ "${DEBUGFLAG}" = "y" ]; then
 305         echo "\n==== Building osnet (DEBUG) ====\n"
 306 else
 307         echo "\n==== Building osnet ====\n"
 308 fi
 309 
 310 cd $SRC
 311 rm -f install.out
 312 /bin/time ${MAKE} -e install | tee -a install.out
 313 
 314 echo "\n==== Build errors ====\n"
 315 
 316 egrep ":" install.out | \
 317         egrep -e "(${MAKE}:|[   ]error[:        \n])" | \
 318         egrep -v warning
 319 
 320 echo "\n==== Building osnet packages ====\n"
 321 cd $SRC/pkg
 322 rm -f install.out
 323 /bin/time ${MAKE} -e install | tee -a install.out
 324 
 325 echo "\n==== Package build errors ====\n"
 326 
 327 egrep "${MAKE}|ERROR|WARNING" $SRC/pkg/install.out | \
 328         grep ':' | \
 329         grep -v PSTAMP
 330 
 331 echo "\n==== Disk space used (Source/Build/Packages) ====\n"
 332 
 333 cd ${BUILDAREA}
 334 /usr/bin/du -s -k usr proto packages
 335 
 336 #
 337 # Copy packages into /pkgs location 
 338 #
 339 if [ "${PKGCPFLAG}" = "y" ]; then
 340         echo "\n==== Copying newly built packages into /pkgs ====\n"
 341         mkdir -p /pkgs
 342         cp -rf $PKGARCHIVE/* /pkgs
 343 fi