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# 45unset CDPATH 46 47USAGE='build_osnet [-B dir] [-E export_archive ] [-C crypt_archive ] 48 [ -H binary_archive ] [-D] [-P] 49 50where: 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 59BUILDAREA=`pwd` 60EXPORT_CPIO= 61CRYPT_CPIO= 62BINARY_CPIO= 63DEBUGFLAG="n" 64PKGCPFLAG="y" 65 66OPTIND=1 67while getopts B:E:C:H:DP FLAG 68do 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 86done 87 88 89# extract source 90 91# verify you are root 92/usr/bin/id | grep root >/dev/null 2>&1 93if [ "$?" != "0" ]; then 94 echo \"$0\" must be run as root. 95 exit 1 96fi 97 98if [ ! -z "${EXPORT_CPIO}" -a ! -f "${EXPORT_CPIO}" ]; then 99 echo "${EXPORT_CPIO} does not exist - aborting." 100 exit 1 101fi 102 103if [ -z "${BUILDAREA}" ]; then 104 echo "BUILDAREA must be set - aborting." 105 exit 1 106fi 107 108if [ -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 116fi 117 118if [ -z "${JAVA_ROOT}" ]; then 119 echo "JAVA_ROOT is not set - defaulting to /usr/java." 120 JAVA_ROOT=/usr/java; export JAVA_ROOT 121fi 122 123# in case you use dmake. Note that dmake on ON has only been 124# tested in parallel make mode. 125if [ -z "${DMAKE_MAX_JOBS}" ]; then 126 DMAKE_MAX_JOBS=4; 127 export DMAKE_MAX_JOBS 128fi 129DMAKE_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 138MAKE=/usr/ccs/bin/make; export MAKE 139 140# 141# force locale to C 142LC_COLLATE=C; export LC_COLLATE 143LC_CTYPE=C; export LC_CTYPE 144LC_MESSAGES=C; export LC_MESSAGES 145LC_MONETARY=C; export LC_MONETARY 146LC_NUMERIC=C; export LC_NUMERIC 147LC_TIME=C; export LC_TIME 148 149# clear environment variables we know to be bad for the build 150unset LD_OPTIONS LD_LIBRARY_PATH LD_AUDIT LD_BIND_NOW LD_BREADTH LD_CONFIG 151unset LD_DEBUG LD_FLAGS LD_LIBRARY_PATH_64 LD_NOVERSION LD_ORIGIN 152unset LD_LOADFLTR LD_NOAUXFLTR LD_NOCONFIG LD_NODIRCONFIG LD_NOOBJALTER 153unset LD_PRELOAD LD_PROFILE 154unset CONFIG 155unset GROUP 156unset OWNER 157unset REMOTE 158unset ENV 159unset ARCH 160unset CLASSPATH 161 162# set magic variables 163 164MACH=`uname -p`; export MACH 165ROOT="${BUILDAREA}/proto/root_${MACH}"; export ROOT 166SRC="${BUILDAREA}/usr/src"; export SRC 167TOOLS_PROTO="${SRC}/tools/proto/root_${MACH}-nd"; export TOOLS_PROTO 168PKGARCHIVE="${BUILDAREA}/packages/${MACH}"; export PKGARCHIVE 169UT_NO_USAGE_TRACKING="1"; export UT_NO_USAGE_TRACKING 170RPCGEN=/usr/bin/rpcgen; export RPCGEN 171TMPDIR=/tmp; export TMPDIR 172ONBLD_ROOT=/tmp/opt/onbld; export ONBLD_ROOT 173STABS=${ONBLD_ROOT}/bin/sparc/stabs; export STABS 174CTFSTABS=${ONBLD_ROOT}/bin/${MACH}/ctfstabs; export CTFSTABS 175CTFCONVERT=${ONBLD_ROOT}/bin/${MACH}/ctfconvert; export CTFCONVERT 176CTFCVTPTBL=${ONBLD_ROOT}/bin/ctfcvtptbl; export CTFCVTPTBL 177CTFFINDMOD=${ONBLD_ROOT}/bin/ctffindmod; export CTFFINDMOD 178CTFMERGE=${ONBLD_ROOT}/bin/${MACH}/ctfmerge; export CTFMERGE 179ENVLDLIBS1= 180ENVLDLIBS2= 181ENVLDLIBS3= 182ENVCPPFLAGS1= 183ENVCPPFLAGS2= 184ENVCPPFLAGS3= 185ENVCPPFLAGS4= 186export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4 187unset RELEASE RELEASE_DATE 188 189ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib" 190ENVCPPFLAGS1="-I$ROOT/usr/include" 191 192export ENVLDLIBS1 ENVLDLIBS2 193 194export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD= 195export RELEASE_BUILD ; RELEASE_BUILD= 196unset EXTRA_OPTIONS 197unset EXTRA_CFLAGS 198 199if [ "${DEBUGFLAG}" = "y" ]; then 200 unset RELEASE_BUILD 201fi 202 203unset CFLAGS LD_LIBRARY_PATH LD_OPTIONS 204 205PATH="/opt/SUNWspro/bin:/usr/ccs/bin:/usr/bin:/usr/sbin" 206export PATH 207 208if [ -z "${ROOT}" ]; then 209 echo "ROOT must be set - aborting." 210 exit 1 211fi 212 213if [ -z "${PKGARCHIVE}" ]; then 214 echo "PKGARCHIVE must be set - aborting." 215 exit 1 216fi 217 218if [ -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 238fi 239 240if [ -d "${ROOT}" ]; then 241 echo "\n==== Removing ${ROOT} ====\n" 242 sleep 15 243 rm -rf ${ROOT} 244fi 245 246if [ -d "${PKGARCHIVE}" ]; then 247 echo "\n==== Removing ${PKGARCHIVE} ====\n" 248 sleep 15 249 rm -rf ${PKGARCHIVE} 250fi 251 252mkdir -p ${BUILDAREA} 253 254cd ${BUILDAREA} 255 256if [ ! -z "${EXPORT_CPIO}" ]; then 257 echo "\n==== Extracting export source ====\n" 258 zcat ${EXPORT_CPIO} | cpio -idmucB 259fi 260 261# hack 262if [ -d usr/src/cmd/sendmail ]; then 263 VERSION="Source" 264else 265 VERSION="MODIFIED_SOURCE_PRODUCT" 266fi 267 268if [ ! -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" 273elif [ ! -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" 278else 279 VERSION="Source:Export" 280 echo "\n==== Performing export build ====\n" 281fi 282export VERSION 283 284echo "\n==== Disk space used (Source) ====\n" 285 286cd ${BUILDAREA} 287/usr/bin/du -s -k usr 288 289mkdir -p ${ROOT} 290mkdir -p ${PKGARCHIVE} 291 292echo "\n==== Building osnet tools ====\n" 293rm -rf /tmp/opt 294cd $SRC/tools; 295rm -f install.out 296export BUILD_TOOLS=/tmp/opt 297/bin/time env TOOLS_PROTO=/tmp ${MAKE} -e install | tee -a install.out 298PATH="${ONBLD_ROOT}/bin:${ONBLD_ROOT}/bin/${MACH}:$PATH" 299export PATH 300 301echo "\n==== Build environment ====\n" 302env 303 304if [ "${DEBUGFLAG}" = "y" ]; then 305 echo "\n==== Building osnet (DEBUG) ====\n" 306else 307 echo "\n==== Building osnet ====\n" 308fi 309 310cd $SRC 311rm -f install.out 312/bin/time ${MAKE} -e install | tee -a install.out 313 314echo "\n==== Build errors ====\n" 315 316egrep ":" install.out | \ 317 egrep -e "(${MAKE}:|[ ]error[: \n])" | \ 318 egrep -v warning 319 320echo "\n==== Building osnet packages ====\n" 321cd $SRC/pkg 322rm -f install.out 323/bin/time ${MAKE} -e install | tee -a install.out 324 325echo "\n==== Package build errors ====\n" 326 327egrep "${MAKE}|ERROR|WARNING" $SRC/pkg/install.out | \ 328 grep ':' | \ 329 grep -v PSTAMP 330 331echo "\n==== Disk space used (Source/Build/Packages) ====\n" 332 333cd ${BUILDAREA} 334/usr/bin/du -s -k usr proto packages 335 336# 337# Copy packages into /pkgs location 338# 339if [ "${PKGCPFLAG}" = "y" ]; then 340 echo "\n==== Copying newly built packages into /pkgs ====\n" 341 mkdir -p /pkgs 342 cp -rf $PKGARCHIVE/* /pkgs 343fi 344