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 2018 Nexenta Systems, Inc.  All rights reserved.
  15 #
  16 
  17 # Use normal make (not dmake) by default.
  18 make=${MAKE:-make}
  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 $targ)
  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 $targ)
  90   test -f $ROOT/usr/include/rpcsvc/daemon_utils.h ||
  91     (cd $SRC/head && $make $targ)
  92 
  93   # always update the smbsrv headers to be safe
  94   (cd $SRC/uts/common/gssapi && $make -k $targ)
  95   (cd $SRC/uts/common/sys && $make -k $targ)
  96   (cd $SRC/uts/common/smb && $make -k $targ)
  97   (cd $SRC/uts/common/smbsrv && $make -k $targ)
  98   (cd $SRC/uts/common/c2 && $make -k $targ)
  99 fi
 100 
 101 if [ "$targ" = lint ]
 102 then
 103   targ=check
 104   (cd $SRC/uts/common/smb && $make -k $targ)
 105   (cd $SRC/uts/common/smbsrv && $make -k $targ)
 106 fi
 107 
 108 # Need some library headers too...
 109 for lib in \
 110   libads \
 111   libbsm \
 112   libcmdutils \
 113   libcryptoutil \
 114   libdevid \
 115   libfakekernel \
 116   libgss \
 117   libidmap \
 118   libkrb5 \
 119   libmlrpc \
 120   libpam \
 121   libsec \
 122   libscf \
 123   libshare \
 124   libsmbfs \
 125   libsqlite \
 126   libuutil \
 127   libzfs_core \
 128   libzfs \
 129   passwdutil \
 130   pkcs11 \
 131   smbsrv
 132 do
 133   (cd $SRC/lib/$lib && $make $targ)
 134 done
 135 }
 136 
 137 ################################################################
 138 
 139 do_kern() {
 140   case $1 in
 141   lint) targ=modlintlib ;;
 142   *) targ=$1 ;;
 143   esac
 144   ( unset SOURCEDEBUG ;
 145   (cd $SRC/uts/$x/nsmb && $make $targ) ;
 146   (cd $SRC/uts/$x/smbfs && $make $targ) ;
 147   (cd $SRC/uts/$x/smbsrv && $make $targ) )
 148 }
 149 
 150 ################################################################
 151 
 152 # Note lib1 builds prerequisite libraries not delivered by the
 153 # tar file we create below.  To accelerate clean/install, we
 154 # skip these on clean (but still nuke them for clobber)
 155 
 156 do_lib1() {
 157 
 158 for lib in \
 159   libavl \
 160   libgss \
 161   libkrb5 \
 162   libcmdutils \
 163   libsqlite \
 164   libuutil
 165 do
 166   (cd $SRC/lib/$lib && $make $1)
 167 done
 168 }
 169 
 170 # lib2 builds stuff we include in the tar file,
 171 # or that we don't mind rebuilding after clean.
 172 
 173 do_lib2() {
 174 
 175 for lib in \
 176   libfakekernel \
 177   libads \
 178   libsmbfs \
 179   libmlrpc
 180 do
 181   (cd $SRC/lib/$lib && $make $1)
 182 done
 183 
 184 (cd $SRC/lib/libshare && $make $1 PLUGINS=smb)
 185 (cd $SRC/lib/smbsrv && $make $1)
 186 (cd $SRC/lib/passwdutil && $make $1)
 187 (cd $SRC/lib/pam_modules/smb && $make $1)
 188 
 189 }
 190 
 191 ################################################################
 192 
 193 do_cmds() {
 194 
 195 case $1 in
 196 install)
 197   # mount programs need fslib.o
 198   (cd $SRC/cmd/fs.d && $make fslib.o)
 199   ;;
 200 clean|clobber)
 201   (cd $SRC/cmd/fs.d && $make ${1}_local)
 202   ;;
 203 esac
 204 
 205 (cd $SRC/cmd/smbsrv && $make $1)
 206 
 207 # Build the MDB modules, WITH the linktest
 208 (cd $SRC/cmd/mdb/tools && $make $1)
 209 
 210 # kmdb_arch is 64-bit only
 211 for a in $kmdb_arch
 212 do
 213   case $1 in
 214   install|lint)
 215     (cd $SRC/cmd/mdb/$x/$a/kmdb &&
 216         $make kmdb_modlinktest.o )
 217     ;;
 218   clean|clobber)
 219     (cd $SRC/cmd/mdb/$x/$a/kmdb &&
 220         $make -k $1 )
 221     ;;
 222   esac
 223   (cd $SRC/cmd/mdb/$x/$a/nsmb &&
 224         $make $1 KMDB_LINKTEST_ENABLE= )
 225   (cd $SRC/cmd/mdb/$x/$a/smbfs &&
 226         $make $1 KMDB_LINKTEST_ENABLE= )
 227   (cd $SRC/cmd/mdb/$x/$a/smbsrv &&
 228         $make $1 KMDB_LINKTEST_ENABLE= )
 229 done
 230 
 231 # mdb_arch is both 32-bit & 64-bit
 232 for a in $mdb_arch
 233 do
 234   # We build these libraries (to the proto area), so we need to
 235   # build the mdb modules for all dependent libraries too.
 236 
 237   for lib in libfksmbsrv libmlsvc libcmdutils libavl
 238   do
 239     (cd $SRC/cmd/mdb/$x/$a/$lib && $make $1 )
 240 
 241   done
 242 done
 243 }
 244 
 245 
 246 ################################################################
 247 # This builds $SRC/TAGS (and cscope.files) in a helpful order.
 248 
 249 do_tags() {
 250         (cd $SRC ;
 251         find uts/common/sys -name '*.[ch]' -print |sort
 252         find uts/common/net -name '*.[ch]' -print |sort
 253         find uts/common/netinet -name '*.[ch]' -print |sort
 254         find uts/common/smb -name '*.[ch]' -print |sort
 255         find uts/common/smbsrv -name '*.ndl' -print |sort
 256         find uts/common/smbsrv -name '*.[ch]' -print |sort
 257         find uts/common/fs/smbsrv -name '*.[ch]' -print |sort
 258         find uts/common/gssapi -name '*.[ch]' -print |sort
 259         find common/smbsrv -name '*.[ch]' -print |sort
 260         find head -name '*.h' -print |sort
 261         find lib/smbsrv -name '*.[ch]' -print |sort
 262         find lib/libsmbfs -name '*.[ch]' -print |sort
 263         find lib/libmlrpc -name '*.ndl' -print |sort
 264         find lib/libmlrpc -name '*.[ch]' -print |sort
 265         find lib/libads -name '*.[ch]' -print |sort
 266         find lib/libgss -name '*.[ch]' -print |sort
 267         find cmd/smbsrv -name '*.[ch]' -print |sort
 268         ) > $SRC/cscope.files
 269 
 270         (cd $SRC ;
 271         exctags -e --langmap=c:+.ndl -h ndl -L - < cscope.files
 272         cscope -b )
 273 }
 274 
 275 ################################################################
 276 # This creates a tarfile one can use to update a test machine.
 277 
 278 do_tar() {
 279         git_rev=`git rev-parse --short=8 HEAD`
 280         files="
 281 lib/svc/manifest/network/smb/server.xml
 282 usr/kernel/drv/$arch64/smbsrv
 283 usr/kernel/kmdb/$arch64/smbsrv
 284 usr/lib/fs/smb/$arch64/libshare_smb.so.1
 285 usr/lib/fs/smb/libshare_smb.so.1
 286 usr/lib/libsmbfs.so.1
 287 usr/lib/mdb/kvm/$arch64/smbsrv.so
 288 usr/lib/mdb/kvm/smbsrv.so
 289 usr/lib/mdb/proc/libmlsvc.so
 290 usr/lib/reparse/libreparse_smb.so.1
 291 usr/lib/security/pam_smb_passwd.so.1
 292 usr/lib/smbsrv/dtrace
 293 usr/lib/libmlrpc.so.2
 294 usr/lib/smbsrv/libmlsvc.so.1
 295 usr/lib/smbsrv/libsmb.so.1
 296 usr/lib/smbsrv/libsmbns.so.1
 297 usr/lib/smbsrv/nvlprint
 298 usr/lib/smbsrv/smbd
 299 usr/sbin/smbadm
 300 usr/sbin/smbstat
 301 "
 302 
 303         (cd $ROOT && tar cfj ../../smbsrv-${git_rev}.tar.bz2 $files)
 304 }
 305 
 306 ################################################################
 307 
 308 if [ "$1" = "" ]; then
 309   set '?' # force usage
 310 fi
 311 
 312 set -x
 313 
 314 for arg
 315 do
 316   case "$arg" in
 317   install)
 318     build_tools
 319     set -e
 320     do_hdrs $arg
 321     do_kern $arg
 322     do_lib1 $arg
 323     do_lib2 $arg
 324     do_cmds $arg
 325     ;;
 326   lint)
 327     do_hdrs $arg
 328     do_kern $arg
 329     do_lib1 $arg
 330     do_lib2 $arg
 331     do_cmds $arg
 332     ;;
 333   clean)
 334     # intentionally skip: lib1, hdrs, tools
 335     do_cmds $arg
 336     do_lib2 $arg
 337     do_kern $arg
 338     ;;
 339   clobber)
 340     do_cmds $arg
 341     do_lib2 $arg
 342     do_lib1 $arg
 343     do_kern $arg
 344     do_hdrs $arg
 345     clobber_tools
 346     ;;
 347   tags)
 348     do_tags
 349     ;;
 350   tar)
 351     do_tar
 352     ;;
 353   *)
 354     echo "Usage: $0 {install|lint|clean|clobber|tags|tar}";
 355     exit 1;
 356     ;;
 357   esac
 358 done