2023-01-16 23:04:53

by Herton R. Krzesinski

[permalink] [raw]
Subject: [PATCH] tools/vm: allow users to provide additional cflags/ldflags

Right now there is no way to provide additional cflags/ldflags when
building tools/vm binaries. And using eg. make CFLAGS=<options> will
override the CFLAGS being set in the Makefile, making the build fail
since it requires the include of the ../lib dir (for libapi).

This change then allows you to specify:
CFLAGS=<options> LDFLAGS=<options> make V=1 -C tools/vm

And the options will be correctly appended as can be seen from the
make output.

Signed-off-by: Herton R. Krzesinski <[email protected]>
---
tools/vm/Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/vm/Makefile b/tools/vm/Makefile
index 9860622cbb15..6c1da51f4177 100644
--- a/tools/vm/Makefile
+++ b/tools/vm/Makefile
@@ -8,8 +8,8 @@ TARGETS=page-types slabinfo page_owner_sort
LIB_DIR = ../lib/api
LIBS = $(LIB_DIR)/libapi.a

-CFLAGS = -Wall -Wextra -I../lib/
-LDFLAGS = $(LIBS)
+CFLAGS += -Wall -Wextra -I../lib/
+LDFLAGS += $(LIBS)

all: $(TARGETS)

--
2.38.1


2023-01-18 01:24:09

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] tools/vm: allow users to provide additional cflags/ldflags

On Mon, 16 Jan 2023 19:49:21 -0300 "Herton R. Krzesinski" <[email protected]> wrote:

> Right now there is no way to provide additional cflags/ldflags when
> building tools/vm binaries. And using eg. make CFLAGS=<options> will
> override the CFLAGS being set in the Makefile, making the build fail
> since it requires the include of the ../lib dir (for libapi).
>
> This change then allows you to specify:
> CFLAGS=<options> LDFLAGS=<options> make V=1 -C tools/vm
>
> And the options will be correctly appended as can be seen from the
> make output.
>
> ...
>
> --- a/tools/vm/Makefile
> +++ b/tools/vm/Makefile
> @@ -8,8 +8,8 @@ TARGETS=page-types slabinfo page_owner_sort
> LIB_DIR = ../lib/api
> LIBS = $(LIB_DIR)/libapi.a
>
> -CFLAGS = -Wall -Wextra -I../lib/
> -LDFLAGS = $(LIBS)
> +CFLAGS += -Wall -Wextra -I../lib/
> +LDFLAGS += $(LIBS)
>

I think EXTRA_CFLAGS is more conventional?

2023-01-18 14:26:30

by Herton R. Krzesinski

[permalink] [raw]
Subject: Re: [PATCH] tools/vm: allow users to provide additional cflags/ldflags

On Tue, Jan 17, 2023 at 04:53:26PM -0800, Andrew Morton wrote:
> On Mon, 16 Jan 2023 19:49:21 -0300 "Herton R. Krzesinski" <[email protected]> wrote:
>
> > Right now there is no way to provide additional cflags/ldflags when
> > building tools/vm binaries. And using eg. make CFLAGS=<options> will
> > override the CFLAGS being set in the Makefile, making the build fail
> > since it requires the include of the ../lib dir (for libapi).
> >
> > This change then allows you to specify:
> > CFLAGS=<options> LDFLAGS=<options> make V=1 -C tools/vm
> >
> > And the options will be correctly appended as can be seen from the
> > make output.
> >
> > ...
> >
> > --- a/tools/vm/Makefile
> > +++ b/tools/vm/Makefile
> > @@ -8,8 +8,8 @@ TARGETS=page-types slabinfo page_owner_sort
> > LIB_DIR = ../lib/api
> > LIBS = $(LIB_DIR)/libapi.a
> >
> > -CFLAGS = -Wall -Wextra -I../lib/
> > -LDFLAGS = $(LIBS)
> > +CFLAGS += -Wall -Wextra -I../lib/
> > +LDFLAGS += $(LIBS)
> >
>
> I think EXTRA_CFLAGS is more conventional?
>

I was looking and there is no standard under tools/

Some use it, some not. To given an example of what uses CFLAGS:
tools/arch/x86/kcpuid/Makefile:override CFLAGS += -O2 -Wall -I../../../include
tools/arch/x86/intel_sdsi/Makefile:override CFLAGS += -O2 -Wall
tools/iio/Makefile:override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
tools/thermal/tmon/Makefile:override CFLAGS += $(shell $(PKG_CONFIG) --cflags $(STATIC) panelw ncursesw 2> /dev/null || \
tools/gpio/Makefile:override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
tools/pci/Makefile:CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
tools/spi/Makefile:CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
tools/wmi/Makefile:CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include
tools/io_uring/Makefile:CFLAGS += -Wall -Wextra -g -D_GNU_SOURCE
tools/counter/Makefile:override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include

I can however use EXTRA_CFLAGS, not a problem, eg. doing instead:
CFLAGS = -Wall -Wextra -I../lib/ $(EXTRA_CFLAGS)
LDFLAGS = $(LIBS) $(EXTRA_LDFLAGS)

Let me know and I'll resend the patch using EXTRA_* instead.

--
[]'s
Herton

2023-01-18 22:28:32

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] tools/vm: allow users to provide additional cflags/ldflags

On Wed, 18 Jan 2023 10:47:21 -0300 "Herton R. Krzesinski" <[email protected]> wrote:

> On Tue, Jan 17, 2023 at 04:53:26PM -0800, Andrew Morton wrote:
> > On Mon, 16 Jan 2023 19:49:21 -0300 "Herton R. Krzesinski" <[email protected]> wrote:
> >
> > > Right now there is no way to provide additional cflags/ldflags when
> > > building tools/vm binaries. And using eg. make CFLAGS=<options> will
> > > override the CFLAGS being set in the Makefile, making the build fail
> > > since it requires the include of the ../lib dir (for libapi).
> > >
> > > This change then allows you to specify:
> > > CFLAGS=<options> LDFLAGS=<options> make V=1 -C tools/vm
> > >
> > > And the options will be correctly appended as can be seen from the
> > > make output.
> > >
> > > ...
> > >
> > > --- a/tools/vm/Makefile
> > > +++ b/tools/vm/Makefile
> > > @@ -8,8 +8,8 @@ TARGETS=page-types slabinfo page_owner_sort
> > > LIB_DIR = ../lib/api
> > > LIBS = $(LIB_DIR)/libapi.a
> > >
> > > -CFLAGS = -Wall -Wextra -I../lib/
> > > -LDFLAGS = $(LIBS)
> > > +CFLAGS += -Wall -Wextra -I../lib/
> > > +LDFLAGS += $(LIBS)
> > >
> >
> > I think EXTRA_CFLAGS is more conventional?
> >
>
> I was looking and there is no standard under tools/
>
> Some use it, some not. To given an example of what uses CFLAGS:
> tools/arch/x86/kcpuid/Makefile:override CFLAGS += -O2 -Wall -I../../../include
> tools/arch/x86/intel_sdsi/Makefile:override CFLAGS += -O2 -Wall
> tools/iio/Makefile:override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
> tools/thermal/tmon/Makefile:override CFLAGS += $(shell $(PKG_CONFIG) --cflags $(STATIC) panelw ncursesw 2> /dev/null || \
> tools/gpio/Makefile:override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
> tools/pci/Makefile:CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
> tools/spi/Makefile:CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
> tools/wmi/Makefile:CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include
> tools/io_uring/Makefile:CFLAGS += -Wall -Wextra -g -D_GNU_SOURCE
> tools/counter/Makefile:override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
>
> I can however use EXTRA_CFLAGS, not a problem, eg. doing instead:
> CFLAGS = -Wall -Wextra -I../lib/ $(EXTRA_CFLAGS)
> LDFLAGS = $(LIBS) $(EXTRA_LDFLAGS)
>
> Let me know and I'll resend the patch using EXTRA_* instead.

Well drat, I was hoping you'd decide ;)

I'll grab it as-is, thanks.

(of course, we could always use both!)