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