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 # Going to build this config:
31 TARGET="${TARGET:-i386}"
32 CONFIG="${CONFIG:-GENERIC}"
33 MAKEOPTS="${MAKEOPTS:-"-j4"}"
36 [ -d "${ROOT}/${TARGET}/${CONFIG}" ] || wtf "${TARGET}/${CONFIG} doesn't exist"
38 # Target world directory
39 world="${ROOT}/${TARGET}/${CONFIG}"
40 # Source chroot seed directory
41 seed="${ROOT}/seed/base/$(uname -m)"
42 # Root directory for chroot
43 build="${ROOT}/seed/chroot-${TARGET}-${CONFIG}"
45 # Default build phases
46 phases="${phases:-buildworld buildkernel distrib-dirs installworld installkernel distribution}"
48 date="$(date +%Y%m%d)"
52 # Prepare chroot for build
54 mount | grep -q "${build}" && wtf "Stuff is mounted under ${build}; cannot continue"
56 # Cleanup trap here, so that an abort during prepare can clean up properly
57 trap "cleanup" exit hup int term kill
59 meh "Preparing build chroot"
60 [ -d "${build}" ] && wtf "${build}: directory exists"
61 mkdir -p "${build}" || wtf
62 ls -1 "${seed}"/base.?? >/dev/null 2>&1 || wtf "Populate seed directory ${seed} first"
63 cat "${seed}"/base.?? | tar xCf "${build}" - || wtf
64 mkdir -p "${build}/usr/obj" || wtf
66 meh "Mounting chroot filesystems"
67 mkdir -p "${world}/obj"
68 mkdir -p "${world}/root"
69 mount -t devfs devfs "${build}/dev" || wtf
70 # Mount /usr/src as a union, so that changes to it will not affect the underlying tree
71 # unionfs suffers from deadlocks; don't use it
72 mount -t nullfs -r /usr/src "${build}/usr/src" || wtf
73 mount -t nullfs "${world}/obj" "${build}/usr/obj" || wtf
74 mount -t nullfs "${world}/root" "${build}/mnt" || wtf
76 if [ -d "${world}/config" ]
78 meh "Installing build-time configuration"
79 [ -f "${world}/config/${CONFIG}" ] && cp "${world}/config/${CONFIG}" "/usr/src/sys/${TARGET}/conf/"
80 [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/"
81 [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/"
88 umount -f "${build}/mnt"
89 umount -f "${build}/usr/obj"
90 umount -f "${build}/usr/src"
91 umount -f "${build}/dev"
92 mount | grep -q "${build}" && wtf "Stuff is still mounted under ${build}; not removing"
93 chflags -R noschg "${build}"
95 trap "" exit hup int term kill
100 omg "${build}: directory exists; purging"
107 meh "Config: ${TARGET}/${CONFIG}"
108 meh "Builddir: ${build}"
109 meh "make ${MAKEOPTS}"
110 meh "DESTDIR=${world}/root"
112 # Construct environment for chroot build
116 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
120 for phase in ${phases}
122 meh "==> Phase: ${phase}"
123 script "${world}/${date}-${phase}.log" env -i ${env} chroot "${build}" sh -c \
124 "cd /usr/src; time make ${MAKEOPTS} ${phase} TARGET=${TARGET} KERNCONF=${CONFIG} DESTDIR=/mnt" || wtf "chroot-cmd ${phase}"
127 # Copy the config files into the target, to keep a record of the build options
128 [ -f "${world}/config/${CONFIG}" ] && cp "${world}/config/${CONFIG}" "${build}/boot/kernel/"
129 [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/"
130 [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/"