4 _root="$(dirname "${0}")"; . "${_root}/lib/env.sh"
13 # Root directory of makeworld
14 ROOT="$(realpath "$(dirname "${0}")/../worlds")"
16 # Makeworld dir structure should contain, at minimum:
18 # makeworld (this file)
21 # <ARCH> (arch of build host: i386, amd64, etc)
22 # base.* (virgin base tree of same arch as host, used to seed chroot for clean build)
23 # <TARGET> (i386, amd64, etc)
24 # <CONFIG> (GENERIC, SABA, SS4200, etc)
28 # CONFIG (Matches config name: GENERIC, SABA, SS4200, etc)
30 # Compute number of simultaneous make jobs (usually 2x cpu/thread count) to set make -j
31 make_cpus="$(sysctl -n hw.ncpu)"
32 make_jobs="$(( ${make_cpus} * 2 ))"
34 # Going to build this config:
35 TARGET="${TARGET:-i386}"
36 CONFIG="${CONFIG:-GENERIC}"
37 MAKEOPTS="-j${make_jobs} ${MAKEOPTS}"
41 [ -d "${ROOT}/${TARGET}/${CONFIG}" ] || wtf "${TARGET}/${CONFIG} doesn't exist"
43 # Target world directory
44 world="${ROOT}/${TARGET}/${CONFIG}"
45 # Source chroot seed directory
46 seed="${ROOT}/seed/base/$(uname -m)"
47 # Root directory for chroot
48 build="${ROOT}/seed/chroot-${TARGET}-${CONFIG}"
50 # Default build phases
51 phases="${phases:-buildworld buildkernel distrib-dirs installworld installkernel distribution}"
53 date="$(date +%Y%m%d)"
57 # Prepare chroot for build
59 mount | grep -q "${build}" && wtf "Stuff is mounted under ${build}; cannot continue"
61 # Cleanup trap here, so that an abort during prepare can clean up properly
62 trap "cleanup" exit hup int term kill
64 meh "Preparing build chroot"
65 [ -d "${build}" ] && wtf "${build}: directory exists"
66 mkdir -p "${build}" || wtf
67 ls -1 "${seed}"/base.?? >/dev/null 2>&1 || wtf "Populate seed directory ${seed} first"
68 cat "${seed}"/base.?? | tar xCf "${build}" - || wtf
69 mkdir -p "${build}/usr/obj" || wtf
71 meh "Mounting chroot filesystems"
72 mkdir -p "${world}/obj"
73 mkdir -p "${world}/root"
74 mount -t devfs devfs "${build}/dev" || wtf
75 # Mount /usr/src as a union, so that changes to it will not affect the underlying tree
76 # unionfs suffers from deadlocks; don't use it
77 mount -t nullfs -r /usr/src "${build}/usr/src" || wtf
78 mount -t nullfs "${world}/obj" "${build}/usr/obj" || wtf
79 mount -t nullfs "${world}/root" "${build}/mnt" || wtf
81 if [ -d "${world}/config" ]
83 meh "Installing build-time configuration"
84 [ -f "${world}/config/${CONFIG}" ] && cp "${world}/config/${CONFIG}" "/usr/src/sys/${TARGET}/conf/"
85 [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/"
86 [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/"
93 umount -f "${build}/mnt"
94 umount -f "${build}/usr/obj"
95 umount -f "${build}/usr/src"
96 umount -f "${build}/dev"
97 mount | grep -q "${build}" && wtf "Stuff is still mounted under ${build}; not removing"
98 chflags -R noschg "${build}"
100 trap "" exit hup int term kill
105 omg "${build}: directory exists; purging"
112 meh "Config: ${TARGET}/${CONFIG}"
113 meh "Builddir: ${build}"
114 meh "make ${MAKEOPTS}"
115 meh "DESTDIR=${world}/root"
117 # Construct environment for chroot build
121 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
125 for phase in ${phases}
127 meh "==> Phase: ${phase}"
128 script "${world}/${date}-${phase}.log" env -i ${env} chroot "${build}" sh -c \
129 "cd /usr/src; time make ${MAKEOPTS} ${phase} TARGET=${TARGET} KERNCONF=${CONFIG} DESTDIR=/mnt" || wtf "chroot-cmd ${phase}"
132 # Copy the config files into the target, to keep a record of the build options
133 [ -f "${world}/config/${CONFIG}" ] && cp "${world}/config/${CONFIG}" "${build}/boot/kernel/"
134 [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/"
135 [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/"