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 2019 Nexenta by DDN, Inc. All rights reserved.
  15 #
  16 
  17 # Use normal make (not dmake) by default.
  18 make=${MAKE:-make}
  19 
  20 # Set this if you want to use dbx or gdb:
  21 # export SOURCEDEBUG=yes
  22 
  23 [ -n "$SRC" ] || {
  24   echo "SRC not set.  Run 'ws' or 'bldenv' first."
  25   exit 1
  26 }
  27 
  28 cpu=`uname -p`
  29 case $cpu in
  30 i386)
  31         x=intel
  32         kmdb_arch="amd64"
  33         mdb_arch="ia32 amd64"
  34         arch64=amd64
  35         ;;
  36 sparc)
  37         x=sparc
  38         kmdb_arch=v9
  39         mdb_arch="v7 v9"
  40         arch64=sparcv9
  41         ;;
  42 *)  echo "Unknown architecture" ; exit 1;;
  43 esac
  44 
  45 ################################################################
  46 
  47 build_tools() {
  48   test -f $SRC/tools/proto/root_i386-nd/opt/onbld/bin/genoffsets ||
  49     (cd $SRC/tools && $make install)
  50   (cd $SRC/common/mapfiles; $make install)
  51 }
  52 
  53 clobber_tools() {
  54   (cd $SRC/tools && $make clobber)
  55   (cd $SRC/common/mapfiles; $make clobber)
  56 }
  57 
  58 # end build_tools()
  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 NFS (kernel) 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/nfs && $make -k $targ)
  97 fi
  98 
  99 # Need some library headers too...
 100 for lib in \
 101   libcmdutils \
 102   libcryptoutil \
 103   libidmap \
 104   libpam \
 105   libsec \
 106   libzfs_core \
 107   libzfs \
 108   libshare \
 109   libuutil \
 110   librpcsvc \
 111   libmapid
 112 do
 113   (cd $SRC/lib/$lib && $make $targ)
 114 done
 115 }
 116 
 117 # end do_hdrs()
 118 
 119 
 120 ################################################################
 121 
 122 do_kern() {
 123   case $1 in
 124   *) targ=$1 ;;
 125   esac
 126   ( unset SOURCEDEBUG ;
 127   (cd $SRC/uts/$x/nfs && $make $targ) ;
 128   (cd $SRC/uts/$x/nfs_dlboot && $make $targ) ;
 129   (cd $SRC/uts/$x/nfssrv && $make $targ) ;
 130   (cd $SRC/uts/$x/klmmod && $make $targ) ;
 131   (cd $SRC/uts/$x/klmops && $make $targ) )
 132 }
 133 
 134 # end do_kern()
 135 
 136 
 137 ################################################################
 138 
 139 # Note lib1 builds prerequisite libraries not delivered by the
 140 # tar file we create below.  To accelerate clean/install, we
 141 # skip these on clean (but still nuke them for clobber)
 142 
 143 do_lib1() {
 144 
 145 for lib in \
 146   libavl \
 147   libuutil \
 148   libcmdutils \
 149   libidmap \
 150   libzfs_core \
 151   libzfs
 152 do
 153   (cd $SRC/lib/$lib && $make $1)
 154 done
 155 }
 156 
 157 # lib2 builds stuff we include in the tar file,
 158 # or that we don't mind rebuilding after clean.
 159 
 160 do_lib2() {
 161 
 162 for lib in \
 163   librpcsvc \
 164   libmapid
 165 do
 166   (cd $SRC/lib/$lib && $make $1)
 167 done
 168 
 169 (cd $SRC/lib/libshare && $make $1 PLUGINS=nfs)
 170 
 171 }
 172 
 173 # end do_lib1() and do_lib2()
 174 
 175 
 176 ################################################################
 177 
 178 do_cmds() {
 179 
 180 case $1 in
 181 install)
 182   # mount programs need fslib.o
 183   (cd $SRC/cmd/fs.d && $make fslib.o)
 184   (cd $SRC/cmd/fs.d/nfs && $make $1 catalog)
 185   ;;
 186 clean|clobber)
 187   (cd $SRC/cmd/fs.d/nfs && $make $1)
 188   (cd $SRC/cmd/fs.d && $make ${1}_local)
 189   ;;
 190 esac
 191 
 192 
 193 }
 194 
 195 # Build the MDB modules, WITH the linktest
 196 # Not yet.  See https://www.illumos.org/issues/3409
 197 
 198 # end do_cmds()
 199 
 200 
 201 ################################################################
 202 # This builds $SRC/TAGS (and cscope.files) in a helpful order.
 203 
 204 do_tags() {
 205         (cd $SRC ;
 206         find uts/common/sys -name '*.[ch]' -print |sort
 207         find uts/common/net -name '*.[ch]' -print |sort
 208         find uts/common/netinet -name '*.[ch]' -print |sort
 209         find uts/common/nfs -name '*.[ch]' -print |sort
 210         find uts/common/rpc -name '*.[ch]' -print |sort
 211         find uts/common/klm -name '*.[ch]' -print |sort
 212         find uts/common/fs/nfs -name '*.[ch]' -print |sort
 213         find uts/common/gssapi -name '*.[ch]' -print |sort
 214         find head -name '*.h' -print |sort
 215         find cmd/fs.d/nfs -name '*.[ch]' -print |sort
 216         ) > $SRC/cscope.files
 217 
 218         (cd $SRC ;
 219         exctags -e --langmap=c:+.ndl -h ndl -L - < cscope.files
 220         cscope -b )
 221 }
 222 
 223 #end do_tags()
 224 
 225 
 226 ################################################################
 227 # This creates tarfiles one can use to update a test machine.
 228 
 229 do_tar() {
 230         git_rev=`git rev-parse --short=8 HEAD`
 231 
 232 # NFS (everything)
 233         files="
 234 kernel/misc/$arch64/klmmod
 235 kernel/misc/$arch64/klmops
 236 kernel/misc/$arch64/nfs_dlboot
 237 kernel/misc/$arch64/nfssrv
 238 kernel/fs/$arch64/nfs
 239 kernel/sys/$arch64/nfs
 240 lib/svc/manifest/network/nfs/cbd.xml
 241 lib/svc/manifest/network/nfs/client.xml
 242 lib/svc/manifest/network/nfs/mapid.xml
 243 lib/svc/manifest/network/nfs/nfslogd.xml
 244 lib/svc/manifest/network/nfs/nlockmgr.xml
 245 lib/svc/manifest/network/nfs/rquota.xml
 246 lib/svc/manifest/network/nfs/server.xml
 247 lib/svc/manifest/network/nfs/status.xml
 248 lib/svc/method/nfs-client
 249 lib/svc/method/nfs-server
 250 lib/svc/method/nlockmgr
 251 usr/bin/nfsstat
 252 usr/lib/fs/nfs/$arch64/libshare_nfs.so.1
 253 usr/lib/fs/nfs/libshare_nfs.so.1
 254 usr/lib/fs/nfs/dfmounts
 255 usr/lib/fs/nfs/dfshares
 256 usr/lib/fs/nfs/nfsfind
 257 usr/lib/fs/nfs/showmount
 258 usr/lib/fs/nfs/umount
 259 usr/lib/nfs/libmapid.so.1
 260 usr/lib/nfs/lockd
 261 usr/lib/nfs/mountd
 262 usr/lib/nfs/nfs4cbd
 263 usr/lib/nfs/nfsd
 264 usr/lib/nfs/nfslogd
 265 usr/lib/nfs/nfsmapid
 266 usr/lib/nfs/rquotad
 267 usr/lib/nfs/statd
 268 usr/lib/reparse/$arch64/libnfs_basic.so.1
 269 usr/lib/reparse/libnfs_basic.so.1
 270 usr/sbin/clear_locks
 271 usr/sbin/exportfs
 272 usr/sbin/nfsref
 273 "
 274         (cd $ROOT && tar cfj ../../nfs-${git_rev}.tar.bz2 $files)
 275 
 276 # KLM kmod
 277         files="
 278 kernel/misc/$arch64/klmmod
 279 kernel/misc/$arch64/klmops
 280 "
 281         (cd $ROOT && tar cfj ../../klm-${git_rev}.tar.bz2 $files)
 282 }
 283 
 284 # end do_tar()
 285 
 286 
 287 ################################################################
 288 
 289 if [ "$1" = "" ]; then
 290   set '?' # force usage
 291 fi
 292 
 293 set -x
 294 
 295 for arg
 296 do
 297   case "$arg" in
 298   install)
 299     build_tools
 300     set -e
 301     do_hdrs $arg
 302     do_kern $arg
 303     do_lib1 $arg
 304     do_lib2 $arg
 305     do_cmds $arg
 306     ;;
 307   clean)
 308     # intentionally skip: lib1, hdrs, tools
 309     do_cmds $arg
 310     do_lib2 $arg
 311     do_kern $arg
 312     ;;
 313   clobber)
 314     do_cmds $arg
 315     do_lib2 $arg
 316     do_lib1 $arg
 317     do_kern $arg
 318     do_hdrs $arg
 319     clobber_tools
 320     ;;
 321   tags)
 322     do_tags
 323     ;;
 324   tar)
 325     do_tar
 326     ;;
 327   *)
 328     echo "Usage: $0 {install|clean|clobber|tags|tar}";
 329     exit 1;
 330     ;;
 331   esac
 332 done