4 # Create a virgin chroot
5 # Copy in build (make.conf) and port (/var/db/ports) configuration
6 # Compute build/runtime dependencies for leaf port
7 # Install build/runtime dependency packages, if they exist from a previous leaf port build
8 # Build a single leaf port
9 # Create packages for leaf port and its runtime dependencies
10 # Create a separate set of packages for its build-time dependencies, to use for later leaf port builds
12 ROOT="$(realpath "$(dirname "${0}")")"
16 meh() { printf " \033[1;32m*\033[0m %s\n" "${*}"; }
17 omg() { printf " \033[1;33m*\033[0m %s\n" "${*}"; }
18 wtf() { printf " \033[1;31m* FAIL\033[0m %s\n" "${*}"; exit 1; }
20 tgtdir="${TARGET}/${CONFIG}"
21 build="${ROOT}/port/root" # Location of build environment
22 date="$(date +%Y%m%d)"
23 srctree="${ROOT}/${tgtdir}" # Virgin build env will be copied from here
25 # Prepare a build chroot
27 mount | grep -q "${build}" && wtf "Stuff is mounted under ${build}; cannot continue"
29 # Put cleanup trap here so that an abort during prepare properly cleans up
30 trap "cleanup" exit hup int term kill
32 meh "Preparing build environment"
33 mkdir -p "${build}" || wtf
34 cd "${srctree}"; find . | cpio -p "${build}" || wtf
35 # Hold packages for build deps
36 mkdir -p "${build}/pkg/build" || wtf
37 # Hold packages for runtime deps
38 mkdir -p "${build}/pkg/run" || wtf
40 meh "Mounting chroot directories" || wtf
41 mkdir -p "${build}/usr/ports" || wtf
42 mkdir -p "${build}/usr/obj" || wtf
43 mount -t devfs devfs "${build}/dev" || wtf
44 mount -t nullfs -r /usr/src "${build}/usr/src" || wtf # Just in case a port needs kernel sources
45 mount -t nullfs -r /usr/ports "${build}/usr/ports" || wtf
47 if [ -d "${world}/config" ]
49 meh "Installing build-time configuration"
51 [ -f "${world}/config/make.conf" ] && cp "${world}/config/make.conf" "${build}/etc/" || wtf
52 # Install port options files
53 [ -d "${world}/config/ports" ] && ( cd "${world}/config/ports"; find . -type d -o -type f -name 'options' | cpio -p "${build}/var/db/ports/" ) || wtf
57 # Evaluate a bit of code within the ${build} chroot
58 # If ${chroot_env} is set, replace environment with it before chrooting
60 [ "${chroot_env}" ] && env="env -i ${chroot_env}"
61 ${env} chroot "${build}" /bin/sh
64 # Clean up and remove the build chroot
67 umount -f "${build}/usr/ports"
68 umount -f "${build}/usr/src"
69 umount -f "${build}/dev"
70 mount |grep -q "${build}" && wtf "Stuff is still mounted under ${build}; not removing"
71 chflags -R noschg "${build}"