From c6adf50e246bfbdb0cd3f204324fbd8ead3259f3 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Sat, 16 Oct 2010 00:48:59 -0500 Subject: [PATCH] script/makeworld: refactor to support command line options; clean up --- script/makeworld | 156 ++++++++++++++++++++++++++--------------------- 1 file changed, 87 insertions(+), 69 deletions(-) diff --git a/script/makeworld b/script/makeworld index 3b9b178..7e5ed7e 100755 --- a/script/makeworld +++ b/script/makeworld @@ -1,69 +1,47 @@ #!/bin/sh -# Boilerplate -_root="$(dirname "${0}")"; . "${_root}/lib/env.sh" - -# Load needed modules -want root log - -alias meh=log -alias omg=warn -alias wtf=err - -# Root directory of makeworld -ROOT="$(realpath "$(dirname "${0}")/../worlds")" - # Makeworld dir structure should contain, at minimum: # script # makeworld (this file) -# seed -# base -# (arch of build host: i386, amd64, etc) -# base.* (virgin base tree of same arch as host, used to seed chroot for clean build) -# (i386, amd64, etc) -# (GENERIC, SABA, SS4200, etc) -# config -# make.conf -# src.conf -# CONFIG (Matches config name: GENERIC, SABA, SS4200, etc) - -# Compute number of simultaneous make jobs (usually 2x cpu/thread count) to set make -j -make_cpus="$(sysctl -n hw.ncpu)" -make_jobs="$(( ${make_cpus} * 2 ))" - -# Was the config specified on the command line? -if [ "${1}" ] -then - TARGET="${1%%/*}" - CONFIG="${1##*/}" -fi - -# Going to build this config: -TARGET="${TARGET:-i386}" -CONFIG="${CONFIG:-GENERIC}" -MAKEOPTS="-j${make_jobs} ${MAKEOPTS}" - - -# Check if it exists -[ -d "${ROOT}/${TARGET}/${CONFIG}" ] || wtf "${TARGET}/${CONFIG} doesn't exist" - -# Target world directory -world="${ROOT}/${TARGET}/${CONFIG}" -# Source chroot seed directory -seed="${ROOT}/seed/base/$(uname -m)" -# Root directory for chroot -build="${ROOT}/seed/chroot-${TARGET}-${CONFIG}" - -# Default build phases -phases="${phases:-buildworld buildkernel distrib-dirs installworld installkernel distribution}" - -date="$(date +%Y%m%d)" +# worlds +# seed +# base +# (arch of build host: i386, amd64, etc) +# base.* (virgin base tree of same arch as host, used to seed chroot for clean build) +# (i386, amd64, etc) +# (GENERIC, SABA, SS4200, etc) +# config +# make.conf +# src.conf +# CONFIG (Matches config name: GENERIC, SABA, SS4200, etc) + +# Load shlib and modules +_root="$(dirname "${0}")"; . "${_root}/lib/env.sh" +want root log -# Functions +pebkac() { + [ "${*}" ] && printf "%s\n\n" "${*}" + echo "Usage: $(basename "${0}") -m -t -c " + echo " -m Provide additional flags to make" + echo " -t Target architecture (i386, amd64)" + echo " -c Target configuration (in worlds//)" + echo " -h Help!" + echo "" + echo "Available make targets:" + for target in ${make_tgts} + do + echo " ${target}" + done + exit 1 +} # Prepare chroot for build prepare() { + # Verify environment sanity + [ -d "${build}" ] && omg "${build}: directory exists; purging" && cleanup mount | grep -q "${build}" && wtf "Stuff is mounted under ${build}; cannot continue" + ls -1 "${seed}"/base.?? >/dev/null 2>&1 || wtf "Populate seed directory ${seed} first" + [ -f /usr/src/sys/conf/newvers.sh ] || wtf "Need sources in /usr/src to build" # Cleanup trap here, so that an abort during prepare can clean up properly trap "cleanup" exit hup int term kill @@ -71,7 +49,6 @@ prepare() { meh "Preparing build chroot" [ -d "${build}" ] && wtf "${build}: directory exists" mkdir -p "${build}" || wtf - ls -1 "${seed}"/base.?? >/dev/null 2>&1 || wtf "Populate seed directory ${seed} first" cat "${seed}"/base.?? | tar xCf "${build}" - || wtf mkdir -p "${build}/usr/obj" || wtf @@ -107,6 +84,55 @@ cleanup() { trap "" exit hup int term kill } +# Root directory of makeworld +ROOT="$(realpath "$(dirname "${0}")/../worlds")" + +# Compute make -j +make_cpus="$(sysctl -n hw.ncpu)" +make_jobs="$(( ${make_cpus} * 2 ))" +make_tgts="buildworld buildkernel distrib-dirs installworld installkernel distribution" + +# Defaults +TARGET="i386" +CONFIG="GENERIC" +MAKEOPTS="-j${make_jobs}" + +while getopts "m:t:c:h" opt +do + case "${opt}" in + m) MAKEOPTS="${MAKEOPTS} ${OPTARG}" ;; + t) TARGET="${OPTARG}" ;; + c) CONFIG="${OPTARG}" ;; + h) pebkac ;; + [?]) pebkac "Unrecognized option ${opt}" ;; + esac +done +shift $(( $OPTIND - 1 )) + +# Build make target sequence +sequence="${*:-${make_tgts}}" + +# Target world directory +world="${ROOT}/${TARGET}/${CONFIG}" +# Source chroot seed directory +seed="${ROOT}/seed/base/$(uname -m)" +# Root directory for chroot +build="${ROOT}/seed/chroot-${TARGET}-${CONFIG}" + +# Environment for chroot build +env=" +USER=root +HOME=/root +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +SHELL=/bin/sh +" + +date="$(date +%Y%m%d)" + +# Check if target config exists +[ -d "${world}" ] || wtf "${TARGET}/${CONFIG} doesn't exist" + +# Purge any build directory that might be left over if [ -d "${build}" ] then omg "${build}: directory exists; purging" @@ -123,19 +149,11 @@ meh "Builddir: ${build}" meh "make ${MAKEOPTS}" meh "DESTDIR=${world}/root" -# Construct environment for chroot build -env=" -USER=root -HOME=/root -PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -SHELL=/bin/sh -" - -for phase in ${phases} +for step in ${sequence} do - meh "==> Phase: ${phase}" - script "${world}/${date}-${phase}.log" env -i ${env} chroot "${build}" sh -c \ - "cd /usr/src; time make ${MAKEOPTS} ${phase} TARGET=${TARGET} KERNCONF=${CONFIG} DESTDIR=/mnt" || wtf "chroot-cmd ${phase}" + meh "==> Phase: ${step}" + script "${world}/${date}-${step}.log" env -i ${env} chroot "${build}" sh -c \ + "cd /usr/src; time make ${MAKEOPTS} ${step} TARGET=${TARGET} KERNCONF=${CONFIG} DESTDIR=/mnt" || wtf "chroot-cmd ${phase}" done # Copy the config files into the target, to keep a record of the build options -- 2.42.0