diff mbox series

build: make _make_dirs robust against too long argument error

Message ID 20240325095149.194489-1-robimarko@gmail.com
State Superseded
Headers show
Series build: make _make_dirs robust against too long argument error | expand

Commit Message

Robert Marko March 25, 2024, 9:51 a.m. UTC
_make_dirs currently can fail as _DIRS can be really long and thus go over
the MAX_ARG_STRLEN limit so it will fail with:
/bin/sh: Argument list too long

Lets avoid this by stripping the $(BUILDDIR) prefix and then restoring it.

Signed-off-by: Robert Marko <robimarko@gmail.com>
---
 src/build.rules | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Felix Fietkau April 4, 2024, 11:06 a.m. UTC | #1
On 25.03.24 10:51, Robert Marko wrote:
> _make_dirs currently can fail as _DIRS can be really long and thus go over
> the MAX_ARG_STRLEN limit so it will fail with:
> /bin/sh: Argument list too long
> 
> Lets avoid this by stripping the $(BUILDDIR) prefix and then restoring it.
> 
> Signed-off-by: Robert Marko <robimarko@gmail.com>
> ---
>   src/build.rules | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/build.rules b/src/build.rules
> index acda88472..497580d88 100644
> --- a/src/build.rules
> +++ b/src/build.rules
> @@ -80,7 +80,7 @@ endif
>   _DIRS := $(BUILDDIR)/$(PROJ)
>   .PHONY: _make_dirs
>   _make_dirs:
> -	@mkdir -p $(_DIRS)
> +	@printf '$(BUILDDIR)/%s ' $(patsubst $(BUILDDIR)/%,%,$(_DIRS)) | xargs mkdir -p

It's simpler and more robust to simply do:
	@mkdir -p $(sort $(_DIRS))

- Felix
Robert Marko April 4, 2024, 12:46 p.m. UTC | #2
On Thu, 4 Apr 2024 at 13:06, Felix Fietkau <nbd@nbd.name> wrote:
>
> On 25.03.24 10:51, Robert Marko wrote:
> > _make_dirs currently can fail as _DIRS can be really long and thus go over
> > the MAX_ARG_STRLEN limit so it will fail with:
> > /bin/sh: Argument list too long
> >
> > Lets avoid this by stripping the $(BUILDDIR) prefix and then restoring it.
> >
> > Signed-off-by: Robert Marko <robimarko@gmail.com>
> > ---
> >   src/build.rules | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/src/build.rules b/src/build.rules
> > index acda88472..497580d88 100644
> > --- a/src/build.rules
> > +++ b/src/build.rules
> > @@ -80,7 +80,7 @@ endif
> >   _DIRS := $(BUILDDIR)/$(PROJ)
> >   .PHONY: _make_dirs
> >   _make_dirs:
> > -     @mkdir -p $(_DIRS)
> > +     @printf '$(BUILDDIR)/%s ' $(patsubst $(BUILDDIR)/%,%,$(_DIRS)) | xargs mkdir -p
>
> It's simpler and more robust to simply do:
>         @mkdir -p $(sort $(_DIRS))

I agree, do you want to send that version?

Regards,
Robert
>
> - Felix
diff mbox series

Patch

diff --git a/src/build.rules b/src/build.rules
index acda88472..497580d88 100644
--- a/src/build.rules
+++ b/src/build.rules
@@ -80,7 +80,7 @@  endif
 _DIRS := $(BUILDDIR)/$(PROJ)
 .PHONY: _make_dirs
 _make_dirs:
-	@mkdir -p $(_DIRS)
+	@printf '$(BUILDDIR)/%s ' $(patsubst $(BUILDDIR)/%,%,$(_DIRS)) | xargs mkdir -p
 
 $(BUILDDIR)/$(PROJ)/src/%.o: $(ROOTDIR)src/%.c $(CONFIG_FILE) | _make_dirs
 	$(Q)$(CC) -c -o $@ $(CFLAGS) $<