xref: /illumos-gate/usr/src/tools/quick/make-idmap (revision 96dd34fce4380f5569e21176b9b310b458e5fb13)
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 2018 Nexenta Systems, Inc.  All rights reserved.
15#
16
17# Use distributed make (dmake) by default.
18make=${MAKE:-dmake}
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	mdb_arch="ia32 amd64"
36	arch64=amd64
37	;;
38sparc)
39	x=sparc
40	mdb_arch=v9
41	arch64=sparcv9
42	;;
43*)  echo "Huh?" ; exit 1;;
44esac
45
46################################################################
47
48build_tools() {
49  test -f $SRC/tools/proto/root_i386-nd/opt/onbld/bin/genoffsets ||
50    (cd $SRC/tools && $make install)
51  (cd $SRC/common/mapfiles; $make install)
52}
53
54clobber_tools() {
55  (cd $SRC/tools && $make clobber)
56  (cd $SRC/common/mapfiles; $make clobber)
57}
58
59################################################################
60
61do_hdrs() {
62
63targ=$1
64if [ "$targ" = clobber ]
65then
66  (cd $SRC/uts && $make -k clobber_h)
67  (cd $SRC/head && $make clobber)
68fi
69
70if [ "$targ" = install ]
71then
72  targ=install_h
73
74  # Just the parts of "make sgs" we need, and
75  # skip them if they appear to be done.
76  # ... stuff under $SRC
77  test -f $SRC/uts/common/sys/priv_names.h ||
78    (cd $SRC/uts && $make -k all_h)
79
80  test -f $SRC/head/rpcsvc/nispasswd.h ||
81    (cd $SRC/head && $make -k install_h)
82
83  # ... stuff under $ROOT (proto area)
84  test -d $ROOT/usr/include/sys ||
85    (cd $SRC && $make rootdirs)
86  test -f $ROOT/usr/include/sys/types.h ||
87    (cd $SRC/uts && $make -k install_h)
88  test -f $ROOT/usr/include/rpcsvc/daemon_utils.h ||
89    (cd $SRC/head && $make install_h)
90
91  # system and smbsrv headers (we need to build libsmb)
92  (cd $SRC/uts/common/sys && $make -k install_h)
93  (cd $SRC/uts/common/smb && $make -k install_h)
94  (cd $SRC/uts/common/smbsrv && $make -k install_h)
95
96fi
97
98# Need some library headers too...
99for lib in \
100  libads \
101  libbsm \
102  libcmdutils \
103  libcryptoutil \
104  libdevid \
105  libgss \
106  libkrb5 \
107  libldap5 \
108  libidmap \
109  libsmbfs \
110  libsqlite \
111  libuutil
112do
113  (cd $SRC/lib/$lib && $make $targ)
114done
115}
116
117################################################################
118
119do_kern() {
120  case $1 in
121  lint) targ=modlintlib ;;
122  *) targ=$1 ;;
123  esac
124  ( unset SOURCEDEBUG ;
125  (cd $SRC/uts/$x/idmap && $make $targ) )
126}
127
128################################################################
129
130do_libs() {
131
132for lib in \
133  libavl \
134  libcmdutils \
135  libldap5 \
136  libadutils \
137  libuutil \
138  libidmap \
139  libads \
140  libsmbfs \
141  libsqlite \
142  nsswitch/ad
143do
144  (cd $SRC/lib/$lib && $make $1)
145done
146
147# need libsmb for cmd/idmap/idmapd (and libsmbfs for libsmb)
148(cd $SRC/lib/smbsrv/libsmb && $make $1)
149
150}
151
152################################################################
153
154do_cmds() {
155
156(cd $SRC/cmd/idmap && $make $1)
157
158}
159
160
161################################################################
162# This builds $SRC/TAGS (and cscope.files) in a helpful order.
163
164do_tags() {
165	(cd $SRC ;
166	find uts/common/sys -name '*.[ch]' -print |sort
167	find uts/common/net -name '*.[ch]' -print |sort
168	find uts/common/netinet -name '*.[ch]' -print |sort
169	find uts/common/rpcsvc -name '*.[ch]' -print |sort
170	find uts/common/idmap -name '*.[ch]' -print |sort
171	find head -name '*.h' -print |sort
172	find lib/libidmap -name '*.[ch]' -print |sort
173	find lib/libadutils -name '*.[ch]' -print |sort
174	find lib/libldap5 -name '*.[ch]' -print |sort
175	find cmd/idmap -name '*.[ch]' -print |sort
176	) > $SRC/cscope.files
177
178	(cd $SRC ;
179	exctags -e --langmap=c:+.ndl -h ndl -L - < cscope.files
180	cscope -b )
181}
182
183################################################################
184# This creates a tarfile one can use to update a test machine.
185
186do_tar() {
187	git_rev=`git rev-parse --short=8 HEAD`
188	files="
189kernel/misc/amd64/idmap
190lib/svc/manifest/system/idmap.xml
191usr/lib/idmapd
192usr/lib/libads.so.1
193usr/lib/$arch64/libads.so.1
194usr/lib/libadutils.so.1
195usr/lib/$arch64/libadutils.so.1
196usr/lib/libidmap.so.1
197usr/lib/$arch64/libidmap.so.1
198usr/lib/libldap.so.5
199usr/lib/$arch64/libldap.so.5
200usr/lib/nss_ad.so.1
201usr/lib/$arch64/nss_ad.so.1
202usr/bin/test-getdc
203usr/sbin/idmap
204usr/sbin/nltest
205"
206
207	(cd $ROOT && tar cfj ../../idmap-${git_rev}.tar.bz2 $files)
208}
209
210################################################################
211
212if [ "$1" = "" ]; then
213  set '?' # force usage
214fi
215
216set -x
217
218for arg
219do
220  case "$arg" in
221  build|install)
222    arg=install
223    build_tools
224    set -e
225    do_hdrs $arg
226    do_kern $arg
227    do_libs $arg
228    do_cmds $arg
229    ;;
230  lint)
231    do_kern $arg
232    do_libs $arg
233    do_cmds $arg
234    ;;
235  clean)
236    do_cmds $arg
237    do_libs $arg
238    do_kern $arg
239    ;;
240  clobber)
241    do_cmds $arg
242    do_libs $arg
243    do_kern $arg
244    do_hdrs $arg
245    clobber_tools
246    ;;
247  tags)
248    do_tags
249    ;;
250  tar)
251    do_tar
252    ;;
253  *)
254    echo "Usage: $0 {build|lint|clean|clobber|tags|tar}";
255    exit 1;
256    ;;
257  esac
258done
259