1 #!/bin/ksh
   2 #
   3 # This file and its contents are supplied under the terms of the
   4 # Common Development and Distribution License ("CDDL"), version 1.0.
   5 # You may only use this file in accordance with the terms of version
   6 # 1.0 of the CDDL.
   7 #
   8 # A full copy of the text of the CDDL should have accompanied this
   9 # source.  A copy of the CDDL is also available via the Internet at
  10 # http://www.illumos.org/license/CDDL.
  11 #
  12 
  13 #
  14 # Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
  15 #
  16 
  17 # Use distributed make (dmake) by default.
  18 make=${MAKE:-dmake}
  19 
  20 CLOSED_IS_PRESENT=no
  21 export CLOSED_IS_PRESENT
  22 
  23 # Do this if you want to use dbx or gdb
  24 # export SOURCEDEBUG=yes
  25 
  26 [ -n "$SRC" ] || {
  27   echo "SRC not set.  Run 'ws' or 'bldenv' first."
  28   exit 1
  29 }
  30 
  31 cpu=`uname -p`
  32 case $cpu in
  33 i386)
  34         x=intel
  35         kmdb_arch="amd64"
  36         mdb_arch="ia32 amd64"
  37         arch64=amd64
  38         ;;
  39 sparc)
  40         x=sparc
  41         kmdb_arch=v9
  42         mdb_arch="v7 v9"
  43         arch64=sparcv9
  44         ;;
  45 *)  echo "Huh?" ; exit 1;;
  46 esac
  47 
  48 ################################################################
  49 
  50 build_tools() {
  51   test -f $SRC/tools/proto/root_i386-nd/opt/onbld/bin/genoffsets ||
  52     (cd $SRC/tools && $make install)
  53   (cd $SRC/common/mapfiles; $make install)
  54 }
  55 
  56 clobber_tools() {
  57   (cd $SRC/tools && $make clobber)
  58   (cd $SRC/common/mapfiles; $make clobber)
  59 }
  60 
  61 ################################################################
  62 
  63 do_hdrs() {
  64 
  65 targ=$1
  66 if [ "$targ" = clobber ]
  67 then
  68   (cd $SRC/uts && $make -k clobber_h)
  69   (cd $SRC/head && $make clobber)
  70 fi
  71 
  72 if [ "$targ" = install ]
  73 then
  74   targ=install_h
  75 
  76   # Just the parts of "make sgs" we need, and
  77   # skip them if they appear to be done.
  78   # ... stuff under $SRC
  79   test -f $SRC/uts/common/sys/priv_names.h ||
  80     (cd $SRC/uts && $make -k all_h)
  81 
  82   test -f $SRC/head/rpcsvc/nispasswd.h ||
  83     (cd $SRC/head && $make -k install_h)
  84 
  85   # ... stuff under $ROOT (proto area)
  86   test -d $ROOT/usr/include/sys ||
  87     (cd $SRC && $make rootdirs)
  88   test -f $ROOT/usr/include/sys/types.h ||
  89     (cd $SRC/uts && $make -k install_h)
  90   test -f $ROOT/usr/include/rpcsvc/daemon_utils.h ||
  91     (cd $SRC/head && $make install_h)
  92 
  93   # always update the netsmb headers to be safe
  94   (cd $SRC/uts/common/sys && $make -k install_h)
  95 
  96 fi
  97 
  98 # Need some library headers too...
  99 for lib in \
 100   libcryptoutil \
 101   libpam \
 102   libsec \
 103   libshare \
 104   libsmbfs \
 105   passwdutil
 106 do
 107   (cd $SRC/lib/$lib && $make $targ)
 108 done
 109 }
 110 
 111 ################################################################
 112 
 113 do_kern() {
 114   case $1 in
 115   lint) targ=modlintlib ;;
 116   *) targ=$1 ;;
 117   esac
 118   ( unset SOURCEDEBUG ;
 119   (cd $SRC/uts/$x/nsmb && $make $targ) ;
 120   (cd $SRC/uts/$x/smbfs && $make $targ) )
 121 }
 122 
 123 ################################################################
 124 
 125 # Note lib1 builds prerequisite libraries not delivered by the
 126 # tar file we create below.  To accelerate clean/install, we
 127 # skip these on clean (but still nuke them for clobber)
 128 
 129 do_lib1() {
 130   :
 131 }
 132 
 133 # lib2 builds stuff we include in the tar file,
 134 # or that we don't mind rebuilding after clean.
 135 
 136 do_lib2() {
 137 
 138 (cd $SRC/lib/libsmbfs && $make $1)
 139 [ "$1" = install ] &&
 140   (cd $SRC/lib/libsmbfs && $make _msg)
 141 (cd $SRC/lib/libmlrpc && $make $1)
 142 (cd $SRC/lib/libshare && $make $1 PLUGINS=smbfs)
 143 (cd $SRC/lib/passwdutil && $make $1)
 144 (cd $SRC/lib/pam_modules/smbfs && $make $1)
 145 
 146 }
 147 
 148 ################################################################
 149 
 150 do_cmds() {
 151 
 152 case $1 in
 153 install)
 154   # mount programs need fslib.o
 155   (cd $SRC/cmd/fs.d && $make fslib.o)
 156   (cd $SRC/cmd/fs.d/smbclnt && $make $1 catalog)
 157   ;;
 158 clean|clobber)
 159   (cd $SRC/cmd/fs.d/smbclnt && $make $1)
 160   (cd $SRC/cmd/fs.d && $make ${1}_local)
 161   ;;
 162 esac
 163 
 164 # Build the MDB modules, WITH the linktest
 165 (cd $SRC/cmd/mdb/tools && $make $1)
 166 
 167 # kmdb_arch is 64-bit only
 168 for a in $kmdb_arch
 169 do
 170   case $1 in
 171   install|lint)
 172     (cd $SRC/cmd/mdb/$x/$a/kmdb &&
 173         $make kmdb_modlinktest.o )
 174     ;;
 175   clean|clobber)
 176     (cd $SRC/cmd/mdb/$x/$a/kmdb &&
 177         $make -k $1 )
 178     ;;
 179   esac
 180 
 181   (cd $SRC/cmd/mdb/$x/$a/nsmb &&
 182         $make $1 KMDB_LINKTEST_ENABLE= )
 183   (cd $SRC/cmd/mdb/$x/$a/smbfs &&
 184         $make $1 KMDB_LINKTEST_ENABLE= )
 185 done
 186 }
 187 
 188 
 189 ################################################################
 190 # This builds $SRC/TAGS (and cscope.files) in a helpful order.
 191 
 192 do_tags() {
 193         (cd $SRC ;
 194         find uts/common/sys -name '*.[ch]' -print |sort
 195         find uts/common/net -name '*.[ch]' -print |sort
 196         find uts/common/netinet -name '*.[ch]' -print |sort
 197         find uts/common/smb -name '*.[ch]' -print |sort
 198         find uts/common/netsmb -name '*.[ch]' -print |sort
 199         find uts/common/fs/smbclnt -name '*.[ch]' -print |sort
 200         find head -name '*.h' -print |sort
 201         find lib/libsmbfs -name '*.[ch]' -print |sort
 202         find cmd/fs.d/smbclnt -name '*.[ch]' -print |sort
 203         find common/smbclnt -name '*.[ch]' -print |sort
 204         ) > $SRC/cscope.files
 205 
 206         (cd $SRC ;
 207         exctags -e --langmap=c:+.ndl -h ndl -L - < cscope.files
 208         cscope -b )
 209 }
 210 
 211 ################################################################
 212 # This creates a tarfile one can use to update a test machine.
 213 
 214 do_tar() {
 215         git_rev=`git rev-parse --short=8 HEAD`
 216         files="
 217 lib/svc/manifest/network/smb/client.xml
 218 lib/svc/method/smb-client
 219 opt/smbcl-tests/tests/srvenum
 220 opt/smbcl-tests/tests/srvinfo
 221 opt/smbcl-tests/tests/tconn
 222 usr/bin/smbutil
 223 usr/kernel/drv/$arch64/nsmb
 224 usr/kernel/fs/$arch64/smbfs
 225 usr/kernel/kmdb/$arch64/nsmb
 226 usr/kernel/kmdb/$arch64/smbfs
 227 usr/lib/$arch64/libsmbfs.so.1
 228 usr/lib/fs/smbfs/$arch64/libshare_smbfs.so.1
 229 usr/lib/fs/smbfs/chacl
 230 usr/lib/fs/smbfs/dfshares
 231 usr/lib/fs/smbfs/libshare_smbfs.so.1
 232 usr/lib/fs/smbfs/lsacl
 233 usr/lib/fs/smbfs/mount
 234 usr/lib/fs/smbfs/share
 235 usr/lib/fs/smbfs/umount
 236 usr/lib/fs/smbfs/unshare
 237 usr/lib/libmlrpc.so.1
 238 usr/lib/libsmbfs.so.1
 239 usr/lib/mdb/kvm/$arch64/nsmb.so
 240 usr/lib/mdb/kvm/$arch64/smbfs.so
 241 usr/lib/mdb/kvm/nsmb.so
 242 usr/lib/mdb/kvm/smbfs.so
 243 usr/lib/security/$arch64/pam_smbfs_login.so.1
 244 usr/lib/security/pam_smbfs_login.so.1
 245 usr/lib/smbfs/smbiod
 246 usr/lib/smbfs/smbiod-svc
 247 "
 248 
 249         (cd $ROOT && tar cfj ../../smbclnt-${git_rev}.tar.bz2 $files)
 250 }
 251 
 252 ################################################################
 253 
 254 if [ "$1" = "" ]; then
 255   set '?' # force usage
 256 fi
 257 
 258 set -x
 259 
 260 for arg
 261 do
 262   case "$arg" in
 263   install)
 264     build_tools
 265     set -e
 266     do_hdrs $arg
 267     do_kern $arg
 268     do_lib1 $arg
 269     do_lib2 $arg
 270     do_cmds $arg
 271     ;;
 272   lint)
 273     do_kern $arg
 274     do_lib1 $arg
 275     do_lib2 $arg
 276     do_cmds $arg
 277     ;;
 278   clean)
 279     # intentionally skip: lib1, hdrs, tools
 280     do_cmds $arg
 281     do_lib2 $arg
 282     do_kern $arg
 283     ;;
 284   clobber)
 285     do_cmds $arg
 286     do_lib2 $arg
 287     do_lib1 $arg
 288     do_kern $arg
 289     do_hdrs $arg
 290     clobber_tools
 291     ;;
 292   tags)
 293     do_tags
 294     ;;
 295   tar)
 296     do_tar
 297     ;;
 298   *)
 299     echo "Usage: $0 {install|lint|clean|clobber|tags|tar}";
 300     exit 1;
 301     ;;
 302   esac
 303 done