Makefile: Use relative paths in configs generated from templates

Use relative paths in configs generated from templates, so the final
build doesn't depend on the absolute location of the repository.  The
coreboot config is part of the final ROM.

Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
This commit is contained in:
Jonathon Hall 2024-05-09 17:00:38 -04:00 committed by Thierry Laurion
parent 6ce3d21e4c
commit c7f652bf89
No known key found for this signature in database
GPG Key ID: 9A53E1BB3FF00461
2 changed files with 30 additions and 5 deletions

View File

@ -268,12 +268,10 @@ all payload:
FORCE:
# Copies config while replacing predefined placeholders with actual values
# This is used in a command like 'this && $(call install_config ...) && that'
# so it needs to evaluate to a shell command.
define install_config =
sed -e 's!@BOARD_BUILD_DIR@!$(board_build)!g' \
-e 's!@BLOB_DIR@!$(pwd)/blobs!g' \
-e 's!@BRAND_DIR@!$(pwd)/branding/$(BRAND_NAME)!g' \
-e 's!@BRAND_NAME@!$(BRAND_NAME)!g' \
"$1" > "$2"
$(pwd)/bin/prepare_module_config.sh "$1" "$2" "$(board_build)" "$(BRAND_NAME)"
endef
# Make helpers to operate on lists of things

27
bin/prepare_module_config.sh Executable file
View File

@ -0,0 +1,27 @@
#! /usr/bin/env bash
TEMPLATE="$1"
RESULT="$2"
BOARD_BUILD="$3"
BRAND_NAME="$4"
repo="$(realpath "$(dirname "${BASH_SOURCE[0]}")/..")"
# For both coreboot and Linux, the config file is in a board-
# specific build directory, but the build occurs from the
# parent of that directory.
module_dir="$(realpath "$(dirname "$2")/..")"
# Use relative paths since the config may be part of the ROM
# artifacts, and relative paths won't depend on the workspace
# absolute path.
board_build_rel="$(realpath --relative-to "$module_dir" "$BOARD_BUILD")"
repo_rel="$(realpath --relative-to "$module_dir" "$repo")"
echo "board_build_rel=$board_build_rel"
echo "repo_rel=$repo_rel"
sed -e "s!@BOARD_BUILD_DIR@!${board_build_rel}!g" \
-e "s!@BLOB_DIR@!${repo_rel}/blobs!g" \
-e "s!@BRAND_DIR@!${repo_rel}/branding/$BRAND_NAME!g" \
-e "s!@BRAND_NAME@!$BRAND_NAME!g" \
"$TEMPLATE" > "$RESULT"