Subject: Re: [PATCH bpf-next 4/4] kbuild: Add resolve_btfids clean to root clean target

From: Jiri Olsa <[email-masked]>
Date: Wed, 10 Feb 2021 19:14:01 +0100

On Wed, Feb 10, 2021 at 09:52:42AM -0800, Andrii Nakryiko wrote:
> On Wed, Feb 10, 2021 at 9:47 AM Nathan Chancellor <[email-masked]> wrote:
> >
> > On Fri, Feb 05, 2021 at 01:40:20PM +0100, Jiri Olsa wrote:
> > > The resolve_btfids tool is used during the kernel build,
> > > so we should clean it on kernel's make clean.
> > >
> > > Invoking the the resolve_btfids clean as part of root
> > > 'make clean'.
> > >
> > > Acked-by: Song Liu <[email-masked]>
> > > Signed-off-by: Jiri Olsa <[email-masked]>
> > > ---
> > >  Makefile | 7 ++++++-
> > >  1 file changed, 6 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/Makefile b/Makefile
> > > index b0e4767735dc..159d9592b587 100644
> > > --- a/Makefile
> > > +++ b/Makefile
> > > @@ -1086,6 +1086,11 @@ ifdef CONFIG_STACK_VALIDATION
> > >    endif
> > >  endif
> > >
> > > +PHONY += resolve_btfids_clean
> > > +
> > > +resolve_btfids_clean:
> > > +     $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(abspath $(objtree))/tools/bpf/resolve_btfids clean
> > > +
> > >  ifdef CONFIG_BPF
> > >  ifdef CONFIG_DEBUG_INFO_BTF
> > >    ifeq ($(has_libelf),1)
> > > @@ -1495,7 +1500,7 @@ vmlinuxclean:
> > >       $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
> > >       $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
> > >
> > > -clean: archclean vmlinuxclean
> > > +clean: archclean vmlinuxclean resolve_btfids_clean
> > >
> > >  # mrproper - Delete all generated files, including .config
> > >  #
> > > --
> > > 2.26.2
> > >
> >
> > This breaks running distclean on a clean tree (my script just
> > unconditionally runs distclean regardless of the tree state):
> >
> > $ make -s O=build distclean
> > ../../scripts/Makefile.include:4: *** O=/home/nathan/cbl/src/linux-next/build/tools/bpf/resolve_btfids does not exist.  Stop.
> >
> 
> Can't reproduce it. It works in all kinds of variants (relative and
> absolute O=, clean and not clean trees, etc). Jiri, please check as
> well.

I can reproduce if I set O=XXX to directory that does not contain kernel build

	$ mkdir /tmp/krava
	$ make O=/tmp/krava distclean
	make[1]: Entering directory '/tmp/krava'
	../../scripts/Makefile.include:4: *** O=/tmp/krava/tools/bpf/resolve_btfids does not exist.  Stop.
	make[1]: *** [/home/jolsa/linux/Makefile:1092: resolve_btfids_clean] Error 2
	make[1]: Leaving directory '/tmp/krava'
	make: *** [Makefile:185: __sub-make] Error 2

will check on fix

jirka