build: Implement CONFIGDIR setting

In effort to support different builds of Aimee OS using the same
scripts, without necessarily having to fork this repository, the build
system now supports a `CONFIGDIR` setting.  When this variable is set,
files defining the target environment, such as the lists of packages to
install, the kernel configuration, the Portage configuration, etc. are
found in the path it specifes.

The reference build, for the Home Assistant Yellow board, is configured
in the `yellow` directory.  To build it, run:

```sh
CONFIGDIR=yellow ./vm-build.sh
```
master
Dustin 2023-03-13 16:21:20 -05:00
parent 1914b3aba0
commit 31d8a98f64
100 changed files with 83 additions and 53 deletions

5
.gitignore vendored
View File

@ -1,10 +1,7 @@
/images
/linux
/output
/portage/config/*/etc/portage/make.profile
/portage/config/*/etc/portage/repos.conf
/portage/config/target/etc/portage/make.conf/10-crossdev.conf
/portage/repos/x-portage
/repos/x-portage
/.built
/.prepared
/.host-tools

View File

@ -1,5 +1,8 @@
O ?= .
IMAGESDIR ?= $(O)/images
CONFIGDIR ?= .
export CONFIGDIR
update.tar: $(IMAGESDIR)/update.tar.zstd
@ -16,8 +19,8 @@ prepare: $(O)/.prepared
$(O)/.host-tools: \
build-host-tools.sh \
host-tools.packages \
$(shell find portage/config/host -type f) \
$(CONFIGDIR)/host-tools.packages \
$(shell find $(CONFIGDIR)/portage/host -type f) \
$(O)/.prepared
./build-host-tools.sh
touch $(O)/.host-tools
@ -26,9 +29,9 @@ host-tools: $(O)/.host-tools
$(O)/.built: \
build.sh \
build.packages \
install.packages \
$(shell find portage/config/target -type f) \
$(CONFIGDIR)/build.packages \
$(CONFIGDIR)/install.packages \
$(shell find $(CONFIGDIR)/portage/target -type f) \
$(O)/.host-tools \
$(O)/.prepared
./build.sh
@ -36,11 +39,12 @@ $(O)/.built: \
$(O)/.ready: \
build-rootfs.sh \
install.packages \
installonly.packages \
busybox.symlinks \
$(CONFIGDIR)/install.packages \
$(CONFIGDIR)/installonly.packages \
$(CONFIGDIR)/busybox.symlinks \
$(O)/linux/arch/arm64/boot/Image.gz \
$(shell find overlay -type f) \
$(shell find $(CONFIGDIR)/overlay -type f 2>/dev/null) \
$(O)/.host-tools \
$(O)/.built
./build-rootfs.sh
@ -48,7 +52,7 @@ $(O)/.ready: \
$(IMAGESDIR)/rootfs.squashfs: \
build-squashfs.sh \
squashfs.exclude \
$(CONFIGDIR)/squashfs.exclude \
$(O)/.ready
./build-squashfs.sh "$(IMAGESDIR)"
@ -56,7 +60,7 @@ squashfs: $(IMAGESDIR)/rootfs.squashfs
$(O)/linux/arch/arm64/boot/Image.gz: \
build-kernel.sh \
linux.config \
$(CONFIGDIR)/linux.config \
$(O)/.host-tools \
$(O)/.prepared
./build-kernel.sh "$(O)"

View File

@ -3,7 +3,7 @@
set -e
. ./config
. "${CONFIGDIR:=${PWD}}"/config
O="${1}"

View File

@ -1,6 +1,6 @@
#!/bin/sh
# vim: set sw=4 ts=4 sts=4 et :
PORTAGE_CONFIGROOT="${PWD}"/portage/config/host \
< host-tools.packages xargs -ro \
PORTAGE_CONFIGROOT="${CONFIGDIR:=${PWD}}"/portage/host \
< "${CONFIGDIR}"/host-tools.packages xargs -ro \
emerge -vnUj

View File

@ -5,9 +5,9 @@ set -e
O="${1}"
. ./config
. "${CONFIGDIR:=${PWD}}"/config
PORTAGE_CONFIGROOT="${PWD}"/portage/config/host \
PORTAGE_CONFIGROOT="${CONFIGDIR}"/portage/host \
emerge -vnj ${kernel_pkg}
export ARCH=arm64 CROSS_COMPILE=${target}-
@ -16,7 +16,7 @@ mkdir -p "${O}"/linux
/usr/src/linux/scripts/kconfig/merge_config.sh -m \
-O "${O}"/linux \
/usr/src/linux/arch/*/configs/${kernel_defconfig}_defconfig \
linux.config
"${CONFIGDIR}"/linux.config
cd "${O}"/linux
make -C /usr/src/linux O=${PWD} olddefconfig
make -j$(nproc)

View File

@ -3,7 +3,7 @@
set -e
. ./config
. "${CONFIGDIR:=${PWD}}"/config
mkdir -p \
/mnt/gentoo/usr/bin \
@ -20,16 +20,15 @@ mkdir -p /mnt/gentoo/etc/portage
ln -snf \
/var/db/repos/gentoo/profiles/${profile} \
/mnt/gentoo/etc/portage/make.profile
cp -r portage/. /mnt/gentoo/etc/portage/
ROOT=/mnt/gentoo \
PORTAGE_CONFIGROOT="${PWD}"/portage/config/target \
< install.packages xargs -ro \
PORTAGE_CONFIGROOT="${CONFIGDIR}"/portage/target \
< "${CONFIGDIR}"/install.packages xargs -ro \
${target}-emerge -KvnuUDj --rebuilt-binaries=y
ROOT=/mnt/gentoo \
PORTAGE_CONFIGROOT="${PWD}"/portage/config/target \
< installonly.packages xargs -ro \
PORTAGE_CONFIGROOT="${CONFIGDIR}"/portage/target \
< "${CONFIGDIR}"/installonly.packages xargs -ro \
${target}-emerge -vnuUDj
ROOT=/mnt/gentoo \
@ -51,9 +50,12 @@ while read name; do
ln -snf busybox /mnt/gentoo/bin/"${name}" \
|| printf 'Failed to create busybox symlink for %s\n' "${name}"
fi
done < busybox.symlinks
done < "${CONFIGDIR}"/busybox.symlinks
rsync -rltpDO overlay/ /mnt/gentoo/
if [ -d "${CONFIGDIR}"/overlay ]; then
rsync -rltpDO "${CONFIGDIR}"/overlay/ /mnt/gentoo/
fi
cp -uv /usr/${target}/usr/bin/grub-editenv /mnt/gentoo/usr/bin/

View File

@ -3,7 +3,7 @@
set -e
. ./config
. "${CONFIGDIR:=${PWD}}"/config
IMAGESDIR="${1}"
@ -12,7 +12,7 @@ mksquashfs \
/mnt/gentoo \
"${IMAGESDIR}"/rootfs.squashfs \
-comp gzip \
-ef squashfs.exclude \
-ef "${CONFIGDIR}"/squashfs.exclude \
-no-exports \
-noappend \
-wildcards

View File

@ -3,7 +3,7 @@
set -e
. ./config
. "${CONFIGDIR:=${PWD}}"/config
IMAGESDIR="$1"

View File

@ -3,17 +3,17 @@
set -e
. ./config
. "${CONFIGDIR}"/config
unset MAKEFLAGS MAKEOVERRIDES MAKELEVEL
export PORTAGE_CONFIGROOT="${PWD}"/portage/config/target
export PORTAGE_CONFIGROOT="${CONFIGDIR}"/portage/target
${target}-emerge -vuUDj sys-apps/util-linux
cat \
build.packages \
install.packages \
"${CONFIGDIR}"/build.packages \
"${CONFIGDIR}"/install.packages \
| xargs -ro \
${target}-emerge -vnuUDj
${target}-emerge -v @preserved-rebuild

View File

@ -12,7 +12,7 @@ cleanup() {
fi
}
. ./config
. "${CONFIGDIR:=${PWD}}"/config
O="${1}"
IMAGESDIR="${2}"

View File

@ -2,7 +2,7 @@
set -e
. ./config
. "${CONFIGDIR:=${PWD}}"/config
name=build_yellow
if ! ocivm list | grep -q localhost/cross-${target}; then

View File

@ -3,7 +3,7 @@
set -e
. ./config
. "${CONFIGDIR:=${PWD}}"/config
cp -uv \
/usr/${target}/boot/*.bin \

View File

@ -3,7 +3,7 @@
set -e
. ./config
. "${CONFIGDIR:=${PWD}}"/config
# Ensure we have a Portage repo
if [ ! -f /var/db/repos/gentoo/metadata/timestamp ]; then
@ -35,7 +35,7 @@ if [ ! -f portage/make.conf/10-crossdev.conf ]; then
-e 's: ?-pam::' \
-e '/PKGDIR=/d' \
/usr/${target}/etc/portage/make.conf \
> portage/config/target/etc/portage/make.conf/10-crossdev.conf
> "${CONFIGDIR}"/portage/target/etc/portage/make.conf/10-crossdev.conf
fi
ln -snf /var/db/repos/gentoo/profiles/default/linux/${ARCH}/17.0 \
@ -58,7 +58,7 @@ merge-usr --root=/usr/${target}
# Set the Portage profile
ln -snf \
/var/db/repos/gentoo/profiles/${profile} \
portage/config/target/etc/portage/make.profile
${CONFIGDIR}/portage/target/etc/portage/make.profile
ln -snf \
$(realpath /etc/portage/make.profile) \
portage/config/host/etc/portage/make.profile
${CONFIGDIR}/portage/host/etc/portage/make.profile

View File

@ -3,10 +3,10 @@
set -e
. ./config
. "${CONFIGDIR:=${PWD}}"/config
unset MAKEFLAGS MAKEOVERRIDES MAKELEVEL
export PORTAGE_CONFIGROOT="${PWD}"/portage/config/target
export PORTAGE_CONFIGROOT="${CONFIGDIR}"/portage/target
${target}-emerge -bv1j --usepkg-exclude="$*" "$@"

View File

@ -3,19 +3,19 @@
set -e
. ./config
. "${CONFIGDIR:=${PWD}}"/config
mkdir -p portage/config/target/etc/portage/repos.conf
mkdir -p "${CONFIGDIR}"/portage/target/etc/portage/repos.conf
cat > portage/config/target/etc/portage/repos.conf/aimee-os.conf <<EOF
cat > "${CONFIGDIR}"/portage/target/etc/portage/repos.conf/aimee-os.conf <<EOF
[aimee-os]
location = ${PWD}/portage/repos/aimee-os
location = ${PWD}/repos/aimee-os
auto-sync = no
EOF
cat > portage/config/target/etc/portage/repos.conf/x-portage.conf <<EOF
cat > "${CONFIGDIR}"/portage/target/etc/portage/repos.conf/x-portage.conf <<EOF
[x-portage]
location = ${PWD}/portage/repos/x-portage
location = ${PWD}/repos/x-portage
auto-sync = no
EOF
@ -24,9 +24,9 @@ for patch in patches/ebuilds/*/*/*.patch; do
cp=${patch#patches/ebuilds/}
cp=${cp%/*.patch}
printf 'Applying patch %s for %s ...\n' "${patch##*/}" "${cp}"
mkdir -p portage/repos/x-portage/${cp}
cp -r /var/db/repos/gentoo/${cp}/. portage/repos/x-portage/${cp}
for f in portage/repos/x-portage/${cp}/*.ebuild; do
mkdir -p repos/x-portage/${cp}
cp -r /var/db/repos/gentoo/${cp}/. repos/x-portage/${cp}
for f in repos/x-portage/${cp}/*.ebuild; do
patch "${f}" "${patch}"
ebuild "${f}" digest
done

View File

@ -3,7 +3,7 @@
set -e
. ./config
. "${CONFIGDIR:=${PWD}}"/config
podman run \
--tmpfs /var/tmp \

3
yellow/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
portage/*/etc/portage/make.profile
portage/*/etc/portage/repos.conf
portage/target/etc/portage/make.conf/10-crossdev.conf

View File

@ -0,0 +1 @@
/var/db/repos/gentoo/profiles/default/linux/amd64/17.1/no-multilib

View File

@ -0,0 +1,22 @@
# Note: profile variables are set/overridden in profile/ files:
# etc/portage/profile/use.force (overrides kernel_* USE variables)
# etc/portage/profile/make.defaults (overrides ARCH, KERNEL, ELIBC variables)
CHOST=aarch64-unknown-linux-gnu
CBUILD=x86_64-pc-linux-gnu
ROOT=/usr/${CHOST}/
ACCEPT_KEYWORDS="${ARCH} ~${ARCH}"
USE="${ARCH}"
CFLAGS="-O2 -pipe -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"
FEATURES="-collision-protect sandbox buildpkg noman noinfo nodoc"
# Be sure we dont overwrite pkgs from another repo..
PORTAGE_TMPDIR=${ROOT}tmp/
PKG_CONFIG_PATH="${ROOT}usr/lib/pkgconfig/"
#PORTDIR_OVERLAY="/var/db/repos/local/"

View File

@ -0,0 +1 @@
/var/db/repos/gentoo/profiles/default/linux/arm64/17.0/systemd/selinux/merged-usr