firmware icon indicating copy to clipboard operation
firmware copied to clipboard

build: TARGET= on the make command line breaks host-libffi's configure

Open openipc-ai opened this issue 3 weeks ago • 1 comments

Reported by DeathCamel58 in #2793. Reproduced off-tree; I have not run a full board build.

Symptom

make BOARD=<board> TARGET=$(PWD)/output-<board> fails in host-libffi on any board that pulls in host-python3, for example s3l_ultimate with Divinus since #2793. CLAUDE.md recommends exactly this pattern for building several boards locally. Plain make BOARD=..., which is what CI runs, is not affected.

Cause

libffi's configure.ac uses autoconf-archive's AX_ENABLE_BUILDDIR. Buildroot sets LIBFFI_AUTORECONF = YES, so the regenerated configure contains:

test ".$TARGET" = "." && TARGET="$target"
test ".$ax_enable_builddir" = ".auto" && ax_enable_builddir="$TARGET"
...
as_dir=$ax_enable_builddir; as_fn_mkdir_p
cd $ax_enable_builddir

The macro reads $TARGET from the environment and treats it as the name of a build subdirectory. It creates that directory under the source tree, cds into it, and re-runs ../../../…/configure from there. Given an absolute path, the relative path back is wrong.

A variable set on the make command line is exported to every recipe's environment and passed through MAKEFLAGS to sub-makes. So TARGET=... given to our top-level make reaches Buildroot and then libffi's configure. The ?= default in our Makefile is not exported, which is why plain builds work.

Reproduction

libffi 3.4.4 with Buildroot 2024.02.10's patches, autoreconf -fi, then:

$ TARGET=/home/x/output-board ./configure --disable-docs --disable-exec-static-tramp
/bin/bash: ../../../.././configure: No such file or directory
(exit 127)

The same tree without TARGET in the environment configures normally.

Possible fixes

  • In our Makefile: keep TARGET out of what Buildroot inherits, e.g. MAKEOVERRIDES := $(filter-out TARGET=%,$(MAKEOVERRIDES)) plus unexport TARGET around BR_MAKE. O=$(TARGET) already tells Buildroot where to build. This also protects any other package whose configure reads a bare TARGET.
  • Or narrowly: append --disable-builddir to host-libffi's configure options (through general/package/all-patches or an override). That fixes libffi only.
  • Or: rename the variable (e.g. OUTPUT). That is the cleanest, but it changes the interface everyone's scripts and CI use.

The first option seems right to me; it needs a multi-board local build to confirm.

openipc-ai avatar Nov 08 '26 06:11 openipc-ai

Fixed by #2795 (ea8aac3c3).

Cause. A variable given on the make command line is both exported to recipes and passed to sub-makes through MAKEFLAGS, so make TARGET=<dir> reached Buildroot and every package's configure. The autoreconf'd libffi uses AX_ENABLE_BUILDDIR, which reads $TARGET as a build subdirectory name, then re-runs ../../configure from there and fails.

Fix. The top-level Makefile now filters TARGET= out of MAKEOVERRIDES and marks TARGET as unexport. Both are needed, because either one alone leaves the other path open. Buildroot still gets the output directory from O=$(TARGET), and repack-final's sub-make passes TARGET explicitly.

Evidence.

  • make BOARD=s3l_ultimate TARGET=<dir> br-host-libffi exits with Error 127 on master and exits 0 with the fix.
  • ci-matrix.py --self-test passes.
  • The change touches the Makefile, so CI built the full matrix: run 42456499572 is green on attempt 2. On attempt 1, seven boards failed on release-asset downloads during a github.com outage (the failing targets were all .stamp_downloaded). Re-running only those seven passed.

Gaps. Not run on a camera. I did not compare the resulting images byte for byte against master.

openipc-ai avatar Nov 08 '26 12:11 openipc-ai