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.
18 make=${MAKE:-dmake}
19
20 CLOSED_IS_PRESENT=no
21 export CLOSED_IS_PRESENT
22
23 [ -n "$SRC" ] || {
24 echo "SRC not set. Run 'ws' or 'bldenv' first."
25 exit 1
26 }
27
28 cpu=`uname -p`
29 case $cpu in
30 i386)
31 x=intel
32 kmdb_arch="amd64"
33 mdb_arch="ia32 amd64"
34 arch32=i86
35 arch64=amd64
36 ;;
37 sparc)
38 x=sparc
39 kmdb_arch=v9
40 mdb_arch="v7 v9"
41 arch32=sparc
42 arch64=sparcv9
43 ;;
44 *) echo "Huh?" ; exit 1;;
45 esac
46
47 ################################################################
48
49 build_tools() {
50 test -f $SRC/tools/proto/root_i386-nd/opt/onbld/bin/genoffsets ||
51 (cd $SRC/tools && $make install)
52 (cd $SRC/common/mapfiles; $make install)
53 }
54
55 clobber_tools() {
56 (cd $SRC/tools && $make clobber)
57 (cd $SRC/common/mapfiles; $make clobber)
58 }
59
60 ################################################################
61
62 do_hdrs() {
63
64 targ=$1
65 if [ "$targ" = clobber ]
66 then
67 (cd $SRC/uts && $make -k clobber_h)
68 (cd $SRC/head && $make clobber)
69 fi
70
71 if [ "$targ" = install ]
72 then
73 targ=install_h
74
75 # Just the parts of "make sgs" we need, and
76 # skip them if they appear to be done.
77 # ... stuff under $SRC
78 test -f $SRC/uts/common/sys/priv_names.h ||
79 (cd $SRC/uts && $make -k all_h)
80
81 test -f $SRC/head/rpcsvc/nispasswd.h ||
82 (cd $SRC/head && $make -k install_h)
83
84 # ... stuff under $ROOT (proto area)
85 test -d $ROOT/usr/include/sys ||
86 (cd $SRC && $make rootdirs)
87 test -f $ROOT/usr/include/sys/types.h ||
88 (cd $SRC/uts && $make -k install_h)
89 test -f $ROOT/usr/include/rpcsvc/daemon_utils.h ||
90 (cd $SRC/head && $make install_h)
91 (cd $SRC/uts/common/c2 && $make -k install_h)
92
93 # always update the sys headers to be safe
94 (cd $SRC/uts/common/sys && $make -k install_h)
95
96 fi
97
98 # Need some library headers too...
99 for lib in \
100 libbsm \
101 libcmdutils \
102 libcryptoutil \
103 libdevid \
104 libdiskmgt \
105 libidmap \
106 libpam \
107 libsec \
108 libscf \
109 libshare \
110 libuutil \
111 libzpool \
112 libzfs_core \
113 libzfs \
114 libzfs_jni
115 do
116 (cd $SRC/lib/$lib && $make $targ)
117 done
118 # Should fix the Makefile here so all_h or install_h works.
119 (cd $SRC/lib/libzpool/$cpu && $make ../common/zfs.h)
120 }
121
122 ################################################################
123
124 do_kern() {
125 case $1 in
126 lint) targ=modlintlib ;;
127 *) targ=$1 ;;
128 esac
129 (cd $SRC/uts/$x/zfs && $make $targ)
130 }
131
132 ################################################################
133 #
134 # Build all libraries used by the other targets in here.
135 #
136 # Run this once (at least) in each new workspace where you
137 # will run "make-zfs install", if you want to avoid linking
138 # against the libraries from your build host.
139 #
140 do_deplibs() {
141
142 # install all the lib headers
143 if [ "$1" = install ] ; then
144 (cd $SRC/lib && $make install_h)
145 fi
146
147 # Wow, building libc takes a while. Really want that?
148 for lib in \
149 libc \
150 libavl \
151 libnvpair \
152 libsec \
153 libcmdutils \
154 libdevinfo \
155 libuutil \
156 libbrand \
157 libzonecfg \
158 libinetutil \
159 libdladm \
160 libdlpi \
161 libdiskmgt \
162 libumem \
163 libdisasm \
164 libidmap \
165 libdevid \
166 libsaveargs
167 do
168 (cd $SRC/lib/$lib && $make $1)
169 done
170 }
171
172 ################################################################
173
174 do_libs() {
175
176 for lib in \
177 libavl \
178 libcmdutils \
179 libuutil \
180 libzpool \
181 libzfs_core \
182 libzfs \
183 libzfs_jni \
184 pyzfs
185 do
186 (cd $SRC/lib/$lib && $make $1)
187 done
188 (cd $SRC/lib/libshare && $make $1 PLUGINS=)
189 }
190
191 ################################################################
192
193 do_cmds() {
194
195 for cmd in \
196 availdevs \
197 isaexec \
198 fstyp \
199 zdb \
200 zfs \
201 zhack \
202 zinject \
203 zpool \
204 ztest \
205 zstreamdump \
206 pyzfs
207 do
208 (cd $SRC/cmd/$cmd && $make $1)
209 done
210
211 case $1 in
212 install)
213 # mount programs need fslib.o
214 (cd $SRC/cmd/fs.d/zfs && $make $1)
215 # Build just the ZFS devfsadm module
216 (cd $SRC/cmd/devfsadm/$cpu && $make SUNW_zfs_link.so \
217 ${ROOT}/usr/lib/devfsadm/linkmod \
218 ${ROOT}/usr/lib/devfsadm/linkmod/SUNW_zfs_link.so )
219 ;;
220 clean|clobber)
221 (cd $SRC/cmd/fs.d/zfs && $make clobber)
222 (cd $SRC/cmd/fs.d && $make ${1}_local)
223 (cd $SRC/cmd/devfsadm && $make $1)
224 ;;
225 esac
226
227 (cd $SRC/cmd/syseventd/modules/zfs_mod && $make $1)
228
229 # Build the MDB modules, WITH the linktest
230 (cd $SRC/cmd/mdb/tools && $make $1)
231
232 # kmdb_arch is 64-bit only
233 for a in $kmdb_arch
234 do
235 case $1 in
236 install|lint)
237 (cd $SRC/cmd/mdb/$x/$a/kmdb &&
238 $make kmdb_modlinktest.o )
239 ;;
240 clean|clobber)
241 (cd $SRC/cmd/mdb/$x/$a/kmdb &&
242 $make -k $1 )
243 ;;
244 esac
245
246 (cd $SRC/cmd/mdb/$x/$a/zfs &&
247 $make $1 KMDB_LINKTEST_ENABLE= )
248
249 done
250
251 # mdb_arch is both 32-bit & 64-bit
252 for a in $mdb_arch
253 do
254 (cd $SRC/cmd/mdb/$x/$a/libzpool &&
255 $make $1 )
256
257 done
258 }
259
260 ################################################################
261
262 do_mans() {
263
264 case "$1" in
265 install)
266 (cd $SRC/man/man1m && make \
267 $ROOT/usr/share/man/man1m/zdb.1m \
268 $ROOT/usr/share/man/man1m/zfs.1m \
269 $ROOT/usr/share/man/man1m/zfs-program.1m \
270 $ROOT/usr/share/man/man1m/zpool.1m )
271 (cd $SRC/man/man5 && make \
272 $ROOT/usr/share/man/man5/zpool-features.5 )
273 ;;
274 lint)
275 (cd $SRC/man/man1m && make zdb.1m.check zfs.1m.check zfs-program.1m.check \
276 zpool.1m.check)
277 (cd $SRC/man/man5 && make zpool-features.5.check)
278 ;;
279 *)
280 (cd $SRC/man/man1m && make $1)
281 (cd $SRC/man/man5 && make $)
282 ;;
283 esac
284 }
285
286 ################################################################
287 # This builds $SRC/TAGS (and cscope.files) in a helpful order.
288
289 do_tags() {
290 (cd $SRC ;
291 find uts/common/sys -name '*.[ch]' -print |sort
292 find uts/common/fs/zfs -name '*.[ch]' -print |sort
293 find lib/libzpool -name '*.[ch]' -print |sort
294 find lib/libzfs -name '*.[ch]' -print |sort
295 find cmd/zpool -name '*.[ch]' -print |sort
296 find cmd/zfs -name '*.[ch]' -print |sort
297 find cmd/zdb -name '*.[ch]' -print |sort
298 find cmd/zhack -name '*.[ch]' -print |sort
299 find cmd/zinject -name '*.[ch]' -print |sort
300 find cmd/ztest -name '*.[ch]' -print |sort
301 find common/zfs -name '*.[ch]' -print |sort
302 echo cmd/mdb/common/modules/zfs/zfs.c
303 ) > $SRC/cscope.files
304
305 (cd $SRC ;
306 exctags -e --langmap=c:+.ndl -h ndl -L - < cscope.files
307 cscope -b )
308 }
309
310 ################################################################
311 # This creates a tarfile one can use to update a test machine.
312
313 do_tar() {
314 git_rev=`git rev-parse --short=8 HEAD`
315 files="
316 kernel/drv/$arch64/zfs
317 kernel/fs/$arch64/zfs
318 kernel/kmdb/$arch64/zfs
319 lib/$arch64/libzfs.so.1
320 lib/$arch64/libzfs_core.so.1
321 lib/libzfs.so.1
322 lib/libzfs_core.so.1
323 usr/bin/$arch32/ztest
324 usr/bin/$arch64/ztest
325 usr/lib/$arch64/libzfs_jni.so.1
326 usr/lib/$arch64/libzpool.so.1
327 usr/lib/devfsadm/linkmod/SUNW_zfs_link.so
328 usr/lib/fs/zfs/bootinstall
329 usr/lib/fs/zfs/fstyp.so.1
330 usr/lib/libzfs_jni.so.1
331 usr/lib/libzpool.so.1
332 usr/lib/mdb/kvm/$arch64/zfs.so
333 usr/lib/mdb/proc/$arch64/libzpool.so
334 usr/lib/mdb/proc/libzpool.so
335 sbin/zfs
336 sbin/zpool
337 usr/lib/sysevent/modules/zfs_mod.so
338 usr/lib/zfs/availdevs
339 usr/lib/zfs/pyzfs.py
340 usr/lib/zfs/pyzfs.pyc
341 usr/sbin/$arch32/zdb
342 usr/sbin/$arch64/zdb
343 usr/sbin/$arch32/zhack
344 usr/sbin/$arch64/zhack
345 usr/sbin/$arch32/zinject
346 usr/sbin/$arch64/zinject
347 usr/sbin/zstreamdump
348 usr/share/man/man1m/zdb.1m
349 usr/share/man/man1m/zfs.1m
350 usr/share/man/man1m/zfs-program.1m
351 usr/share/man/man1m/zpool.1m
352 usr/share/man/man5/zpool-features.5
353 "
354 (cd $ROOT && tar cfj ../../zfs-${git_rev}.tar.bz2 $files)
355 }
356
357 ################################################################
358
359 if [ "$1" = "" ]; then
360 set '?' # force usage
361 fi
362
363 set -x
364
365 for arg
366 do
367 case "$arg" in
368 install)
369 build_tools
370 set -e
371 do_hdrs $arg
372 do_kern $arg
373 do_libs $arg
374 do_cmds $arg
375 do_mans $arg
376 ;;
377 lint)
378 do_kern $arg
379 do_libs $arg
380 do_cmds $arg
381 do_mans $arg
382 ;;
383 clean)
384 do_mans $arg
385 do_cmds $arg
386 do_libs $arg
387 do_kern $arg
388 ;;
389 clobber)
390 do_mans $arg
391 do_cmds $arg
392 do_libs $arg
393 do_kern $arg
394 do_hdrs $arg
395 clobber_tools
396 ;;
397 deplibs)
398 build_tools
399 set -e
400 do_hdrs install
401 do_deplibs install
402 ;;
403 tags)
404 do_tags
405 ;;
406 tar)
407 do_tar
408 ;;
409 *)
410 echo "Usage: $0 {install|lint|clean|clobber|deplibs|tags|tar}";
411 exit 1;
412 ;;
413 esac
414 done