From 5ff38128cb2932e3714c104ae3dee81542e6acf6 Mon Sep 17 00:00:00 2001
From: Kevin Crowe <kevin.crowe@nexenta.com>
Date: Tue, 16 Feb 2016 13:44:00 -0500
Subject: [PATCH 01/30] NEX-5507 make-nfs quickbuild script

Reviewed by: Gordon Ross <gwr@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Dan Fields <dan.fields@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
---
 usr/src/tools/quick/make-nfs | 334 +++++++++++++++++++++++++++++++++++
 1 file changed, 334 insertions(+)
 create mode 100755 usr/src/tools/quick/make-nfs

diff --git a/usr/src/tools/quick/make-nfs b/usr/src/tools/quick/make-nfs
new file mode 100755
index 0000000000..9f6e2ee04f
--- /dev/null
+++ b/usr/src/tools/quick/make-nfs
@@ -0,0 +1,334 @@
+#!/bin/ksh
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
+#
+
+# Use distributed make (dmake) by default.
+make=${MAKE:-dmake}
+
+# Set this if you want to use dbx or gdb:
+# export SOURCEDEBUG=yes
+
+[ -n "$SRC" ] || {
+  echo "SRC not set.  Run 'ws' or 'bldenv' first."
+  exit 1
+}
+
+cpu=`uname -p`
+case $cpu in
+i386)
+	x=intel
+	mdb_arch="ia32 amd64"
+	arch64=amd64
+	;;
+sparc)
+	x=sparc
+	mdb_arch=v9
+	arch64=sparcv9
+	;;
+*)  echo "Unknown architecture" ; exit 1;;
+esac
+
+################################################################
+
+build_tools() {
+  test -f $SRC/tools/proto/root_i386-nd/opt/onbld/bin/genoffsets ||
+    (cd $SRC/tools && $make install)
+  (cd $SRC/common/mapfiles; $make install)
+}
+
+clobber_tools() {
+  (cd $SRC/tools && $make clobber)
+  (cd $SRC/common/mapfiles; $make clobber)
+}
+
+# end build_tools()
+
+
+################################################################
+
+do_hdrs() {
+
+targ=$1
+if [ "$targ" = clobber ]
+then
+  (cd $SRC/uts && $make -k clobber_h)
+  (cd $SRC/head && $make clobber)
+fi
+
+if [ "$targ" = install ]
+then
+  targ=install_h
+
+  # Just the parts of "make sgs" we need, and
+  # skip them if they appear to be done.
+  # ... stuff under $SRC
+  test -f $SRC/uts/common/sys/priv_names.h ||
+    (cd $SRC/uts && $make -k all_h)
+
+  test -f $SRC/head/rpcsvc/nispasswd.h ||
+    (cd $SRC/head && $make -k $targ)
+
+  # ... stuff under $ROOT (proto area)
+  test -d $ROOT/usr/include/sys ||
+    (cd $SRC && $make rootdirs)
+  test -f $ROOT/usr/include/sys/types.h ||
+    (cd $SRC/uts && $make -k $targ)
+  test -f $ROOT/usr/include/rpcsvc/daemon_utils.h ||
+    (cd $SRC/head && $make $targ)
+
+  # always update the NFS (kernel) headers to be safe
+  (cd $SRC/uts/common/gssapi && $make -k install_h)
+  (cd $SRC/uts/common/sys && $make -k install_h)
+  (cd $SRC/uts/common/nfs && $make -k install_h)
+
+fi
+
+# Need some library headers too...
+for lib in \
+  libcryptoutil \
+  libidmap \
+  libpam \
+  libsec \
+  libzfs_core \
+  libzfs \
+  libshare \
+  libuutil \
+  librpcsvc \
+  libmapid
+do
+  (cd $SRC/lib/$lib && $make $targ)
+done
+}
+
+# end do_hdrs()
+
+
+################################################################
+
+do_kern() {
+  case $1 in
+  lint) targ=modlintlib ;;
+  *) targ=$1 ;;
+  esac
+  ( unset SOURCEDEBUG ;
+  (cd $SRC/uts/$x/nfs && $make $targ) ;
+  (cd $SRC/uts/$x/nfs_dlboot && $make $targ) ;
+  (cd $SRC/uts/$x/nfssrv && $make $targ) ;
+  (cd $SRC/uts/$x/klmmod && $make $targ) ;
+  (cd $SRC/uts/$x/klmops && $make $targ) )
+}
+
+# end do_kern()
+
+
+################################################################
+
+# Note lib1 builds prerequisite libraries not delivered by the
+# tar file we create below.  To accelerate clean/install, we
+# skip these on clean (but still nuke them for clobber)
+
+do_lib1() {
+
+for lib in \
+  libavl \
+  libuutil \
+  libidmap \
+  libzfs_core \
+  libzfs
+do
+  (cd $SRC/lib/$lib && $make $1)
+done
+}
+
+# lib2 builds stuff we include in the tar file,
+# or that we don't mind rebuilding after clean.
+
+do_lib2() {
+
+for lib in \
+  librpcsvc \
+  libmapid
+do
+  (cd $SRC/lib/$lib && $make $1)
+done
+
+(cd $SRC/lib/libshare && $make $1 PLUGINS=nfs)
+
+}
+
+# end do_lib1() and do_lib2()
+
+
+################################################################
+
+do_cmds() {
+
+case $1 in
+install)
+  # mount programs need fslib.o
+  (cd $SRC/cmd/fs.d && $make fslib.o)
+  (cd $SRC/cmd/fs.d/nfs && $make $1 catalog)
+  ;;
+clean|clobber)
+  (cd $SRC/cmd/fs.d/nfs && $make $1)
+  (cd $SRC/cmd/fs.d && $make ${1}_local)
+  ;;
+esac
+
+
+}
+
+# Build the MDB modules, WITH the linktest
+# Not yet.  See https://www.illumos.org/issues/3409
+
+# end do_cmds()
+
+
+################################################################
+# This builds $SRC/TAGS (and cscope.files) in a helpful order.
+
+do_tags() {
+	(cd $SRC ;
+	find uts/common/sys -name '*.[ch]' -print |sort
+	find uts/common/net -name '*.[ch]' -print |sort
+	find uts/common/netinet -name '*.[ch]' -print |sort
+	find uts/common/nfs -name '*.[ch]' -print |sort
+	find uts/common/fs/nfs -name '*.[ch]' -print |sort
+	find uts/common/gssapi -name '*.[ch]' -print |sort
+	find head -name '*.h' -print |sort
+	find cmd/fs.d/nfs -name '*.[ch]' -print |sort
+	) > $SRC/cscope.files
+
+	(cd $SRC ;
+	exctags -e --langmap=c:+.ndl -h ndl -L - < cscope.files
+	cscope -b )
+}
+
+#end do_tags()
+
+
+################################################################
+# This creates a tarfile one can use to update a test machine.
+
+do_tar() {
+	git_rev=`git rev-parse --short=8 HEAD`
+	files="
+kernel/misc/$arch64/klmmod
+kernel/misc/$arch64/klmops
+kernel/misc/$arch64/nfs_dlboot
+kernel/misc/$arch64/nfssrv
+kernel/misc/klmmod
+kernel/misc/klmops
+kernel/misc/nfs_dlboot
+kernel/misc/nfssrv
+kernel/fs/$arch64/nfs
+kernel/fs/nfs
+kernel/sys/$arch64/nfs
+kernel/sys/nfs
+lib/svc/manifest/network/nfs/cbd.xml
+lib/svc/manifest/network/nfs/client.xml
+lib/svc/manifest/network/nfs/mapid.xml
+lib/svc/manifest/network/nfs/nfslogd.xml
+lib/svc/manifest/network/nfs/nlockmgr.xml
+lib/svc/manifest/network/nfs/rquota.xml
+lib/svc/manifest/network/nfs/server.xml
+lib/svc/manifest/network/nfs/status.xml
+lib/svc/method/nfs-client
+lib/svc/method/nfs-server
+lib/svc/method/nlockmgr
+usr/bin/nfsstat
+usr/lib/fs/nfs/$arch64/libshare_nfs.so.1
+usr/lib/fs/nfs/libshare_nfs.so.1
+usr/lib/fs/nfs/dfmounts
+usr/lib/fs/nfs/dfshares
+usr/lib/fs/nfs/nfsfind
+usr/lib/fs/nfs/showmount
+usr/lib/fs/nfs/umount
+usr/lib/nfs/libmapid.so.1
+usr/lib/nfs/llib-lmapid
+usr/lib/nfs/llib-lmapid.ln
+usr/lib/nfs/lockd
+usr/lib/nfs/mountd
+usr/lib/nfs/nfs4cbd
+usr/lib/nfs/nfsd
+usr/lib/nfs/nfslogd
+usr/lib/nfs/nfsmapid
+usr/lib/nfs/rquotad
+usr/lib/nfs/statd
+usr/lib/reparse/$arch64/libnfs_basic.so.1
+usr/lib/reparse/libnfs_basic.so.1
+usr/sbin/clear_locks
+usr/sbin/exportfs
+usr/sbin/nfsref
+"
+
+	(cd $ROOT && tar cfj ../../nfs-${git_rev}.tar.bz2 $files)
+}
+
+# end do_tar()
+
+
+################################################################
+
+if [ "$1" = "" ]; then
+  set '?' # force usage
+fi
+
+set -x
+
+for arg
+do
+  case "$arg" in
+  install)
+    build_tools
+    set -e
+    do_hdrs $arg
+    do_kern $arg
+    do_lib1 $arg
+    do_lib2 $arg
+    do_cmds $arg
+    ;;
+  lint)
+    do_kern $arg
+    do_lib1 $arg
+    do_lib2 $arg
+    do_cmds $arg
+    ;;
+  clean)
+    # intentionally skip: lib1, hdrs, tools
+    do_cmds $arg
+    do_lib2 $arg
+    do_kern $arg
+    ;;
+  clobber)
+    do_cmds $arg
+    do_lib2 $arg
+    do_lib1 $arg
+    do_kern $arg
+    do_hdrs $arg
+    clobber_tools
+    ;;
+  tags)
+    do_tags
+    ;;
+  tar)
+    do_tar
+    ;;
+  *)
+    echo "Usage: $0 {install|lint|clean|clobber|tags|tar}";
+    exit 1;
+    ;;
+  esac
+done
-- 
2.21.0

