#!/usr/local/bin/cbsd
#v11.0.0
CBSDMODULE="build"
MYARG="destdir"
MYOPTARG="ver arch target_arch basename stable"
MYDESC="Make distribtion for FreeBSD base"
ADDHELP=""

. ${subrdir}/nc.subr
readconf buildworld.conf
. ${subrdir}/universe.subr
. ${cbsdinit}

over="${ver}"
oarch="${arch}"

# By default ver=current version
. ${subrdir}/build.subr

init_distcc
init_notify
init_target_arch
init_srcdir
init_supported_arch
init_basedir

#TARGET_ARCH="${target_arch}"

LOCKFILE=${ftmpdir}/$( /sbin/md5 -qs ${MAKEOBJDIRPREFIX} ).lock
makelock $LOCKFILE

[ -f ${SRC_DIR}/etc/mtree/BSD.root.dist ] && /usr/sbin/mtree -deU -f ${SRC_DIR}/etc/mtree/BSD.root.dist -p ${destdir} >/dev/null
[ -f ${SRC_DIR}/etc/mtree/BSD.usr.dist ] && /usr/sbin/mtree -deU -f ${SRC_DIR}/etc/mtree/BSD.usr.dist -p ${destdir}/usr >/dev/null
[ -f ${SRC_DIR}/etc/mtree/BSD.var.dist ] && /usr/sbin/mtree -deU -f ${SRC_DIR}/etc/mtree/BSD.var.dist -p ${destdir}/var >/dev/null
[ -f ${SRC_DIR}/etc/mtree/BIND.chroot.dist ] && /usr/sbin/mtree -deU -f ${SRC_DIR}/etc/mtree/BIND.chroot.dist -p ${destdir}/var/named >/dev/null
[ -f ${SRC_DIR}/etc/mtree/BSD.sendmail.dist ] && /usr/sbin/mtree -deU -f ${SRC_DIR}/etc/mtree/BSD.sendmail.dist -p ${destdir} >/dev/null
[ -f ${SRC_DIR}/etc/mtree/BSD.include.dist ] && /usr/sbin/mtree -deU -f ${SRC_DIR}/etc/mtree/BSD.include.dist -p ${destdir}/usr/include >/dev/null
[ -f ${SRC_DIR}/etc/mtree/BSD.tests.dist ] && /usr/sbin/mtree -deU -f ${SRC_DIR}/etc/mtree/BSD.tests.dist -p ${destdir}/usr/tests >/dev/null

/usr/bin/make -C ${SRC_DIR}/etc distribution DESTDIR=${destdir} TARGET=${arch}
