7.4. Copy selected build variables and helper functions into target profile

Write selected current Linux by Intent build variables and reusable build helper functions into the target profile so chroot starts with the expected tuning and tools.

Goal: create $LBI_ROOT/system/configuration/profile and a zprofile link with selected current book variables (defaulting each one to a single-space string when empty or unset) and reusable configure/meson/cmake helper functions.

Before entering chroot, write a target profile file that carries selected book variables into the new environment.

This step intentionally excludes these host-path and mirror variables:

All commands in this section should be run as root.

Write the target profile with cat <<EOF

dollar='$'
cat > "$LBI_ROOT/system/configuration/profile" <<EOF
# Linux by Intent variable handoff profile

export LBI_ARCH="${LBI_ARCH:- }"
export LBI_TARGET="${LBI_TARGET:- }"
export LWI_MAKE_JOBS="${LWI_MAKE_JOBS:- }"
export LWI_MAKE_FLAGS="${LWI_MAKE_FLAGS:- }"
export LWI_CFLAGS="${LWI_CFLAGS:- }"
export LWI_CXXFLAGS="${LWI_CXXFLAGS:- }"
export LBI_CUSTOM_LDFLAGS="${LBI_CUSTOM_LDFLAGS:- }"
export LBI_BOOTLOADER_ID="${LBI_BOOTLOADER_ID:- }"

lbi_configure() {
    CFLAGS="${LWI_CFLAGS}" \
    CXXFLAGS="${LWI_CXXFLAGS}" \
    LDFLAGS="${LBI_CUSTOM_LDFLAGS}" \
    ./configure \
        --prefix=/system \
        --bindir=/system/binaries \
        --sbindir=/system/systembinaries \
        --libdir=/system/libraries \
        --libexecdir=/system/systembinaries \
        --includedir=/system/headers \
        --sysconfdir=/system/configuration \
        --localstatedir=/system/variable \
        --mandir=/system/documentation/man-pages \
        --infodir=/system/documentation/info \
        "${dollar}@"
}

lbi_meson() {
    lbi_meson_builddir=build

    case "${dollar}{1-}" in
        '') ;;
        -*) ;;
        *)
            lbi_meson_builddir=${dollar}1
            shift
            ;;
    esac

    meson setup "${dollar}lbi_meson_builddir" \
        --prefix=/system \
        --bindir=/system/binaries \
        --sbindir=/system/systembinaries \
        --libdir=/system/libraries \
        --libexecdir=/system/systembinaries \
        --includedir=/system/headers \
        --sysconfdir=/system/configuration \
        --localstatedir=/system/variable \
        --mandir=/system/documentation/man-pages \
        --infodir=/system/documentation/info \
        "${dollar}@"
}

lbi_cmake() {
    lbi_cmake_builddir=build

    case "${dollar}{1-}" in
        '') ;;
        -*) ;;
        *)
            lbi_cmake_builddir=${dollar}1
            shift
            ;;
    esac

    cmake -S . -B "${dollar}lbi_cmake_builddir" \
        -DCMAKE_INSTALL_PREFIX=/system \
        -DCMAKE_INSTALL_BINDIR=/system/binaries \
        -DCMAKE_INSTALL_SBINDIR=/system/systembinaries \
        -DCMAKE_INSTALL_LIBDIR=/system/libraries \
        -DCMAKE_INSTALL_LIBEXECDIR=/system/systembinaries \
        -DCMAKE_INSTALL_INCLUDEDIR=/system/headers \
        -DCMAKE_INSTALL_SYSCONFDIR=/system/configuration \
        -DCMAKE_INSTALL_LOCALSTATEDIR=/system/variable \
        -DCMAKE_INSTALL_MANDIR=/system/documentation/man-pages \
        -DCMAKE_INSTALL_INFODIR=/system/documentation/info \
        "${dollar}@"
}
EOF

Because the heredoc delimiter is unquoted (<<EOF), the file receives the current values at write time. The ${VAR:- } form makes each missing or empty value become a single space.

Quick verification

cat "$LBI_ROOT/system/configuration/profile"

Command Explanations