xref: /illumos-gate/usr/src/tools/quick/make-smbsrv (revision 6f1fa39e)
110b444a8SGordon Ross#!/bin/ksh
210b444a8SGordon Ross#
310b444a8SGordon Ross# This file and its contents are supplied under the terms of the
410b444a8SGordon Ross# Common Development and Distribution License ("CDDL"), version 1.0.
510b444a8SGordon Ross# You may only use this file in accordance with the terms of version
610b444a8SGordon Ross# 1.0 of the CDDL.
710b444a8SGordon Ross#
810b444a8SGordon Ross# A full copy of the text of the CDDL should have accompanied this
910b444a8SGordon Ross# source.  A copy of the CDDL is also available via the Internet at
1010b444a8SGordon Ross# http://www.illumos.org/license/CDDL.
1110b444a8SGordon Ross#
1210b444a8SGordon Ross
1310b444a8SGordon Ross#
14*6f1fa39eSGordon Ross# Copyright 2020 Tintri by DDN, Inc.  All rights reserved.
1510b444a8SGordon Ross#
1610b444a8SGordon Ross
1754026d5aSGordon Ross# Use normal make (not dmake) by default.
1854026d5aSGordon Rossmake=${MAKE:-make}
1910b444a8SGordon Ross
2010b444a8SGordon RossCLOSED_IS_PRESENT=no
2110b444a8SGordon Rossexport CLOSED_IS_PRESENT
2210b444a8SGordon Ross
23b3700b07SGordon Ross# Do this if you want to use dbx or gdb
24b3700b07SGordon Ross# export SOURCEDEBUG=yes
2510b444a8SGordon Ross
2610b444a8SGordon Ross[ -n "$SRC" ] || {
2710b444a8SGordon Ross  echo "SRC not set.  Run 'ws' or 'bldenv' first."
2810b444a8SGordon Ross  exit 1
2910b444a8SGordon Ross}
3010b444a8SGordon Ross
3110b444a8SGordon Rosscpu=`uname -p`
3210b444a8SGordon Rosscase $cpu in
3310b444a8SGordon Rossi386)
3410b444a8SGordon Ross	x=intel
35b9538c21SGordon Ross	kmdb_arch="amd64"
3610b444a8SGordon Ross	mdb_arch="ia32 amd64"
3710b444a8SGordon Ross	arch64=amd64
3810b444a8SGordon Ross	;;
3910b444a8SGordon Rosssparc)
4010b444a8SGordon Ross	x=sparc
41b9538c21SGordon Ross	kmdb_arch=v9
42b9538c21SGordon Ross	mdb_arch="v7 v9"
4310b444a8SGordon Ross	arch64=sparcv9
4410b444a8SGordon Ross	;;
4510b444a8SGordon Ross*)  echo "Huh?" ; exit 1;;
4610b444a8SGordon Rossesac
4710b444a8SGordon Ross
4810b444a8SGordon Ross################################################################
4910b444a8SGordon Ross
5010b444a8SGordon Rossbuild_tools() {
5110b444a8SGordon Ross  test -f $SRC/tools/proto/root_i386-nd/opt/onbld/bin/genoffsets ||
5210b444a8SGordon Ross    (cd $SRC/tools && $make install)
5310b444a8SGordon Ross  (cd $SRC/common/mapfiles; $make install)
5410b444a8SGordon Ross}
5510b444a8SGordon Ross
5610b444a8SGordon Rossclobber_tools() {
5710b444a8SGordon Ross  (cd $SRC/tools && $make clobber)
5810b444a8SGordon Ross  (cd $SRC/common/mapfiles; $make clobber)
5910b444a8SGordon Ross}
6010b444a8SGordon Ross
6110b444a8SGordon Ross################################################################
6210b444a8SGordon Ross
6310b444a8SGordon Rossdo_hdrs() {
6410b444a8SGordon Ross
6510b444a8SGordon Rosstarg=$1
6610b444a8SGordon Rossif [ "$targ" = clobber ]
6710b444a8SGordon Rossthen
6810b444a8SGordon Ross  (cd $SRC/uts && $make -k clobber_h)
6910b444a8SGordon Ross  (cd $SRC/head && $make clobber)
7010b444a8SGordon Rossfi
7110b444a8SGordon Ross
7210b444a8SGordon Rossif [ "$targ" = install ]
7310b444a8SGordon Rossthen
7410b444a8SGordon Ross  targ=install_h
7510b444a8SGordon Ross
7610b444a8SGordon Ross  # Just the parts of "make sgs" we need, and
7710b444a8SGordon Ross  # skip them if they appear to be done.
7810b444a8SGordon Ross  # ... stuff under $SRC
7910b444a8SGordon Ross  test -f $SRC/uts/common/sys/priv_names.h ||
8010b444a8SGordon Ross    (cd $SRC/uts && $make -k all_h)
8110b444a8SGordon Ross
8210b444a8SGordon Ross  test -f $SRC/head/rpcsvc/nispasswd.h ||
8354026d5aSGordon Ross    (cd $SRC/head && $make -k $targ)
8410b444a8SGordon Ross
8510b444a8SGordon Ross  # ... stuff under $ROOT (proto area)
8610b444a8SGordon Ross  test -d $ROOT/usr/include/sys ||
8710b444a8SGordon Ross    (cd $SRC && $make rootdirs)
8810b444a8SGordon Ross  test -f $ROOT/usr/include/sys/types.h ||
8954026d5aSGordon Ross    (cd $SRC/uts && $make -k $targ)
9010b444a8SGordon Ross  test -f $ROOT/usr/include/rpcsvc/daemon_utils.h ||
9154026d5aSGordon Ross    (cd $SRC/head && $make $targ)
9210b444a8SGordon Ross
93*6f1fa39eSGordon Ross  # always update the sys,smbsrv headers to be safe
9454026d5aSGordon Ross  (cd $SRC/uts/common/gssapi && $make -k $targ)
9554026d5aSGordon Ross  (cd $SRC/uts/common/sys && $make -k $targ)
9654026d5aSGordon Ross  (cd $SRC/uts/common/smb && $make -k $targ)
9754026d5aSGordon Ross  (cd $SRC/uts/common/smbsrv && $make -k $targ)
98*6f1fa39eSGordon Ross  (cd $SRC/uts/common/c2 && $make -k $targ)
9954026d5aSGordon Rossfi
10010b444a8SGordon Ross
10154026d5aSGordon Rossif [ "$targ" = lint ]
10254026d5aSGordon Rossthen
10354026d5aSGordon Ross  targ=check
10454026d5aSGordon Ross  (cd $SRC/uts/common/smb && $make -k $targ)
10554026d5aSGordon Ross  (cd $SRC/uts/common/smbsrv && $make -k $targ)
10610b444a8SGordon Rossfi
10710b444a8SGordon Ross
10810b444a8SGordon Ross# Need some library headers too...
10910b444a8SGordon Rossfor lib in \
110*6f1fa39eSGordon Ross  libc \
111*6f1fa39eSGordon Ross  libnsl \
112*6f1fa39eSGordon Ross  libnvpair \
113*6f1fa39eSGordon Ross  libsocket \
114*6f1fa39eSGordon Ross  \
115b3700b07SGordon Ross  libads \
116*6f1fa39eSGordon Ross  libbrand \
11710b444a8SGordon Ross  libbsm \
11810b444a8SGordon Ross  libcmdutils \
11910b444a8SGordon Ross  libcryptoutil \
12010b444a8SGordon Ross  libdevid \
121*6f1fa39eSGordon Ross  libdisasm \
122b819cea2SGordon Ross  libfakekernel	\
12312b65585SGordon Ross  libgss \
12410b444a8SGordon Ross  libidmap \
125*6f1fa39eSGordon Ross  libinetutil \
126*6f1fa39eSGordon Ross  libipsecutil \
1273299f39fSGordon Ross  libkrb5 \
1283299f39fSGordon Ross  libmlrpc \
12910b444a8SGordon Ross  libpam \
130*6f1fa39eSGordon Ross  libsaveargs \
13110b444a8SGordon Ross  libsec \
13210b444a8SGordon Ross  libscf \
13310b444a8SGordon Ross  libshare \
13410b444a8SGordon Ross  libsmbfs \
13510b444a8SGordon Ross  libsqlite \
13610b444a8SGordon Ross  libuutil \
13754026d5aSGordon Ross  libzfs_core \
13854026d5aSGordon Ross  libzfs \
13910b444a8SGordon Ross  passwdutil \
14054026d5aSGordon Ross  pkcs11 \
14110b444a8SGordon Ross  smbsrv
14210b444a8SGordon Rossdo
14310b444a8SGordon Ross  (cd $SRC/lib/$lib && $make $targ)
14410b444a8SGordon Rossdone
14510b444a8SGordon Ross}
14610b444a8SGordon Ross
14710b444a8SGordon Ross################################################################
14810b444a8SGordon Ross
14910b444a8SGordon Rossdo_kern() {
15010b444a8SGordon Ross  case $1 in
15110b444a8SGordon Ross  lint) targ=modlintlib ;;
15210b444a8SGordon Ross  *) targ=$1 ;;
15310b444a8SGordon Ross  esac
15410b444a8SGordon Ross  ( unset SOURCEDEBUG ;
15510b444a8SGordon Ross  (cd $SRC/uts/$x/smbsrv && $make $targ) )
15610b444a8SGordon Ross}
15710b444a8SGordon Ross
15810b444a8SGordon Ross################################################################
159*6f1fa39eSGordon Ross#
160*6f1fa39eSGordon Ross# Build all libraries used by the other targets in here.
161*6f1fa39eSGordon Ross#
162*6f1fa39eSGordon Ross# Run this once (at least) in each new workspace where you
163*6f1fa39eSGordon Ross# will run "make-smbsrv install", if you want to avoid linking
164*6f1fa39eSGordon Ross# against the libraries from your build host.
165*6f1fa39eSGordon Ross#
166*6f1fa39eSGordon Rossdo_deplibs() {
16710b444a8SGordon Ross
168*6f1fa39eSGordon Ross(cd $SRC/lib/ssp_ns && $make $1)
169*6f1fa39eSGordon Ross(cd $SRC/lib/libc && $make $1)
17010b444a8SGordon Ross
17110b444a8SGordon Rossfor lib in \
172*6f1fa39eSGordon Ross  libm \
173*6f1fa39eSGordon Ross  libmd \
174*6f1fa39eSGordon Ross  libnsl \
175*6f1fa39eSGordon Ross  libnvpair \
176*6f1fa39eSGordon Ross  libsocket \
17710b444a8SGordon Ross  libavl \
17812b65585SGordon Ross  libgss \
179*6f1fa39eSGordon Ross  libgen \
18012b65585SGordon Ross  libkrb5 \
181*6f1fa39eSGordon Ross  libkstat \
18210b444a8SGordon Ross  libcmdutils \
183*6f1fa39eSGordon Ross  libresolv2 \
184*6f1fa39eSGordon Ross  libldap5 \
185*6f1fa39eSGordon Ross  libsldap \
186*6f1fa39eSGordon Ross  libreparse \
187*6f1fa39eSGordon Ross  libpam \
188*6f1fa39eSGordon Ross  libuutil \
189*6f1fa39eSGordon Ross  libidmap \
190*6f1fa39eSGordon Ross  libinetutil \
191*6f1fa39eSGordon Ross  libdlpi \
192*6f1fa39eSGordon Ross  libbsm \
193*6f1fa39eSGordon Ross  libsec \
194*6f1fa39eSGordon Ross  libsecdb \
19510b444a8SGordon Ross  libsqlite \
196*6f1fa39eSGordon Ross  libumem \
197*6f1fa39eSGordon Ross  libuuid \
198*6f1fa39eSGordon Ross  libsaveargs \
199*6f1fa39eSGordon Ross  libproc \
200*6f1fa39eSGordon Ross  libscf \
201*6f1fa39eSGordon Ross  libcryptoutil \
202*6f1fa39eSGordon Ross  libmd5 \
203*6f1fa39eSGordon Ross  libzfs_core \
204*6f1fa39eSGordon Ross  libzfs \
205*6f1fa39eSGordon Ross  pkcs11/libpkcs11
20610b444a8SGordon Rossdo
207*6f1fa39eSGordon Ross  # So we don't have to build EVERYTHING, set LDCHECKS=
208*6f1fa39eSGordon Ross  # when building the dependent libraries.
209*6f1fa39eSGordon Ross  (cd $SRC/lib/$lib && LDCHECKS='' $make $1)
21010b444a8SGordon Rossdone
211b819cea2SGordon Ross}
212b819cea2SGordon Ross
213*6f1fa39eSGordon Ross################################################################
214b819cea2SGordon Ross
215*6f1fa39eSGordon Rossdo_libs() {
216b819cea2SGordon Ross
217b819cea2SGordon Rossfor lib in \
218b819cea2SGordon Ross  libfakekernel \
219b3700b07SGordon Ross  libads \
2203299f39fSGordon Ross  libsmbfs \
2213299f39fSGordon Ross  libmlrpc
222b819cea2SGordon Rossdo
223b819cea2SGordon Ross  (cd $SRC/lib/$lib && $make $1)
224b819cea2SGordon Rossdone
22510b444a8SGordon Ross
22610b444a8SGordon Ross(cd $SRC/lib/libshare && $make $1 PLUGINS=smb)
22710b444a8SGordon Ross(cd $SRC/lib/smbsrv && $make $1)
22810b444a8SGordon Ross(cd $SRC/lib/passwdutil && $make $1)
22910b444a8SGordon Ross(cd $SRC/lib/pam_modules/smb && $make $1)
23010b444a8SGordon Ross
23110b444a8SGordon Ross}
23210b444a8SGordon Ross
23310b444a8SGordon Ross################################################################
23410b444a8SGordon Ross
23510b444a8SGordon Rossdo_cmds() {
23610b444a8SGordon Ross
23710b444a8SGordon Ross(cd $SRC/cmd/smbsrv && $make $1)
23810b444a8SGordon Ross
23910b444a8SGordon Ross# Build the MDB modules, WITH the linktest
24010b444a8SGordon Ross(cd $SRC/cmd/mdb/tools && $make $1)
241b9538c21SGordon Ross
242b9538c21SGordon Ross# kmdb_arch is 64-bit only
243b9538c21SGordon Rossfor a in $kmdb_arch
24410b444a8SGordon Rossdo
24510b444a8SGordon Ross  case $1 in
24610b444a8SGordon Ross  install|lint)
24710b444a8SGordon Ross    (cd $SRC/cmd/mdb/$x/$a/kmdb &&
24810b444a8SGordon Ross	$make kmdb_modlinktest.o )
24910b444a8SGordon Ross    ;;
25010b444a8SGordon Ross  clean|clobber)
25110b444a8SGordon Ross    (cd $SRC/cmd/mdb/$x/$a/kmdb &&
25210b444a8SGordon Ross	$make -k $1 )
25310b444a8SGordon Ross    ;;
25410b444a8SGordon Ross  esac
25510b444a8SGordon Ross  (cd $SRC/cmd/mdb/$x/$a/smbsrv &&
25610b444a8SGordon Ross	$make $1 KMDB_LINKTEST_ENABLE= )
257b9538c21SGordon Rossdone
258b9538c21SGordon Ross
259b9538c21SGordon Ross# mdb_arch is both 32-bit & 64-bit
260b9538c21SGordon Rossfor a in $mdb_arch
261b9538c21SGordon Rossdo
262e0687fa3SGordon Ross  # We build these libraries (to the proto area), so we need to
263e0687fa3SGordon Ross  # build the mdb modules for all dependent libraries too.
264b819cea2SGordon Ross
265e0687fa3SGordon Ross  for lib in libfksmbsrv libmlsvc libcmdutils libavl
266e0687fa3SGordon Ross  do
267e0687fa3SGordon Ross    (cd $SRC/cmd/mdb/$x/$a/$lib && $make $1 )
268b819cea2SGordon Ross
269e0687fa3SGordon Ross  done
27010b444a8SGordon Rossdone
27110b444a8SGordon Ross}
27210b444a8SGordon Ross
27310b444a8SGordon Ross################################################################
27410b444a8SGordon Ross# This builds $SRC/TAGS (and cscope.files) in a helpful order.
27510b444a8SGordon Ross
27610b444a8SGordon Rossdo_tags() {
27710b444a8SGordon Ross	(cd $SRC ;
27810b444a8SGordon Ross	find uts/common/sys -name '*.[ch]' -print |sort
27910b444a8SGordon Ross	find uts/common/net -name '*.[ch]' -print |sort
28010b444a8SGordon Ross	find uts/common/netinet -name '*.[ch]' -print |sort
28110b444a8SGordon Ross	find uts/common/smb -name '*.[ch]' -print |sort
28210b444a8SGordon Ross	find uts/common/smbsrv -name '*.ndl' -print |sort
28310b444a8SGordon Ross	find uts/common/smbsrv -name '*.[ch]' -print |sort
28410b444a8SGordon Ross	find uts/common/fs/smbsrv -name '*.[ch]' -print |sort
28512b65585SGordon Ross	find uts/common/gssapi -name '*.[ch]' -print |sort
28654026d5aSGordon Ross	find common/smbsrv -name '*.[ch]' -print |sort
28712b65585SGordon Ross	find head -name '*.h' -print |sort
28810b444a8SGordon Ross	find lib/smbsrv -name '*.[ch]' -print |sort
28912b65585SGordon Ross	find lib/libsmbfs -name '*.[ch]' -print |sort
290d1855c81SGordon Ross	find lib/libmlrpc -name '*.ndl' -print |sort
291d1855c81SGordon Ross	find lib/libmlrpc -name '*.[ch]' -print |sort
29212b65585SGordon Ross	find lib/libads -name '*.[ch]' -print |sort
29312b65585SGordon Ross	find lib/libgss -name '*.[ch]' -print |sort
29410b444a8SGordon Ross	find cmd/smbsrv -name '*.[ch]' -print |sort
29510b444a8SGordon Ross	) > $SRC/cscope.files
29610b444a8SGordon Ross
29710b444a8SGordon Ross	(cd $SRC ;
29810b444a8SGordon Ross	exctags -e --langmap=c:+.ndl -h ndl -L - < cscope.files
29910b444a8SGordon Ross	cscope -b )
30010b444a8SGordon Ross}
30110b444a8SGordon Ross
30210b444a8SGordon Ross################################################################
30310b444a8SGordon Ross# This creates a tarfile one can use to update a test machine.
30410b444a8SGordon Ross
30510b444a8SGordon Rossdo_tar() {
306ed81dd52SAlek Pinchuk	git_rev=`git rev-parse --short=8 HEAD`
30710b444a8SGordon Ross	files="
308ed81dd52SAlek Pinchuklib/svc/manifest/network/smb/server.xml
30910b444a8SGordon Rossusr/kernel/drv/$arch64/smbsrv
31010b444a8SGordon Rossusr/kernel/kmdb/$arch64/smbsrv
31110b444a8SGordon Rossusr/lib/fs/smb/$arch64/libshare_smb.so.1
31210b444a8SGordon Rossusr/lib/fs/smb/libshare_smb.so.1
31310b444a8SGordon Rossusr/lib/libsmbfs.so.1
31410b444a8SGordon Rossusr/lib/mdb/kvm/$arch64/smbsrv.so
315e0687fa3SGordon Rossusr/lib/mdb/proc/libmlsvc.so
31610b444a8SGordon Rossusr/lib/reparse/libreparse_smb.so.1
31710b444a8SGordon Rossusr/lib/security/pam_smb_passwd.so.1
318ed81dd52SAlek Pinchukusr/lib/smbsrv/dtrace
3193299f39fSGordon Rossusr/lib/libmlrpc.so.2
32010b444a8SGordon Rossusr/lib/smbsrv/libmlsvc.so.1
32110b444a8SGordon Rossusr/lib/smbsrv/libsmb.so.1
32210b444a8SGordon Rossusr/lib/smbsrv/libsmbns.so.1
3238d94f651SGordon Rossusr/lib/smbsrv/nvlprint
32410b444a8SGordon Rossusr/lib/smbsrv/smbd
32510b444a8SGordon Rossusr/sbin/smbadm
32610b444a8SGordon Rossusr/sbin/smbstat
32710b444a8SGordon Ross"
328ed81dd52SAlek Pinchuk	(cd $ROOT && tar cfj ../../smbsrv-${git_rev}.tar.bz2 $files)
32910b444a8SGordon Ross}
33010b444a8SGordon Ross
33110b444a8SGordon Ross################################################################
33210b444a8SGordon Ross
33310b444a8SGordon Rossif [ "$1" = "" ]; then
33410b444a8SGordon Ross  set '?' # force usage
33510b444a8SGordon Rossfi
33610b444a8SGordon Ross
33710b444a8SGordon Rossset -x
33810b444a8SGordon Ross
33910b444a8SGordon Rossfor arg
34010b444a8SGordon Rossdo
34110b444a8SGordon Ross  case "$arg" in
342b819cea2SGordon Ross  install)
34310b444a8SGordon Ross    build_tools
34410b444a8SGordon Ross    set -e
34510b444a8SGordon Ross    do_hdrs $arg
34610b444a8SGordon Ross    do_kern $arg
347*6f1fa39eSGordon Ross    do_libs $arg
34810b444a8SGordon Ross    do_cmds $arg
34910b444a8SGordon Ross    ;;
35010b444a8SGordon Ross  lint)
35154026d5aSGordon Ross    do_hdrs $arg
35210b444a8SGordon Ross    do_kern $arg
353*6f1fa39eSGordon Ross    do_libs $arg
35410b444a8SGordon Ross    do_cmds $arg
35510b444a8SGordon Ross    ;;
35610b444a8SGordon Ross  clean)
357b819cea2SGordon Ross    # intentionally skip: lib1, hdrs, tools
35810b444a8SGordon Ross    do_cmds $arg
359*6f1fa39eSGordon Ross    do_libs $arg
36010b444a8SGordon Ross    do_kern $arg
36110b444a8SGordon Ross    ;;
36210b444a8SGordon Ross  clobber)
36310b444a8SGordon Ross    do_cmds $arg
364*6f1fa39eSGordon Ross    do_libs $arg
36510b444a8SGordon Ross    do_kern $arg
36610b444a8SGordon Ross    do_hdrs $arg
367*6f1fa39eSGordon Ross    do_deplibs $arg
36810b444a8SGordon Ross    clobber_tools
36910b444a8SGordon Ross    ;;
370*6f1fa39eSGordon Ross  deplibs)
371*6f1fa39eSGordon Ross    build_tools
372*6f1fa39eSGordon Ross    set -e
373*6f1fa39eSGordon Ross    do_hdrs install
374*6f1fa39eSGordon Ross    do_deplibs install
375*6f1fa39eSGordon Ross    ;;
37610b444a8SGordon Ross  tags)
37710b444a8SGordon Ross    do_tags
37810b444a8SGordon Ross    ;;
37910b444a8SGordon Ross  tar)
38010b444a8SGordon Ross    do_tar
38110b444a8SGordon Ross    ;;
38210b444a8SGordon Ross  *)
383*6f1fa39eSGordon Ross    echo "Usage: $0 {install|lint|clean|clobber|deplibs|tags|tar}";
38410b444a8SGordon Ross    exit 1;
38510b444a8SGordon Ross    ;;
38610b444a8SGordon Ross  esac
38710b444a8SGordon Rossdone
388