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