xref: /illumos-gate/usr/src/tools/quick/make-smbsrv (revision f17620a4f72a29025a22655ba8735ccd20ae174f)
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 2022 Tintri by DDN, 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 sys,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)
99fi
100
101if [ "$targ" = lint ]
102then
103  targ=check
104  (cd $SRC/uts/common/smb && $make -k $targ)
105  (cd $SRC/uts/common/smbsrv && $make -k $targ)
106fi
107
108# Need some library headers too...
109for lib in \
110  libc \
111  libnsl \
112  libnvpair \
113  libsocket \
114  \
115  libads \
116  libbrand \
117  libbsm \
118  libcmdutils \
119  libcryptoutil \
120  libdevid \
121  libdisasm \
122  libfakekernel	\
123  libgss \
124  libidmap \
125  libinetutil \
126  libipsecutil \
127  libkrb5 \
128  libmlrpc \
129  libofmt \
130  libpam \
131  libsaveargs \
132  libsec \
133  libscf \
134  libshare \
135  libsmbfs \
136  libsqlite \
137  libuutil \
138  libzfs_core \
139  libzfs \
140  passwdutil \
141  pkcs11 \
142  smbsrv
143do
144  (cd $SRC/lib/$lib && $make $targ)
145done
146}
147
148################################################################
149
150do_kern() {
151  case $1 in
152  lint) targ=modlintlib ;;
153  *) targ=$1 ;;
154  esac
155  ( unset SOURCEDEBUG ;
156   export NO_GENUNIX_UNIQUIFY= ;
157  (cd $SRC/uts/$x/smbsrv && $make $targ) )
158}
159
160################################################################
161#
162# Build all libraries used by the other targets in here.
163#
164# Run this once (at least) in each new workspace where you
165# will run "make-smbsrv install", if you want to avoid linking
166# against the libraries from your build host.
167#
168do_deplibs() {
169
170(cd $SRC/lib/ssp_ns && $make $1)
171(cd $SRC/lib/libc && $make $1)
172
173for lib in \
174  libm \
175  libmd \
176  libnsl \
177  libnvpair \
178  libsocket \
179  libavl \
180  libgss \
181  libgen \
182  libkrb5 \
183  libkstat \
184  libcmdutils \
185  libresolv2 \
186  libldap5 \
187  libsldap \
188  libreparse \
189  libpam \
190  libuutil \
191  libidmap \
192  libinetutil \
193  libdlpi \
194  libbsm \
195  libsec \
196  libsecdb \
197  libsqlite \
198  libumem \
199  libuuid \
200  libsaveargs \
201  libproc \
202  libscf \
203  libcryptoutil \
204  libmd5 \
205  libzfs_core \
206  libzfs \
207  pkcs11/libpkcs11
208do
209  # So we don't have to build EVERYTHING, set LDCHECKS=
210  # when building the dependent libraries.
211  (cd $SRC/lib/$lib && LDCHECKS='' $make $1)
212done
213}
214
215################################################################
216
217do_libs() {
218
219for lib in \
220  libfakekernel \
221  libads \
222  libidmap \
223  libofmt \
224  libsmbfs \
225  libmlrpc
226do
227  (cd $SRC/lib/$lib && $make $1)
228done
229
230(cd $SRC/lib/libshare && $make $1 PLUGINS=smb)
231(cd $SRC/lib/smbsrv && $make $1)
232(cd $SRC/lib/passwdutil && $make $1)
233(cd $SRC/lib/pam_modules/smb && $make $1)
234
235}
236
237################################################################
238
239do_cmds() {
240
241(cd $SRC/cmd/smbsrv && $make $1)
242
243# Build the MDB modules, WITH the linktest
244(cd $SRC/cmd/mdb/tools && $make $1)
245
246# kmdb_arch is 64-bit only
247for a in $kmdb_arch
248do
249  case $1 in
250  install|lint)
251    (cd $SRC/cmd/mdb/$x/$a/kmdb &&
252	$make kmdb_modlinktest.o )
253    ;;
254  clean|clobber)
255    (cd $SRC/cmd/mdb/$x/$a/kmdb &&
256	$make -k $1 )
257    ;;
258  esac
259  (cd $SRC/cmd/mdb/$x/$a/smbsrv &&
260	$make $1 KMDB_LINKTEST_ENABLE= )
261done
262
263# mdb_arch is both 32-bit & 64-bit
264for a in $mdb_arch
265do
266  # We build these libraries (to the proto area), so we need to
267  # build the mdb modules for all dependent libraries too.
268
269  for lib in libfksmbsrv libmlsvc list libavl
270  do
271    (cd $SRC/cmd/mdb/$x/$a/$lib && $make $1 )
272
273  done
274done
275}
276
277################################################################
278
279do_tests() {
280
281  for d in test/test-runner test/libmlrpc-tests test/smbsrv-tests
282  do
283       [ -f $SRC/$d/Makefile ] && (cd $SRC/$d && $make $1)
284  done
285}
286
287################################################################
288# This builds $SRC/TAGS (and cscope.files) in a helpful order.
289
290do_tags() {
291	(cd $SRC ;
292	find uts/common/sys -name '*.[ch]' -print |sort
293	find uts/common/net -name '*.[ch]' -print |sort
294	find uts/common/netinet -name '*.[ch]' -print |sort
295	find uts/common/smb -name '*.[ch]' -print |sort
296	find uts/common/smbsrv -name '*.ndl' -print |sort
297	find uts/common/smbsrv -name '*.[ch]' -print |sort
298	find uts/common/fs/smbsrv -name '*.[ch]' -print |sort
299	find uts/common/gssapi -name '*.[ch]' -print |sort
300	find common/smbsrv -name '*.[ch]' -print |sort
301	find head -name '*.h' -print |sort
302	find lib/smbsrv -name '*.[ch]' -print |sort
303	find lib/libsmbfs -name '*.[ch]' -print |sort
304	find lib/libmlrpc -name '*.ndl' -print |sort
305	find lib/libmlrpc -name '*.[ch]' -print |sort
306	find lib/libads -name '*.[ch]' -print |sort
307	find lib/libgss -name '*.[ch]' -print |sort
308	find cmd/smbsrv -name '*.[ch]' -print |sort
309	) > $SRC/cscope.files
310
311	(cd $SRC ;
312	exctags -e --langmap=c:+.ndl -h ndl -L - < cscope.files
313	cscope -b )
314}
315
316################################################################
317# This creates a tarfile one can use to update a test machine.
318
319do_tar() {
320	git_rev=`git rev-parse --short=8 HEAD`
321	files="
322lib/svc/manifest/network/smb/server.xml
323usr/kernel/drv/$arch64/smbsrv
324usr/kernel/kmdb/$arch64/smbsrv
325usr/lib/fs/smb/$arch64/libshare_smb.so.1
326usr/lib/fs/smb/libshare_smb.so.1
327usr/lib/libsmbfs.so.1
328usr/lib/mdb/kvm/$arch64/smbsrv.so
329usr/lib/mdb/proc/libmlsvc.so
330usr/lib/reparse/libreparse_smb.so.1
331usr/lib/security/pam_smb_passwd.so.1
332usr/lib/smbsrv/dtrace
333usr/lib/libmlrpc.so.2
334usr/lib/smbsrv/libmlsvc.so.1
335usr/lib/smbsrv/libsmb.so.1
336usr/lib/smbsrv/libsmbns.so.1
337usr/lib/smbsrv/nvlprint
338usr/lib/smbsrv/smbd
339usr/sbin/smbadm
340usr/sbin/smbstat
341"
342	(cd $ROOT && tar cfj ../../smbsrv-${git_rev}.tar.bz2 $files)
343}
344
345################################################################
346
347if [ "$1" = "" ]; then
348  set '?' # force usage
349fi
350
351set -x
352
353for arg
354do
355  case "$arg" in
356  install)
357    build_tools
358    set -e
359    do_hdrs $arg
360    do_kern $arg
361    do_libs $arg
362    do_cmds $arg
363    do_tests $arg
364    ;;
365  lint)
366    do_hdrs $arg
367    do_kern $arg
368    do_libs $arg
369    do_cmds $arg
370    ;;
371  clean)
372    # intentionally skip: deplib, hdrs, tools
373    do_tests $arg
374    do_cmds $arg
375    do_libs $arg
376    do_kern $arg
377    ;;
378  clobber)
379    do_tests $arg
380    do_cmds $arg
381    do_libs $arg
382    do_deplibs $arg
383    do_kern $arg
384    do_hdrs $arg
385    clobber_tools
386    ;;
387  deplibs)
388    build_tools
389    set -e
390    do_hdrs install
391    do_deplibs install
392    ;;
393  tags)
394    do_tags
395    ;;
396  tar)
397    do_tar
398    ;;
399  *)
400    echo "Usage: $0 {install|lint|clean|clobber|deplibs|tags|tar}";
401    exit 1;
402    ;;
403  esac
404done
405