3 # Root directory of makeworld
4 ROOT="$(realpath "$(dirname "${0}")/../worlds")"
6 # Makeworld dir structure should contain, at minimum:
8 # makeworld (this file)
11 # <ARCH> (arch of build host: i386, amd64, etc)
12 # base.* (virgin base tree of same arch as host, used to seed chroot for clean build)
13 # <TARGET> (i386, amd64, etc)
14 # <CONFIG> (GENERIC, SABA, SS4200, etc)
18 # CONFIG (Matches config name: GENERIC, SABA, SS4200, etc)
20 # Going to build this config:
21 TARGET="${TARGET:-i386}"
22 CONFIG="${CONFIG:-GENERIC}"
23 MAKEOPTS="${MAKEOPTS:-"-j4"}"
26 [ -d "${ROOT}/${TARGET}/${CONFIG}" ] || wtf "${TARGET}/${CONFIG} doesn't exist"
28 # Target world directory
29 world="${ROOT}/${TARGET}/${CONFIG}"
30 # Source chroot seed directory
31 seed="${ROOT}/seed/base/$(uname -m)"
32 # Root directory for chroot
33 build="${ROOT}/seed/chroot-${TARGET}-${CONFIG}"
35 # Default build phases
36 phases="${phases:-buildworld buildkernel distrib-dirs installworld installkernel distribution}"
38 date="$(date +%Y%m%d)"
41 meh() { printf " \033[1;32m*\033[0m %s\n" "${*}"; }
42 omg() { printf " \033[1;33m*\033[0m %s\n" "${*}"; }
43 wtf() { printf " \033[1;31m* FAIL\033[0m %s\n" "${*}"; exit 1; }
45 # Prepare chroot for build
47 mount | grep -q "${build}" && wtf "Stuff is mounted under ${build}; cannot continue"
49 # Cleanup trap here, so that an abort during prepare can clean up properly
50 trap "cleanup" exit hup int term kill
52 meh "Preparing build chroot"
53 [ -d "${build}" ] && wtf "${build}: directory exists"
54 mkdir -p "${build}" || wtf
55 cat "${seed}"/base.?? | tar xCf "${build}" - || wtf
56 mkdir -p "${build}/usr/obj" || wtf
58 meh "Mounting chroot filesystems"
59 mkdir -p "${world}/obj"
60 mkdir -p "${world}/root"
61 mount -t devfs devfs "${build}/dev" || wtf
62 # Mount /usr/src as a union, so that changes to it will not affect the underlying tree
63 # unionfs suffers from deadlocks; don't use it
64 mount -t nullfs -r /usr/src "${build}/usr/src" || wtf
65 mount -t nullfs "${world}/obj" "${build}/usr/obj" || wtf
66 mount -t nullfs "${world}/root" "${build}/mnt" || wtf
68 if [ -d "${world}/config" ]
70 meh "Installing build-time configuration"
71 [ -f "${world}/config/${CONFIG}" ] && cp "${world}/config/${CONFIG}" "/usr/src/sys/${TARGET}/conf/"
72 [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/"
73 [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/"
80 umount -f "${build}/mnt"
81 umount -f "${build}/usr/obj"
82 umount -f "${build}/usr/src"
83 umount -f "${build}/dev"
84 mount | grep -q "${build}" && wtf "Stuff is still mounted under ${build}; not removing"
85 chflags -R noschg "${build}"
87 trap "" exit hup int term kill
92 omg "${build}: directory exists; purging"
99 meh "Config: ${TARGET}/${CONFIG}"
100 meh "Builddir: ${build}"
101 meh "make ${MAKEOPTS}"
102 meh "DESTDIR=${world}/root"
104 # Construct environment for chroot build
108 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
112 for phase in ${phases}
114 meh "==> Phase: ${phase}"
115 script "${world}/${date}-${phase}.log" env -i ${env} chroot "${build}" sh -c \
116 "cd /usr/src; time make ${MAKEOPTS} ${phase} TARGET=${TARGET} KERNCONF=${CONFIG} DESTDIR=/mnt" || wtf "chroot-cmd ${phase}"
119 # Copy the config files into the target, to keep a record of the build options
120 [ -f "${world}/config/${CONFIG}" ] && cp "${world}/config/${CONFIG}" "${build}/boot/kernel/"
121 [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/"
122 [ -f "${world}/config/src.conf" ] && cp "${world}/config/src.conf" "${build}/etc/"