2014-06-20 18:31:37

by Markus Mayer

[permalink] [raw]
Subject: [RFC PATCH 0/2] Make host compiler and linker flags modifyable

Being able to pass in extra compiler or linker flags for the host
compiler can be quite helpful. This proposed series would allow a user
to do just that.

Please let me know if you would consider this kind of change for
inclusion or if there is an alternate approach to achieve the same
goal.

Markus Mayer (2):
Makefile: Make HOSTCFLAGS and HOSTCXXFLAGS user modifyable
Makefile: Introduce HOSTLDFLAGS environment variable

Makefile | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

--
1.9.1


2014-06-20 18:31:52

by Markus Mayer

[permalink] [raw]
Subject: [RFC PATCH 1/2] Makefile: Make HOSTCFLAGS and HOSTCXXFLAGS user modifyable

In order to allow the user to pass extra arguments to the host
compiler, we no longer overwrite the host compiler flags in the
makefile, but append them to what was passed in.

Signed-off-by: Markus Mayer <[email protected]>
---
Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 97b2861..5795eea 100644
--- a/Makefile
+++ b/Makefile
@@ -251,8 +251,8 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \

HOSTCC = gcc
HOSTCXX = g++
-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
-HOSTCXXFLAGS = -O2
+HOSTCFLAGS += -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
+HOSTCXXFLAGS += -O2

ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
--
1.9.1

2014-06-20 18:32:05

by Markus Mayer

[permalink] [raw]
Subject: [RFC PATCH 2/2] Makefile: Introduce HOSTLDFLAGS environment variable

By default we don't need HOSTLDFLAGS. However, providing it gives the
user the ability to pass extra flags to the host linker should they be
required.

The variables AS LD CC are moved to the next line to keep line length
in check.

Signed-off-by: Markus Mayer <[email protected]>
---
Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 5795eea..f6e2f53 100644
--- a/Makefile
+++ b/Makefile
@@ -414,8 +414,8 @@ KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)

export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
-export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
-export CPP AR NM STRIP OBJCOPY OBJDUMP
+export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS HOSTLDFLAGS CROSS_COMPILE
+export AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP
export MAKE AWK GENKSYMS INSTALLKERNEL PERL UTS_MACHINE
export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS

--
1.9.1

2014-06-20 18:44:15

by Sam Ravnborg

[permalink] [raw]
Subject: Re: [RFC PATCH 1/2] Makefile: Make HOSTCFLAGS and HOSTCXXFLAGS user modifyable

On Fri, Jun 20, 2014 at 11:31:28AM -0700, Markus Mayer wrote:
> In order to allow the user to pass extra arguments to the host
> compiler, we no longer overwrite the host compiler flags in the
> makefile, but append them to what was passed in.
>
> Signed-off-by: Markus Mayer <[email protected]>
> ---
> Makefile | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 97b2861..5795eea 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -251,8 +251,8 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
>
> HOSTCC = gcc
> HOSTCXX = g++
> -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
> -HOSTCXXFLAGS = -O2
> +HOSTCFLAGS += -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
> +HOSTCXXFLAGS += -O2
>
> ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
> HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \

With this patch you can only override HOSTCFLAGS.
In many cases appending to the falgs is actually what you want.

Please take a look at how we have implemented it for the kernel with KCFLAGS.
And notice that this is also described in Documentation/kbuild

Sam

2014-06-20 19:35:12

by Markus Mayer

[permalink] [raw]
Subject: Re: [RFC PATCH 1/2] Makefile: Make HOSTCFLAGS and HOSTCXXFLAGS user modifyable

On 20 June 2014 11:44, Sam Ravnborg <[email protected]> wrote:
> On Fri, Jun 20, 2014 at 11:31:28AM -0700, Markus Mayer wrote:
>> In order to allow the user to pass extra arguments to the host
>> compiler, we no longer overwrite the host compiler flags in the
>> makefile, but append them to what was passed in.
>>
>> Signed-off-by: Markus Mayer <[email protected]>
>> ---
>> Makefile | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/Makefile b/Makefile
>> index 97b2861..5795eea 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -251,8 +251,8 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
>>
>> HOSTCC = gcc
>> HOSTCXX = g++
>> -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
>> -HOSTCXXFLAGS = -O2
>> +HOSTCFLAGS += -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
>> +HOSTCXXFLAGS += -O2
>>
>> ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
>> HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
>
> With this patch you can only override HOSTCFLAGS.
> In many cases appending to the falgs is actually what you want.
>
> Please take a look at how we have implemented it for the kernel with KCFLAGS.
> And notice that this is also described in Documentation/kbuild

Thanks. I am able to do what I need using HOST_EXTRACFLAGS and HOST_LOADLIBES.

-Markus