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
```
gentoo
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 /images
/linux /linux
/output /output
/portage/config/*/etc/portage/make.profile /repos/x-portage
/portage/config/*/etc/portage/repos.conf
/portage/config/target/etc/portage/make.conf/10-crossdev.conf
/portage/repos/x-portage
/.built /.built
/.prepared /.prepared
/.host-tools /.host-tools

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
set -e set -e
. ./config . "${CONFIGDIR:=${PWD}}"/config
# Ensure we have a Portage repo # Ensure we have a Portage repo
if [ ! -f /var/db/repos/gentoo/metadata/timestamp ]; then 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 's: ?-pam::' \
-e '/PKGDIR=/d' \ -e '/PKGDIR=/d' \
/usr/${target}/etc/portage/make.conf \ /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 fi
ln -snf /var/db/repos/gentoo/profiles/default/linux/${ARCH}/17.0 \ 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 # Set the Portage profile
ln -snf \ ln -snf \
/var/db/repos/gentoo/profiles/${profile} \ /var/db/repos/gentoo/profiles/${profile} \
portage/config/target/etc/portage/make.profile ${CONFIGDIR}/portage/target/etc/portage/make.profile
ln -snf \ ln -snf \
$(realpath /etc/portage/make.profile) \ $(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 set -e
. ./config . "${CONFIGDIR:=${PWD}}"/config
unset MAKEFLAGS MAKEOVERRIDES MAKELEVEL unset MAKEFLAGS MAKEOVERRIDES MAKELEVEL
export PORTAGE_CONFIGROOT="${PWD}"/portage/config/target export PORTAGE_CONFIGROOT="${CONFIGDIR}"/portage/target
${target}-emerge -bv1j --usepkg-exclude="$*" "$@" ${target}-emerge -bv1j --usepkg-exclude="$*" "$@"

View File

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

View File

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