diff mbox series

[bpf-next,1/4] tools/resolve_btfids: Build libbpf and libsubcmd in separate directories

Message ID 20210204211825.588160-2-jolsa@kernel.org (mailing list archive)
State New
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
Setting up separate build directories for libbpf and libpsubcmd,
so it's separated from other objects and we don't get them mixed
in the future.

It also simplifies cleaning, which is now simple rm -rf.

Also there's no need for FEATURE-DUMP.libbpf and bpf_helper_defs.h
files in .gitignore anymore.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/bpf/resolve_btfids/.gitignore |  2 --
 tools/bpf/resolve_btfids/Makefile   | 26 +++++++++++---------------
 2 files changed, 11 insertions(+), 17 deletions(-)

Comments

Song Liu Feb. 4, 2021, 11:33 p.m. UTC | #1
> On Feb 4, 2021, at 1:18 PM, Jiri Olsa <jolsa@kernel.org> wrote:
> 
> Setting up separate build directories for libbpf and libpsubcmd,
> so it's separated from other objects and we don't get them mixed
> in the future.
> 
> It also simplifies cleaning, which is now simple rm -rf.
> 
> Also there's no need for FEATURE-DUMP.libbpf and bpf_helper_defs.h
> files in .gitignore anymore.
> 
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>


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

[...]
Andrii Nakryiko Feb. 5, 2021, 12:39 a.m. UTC | #2
On Thu, Feb 4, 2021 at 1:20 PM Jiri Olsa <jolsa@kernel.org> wrote:
>
> Setting up separate build directories for libbpf and libpsubcmd,
> so it's separated from other objects and we don't get them mixed
> in the future.
>
> It also simplifies cleaning, which is now simple rm -rf.
>
> Also there's no need for FEATURE-DUMP.libbpf and bpf_helper_defs.h
> files in .gitignore anymore.
>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/bpf/resolve_btfids/.gitignore |  2 --
>  tools/bpf/resolve_btfids/Makefile   | 26 +++++++++++---------------
>  2 files changed, 11 insertions(+), 17 deletions(-)
>
> diff --git a/tools/bpf/resolve_btfids/.gitignore b/tools/bpf/resolve_btfids/.gitignore
> index a026df7dc280..25f308c933cc 100644
> --- a/tools/bpf/resolve_btfids/.gitignore
> +++ b/tools/bpf/resolve_btfids/.gitignore
> @@ -1,4 +1,2 @@
> -/FEATURE-DUMP.libbpf
> -/bpf_helper_defs.h
>  /fixdep
>  /resolve_btfids
> diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
> index bf656432ad73..b780b3a9fb07 100644
> --- a/tools/bpf/resolve_btfids/Makefile
> +++ b/tools/bpf/resolve_btfids/Makefile
> @@ -28,22 +28,22 @@ OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
>  LIBBPF_SRC := $(srctree)/tools/lib/bpf/
>  SUBCMD_SRC := $(srctree)/tools/lib/subcmd/
>
> -BPFOBJ     := $(OUTPUT)/libbpf.a
> -SUBCMDOBJ  := $(OUTPUT)/libsubcmd.a
> +BPFOBJ     := $(OUTPUT)/libbpf/libbpf.a
> +SUBCMDOBJ  := $(OUTPUT)/libsubcmd/libsubcmd.a
>
>  BINARY     := $(OUTPUT)/resolve_btfids
>  BINARY_IN  := $(BINARY)-in.o
>
>  all: $(BINARY)
>
> -$(OUTPUT):
> +$(OUTPUT) $(OUTPUT)/libbpf $(OUTPUT)/libsubcmd:
>         $(call msg,MKDIR,,$@)
> -       $(Q)mkdir -p $(OUTPUT)
> +       $(Q)mkdir -p $(@)
>
> -$(SUBCMDOBJ): fixdep FORCE
> -       $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(OUTPUT)
> +$(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd
> +       $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
>
> -$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)
> +$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/libbpf
>         $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC)  OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
>
>  CFLAGS := -g \
> @@ -57,23 +57,19 @@ LIBS = -lelf -lz
>  export srctree OUTPUT CFLAGS Q
>  include $(srctree)/tools/build/Makefile.include
>
> -$(BINARY_IN): fixdep FORCE
> +$(BINARY_IN): fixdep FORCE | $(OUTPUT)
>         $(Q)$(MAKE) $(build)=resolve_btfids
>
>  $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
>         $(call msg,LINK,$@)
>         $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
>
> -libsubcmd-clean:
> -       $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(OUTPUT) clean
> -
> -libbpf-clean:
> -       $(Q)$(MAKE) -C $(LIBBPF_SRC) OUTPUT=$(OUTPUT) clean
> -
> -clean: libsubcmd-clean libbpf-clean fixdep-clean
> +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; \

If someone specifies OUTPUT=bla, you will attempt to delete blalibbpf,
not bla/libbpf

>         find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o -or -name \*.o.cmd -or -name \*.o.d | xargs $(RM)
>
>  tags:
> --
> 2.26.2
>
Jiri Olsa Feb. 5, 2021, 10:35 a.m. UTC | #3
On Thu, Feb 04, 2021 at 04:39:38PM -0800, Andrii Nakryiko wrote:
> On Thu, Feb 4, 2021 at 1:20 PM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > Setting up separate build directories for libbpf and libpsubcmd,
> > so it's separated from other objects and we don't get them mixed
> > in the future.
> >
> > It also simplifies cleaning, which is now simple rm -rf.
> >
> > Also there's no need for FEATURE-DUMP.libbpf and bpf_helper_defs.h
> > files in .gitignore anymore.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  tools/bpf/resolve_btfids/.gitignore |  2 --
> >  tools/bpf/resolve_btfids/Makefile   | 26 +++++++++++---------------
> >  2 files changed, 11 insertions(+), 17 deletions(-)
> >
> > diff --git a/tools/bpf/resolve_btfids/.gitignore b/tools/bpf/resolve_btfids/.gitignore
> > index a026df7dc280..25f308c933cc 100644
> > --- a/tools/bpf/resolve_btfids/.gitignore
> > +++ b/tools/bpf/resolve_btfids/.gitignore
> > @@ -1,4 +1,2 @@
> > -/FEATURE-DUMP.libbpf
> > -/bpf_helper_defs.h
> >  /fixdep
> >  /resolve_btfids
> > diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
> > index bf656432ad73..b780b3a9fb07 100644
> > --- a/tools/bpf/resolve_btfids/Makefile
> > +++ b/tools/bpf/resolve_btfids/Makefile
> > @@ -28,22 +28,22 @@ OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
> >  LIBBPF_SRC := $(srctree)/tools/lib/bpf/
> >  SUBCMD_SRC := $(srctree)/tools/lib/subcmd/
> >
> > -BPFOBJ     := $(OUTPUT)/libbpf.a
> > -SUBCMDOBJ  := $(OUTPUT)/libsubcmd.a
> > +BPFOBJ     := $(OUTPUT)/libbpf/libbpf.a
> > +SUBCMDOBJ  := $(OUTPUT)/libsubcmd/libsubcmd.a
> >
> >  BINARY     := $(OUTPUT)/resolve_btfids
> >  BINARY_IN  := $(BINARY)-in.o
> >
> >  all: $(BINARY)
> >
> > -$(OUTPUT):
> > +$(OUTPUT) $(OUTPUT)/libbpf $(OUTPUT)/libsubcmd:
> >         $(call msg,MKDIR,,$@)
> > -       $(Q)mkdir -p $(OUTPUT)
> > +       $(Q)mkdir -p $(@)
> >
> > -$(SUBCMDOBJ): fixdep FORCE
> > -       $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(OUTPUT)
> > +$(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd
> > +       $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
> >
> > -$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)
> > +$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/libbpf
> >         $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC)  OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
> >
> >  CFLAGS := -g \
> > @@ -57,23 +57,19 @@ LIBS = -lelf -lz
> >  export srctree OUTPUT CFLAGS Q
> >  include $(srctree)/tools/build/Makefile.include
> >
> > -$(BINARY_IN): fixdep FORCE
> > +$(BINARY_IN): fixdep FORCE | $(OUTPUT)
> >         $(Q)$(MAKE) $(build)=resolve_btfids
> >
> >  $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
> >         $(call msg,LINK,$@)
> >         $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
> >
> > -libsubcmd-clean:
> > -       $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(OUTPUT) clean
> > -
> > -libbpf-clean:
> > -       $(Q)$(MAKE) -C $(LIBBPF_SRC) OUTPUT=$(OUTPUT) clean
> > -
> > -clean: libsubcmd-clean libbpf-clean fixdep-clean
> > +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; \
> 
> If someone specifies OUTPUT=bla, you will attempt to delete blalibbpf,
> not bla/libbpf

will add missing '/', thanks

jirka
diff mbox series

Patch

diff --git a/tools/bpf/resolve_btfids/.gitignore b/tools/bpf/resolve_btfids/.gitignore
index a026df7dc280..25f308c933cc 100644
--- a/tools/bpf/resolve_btfids/.gitignore
+++ b/tools/bpf/resolve_btfids/.gitignore
@@ -1,4 +1,2 @@ 
-/FEATURE-DUMP.libbpf
-/bpf_helper_defs.h
 /fixdep
 /resolve_btfids
diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
index bf656432ad73..b780b3a9fb07 100644
--- a/tools/bpf/resolve_btfids/Makefile
+++ b/tools/bpf/resolve_btfids/Makefile
@@ -28,22 +28,22 @@  OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
 LIBBPF_SRC := $(srctree)/tools/lib/bpf/
 SUBCMD_SRC := $(srctree)/tools/lib/subcmd/
 
-BPFOBJ     := $(OUTPUT)/libbpf.a
-SUBCMDOBJ  := $(OUTPUT)/libsubcmd.a
+BPFOBJ     := $(OUTPUT)/libbpf/libbpf.a
+SUBCMDOBJ  := $(OUTPUT)/libsubcmd/libsubcmd.a
 
 BINARY     := $(OUTPUT)/resolve_btfids
 BINARY_IN  := $(BINARY)-in.o
 
 all: $(BINARY)
 
-$(OUTPUT):
+$(OUTPUT) $(OUTPUT)/libbpf $(OUTPUT)/libsubcmd:
 	$(call msg,MKDIR,,$@)
-	$(Q)mkdir -p $(OUTPUT)
+	$(Q)mkdir -p $(@)
 
-$(SUBCMDOBJ): fixdep FORCE
-	$(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(OUTPUT)
+$(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd
+	$(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
 
-$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)
+$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/libbpf
 	$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC)  OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
 
 CFLAGS := -g \
@@ -57,23 +57,19 @@  LIBS = -lelf -lz
 export srctree OUTPUT CFLAGS Q
 include $(srctree)/tools/build/Makefile.include
 
-$(BINARY_IN): fixdep FORCE
+$(BINARY_IN): fixdep FORCE | $(OUTPUT)
 	$(Q)$(MAKE) $(build)=resolve_btfids
 
 $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
 	$(call msg,LINK,$@)
 	$(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
 
-libsubcmd-clean:
-	$(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(OUTPUT) clean
-
-libbpf-clean:
-	$(Q)$(MAKE) -C $(LIBBPF_SRC) OUTPUT=$(OUTPUT) clean
-
-clean: libsubcmd-clean libbpf-clean fixdep-clean
+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)
 
 tags: