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