3 # Copyright (c) 2005 Poul-Henning Kamp.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #######################################################################
34 # Setup default values for all controlling variables.
35 # These values can be overridden from the config file(s)
37 #######################################################################
39 # Name of this NanoBSD build. (Used to construct workdir names)
42 # Source tree directory
45 # Where nanobsd additional files live under the source tree
46 NANO_TOOLS=tools/tools/nanobsd
48 # Where cust_pkgng() finds packages to install
49 NANO_PACKAGE_DIR=${NANO_SRC}/${NANO_TOOLS}/Pkg
52 # where package metadata gets placed
53 NANO_PKG_META_BASE=/var/db
55 # Path to mtree file to apply to anything copied by cust_install_files().
56 # If you specify this, the mtree file *must* have an entry for every file and
57 # directory located in Files.
58 #NANO_CUST_FILES_MTREE=""
60 # Object tree directory
61 # default is subdir of /usr/obj
64 # The directory to put the final images
65 # default is ${NANO_OBJ}
68 # Make & parallel Make
70 NANO_PMAKE="make -j 3"
72 # The default name for any image we create.
73 NANO_IMGNAME="_.disk.full"
74 NANO_IMG1NAME="_.disk.image"
76 # Options to put in make.conf during buildworld only
79 # Options to put in make.conf during installworld only
82 # Options to put in make.conf during both build- & installworld.
85 # Kernel config file to use
88 # Kernel modules to install. If empty, no modules are installed.
89 # Use "default" to install all built modules.
92 # Early customize commands.
93 NANO_EARLY_CUSTOMIZE=""
98 # Late customize commands.
99 NANO_LATE_CUSTOMIZE=""
101 # Newfs parameters to use
102 NANO_NEWFS="-b 4096 -f 512 -i 8192 -U"
104 # The drive name of the media at runtime
107 # Target media size in 512 bytes sectors
108 NANO_MEDIASIZE=2000000
110 # Number of code images on media (1 or 2)
113 # 0 -> Leave second image all zeroes so it compresses better.
114 # 1 -> Initialize second image with a copy of the first
117 # Size of code file system in 512 bytes sectors
118 # If zero, size will be as large as possible.
121 # Size of configuration file system in 512 bytes sectors
125 # Size of data file system in 512 bytes sectors
126 # If zero: no partition configured.
127 # If negative: max size possible
130 # Size of the /etc ramdisk in 512 bytes sectors
131 NANO_RAM_ETCSIZE=10240
133 # Size of the /tmp+/var ramdisk in 512 bytes sectors
134 NANO_RAM_TMPVARSIZE=10240
136 # boot0 flags/options and configuration
137 NANO_BOOT0CFG="-o packet -s 1 -m 3"
138 NANO_BOOTLOADER="boot/boot0sio"
140 # boot2 flags/options
141 # default force serial console
142 NANO_BOOT2CFG="-h -S115200"
144 # Backing type of md(4) device
145 # Can be "file" or "swap"
146 NANO_MD_BACKING="file"
148 # for swap type md(4) backing, write out the mbr only
149 NANO_IMAGE_MBRONLY=true
151 # Progress Print level
154 # Set NANO_LABEL to non-blank to form the basis for using /dev/ufs/label
155 # in preference to /dev/${NANO_DRIVE}
156 # Root partition will be ${NANO_LABEL}s{1,2}
157 # /cfg partition will be ${NANO_LABEL}s3
158 # /data partition will be ${NANO_LABEL}s4
161 NANO_SLICE_ALTROOT=s2
167 # Default ownwership for nopriv build
171 #######################################################################
172 # Architecture to build. Corresponds to TARGET_ARCH in a buildworld.
173 # Unfortunately, there's no way to set TARGET at this time, and it
174 # conflates the two, so architectures where TARGET != TARGET_ARCH and
175 # TARGET can't be guessed from TARGET_ARCH do not work. This defaults
176 # to the arch of the current machine.
179 # CPUTYPE defaults to "" which is the default when CPUTYPE isn't
183 # Directory to populate /cfg from
186 # Directory to populate /data from
189 # We don't need SRCCONF or SRC_ENV_CONF. NanoBSD puts everything we
190 # need for the build in files included with __MAKE_CONF. Override in your
191 # config file if you really must. We set them unconditionally here, though
192 # in case they are stray in the build environment
194 SRC_ENV_CONF=/dev/null
196 #######################################################################
198 # The functions which do the real work.
199 # Can be overridden from the config file(s)
201 #######################################################################
203 # Export values into the shell. Must use { } instead of ( ) like
204 # other functions to avoid a subshell.
205 # We set __MAKE_CONF as a global since it is easier to get quoting
206 # right for paths with spaces in them.
208 # Similar to export_var, except puts the data out to stdout
211 echo "Setting variable: $var=\"$val\""
215 nano_make_build_env ( ) {
216 __MAKE_CONF="${NANO_MAKE_CONF_BUILD}"
217 make_export __MAKE_CONF
220 nano_make_install_env ( ) {
221 __MAKE_CONF="${NANO_MAKE_CONF_INSTALL}"
222 make_export __MAKE_CONF
225 # Extra environment variables for kernel builds
226 nano_make_kernel_env ( ) {
227 if [ -f "${NANO_KERNEL}" ] ; then
228 KERNCONFDIR="$(realpath $(dirname ${NANO_KERNEL}))"
229 KERNCONF="$(basename ${NANO_KERNEL})"
230 make_export KERNCONFDIR
233 export KERNCONF="${NANO_KERNEL}"
238 nano_global_make_env ( ) (
239 # global settings for the make.conf file, if set
240 [ -z "${NANO_ARCH}" ] || echo TARGET_ARCH="${NANO_ARCH}"
241 [ -z "${NANO_CPUTYPE}" ] || echo TARGET_CPUTYPE="${NANO_CPUTYPE}"
244 # rm doesn't know -x prior to FreeBSD 10, so cope with a variety of build
245 # hosts for now. This will go away when support in the base goes away.
249 7*|8*|9*) command rm $* ;;
250 *) command rm -x $* ;;
255 # Create empty files in the target tree, and record the fact. All paths
256 # are relative to NANO_WORLDDIR.
260 cd "${NANO_WORLDDIR}"
263 echo "./${i} type=file" >> ${NANO_METALOG}
268 # Convert a directory into a symlink. Takes two arguments, the
269 # current directory and what it should become a symlink to. The
270 # directory is removed and a symlink is created. If we're doing
271 # a nopriv build, then append this fact to the metalog
277 cd "${NANO_WORLDDIR}"
279 ln -s "$symlink" "$dir"
280 if [ -n "$NANO_METALOG" ]; then
281 echo "./${dir} type=link mode=0777 link=${symlink}" >> ${NANO_METALOG}
285 # run in the world chroot, errors fatal
287 chroot "${NANO_WORLDDIR}" /bin/sh -exc "$*"
290 # run in the world chroot, errors not fatal
292 chroot "${NANO_WORLDDIR}" /bin/sh -c "$*" || true
296 [ $? -eq 0 ] || echo "Error encountered. Check for errors in last log file." 1>&2
301 pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})"
303 if ! rm -rf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then
304 chflags -R noschg ${MAKEOBJDIRPREFIX}/
305 rm -r ${MAKEOBJDIRPREFIX}/
309 make_conf_build ( ) (
310 pprint 2 "Construct build make.conf ($NANO_MAKE_CONF_BUILD)"
312 mkdir -p ${MAKEOBJDIRPREFIX}
313 printenv > ${MAKEOBJDIRPREFIX}/_.env
315 # Make sure we get all the global settings that NanoBSD wants
316 # in addition to the user's global settings
321 ) > ${NANO_MAKE_CONF_BUILD}
325 pprint 2 "run buildworld"
326 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bw"
332 ${NANO_PMAKE} buildworld
333 ) > ${MAKEOBJDIRPREFIX}/_.bw 2>&1
339 pprint 2 "build kernel ($NANO_KERNEL)"
340 pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bk"
346 # Note: We intentionally build all modules, not only the ones in
347 # NANO_MODULES so the built world can be reused by multiple images.
348 # Although MODULES_OVERRIDE can be defined in the kernel config
349 # file to override this behavior. Just set NANO_MODULES=default.
352 ${NANO_PMAKE} buildkernel
353 ) > ${MAKEOBJDIRPREFIX}/_.bk 2>&1
357 if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then
358 pprint 2 "Clean and create object directory (${NANO_OBJ})"
359 if ! rm -rf ${NANO_OBJ}/ > /dev/null 2>&1 ; then
360 chflags -R noschg ${NANO_OBJ}
363 mkdir -p "${NANO_OBJ}" "${NANO_WORLDDIR}"
364 printenv > ${NANO_LOG}/_.env
366 pprint 2 "Clean and create world directory (${NANO_WORLDDIR})"
367 if ! rm -rf "${NANO_WORLDDIR}/" > /dev/null 2>&1 ; then
368 chflags -R noschg "${NANO_WORLDDIR}"
369 rm -rf "${NANO_WORLDDIR}/"
371 mkdir -p "${NANO_WORLDDIR}"
375 make_conf_install ( ) (
376 pprint 2 "Construct install make.conf ($NANO_MAKE_CONF_INSTALL)"
378 # Make sure we get all the global settings that NanoBSD wants
379 # in addition to the user's global settings
383 echo "${CONF_INSTALL}"
384 if [ -n "${NANO_NOPRIV_BUILD}" ]; then
386 echo METALOG=${NANO_METALOG}
388 ) > ${NANO_MAKE_CONF_INSTALL}
392 pprint 2 "installworld"
393 pprint 3 "log: ${NANO_LOG}/_.iw"
396 nano_make_install_env
399 ${NANO_MAKE} installworld DESTDIR="${NANO_WORLDDIR}"
400 chflags -R noschg "${NANO_WORLDDIR}"
401 ) > ${NANO_LOG}/_.iw 2>&1
406 pprint 2 "install /etc"
407 pprint 3 "log: ${NANO_LOG}/_.etc"
410 nano_make_install_env
413 ${NANO_MAKE} distribution DESTDIR="${NANO_WORLDDIR}"
414 # make.conf doesn't get created by default, but some ports need it
415 # so they can spam it.
416 cp /dev/null "${NANO_WORLDDIR}"/etc/make.conf
417 ) > ${NANO_LOG}/_.etc 2>&1
423 pprint 2 "install kernel ($NANO_KERNEL)"
424 pprint 3 "log: ${NANO_LOG}/_.ik"
428 nano_make_install_env
431 if [ "${NANO_MODULES}" != "default" ]; then
432 MODULES_OVERRIDE="${NANO_MODULES}"
433 make_export MODULES_OVERRIDE
438 ${NANO_MAKE} installkernel DESTDIR="${NANO_WORLDDIR}"
440 ) > ${NANO_LOG}/_.ik 2>&1
444 print 2 "Installing the optimized native build tools for cross env"
445 pprint 3 "log: ${NANO_LOG}/_.native_xtools"
449 nano_make_install_env
452 ${NANO_MAKE} native-xtools DESTDIR="${NANO_WORLDDIR}"
454 ) > ${NANO_LOG}/_.native_xtools 2>&1
458 # Run the requested set of early customization scripts, run before
461 run_early_customize() {
463 pprint 2 "run early customize scripts"
464 for c in $NANO_EARLY_CUSTOMIZE
466 pprint 2 "early customize \"$c\""
467 pprint 3 "log: ${NANO_LOG}/_.early_cust.$c"
469 { set -x ; $c ; set +x ; } >${NANO_LOG}/_.early_cust.$c 2>&1
474 # Run the requested set of customization scripts, run after we've
475 # done an installworld, installed the etc files, installed the kernel
476 # and tweaked them in the standard way.
480 pprint 2 "run customize scripts"
481 for c in $NANO_CUSTOMIZE
483 pprint 2 "customize \"$c\""
484 pprint 3 "log: ${NANO_LOG}/_.cust.$c"
486 ( set -x ; $c ) > ${NANO_LOG}/_.cust.$c 2>&1
491 # Run any last-minute customization commands after we've had a chance to
492 # setup nanobsd, prune empty dirs from /usr, etc
494 run_late_customize ( ) (
496 pprint 2 "run late customize scripts"
497 for c in $NANO_LATE_CUSTOMIZE
499 pprint 2 "late customize \"$c\""
500 pprint 3 "log: ${NANO_LOG}/_.late_cust.$c"
502 ( set -x ; $c ) > ${NANO_LOG}/_.late_cust.$c 2>&1
507 # Hook called after we run all the late customize commands, but
508 # before we invoke the disk imager. The nopriv build uses it to
509 # read in the meta log, apply the changes other parts of nanobsd
510 # have been recording their actions. It's not anticipated that
511 # a user's cfg file would override this.
513 fixup_before_diskimage ( ) (
515 # Run the deduplication script that takes the matalog journal and
516 # combines multiple entries for the same file (see source for
517 # details). We take the extra step of removing the size keywords. This
518 # script, and many of the user scripts, copies, appeneds and otherwise
519 # modifies files in the build, changing their sizes. These actions are
520 # impossible to trap, so go ahead remove the size= keyword. For this
521 # narrow use, it doesn't buy us any protection and just gets in the way.
522 # The dedup tool's output must be sorted due to limitations in awk.
523 if [ -n "${NANO_METALOG}" ]; then
524 pprint 2 "Fixing metalog"
525 cp ${NANO_METALOG} ${NANO_METALOG}.pre
526 echo "/set uname=${NANO_DEF_UNAME} gname=${NANO_DEF_GNAME}" > ${NANO_METALOG}
527 cat ${NANO_METALOG}.pre | ${NANO_TOOLS}/mtree-dedup.awk | \
528 sed -e 's/ size=[0-9][0-9]*//' | sort >> ${NANO_METALOG}
533 pprint 2 "configure nanobsd setup"
534 pprint 3 "log: ${NANO_LOG}/_.dl"
537 cd "${NANO_WORLDDIR}"
539 # Move /usr/local/etc to /etc/local so that the /cfg stuff
540 # can stomp on it. Otherwise packages like ipsec-tools which
541 # have hardcoded paths under ${prefix}/etc are not tweakable.
542 if [ -d usr/local/etc ] ; then
546 find . -print | cpio -dumpl ../../../etc/local
549 ln -s ../../etc/local etc
555 # link /$d under /conf
556 # we use hard links so we have them both places.
557 # the files in /$d will be hidden by the mount.
558 mkdir -p conf/base/$d conf/default/$d
559 find $d -print | cpio -dumpl conf/base/
562 echo "$NANO_RAM_ETCSIZE" > conf/base/etc/md_size
563 echo "$NANO_RAM_TMPVARSIZE" > conf/base/var/md_size
565 # pick up config files from the special partition
566 echo "mount -o ro /dev/${NANO_DRIVE}${NANO_SLICE_CFG}" > conf/default/etc/remount
568 # Put /tmp on the /var ramdisk (could be symlink already)
569 tgt_dir2symlink tmp var/tmp
571 ) > ${NANO_LOG}/_.dl 2>&1
574 setup_nanobsd_etc ( ) (
575 pprint 2 "configure nanobsd /etc"
578 cd "${NANO_WORLDDIR}"
580 # create diskless marker file
583 [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 666 etc/defaults/rc.conf
585 # Make root filesystem R/O by default
586 echo "root_rw_mount=NO" >> etc/defaults/rc.conf
587 # Disable entropy file, since / is read-only /var/db/entropy should be enough?
588 echo "entropy_file=NO" >> etc/defaults/rc.conf
590 [ -n "${NANO_NOPRIV_BUILD}" ] && chmod 444 etc/defaults/rc.conf
592 # save config file for scripts
593 echo "NANO_DRIVE=${NANO_DRIVE}" > etc/nanobsd.conf
595 echo "/dev/${NANO_DRIVE}${NANO_ROOT} / ufs ro 1 1" > etc/fstab
596 echo "/dev/${NANO_DRIVE}${NANO_SLICE_CFG} /cfg ufs rw,noauto 2 2" >> etc/fstab
603 # Remove all empty directories in /usr
604 find "${NANO_WORLDDIR}"/usr -type d -depth -print |
607 rmdir $d > /dev/null 2>&1 || true
616 echo newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev}
617 newfs ${NANO_NEWFS} ${NANO_LABEL:+-L${NANO_LABEL}${lbl}} ${dev}
618 mount -o async ${dev} ${mnt}
621 # Convenient spot to work around any umount issues that your build environment
622 # hits by overriding this method.
628 local dev dir mnt lbl
633 echo "Creating ${dev} (mounting on ${mnt})"
634 newfs_part ${dev} ${mnt} ${lbl}
635 if [ -n "${dir}" -a -d "${dir}" ]; then
636 echo "Populating ${lbl} from ${dir}"
638 find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)/' | cpio -dumpv ${mnt}
644 populate_cfg_slice ( ) (
645 populate_slice "$1" "$2" "$3" "$4"
648 populate_data_slice ( ) (
649 populate_slice "$1" "$2" "$3" "$4"
653 # Redefine this function with any last orders you may have
654 # after the build completed, for instance to copy the finished
655 # image to a more convenient place:
656 # cp ${NANO_DISKIMGDIR}/${NANO_IMG1NAME} /home/ftp/pub/nanobsd.disk
660 #######################################################################
662 # Optional convenience functions.
664 #######################################################################
666 #######################################################################
667 # Common Flash device geometries
671 if [ -d ${NANO_TOOLS} ] ; then
672 . ${NANO_TOOLS}/FlashDevice.sub
674 . ${NANO_SRC}/${NANO_TOOLS}/FlashDevice.sub
676 sub_FlashDevice $1 $2
679 #######################################################################
680 # USB device geometries
683 # UsbDevice Generic 1000 # a generic flash key sold as having 1GB
685 # This function will set NANO_MEDIASIZE, NANO_HEADS and NANO_SECTS for you.
687 # Note that the capacity of a flash key is usually advertised in MB or
688 # GB, *not* MiB/GiB. As such, the precise number of cylinders available
689 # for C/H/S geometry may vary depending on the actual flash geometry.
691 # The following generic device layouts are understood:
692 # generic An alias for generic-hdd.
693 # generic-hdd 255H 63S/T xxxxC with no MBR restrictions.
694 # generic-fdd 64H 32S/T xxxxC with no MBR restrictions.
696 # The generic-hdd device is preferred for flash devices larger than 1GB.
700 a1=`echo $1 | tr '[:upper:]' '[:lower:]'`
705 NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 ))
710 NANO_MEDIASIZE=$(( $2 * 1000 * 1000 / 512 ))
713 echo "Unknown USB flash device"
719 #######################################################################
720 # Setup serial console
722 cust_comconsole ( ) (
723 # Enable getty on console
724 sed -i "" -e /tty[du]0/s/off/on/ ${NANO_WORLDDIR}/etc/ttys
726 # Disable getty on syscons devices
727 sed -i "" -e '/^ttyv[0-8]/s/ on/ off/' ${NANO_WORLDDIR}/etc/ttys
729 # Tell loader to use serial console early.
730 echo "${NANO_BOOT2CFG}" > ${NANO_WORLDDIR}/boot.config
733 #######################################################################
734 # Allow root login via ssh
736 cust_allow_ssh_root ( ) (
737 sed -i "" -e '/PermitRootLogin/s/.*/PermitRootLogin yes/' \
738 ${NANO_WORLDDIR}/etc/ssh/sshd_config
741 #######################################################################
742 # Install the stuff under ./Files
744 cust_install_files ( ) (
745 cd "${NANO_TOOLS}/Files"
746 find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)/' | cpio -Ldumpv ${NANO_WORLDDIR}
748 if [ -n "${NANO_CUST_FILES_MTREE}" -a -f ${NANO_CUST_FILES_MTREE} ]; then
749 CR "mtree -eiU -p /" <${NANO_CUST_FILES_MTREE}
753 #######################################################################
754 # Install packages from ${NANO_PACKAGE_DIR}
758 mkdir -p ${NANO_WORLDDIR}/usr/local/etc
759 local PKG_CONF="${NANO_WORLDDIR}/usr/local/etc/pkg.conf"
760 local PKGCMD="env ASSUME_ALWAYS_YES=YES PKG_DBDIR=${NANO_PKG_META_BASE}/pkg SIGNATURE_TYPE=none /usr/sbin/pkg"
762 # Ensure pkg.conf points pkg to where the package meta data lives.
764 if grep -Eiq '^PKG_DBDIR:.*' ${PKG_CONF}; then
765 sed -i -e "\|^PKG_DBDIR:.*|Is||PKG_DBDIR: "\"${NANO_PKG_META_BASE}/pkg\""|" ${PKG_CONF}
767 echo "PKG_DBDIR: \"${NANO_PKG_META_BASE}/pkg\"" >> ${PKG_CONF}
770 # If the package directory doesn't exist, we're done.
771 if [ ! -d ${NANO_PACKAGE_DIR} ]; then
772 echo "DONE 0 packages"
776 # Find a pkg-* package
777 for x in `find -s ${NANO_PACKAGE_DIR} -iname 'pkg-*'`; do
778 _NANO_PKG_PACKAGE=`basename "$x"`
780 if [ -z "${_NANO_PKG_PACKAGE}" -o ! -f "${NANO_PACKAGE_DIR}/${_NANO_PKG_PACKAGE}" ]; then
781 echo "FAILED: need a pkg/ package for bootstrapping"
785 # Mount packages into chroot
786 mkdir -p ${NANO_WORLDDIR}/_.p
787 mount -t nullfs -o noatime -o ro ${NANO_PACKAGE_DIR} ${NANO_WORLDDIR}/_.p
789 trap "umount ${NANO_WORLDDIR}/_.p ; rm -rf ${NANO_WORLDDIR}/_.p" 1 2 15 EXIT
791 # Install pkg-* package
792 CR "${PKGCMD} add /_.p/${_NANO_PKG_PACKAGE}"
795 # Expand any glob characters in pacakge list
796 cd "${NANO_PACKAGE_DIR}"
797 _PKGS=`find ${NANO_PACKAGE_LIST} -not -name "${_NANO_PKG_PACKAGE}" -print | sort | uniq`
800 todo=`echo "$_PKGS" | wc -l`
801 echo "=== TODO: $todo"
806 for _PKG in $_PKGS; do
807 CR "${PKGCMD} add /_.p/${_PKG}"
814 umount ${NANO_WORLDDIR}/_.p
815 rm -rf ${NANO_WORLDDIR}/_.p
818 #######################################################################
819 # Convenience function:
820 # Register all args as early customize function to run just before
823 early_customize_cmd () {
824 NANO_EARLY_CUSTOMIZE="$NANO_EARLY_CUSTOMIZE $*"
827 #######################################################################
828 # Convenience function:
829 # Register all args as customize function.
832 NANO_CUSTOMIZE="$NANO_CUSTOMIZE $*"
835 #######################################################################
836 # Convenience function:
837 # Register all args as late customize function to run just before
840 late_customize_cmd ( ) {
841 NANO_LATE_CUSTOMIZE="$NANO_LATE_CUSTOMIZE $*"
844 #######################################################################
846 # All set up to go...
848 #######################################################################
851 # Print $2 at level $1.
853 if [ "$1" -le $PPLEVEL ]; then
854 runtime=$(( `date +%s` - $NANO_STARTTIME ))
855 printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 1>&3
861 echo "Usage: $0 [-bfhiKknqvwX] [-c config_file]"
862 echo " -b suppress builds (both kernel and world)"
863 echo " -c specify config file"
864 echo " -f suppress code slice extraction"
865 echo " -h print this help summary page"
866 echo " -i suppress disk image build"
867 echo " -K suppress installkernel"
868 echo " -k suppress buildkernel"
869 echo " -n add -DNO_CLEAN to buildworld, buildkernel, etc"
870 echo " -q make output more quiet"
871 echo " -v make output more verbose"
872 echo " -w suppress buildworld"
873 echo " -X make native-xtools"
878 #######################################################################
879 # Setup and Export Internal variables
882 export_var ( ) { # Don't wawnt a subshell
884 # Lookup value of the variable.
886 pprint 3 "Setting variable: $var=\"$val\""
890 # Call this function to set defaults _after_ parsing options.
891 # dont want a subshell otherwise variable setting is thrown away.
892 set_defaults_and_export ( ) {
893 : ${NANO_OBJ:=/usr/obj/nanobsd.${NANO_NAME}}
894 : ${MAKEOBJDIRPREFIX:=${NANO_OBJ}}
895 : ${NANO_DISKIMGDIR:=${NANO_OBJ}}
896 : ${NANO_WORLDDIR:=${NANO_OBJ}/_.w}
897 : ${NANO_LOG:=${NANO_OBJ}}
898 NANO_MAKE_CONF_BUILD=${MAKEOBJDIRPREFIX}/make.conf.build
899 NANO_MAKE_CONF_INSTALL=${NANO_OBJ}/make.conf.install
901 # Override user's NANO_DRIVE if they specified a NANO_LABEL
902 [ -n "${NANO_LABEL}" ] && NANO_DRIVE="ufs/${NANO_LABEL}" || true
904 # Set a default NANO_TOOLS to NANO_SRC/NANO_TOOLS if it exists.
905 [ ! -d "${NANO_TOOLS}" ] && [ -d "${NANO_SRC}/${NANO_TOOLS}" ] && \
906 NANO_TOOLS="${NANO_SRC}/${NANO_TOOLS}" || true
908 [ -n "${NANO_NOPRIV_BUILD}" ] && [ -z "${NANO_METALOG}" ] && \
909 NANO_METALOG=${NANO_OBJ}/_.metalog || true
911 NANO_STARTTIME=`date +%s`
912 pprint 3 "Exporting NanoBSD variables"
913 export_var MAKEOBJDIRPREFIX
915 export_var NANO_CODESIZE
916 export_var NANO_CONFSIZE
917 export_var NANO_CUSTOMIZE
918 export_var NANO_DATASIZE
919 export_var NANO_DRIVE
920 export_var NANO_HEADS
921 export_var NANO_IMAGES
922 export_var NANO_IMGNAME
923 export_var NANO_IMG1NAME
925 export_var NANO_MAKE_CONF_BUILD
926 export_var NANO_MAKE_CONF_INSTALL
927 export_var NANO_MEDIASIZE
929 export_var NANO_NEWFS
931 export_var NANO_PMAKE
932 export_var NANO_SECTS
934 export_var NANO_TOOLS
935 export_var NANO_WORLDDIR
936 export_var NANO_BOOT0CFG
937 export_var NANO_BOOTLOADER
938 export_var NANO_LABEL
939 export_var NANO_MODULES
940 export_var NANO_NOPRIV_BUILD
941 export_var NANO_METALOG
944 export_var SRC_ENV_CONF