Re: [PATCH 5/7] kbuild: get rid of duplication in *.mod files

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

 



On Fri, Apr 8, 2022 at 2:55 AM Nick Desaulniers <ndesaulniers@xxxxxxxxxx> wrote:
>
> On Wed, Apr 6, 2022 at 8:31 AM Masahiro Yamada <masahiroy@xxxxxxxxxx> wrote:
> >
> > It is allowed to add the same objects multiple times to obj-y / obj-m:
> >
> >   obj-y += foo.o foo.o foo.o
> >   obj-m += bar.o bar.o bar.o
> >
> > It is also allowed to add the same objects multiple times to a composite
> > module:
> >
> >   obj-m    += foo.o
> >   foo-objs := foo1.o foo2.o foo2.o foo1.o
> >
> > This flexibility is useful because the same object might be selected by
> > different CONFIG options, like this:
> >
> >   obj-m               += foo.o
> >   foo-y               := foo1.o
> >   foo-$(CONFIG_FOO_X) += foo2.o
> >   foo-$(CONFIG_FOO_Y) += foo2.o
> >
> > The duplicated objects are omitted at link time. It works naturally in
> > Makefiles because GNU Make removes duplication in $^ without changing
> > the order.
> >
> > It is working well, almost...
> >
> > A small flaw I notice is, *.mod contains duplication in such a case.
> >
> > This is probably not a big deal. As far as I know, the only small
> > problem is scripts/mod/sumversion.c parses the same file multiple
> > times.
> >
> > I am fixing this because I plan to reuse *.mod for other purposes,
> > where the duplication can be problematic.
> >
> > The code change is quite simple. We already use awk to drop duplicated
> > lines in modules.order (see cmd_modules_order in the same file).
>
> Why does the top level Makefile reassign cmd_modules_order rather than
> use the original value in scripts/Makefile.build?


Because the top level Makefile does not include scripts/Makefile.build



> > I copied the code, but changed RS to use spaces as record separators.
> >
> > I also changed the file format to list one object per line.
> >
> > Signed-off-by: Masahiro Yamada <masahiroy@xxxxxxxxxx>
> > ---
> >
> >  scripts/Makefile.build   | 3 ++-
> >  scripts/mod/sumversion.c | 2 +-
> >  2 files changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> > index 6ae92d119dfa..f7a30f378e20 100644
> > --- a/scripts/Makefile.build
> > +++ b/scripts/Makefile.build
> > @@ -303,7 +303,8 @@ $(obj)/%.prelink.o: $(obj)/%.o FORCE
> >         $(call if_changed,cc_prelink_modules)
> >  endif
> >
> > -cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) > $@
> > +cmd_mod = echo $(addprefix $(obj)/, $(call real-search, $*.o, .o, -objs -y -m)) | \
> > +       $(AWK) -v RS='( |\n)' '!x[$$0]++' > $@
>
> God AWK is unreadable. Any reason we can't use GNU make's sort builtin?
> https://www.gnu.org/software/make/manual/html_node/Text-Functions.html


I did that in the previous submission.
https://lore.kernel.org/lkml/20220405113359.2880241-8-masahiroy@xxxxxxxxxx/


After some thoughts, I decided to drop duplicates without sorting.

If I alphabetically sorted the object list,
7/7 of this series would be impossible.


I am not a big fan of AWK, but I do not know a cleaner way.
If you know a better idea, please tell me.


-- 
Best Regards
Masahiro Yamada



[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux