Home | History | Annotate | Download | only in scripts
      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, Version 1.0 only
      7 # (the "License").  You may not use this file except in compliance
      8 # with the License.
      9 #
     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.
     14 #
     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]
     20 #
     21 # CDDL HEADER END
     22 #
     23 #
     24 # Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
     25 # Use is subject to license terms.
     26 #
     27 # ident	"%Z%%M%	%I%	%E% SMI"
     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 PKGARCHIVE="${BUILDAREA}/packages/${MACH}";	export PKGARCHIVE
    168 UT_NO_USAGE_TRACKING="1";		export UT_NO_USAGE_TRACKING
    169 RPCGEN=/usr/bin/rpcgen;			export RPCGEN
    170 TMPDIR=/tmp;				export TMPDIR
    171 ONBLD_ROOT=/tmp/opt/onbld;		export ONBLD_ROOT
    172 STABS=${ONBLD_ROOT}/bin/sparc/stabs;	export STABS
    173 CTFSTABS=${ONBLD_ROOT}/bin/${MACH}/ctfstabs;	 export CTFSTABS
    174 CTFCONVERT=${ONBLD_ROOT}/bin/${MACH}/ctfconvert; export CTFCONVERT
    175 CTFCVTPTBL=${ONBLD_ROOT}/bin/ctfcvtptbl;	 export CTFCVTPTBL
    176 CTFFINDMOD=${ONBLD_ROOT}/bin/ctffindmod;	 export CTFFINDMOD
    177 CTFMERGE=${ONBLD_ROOT}/bin/${MACH}/ctfmerge;	 export CTFMERGE
    178 ENVLDLIBS1=
    179 ENVLDLIBS2=
    180 ENVLDLIBS3=
    181 ENVCPPFLAGS1=
    182 ENVCPPFLAGS2=
    183 ENVCPPFLAGS3=
    184 ENVCPPFLAGS4=
    185 export ENVLDLIBS3 ENVCPPFLAGS1 ENVCPPFLAGS2 ENVCPPFLAGS3 ENVCPPFLAGS4
    186 unset RELEASE RELEASE_DATE
    187 
    188 ENVLDLIBS1="-L$ROOT/lib -L$ROOT/usr/lib"
    189 ENVCPPFLAGS1="-I$ROOT/usr/include"
    190 
    191 export ENVLDLIBS1 ENVLDLIBS2
    192 
    193 export INTERNAL_RELEASE_BUILD ; INTERNAL_RELEASE_BUILD=
    194 export RELEASE_BUILD ; RELEASE_BUILD=
    195 unset EXTRA_OPTIONS
    196 unset EXTRA_CFLAGS
    197 
    198 if [ "${DEBUGFLAG}" = "y" ]; then
    199 	unset RELEASE_BUILD
    200 fi
    201 
    202 unset CFLAGS LD_LIBRARY_PATH LD_OPTIONS
    203 
    204 PATH="/opt/SUNWspro/bin:/usr/ccs/bin:/usr/bin:/usr/sbin"
    205 export PATH
    206 
    207 if [ -z "${ROOT}" ]; then
    208 	echo "ROOT must be set - aborting."
    209 	exit 1
    210 fi
    211 
    212 if [ -z "${PKGARCHIVE}" ]; then
    213 	echo "PKGARCHIVE must be set - aborting."
    214 	exit 1
    215 fi
    216 
    217 if [ -d "${BUILDAREA}" ]; then
    218 	if [ -z "${EXPORT_CPIO}" ]; then
    219 		# clobber doesn't work on the free source product,
    220 		# since it will destroy the preinstalled object modules
    221 		# so we just comment it out for now
    222 		echo "\n==== Not clobbering in ${BUILDAREA} ====\n"
    223 		#echo "\n==== Clobbering in ${BUILDAREA} ====\n"
    224 		#cd $SRC
    225 		#rm -f clobber.out
    226 		#/bin/time ${MAKE} -e clobber | tee -a clobber.out
    227 		#find . -name SCCS -prune -o \
    228 		#    \( -name '.make.*' -o -name 'lib*.a' -o -name 'lib*.so*' -o \
    229 		#    -name '*.o' \) \
    230 		#    -exec rm -f {} \;
    231 
    232 	else
    233 		echo "\n==== Removing ${BUILDAREA} ====\n"
    234 		sleep 15
    235 		rm -rf ${BUILDAREA}
    236 	fi
    237 fi
    238 
    239 if [ -d "${ROOT}" ]; then
    240 	echo "\n==== Removing ${ROOT} ====\n"
    241 	sleep 15
    242 	rm -rf ${ROOT}
    243 fi
    244 
    245 if [ -d "${PKGARCHIVE}" ]; then
    246 	echo "\n==== Removing ${PKGARCHIVE} ====\n"
    247 	sleep 15
    248 	rm -rf ${PKGARCHIVE}
    249 fi
    250 
    251 mkdir -p ${BUILDAREA}
    252 
    253 cd ${BUILDAREA}
    254 
    255 if [ ! -z "${EXPORT_CPIO}" ]; then
    256 	echo "\n==== Extracting export source ====\n"
    257 	zcat ${EXPORT_CPIO} | cpio -idmucB
    258 fi
    259 
    260 # hack
    261 if [ -d usr/src/cmd/sendmail ]; then
    262 	VERSION="Source"
    263 else
    264 	VERSION="MODIFIED_SOURCE_PRODUCT"
    265 fi
    266 
    267 if [ ! -z "${CRYPT_CPIO}" -a -f "${CRYPT_CPIO}" ]; then
    268 	echo "\n==== Extracting crypt source ====\n"
    269 	zcat ${CRYPT_CPIO} | cpio -idmucB
    270 	VERSION="Source:Crypt"
    271 	echo "\n==== Performing crypt build ====\n"
    272 elif [ ! -z "${BINARY_CPIO}" -a -f "${BINARY_CPIO}" ]; then
    273 	echo "\n==== Extracting binary modules ====\n"
    274 	zcat ${BINARY_CPIO} | cpio -idmucB
    275 	VERSION="MODIFIED_SOURCE_PRODUCT"
    276 	echo "\n==== Performing hybrid build ====\n"
    277 else
    278 	VERSION="Source:Export"
    279 	echo "\n==== Performing export build ====\n"
    280 fi
    281 export VERSION
    282 
    283 echo "\n==== Disk space used (Source) ====\n"
    284 
    285 cd ${BUILDAREA}
    286 /usr/bin/du -s -k usr
    287 
    288 mkdir -p ${ROOT}
    289 mkdir -p ${PKGARCHIVE}
    290 
    291 echo "\n==== Building osnet tools ====\n"
    292 rm -rf /tmp/opt
    293 cd $SRC/tools;
    294 rm -f install.out
    295 export BUILD_TOOLS=/tmp/opt
    296 /bin/time env TOOLS_PROTO=/tmp ${MAKE} -e install | tee -a install.out
    297 PATH="${ONBLD_ROOT}/bin:${ONBLD_ROOT}/bin/${MACH}:$PATH"
    298 export PATH
    299 
    300 echo "\n==== Build environment ====\n"
    301 env
    302 
    303 if [ "${DEBUGFLAG}" = "y" ]; then
    304 	echo "\n==== Building osnet (DEBUG) ====\n"
    305 else
    306 	echo "\n==== Building osnet ====\n"
    307 fi
    308 
    309 cd $SRC
    310 rm -f install.out
    311 /bin/time ${MAKE} -e install | tee -a install.out
    312 
    313 echo "\n==== Build errors ====\n"
    314 
    315 egrep ":" install.out | \
    316 	egrep -e "(${MAKE}:|[ 	]error[: 	\n])" | \
    317 	egrep -v warning
    318 
    319 echo "\n==== Building osnet packages ====\n"
    320 cd $SRC/pkgdefs
    321 rm -f install.out
    322 /bin/time ${MAKE} -e install | tee -a install.out
    323 
    324 echo "\n==== Package build errors ====\n"
    325 
    326 egrep "${MAKE}|ERROR|WARNING" $SRC/pkgdefs/install.out | \
    327 	grep ':' | \
    328 	grep -v PSTAMP
    329 
    330 echo "\n==== Disk space used (Source/Build/Packages) ====\n"
    331 
    332 cd ${BUILDAREA}
    333 /usr/bin/du -s -k usr proto packages
    334 
    335 #
    336 # Copy packages into /pkgs location 
    337 #
    338 if [ "${PKGCPFLAG}" = "y" ]; then
    339 	echo "\n==== Copying newly built packages into /pkgs ====\n"
    340 	mkdir -p /pkgs
    341 	cp -rf $PKGARCHIVE/* /pkgs
    342 fi
    343