1 #! /usr/bin/ksh -p
   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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  25 #
  26 # Create an encumbered binaries tarball from a full build proto area,
  27 # less the contents of an OpenSolaris proto area.
  28 #
  29 
  30 usage="bindrop [-n] basename"
  31 
  32 isa=`uname -p`
  33 
  34 PATH="$PATH:/usr/bin:/usr/sfw/bin"
  35 
  36 function fail {
  37         print -u2 "bindrop: $@"
  38         exit 1
  39 }
  40 
  41 function warn {
  42         print -u2 "bindrop: warning: $@"
  43 }
  44 
  45 [[ -n "$SRC" ]] || fail "SRC must be set."
  46 [[ -n "$CODEMGR_WS" ]] || fail "CODEMGR_WS must be set."
  47 
  48 #
  49 # Create the README from boilerplate and the contents of the closed
  50 # binary tree.
  51 #
  52 # usage: mkreadme targetdir
  53 #
  54 function mkreadme {
  55         typeset targetdir="$1"
  56         typeset readme="README.ON-BINARIES.$isa"
  57 
  58         sed -e s/@ISA@/$isa/ -e s/@DELIVERY@/ON-BINARIES/ \
  59             "$SRC/tools/opensolaris/README.binaries.tmpl" > "$targetdir/$readme"
  60         (cd "$targetdir"; find "$rootdir" -type f -print | \
  61             sort >> "$targetdir/$readme")
  62 }
  63 
  64 nondebug=n
  65 while getopts n flag; do
  66         case $flag in
  67         n)
  68                 nondebug=y
  69                 ;;
  70         ?)
  71                 print -u2 "usage: $usage"
  72                 exit 1
  73                 ;;
  74         esac
  75 done
  76 shift $(($OPTIND - 1))
  77 
  78 if [[ $# -ne 1 ]]; then
  79         print -u2 "usage: $usage"
  80         exit 1
  81 fi
  82 
  83 tarfile="$CODEMGR_WS/$1.$isa.tar"
  84 
  85 rootdir="root_$isa"
  86 suffix=""
  87 if [[ "$nondebug" = y ]]; then
  88         rootdir="root_$isa-nd"
  89         suffix="-nd"
  90 fi
  91 
  92 [[ -d "${ROOT}${suffix}-closed" ]] || fail "can't find closed root proto area."
  93 
  94 tmpdir=$(mktemp -dt bindropXXXXX)
  95 [[ -n "$tmpdir" ]] || fail "can't create temporary directory."
  96 mkdir -p "$tmpdir/closed/$rootdir" || exit 1
  97 
  98 #
  99 # This will hold a temp list of directories that must be kept, even if
 100 # empty.
 101 #
 102 needdirs=$(mktemp -t needdirsXXXXX)
 103 [[ -n "$needdirs" ]] || fail "can't create temporary directory list file."
 104 
 105 #
 106 # Copy the closed root parallel tree into a temp directory.
 107 #
 108 (cd "${ROOT}${suffix}-closed"; tar cf - .) | (cd "$tmpdir/closed/$rootdir"; tar xpf -)
 109 
 110 #
 111 # Remove miscellaneous files that we don't want to ship.
 112 #
 113 
 114 # SUNWsvvs (SVVS test drivers).
 115 delete="
 116         usr/include/sys/svvslo.h
 117         usr/include/sys/tidg.h
 118         usr/include/sys/tivc.h
 119         usr/include/sys/tmux.h
 120         usr/kernel/drv/amd64/svvslo
 121         usr/kernel/drv/amd64/tidg
 122         usr/kernel/drv/amd64/tivc
 123         usr/kernel/drv/amd64/tmux
 124         usr/kernel/drv/sparcv9/svvslo
 125         usr/kernel/drv/sparcv9/tidg
 126         usr/kernel/drv/sparcv9/tivc
 127         usr/kernel/drv/sparcv9/tmux
 128         usr/kernel/drv/svvslo
 129         usr/kernel/drv/svvslo.conf
 130         usr/kernel/drv/tidg
 131         usr/kernel/drv/tidg.conf
 132         usr/kernel/drv/tivc
 133         usr/kernel/drv/tivc.conf
 134         usr/kernel/drv/tmux
 135         usr/kernel/drv/tmux.conf
 136         usr/kernel/strmod/amd64/lmodb
 137         usr/kernel/strmod/amd64/lmode
 138         usr/kernel/strmod/amd64/lmodr
 139         usr/kernel/strmod/amd64/lmodt
 140         usr/kernel/strmod/lmodb
 141         usr/kernel/strmod/lmode
 142         usr/kernel/strmod/lmodr
 143         usr/kernel/strmod/lmodt
 144         usr/kernel/strmod/sparcv9/lmodb
 145         usr/kernel/strmod/sparcv9/lmode
 146         usr/kernel/strmod/sparcv9/lmodr
 147         usr/kernel/strmod/sparcv9/lmodt
 148 "
 149 # encumbered binaries and associated files
 150 delete="$delete
 151         kernel/drv/amd64/bmc
 152         kernel/drv/bmc
 153         kernel/drv/bmc.conf
 154         kernel/drv/ifp.conf
 155         kernel/drv/sparcv9/ifp
 156         kernel/drv/sparcv9/isp
 157         kernel/drv/sparcv9/qus
 158         kernel/drv/spwr
 159         kernel/kmdb/sparcv9/isp
 160         usr/has/bin/ksh
 161         usr/has/bin/pfksh
 162         usr/has/bin/rksh
 163         usr/include/sys/scsi/adapters/ifpcmd.h
 164         usr/include/sys/scsi/adapters/ifpio.h
 165         usr/include/sys/scsi/adapters/ifpmail.h
 166         usr/include/sys/scsi/adapters/ifpreg.h
 167         usr/include/sys/scsi/adapters/ifpvar.h
 168         usr/include/sys/scsi/adapters/ispcmd.h
 169         usr/include/sys/scsi/adapters/ispmail.h
 170         usr/include/sys/scsi/adapters/ispreg.h
 171         usr/include/sys/scsi/adapters/ispvar.h
 172         usr/lib/mdb/kvm/sparcv9/isp.so
 173         usr/platform/sun4u/include/sys/memtestio.h
 174         usr/platform/sun4u/include/sys/memtestio_ch.h
 175         usr/platform/sun4u/include/sys/memtestio_chp.h
 176         usr/platform/sun4u/include/sys/memtestio_ja.h
 177         usr/platform/sun4u/include/sys/memtestio_jg.h
 178         usr/platform/sun4u/include/sys/memtestio_sf.h
 179         usr/platform/sun4u/include/sys/memtestio_sr.h
 180         usr/platform/sun4u/include/sys/memtestio_u.h
 181         usr/platform/sun4u/include/sys/memtestio_pn.h
 182         usr/platform/sun4v/include/sys/memtestio.h
 183         usr/platform/sun4v/include/sys/memtestio_ni.h
 184         usr/platform/sun4v/include/sys/memtestio_v.h
 185 "
 186 # memory fault injector test framework
 187 delete="$delete
 188         usr/bin/mtst
 189         platform/sun4u/kernel/drv/sparcv9/memtest
 190         platform/sun4u/kernel/drv/memtest.conf
 191         platform/sun4v/kernel/drv/sparcv9/memtest
 192         platform/sun4v/kernel/drv/memtest.conf
 193         kernel/drv/memtest.conf
 194         kernel/drv/memtest
 195         kernel/drv/amd64/memtest
 196         usr/platform/i86pc/lib/mtst/mtst_AuthenticAMD_15.so
 197         usr/platform/i86pc/lib/mtst/mtst_AuthenticAMD.so
 198         usr/platform/i86pc/lib/mtst/mtst_generic.so
 199         usr/platform/i86pc/lib/mtst/mtst_GenuineIntel.so
 200 "
 201 for f in $delete; do
 202         rm -rf "$tmpdir/closed/$rootdir/$f"
 203 done
 204 
 205 #
 206 # Remove any header files.  If they're in the closed tree, they're
 207 # probably not freely redistributable.
 208 #
 209 (cd "$tmpdir/closed/$rootdir"; find . -name \*.h \
 210         -a \! -name lc_core.h \
 211         -a \! -name localedef.h \
 212         -exec rm -f {} \;)
 213 
 214 #
 215 # Remove empty directories that the open tree doesn't need.
 216 #
 217 # Step 1: walk the redistributable manifests to find out which directories
 218 # are specified in the open packages; save that list to a temporary
 219 # file $needdirs.
 220 #
 221 MACH=$(uname -p)
 222 (cd "$SRC/pkg/packages.$MACH"; \
 223         nawk '/^dir/ {sub(/.+ path=/, ""); print $1;}' *.metadata.*.redist | \
 224         sort -u > "$needdirs")
 225 
 226 #
 227 # Step 2: go to our closed directory, and find all the subdirectories,
 228 # filtering out the ones needed by the open packages (saved in that
 229 # temporary file).  Sort in reverse order, so that parent directories
 230 # come after any subdirectories, and pipe that to rmdir.  If there are
 231 # still any lingering files, rmdir will complain.  That's fine--we
 232 # only want to delete empty directories--so redirect the complaints to
 233 # /dev/null.
 234 #
 235 (cd "$tmpdir/closed/$rootdir"; \
 236         find * -type d -print | /usr/xpg4/bin/grep -xv -f $needdirs | \
 237         sort -r | xargs -l rmdir 2>/dev/null )
 238 
 239 rm "$needdirs"
 240 
 241 #
 242 # Add binary license files.
 243 #
 244 
 245 cp -p "$SRC/tools/opensolaris/BINARYLICENSE.txt" "$tmpdir/closed" || \
 246     fail "can't add BINARYLICENSE.txt"
 247 mkreadme "$tmpdir/closed"
 248 if [ -f "$CODEMGR_WS/THIRDPARTYLICENSE.ON-BINARIES" ]; then
 249     cp -p "$CODEMGR_WS/THIRDPARTYLICENSE.ON-BINARIES" "$tmpdir/closed"
 250 fi
 251 
 252 (cd "$tmpdir"; tar cf "$tarfile" closed) || fail "can't create $tarfile."
 253 bzip2 -f "$tarfile" || fail "can't compress $tarfile".
 254 
 255 rm -rf "$tmpdir"
 256 
 257 exit 0