diff mbox series

[bpf-next,2/4] tools/resolve_btfids: Check objects before removing

Message ID 20210204211825.588160-3-jolsa@kernel.org (mailing list archive)
State New, archived
Headers show
Series [bpf-next,1/4] tools/resolve_btfids: Build libbpf and libsubcmd in separate directories | expand

Commit Message

Jiri Olsa Feb. 4, 2021, 9:18 p.m. UTC
We want this clean to be called from tree's root clean
and that one is silent if there's nothing to clean.

Adding check for all object to clean and display CLEAN
messages only if there are objects to remove.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/bpf/resolve_btfids/Makefile | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

Comments

Song Liu Feb. 4, 2021, 11:41 p.m. UTC | #1
> On Feb 4, 2021, at 1:18 PM, Jiri Olsa <jolsa@kernel.org> wrote:
> 
> We want this clean to be called from tree's root clean
> and that one is silent if there's nothing to clean.
> 
> Adding check for all object to clean and display CLEAN
> messages only if there are objects to remove.
> 
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Acked-by: Song Liu <songliubraving@fb.com>

> ---
> tools/bpf/resolve_btfids/Makefile | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
> index b780b3a9fb07..3007cfabf5e6 100644
> --- a/tools/bpf/resolve_btfids/Makefile
> +++ b/tools/bpf/resolve_btfids/Makefile
> @@ -64,13 +64,20 @@ $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
> 	$(call msg,LINK,$@)
> 	$(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
> 
> +clean_objects := $(wildcard $(OUTPUT)/*.o                \
> +                            $(OUTPUT)/.*.o.cmd           \
> +                            $(OUTPUT)/.*.o.d             \
> +                            $(OUTPUT)/libbpf             \
> +                            $(OUTPUT)/libsubcmd          \
> +                            $(OUTPUT)/resolve_btfids)
> +
> +clean:
> +
> +ifneq ($(clean_objects),)
> clean: fixdep-clean
> 	$(call msg,CLEAN,$(BINARY))
> -	$(Q)$(RM) -f $(BINARY); \
> -	$(RM) -rf $(if $(OUTPUT),$(OUTPUT),.)/feature; \
> -	$(RM) -rf $(OUTPUT)libbpf; \
> -	$(RM) -rf $(OUTPUT)libsubcmd; \
> -	find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
> +	$(Q)$(RM) -rf $(clean_objects)
> +endif
> 
> tags:
> 	$(call msg,GEN,,tags)
> -- 
> 2.26.2
>
Andrii Nakryiko Feb. 5, 2021, 12:42 a.m. UTC | #2
On Thu, Feb 4, 2021 at 1:20 PM Jiri Olsa <jolsa@kernel.org> wrote:
>
> We want this clean to be called from tree's root clean
> and that one is silent if there's nothing to clean.
>
> Adding check for all object to clean and display CLEAN
> messages only if there are objects to remove.
>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/bpf/resolve_btfids/Makefile | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
> index b780b3a9fb07..3007cfabf5e6 100644
> --- a/tools/bpf/resolve_btfids/Makefile
> +++ b/tools/bpf/resolve_btfids/Makefile
> @@ -64,13 +64,20 @@ $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
>         $(call msg,LINK,$@)
>         $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
>
> +clean_objects := $(wildcard $(OUTPUT)/*.o                \
> +                            $(OUTPUT)/.*.o.cmd           \
> +                            $(OUTPUT)/.*.o.d             \
> +                            $(OUTPUT)/libbpf             \
> +                            $(OUTPUT)/libsubcmd          \
> +                            $(OUTPUT)/resolve_btfids)
> +
> +clean:
> +
> +ifneq ($(clean_objects),)
>  clean: fixdep-clean

this looks a bit weird, declaring clean twice. Wouldn't moving ifneq
inside the clean work just fine?

>         $(call msg,CLEAN,$(BINARY))
> -       $(Q)$(RM) -f $(BINARY); \
> -       $(RM) -rf $(if $(OUTPUT),$(OUTPUT),.)/feature; \
> -       $(RM) -rf $(OUTPUT)libbpf; \
> -       $(RM) -rf $(OUTPUT)libsubcmd; \
> -       find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
> +       $(Q)$(RM) -rf $(clean_objects)
> +endif
>
>  tags:
>         $(call msg,GEN,,tags)
> --
> 2.26.2
>
Jiri Olsa Feb. 5, 2021, 10:40 a.m. UTC | #3
On Thu, Feb 04, 2021 at 04:42:41PM -0800, Andrii Nakryiko wrote:
> On Thu, Feb 4, 2021 at 1:20 PM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > We want this clean to be called from tree's root clean
> > and that one is silent if there's nothing to clean.
> >
> > Adding check for all object to clean and display CLEAN
> > messages only if there are objects to remove.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  tools/bpf/resolve_btfids/Makefile | 17 ++++++++++++-----
> >  1 file changed, 12 insertions(+), 5 deletions(-)
> >
> > diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
> > index b780b3a9fb07..3007cfabf5e6 100644
> > --- a/tools/bpf/resolve_btfids/Makefile
> > +++ b/tools/bpf/resolve_btfids/Makefile
> > @@ -64,13 +64,20 @@ $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
> >         $(call msg,LINK,$@)
> >         $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
> >
> > +clean_objects := $(wildcard $(OUTPUT)/*.o                \
> > +                            $(OUTPUT)/.*.o.cmd           \
> > +                            $(OUTPUT)/.*.o.d             \
> > +                            $(OUTPUT)/libbpf             \
> > +                            $(OUTPUT)/libsubcmd          \
> > +                            $(OUTPUT)/resolve_btfids)
> > +
> > +clean:
> > +
> > +ifneq ($(clean_objects),)
> >  clean: fixdep-clean
> 
> this looks a bit weird, declaring clean twice. Wouldn't moving ifneq
> inside the clean work just fine?

it has the fixdep-clean dependency we don't want to run
if clean_objects is not defined.. I could move the empty
clean to the the else path

jirka


---
diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
index 1d46a247ec95..be09ec4f03ff 100644
--- a/tools/bpf/resolve_btfids/Makefile
+++ b/tools/bpf/resolve_btfids/Makefile
@@ -64,13 +64,20 @@ $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
 	$(call msg,LINK,$@)
 	$(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
 
+clean_objects := $(wildcard $(OUTPUT)/*.o                \
+                            $(OUTPUT)/.*.o.cmd           \
+                            $(OUTPUT)/.*.o.d             \
+                            $(OUTPUT)/libbpf             \
+                            $(OUTPUT)/libsubcmd          \
+                            $(OUTPUT)/resolve_btfids)
+
+ifneq ($(clean_objects),)
 clean: fixdep-clean
 	$(call msg,CLEAN,$(BINARY))
-	$(Q)$(RM) -f $(BINARY); \
-	$(RM) -rf $(if $(OUTPUT),$(OUTPUT),.)/feature; \
-	$(RM) -rf $(OUTPUT)/libbpf; \
-	$(RM) -rf $(OUTPUT)/libsubcmd; \
-	find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
+	$(Q)$(RM) -rf $(clean_objects)
+else
+clean:
+endif
 
 tags:
 	$(call msg,GEN,,tags)
diff mbox series

Patch

diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
index b780b3a9fb07..3007cfabf5e6 100644
--- a/tools/bpf/resolve_btfids/Makefile
+++ b/tools/bpf/resolve_btfids/Makefile
@@ -64,13 +64,20 @@  $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
 	$(call msg,LINK,$@)
 	$(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
 
+clean_objects := $(wildcard $(OUTPUT)/*.o                \
+                            $(OUTPUT)/.*.o.cmd           \
+                            $(OUTPUT)/.*.o.d             \
+                            $(OUTPUT)/libbpf             \
+                            $(OUTPUT)/libsubcmd          \
+                            $(OUTPUT)/resolve_btfids)
+
+clean:
+
+ifneq ($(clean_objects),)
 clean: fixdep-clean
 	$(call msg,CLEAN,$(BINARY))
-	$(Q)$(RM) -f $(BINARY); \
-	$(RM) -rf $(if $(OUTPUT),$(OUTPUT),.)/feature; \
-	$(RM) -rf $(OUTPUT)libbpf; \
-	$(RM) -rf $(OUTPUT)libsubcmd; \
-	find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
+	$(Q)$(RM) -rf $(clean_objects)
+endif
 
 tags:
 	$(call msg,GEN,,tags)