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 normal make (not dmake) by default.
  18 make=${MAKE:-make}
  19 
  20 CLOSED_IS_PRESENT=no
  21 export 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 
  31 cpu=`uname -p`
  32 case $cpu in
  33 i386)
  34         x=intel
  35         kmdb_arch="amd64"
  36         mdb_arch="ia32 amd64"
  37         arch64=amd64
  38         ;;
  39 sparc)
  40         x=sparc
  41         kmdb_arch=v9
  42         mdb_arch="v7 v9"
  43         arch64=sparcv9
  44         ;;
  45 *)  echo "Huh?" ; exit 1;;
  46 esac
  47 
  48 ################################################################
  49 
  50 build_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 
  56 clobber_tools() {
  57   (cd $SRC/tools && $make clobber)
  58   (cd $SRC/common/mapfiles; $make clobber)
  59 }
  60 
  61 ################################################################
  62 
  63 do_hdrs() {
  64 
  65 targ=$1
  66 if [ "$targ" = clobber ]
  67 then
  68   (cd $SRC/uts && $make -k clobber_h)
  69   (cd $SRC/head && $make clobber)
  70 fi
  71 
  72 if [ "$targ" = install ]
  73 then
  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   # ... 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 $targ)
  87 
  88   # always update headers to be safe
  89   (cd $SRC/uts/common/sys && $make -k $targ)
  90   (cd $SRC/uts/common/c2 && $make -k $targ)
  91 fi
  92 
  93 if [ "$targ" = lint ]
  94 then
  95   targ=check
  96   (cd $SRC/uts/common/c2 && $make -k $targ)
  97 fi
  98 
  99 # Need some library headers too...
 100 for lib in \
 101   libbsm \
 102   auditd_plugins
 103 do
 104   (cd $SRC/lib/$lib && $make $targ)
 105 done
 106 }
 107 
 108 ################################################################
 109 
 110 do_kern() {
 111   case $1 in
 112   lint) targ=modlintlib ;;
 113   *) targ=$1 ;;
 114   esac
 115   ( unset SOURCEDEBUG ;
 116   (cd $SRC/uts/$x/c2audit && $make $targ) )
 117 }
 118 
 119 ################################################################
 120 
 121 # Note lib1 builds prerequisite libraries not delivered by the
 122 # tar file we create below.  To accelerate clean/install, we
 123 # skip these on clean (but still nuke them for clobber)
 124 
 125 do_lib1() {
 126 
 127 for lib in \
 128   libinetutil \
 129   smbsrv/libsmb
 130 do
 131   (cd $SRC/lib/$lib && $make $1)
 132 done
 133 }
 134 
 135 # lib2 builds stuff we include in the tar file,
 136 # or that we don't mind rebuilding after clean.
 137 
 138 do_lib2() {
 139 
 140 for lib in \
 141   auditd_plugins \
 142   libbsm
 143 do
 144   (cd $SRC/lib/$lib && $make $1)
 145 done
 146 
 147 }
 148 
 149 ################################################################
 150 
 151 do_cmds() {
 152 
 153 (cd $SRC/cmd/audit && $make $1)
 154 (cd $SRC/cmd/auditconfig && $make $1)
 155 (cd $SRC/cmd/auditd && $make $1)
 156 (cd $SRC/cmd/auditrecord && $make $1)
 157 (cd $SRC/cmd/auditreduce && $make $1)
 158 (cd $SRC/cmd/auditset && $make $1)
 159 (cd $SRC/cmd/auditstat && $make $1)
 160 (cd $SRC/cmd/audit_warn && $make $1)
 161 (cd $SRC/cmd/praudit && $make $1)
 162 
 163 #Doesn't look like there are any audit mdb modules.
 164 }
 165 ################################################################
 166 # This builds $SRC/TAGS (and cscope.files) in a helpful order.
 167 
 168 do_tags() {
 169         (cd $SRC ;
 170         find uts/common/sys -name '*.[ch]' -print |sort
 171         find uts/common/c2 -name '*.[ch]' -print |sort
 172         find head -name '*.h' -print |sort
 173         find lib/auditd_plugins -name '*.[ch]' -print |sort
 174         find lib/libbsm -name '*.[ch]' -print |sort
 175         find cmd/audit -name '*.[ch]' -print |sort
 176         find cmd/auditconfig -name '*.[ch]' -print |sort
 177         find cmd/auditd -name '*.[ch]' -print |sort
 178         find cmd/auditrecord -name '*.[ch]' -print |sort
 179         find cmd/auditreduce -name '*.[ch]' -print |sort
 180         find cmd/auditset -name '*.[ch]' -print |sort
 181         find cmd/auditstat -name '*.[ch]' -print |sort
 182         find cmd/audit_warn -name '*.[ch]' -print |sort
 183         find cmd/praudit -name '*.[ch]' -print |sort
 184         ) > $SRC/cscope.files
 185 
 186         (cd $SRC ;
 187         exctags -e --langmap=c:+.ndl -h ndl -L - < cscope.files
 188         cscope -b )
 189 }
 190 
 191 ################################################################
 192 # This creates a tarfile one can use to update a test machine.
 193 
 194 do_tar() {
 195         git_rev=`git rev-parse --short=8 HEAD`
 196         files="
 197 etc/security/audit_warn
 198 etc/security/audit_event
 199 etc/security/audit
 200 etc/security/audit_class
 201 lib/svc/manifest/system/auditd.xml
 202 lib/svc/manifest/system/auditset.xml
 203 lib/svc/method/svc-auditd
 204 lib/svc/method/svc-auditset
 205 lib/amd64/libbsm.so.1
 206 lib/libbsm.so.1
 207 kernel/sys/$arch64/c2audit
 208 usr/lib/amd64/libbsm.so.1
 209 usr/lib/libbsm.so.1
 210 usr/lib/audit/audit_record_attr
 211 usr/lib/security/audit_binfile.so.1
 212 usr/lib/security/audit_remote.so.1
 213 usr/lib/security/audit_syslog.so.1
 214 usr/sbin/auditreduce
 215 usr/sbin/praudit
 216 usr/sbin/auditstat
 217 usr/sbin/auditrecord
 218 usr/sbin/auditd
 219 usr/sbin/auditconfig
 220 usr/sbin/audit
 221 usr/share/lib/xml/dtd/adt_record.dtd.1
 222 usr/share/lib/xml/style/adt_record.xsl.1
 223 "
 224 # NOTE: usr/lib/security/audit_*.so.1 will have incorrect owners
 225 # after untarring. You'll need to set them to root.
 226 # chown root $ROOT/usr/lib/security/audit_*.so.1
 227         (cd $ROOT && tar cfj ../../audit-${git_rev}.tar.bz2 $files)
 228 }
 229 
 230 ################################################################
 231 
 232 if [ "$1" = "" ]; then
 233   set '?' # force usage
 234 fi
 235 
 236 set -x
 237 
 238 for arg
 239 do
 240   case "$arg" in
 241   install)
 242     build_tools
 243     set -e
 244     do_hdrs $arg
 245     do_kern $arg
 246     do_lib1 $arg
 247     do_lib2 $arg
 248     do_cmds $arg
 249     ;;
 250   lint)
 251     do_hdrs $arg
 252     do_kern $arg
 253     do_lib1 $arg
 254     do_lib2 $arg
 255     do_cmds $arg
 256     ;;
 257   clean)
 258     # intentionally skip: lib1, hdrs, tools
 259     do_cmds $arg
 260     do_lib2 $arg
 261     do_kern $arg
 262     ;;
 263   clobber)
 264     do_cmds $arg
 265     do_lib2 $arg
 266     do_lib1 $arg
 267     do_kern $arg
 268     do_hdrs $arg
 269     clobber_tools
 270     ;;
 271   tags)
 272     do_tags
 273     ;;
 274   tar)
 275     do_tar
 276     ;;
 277   *)
 278     echo "Usage: $0 {install|lint|clean|clobber|tags|tar}";
 279     exit 1;
 280     ;;
 281   esac
 282 done