RE: [PATCH] kbuild: avoid regex RS for POSIX awk

From: David Laight
Date: Wed Jun 08 2022 - 04:16:56 EST


From: Kevin Locke
> Sent: 07 June 2022 03:43
>
> In 22f26f21774f8 awk was added to deduplicate *.mod files.

Can't this be done with gmake's $(sort) function?

$(sort list)

Sorts the words of list in lexical order, removing duplicate words.
The output is a list of words separated by single spaces.

...
> # To make this rule robust against "Argument list too long" error,
> # ensure to add $(obj)/ prefix by a shell command.
> -cmd_mod = echo $(call real-search, $*.o, .o, -objs -y -m) | \
> - $(AWK) -v RS='( |\n)' '!x[$$0]++ { print("$(obj)/"$$0) }' > $@
> +cmd_mod = printf '%s\n' $(call real-search, $*.o, .o, -objs -y -m) | \
> + $(AWK) '!x[$$0]++ { print("$(obj)/"$$0) }' > $@

I think the above only works because 'printf' is (usually) a
shell builtin - so the kernel's argv[] limit doesn't apply.
So the comment isn't really right.

But I think:

cmd_mod = $(addprefix $(obj)/,$(sort $(call real-search, $*.o, .o, -objs -y -m))) >$@

will have the required effect.
Without forking and execing multiple processes.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)