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