tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: (b)make: Outputting a huge variable value



Am 16.05.2024 um 18:09 schrieb Edgar Fuß:
> Following a discussion (make mdi: shell limit exceeded) on tech-pkg@,
> I keep asking myself whether there's a sensible way to output the
> contents of a make variable to a file (or pipe), even if the contents
> exceeds ARG_MAX.

In usr.bin/make from May 2024, you can do this:

HUGE=   ${:U:range=10000000}
_!=     echo ${HUGE} > huge
all:

It took about 30 seconds on my machine but succeeded in creating a 77 MB
file. This works because make now treats commands longer than 1000 bytes
differently by writing the command to a temporary file and then running
the shell on this temporary file. Since 'echo' is a shell builtin, this
approach works around the ARG_MAX limit.

The above approach doesn't work in bmake from 2020-05-24, which does not
create the 'huge' file, and you get an error message instead:

bmake: ".../Makefile" line 3: warning:
    "echo 1 2 3 4 ... 10000000 > huge" returned non-zero status

But no details on why the child command returned the non-zero status.

In older bmake, the only way I see is to fall back to a .for loop:

_!=	> huge
.for i in ${HUGE}
_!=	printf '%s\n' ${i:Q} >> huge
.endfor

This approach is much slower because it executes a separate child
process for each word in the variable.

So there's no good solution that works everywhere (bmake and
usr.bin/make, as well as compat mode and parallel mode), except for the
suggestion from Mouse to use 'make -v HUGE'.

Roland


Home | Main Index | Thread Index | Old Index