multipath-tools: Makefile: Respect standard toolchain related envvars
Subsystems (2)
PATCH 1/1 multipath-tools: Makefile: Respect standard toolchain related envvars
The Makefile overrides standard envvars that control the toolchain flags. This patch should set things right without reducing default behavior.
--- Makefile.inc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Makefile.inc +3 -2
@@ -90,11 +90,12 @@ OPTFLAGS = -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \ -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \ --param=ssp-buffer-size=4 -CFLAGS = $(OPTFLAGS) -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" +CFLAGS ?= $(OPTFLAGS) +CFLAGS += -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" BIN_CFLAGS = -fPIE -DPIE LIB_CFLAGS = -fPIC SHARED_FLAGS = -shared -LDFLAGS = -Wl,-z,relro -Wl,-z,now +LDFLAGS += -Wl,-z,relro -Wl,-z,now BIN_LDFLAGS = -pie # Check whether a function with name $1 has been declared in header file $2.
Signature · 1 line
2.15.1
Quoted 17 lines · Thomas Deutschmann
The
Makefileoverrides standard envvars that control the toolchain flags. This patch should set things right without reducing default behavior.Signed-off-by Thomas Deutschmann <[email protected]>--- Makefile.inc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)Makefile.inc +0
-1@@ -90,11 +90,12 @@ OPTFLAGS = -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \ -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \ --param=ssp-buffer-size=4 -CFLAGS = $(OPTFLAGS) -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\"
Makefile.inc OPTFLAGS = -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \ · line 101
Quoted 10 lines
Makefile.inc +3
-1+CFLAGS ?= $(OPTFLAGS) +CFLAGS += -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" BIN_CFLAGS = -fPIE -DPIE LIB_CFLAGS = -fPIC SHARED_FLAGS = -shared -LDFLAGS = -Wl,-z,relro -Wl,-z,now +LDFLAGS += -Wl,-z,relro -Wl,-z,now BIN_LDFLAGS = -pie # Check whether a function with name $1 has been declared in header file $2.
Hello Thomas,
I agree that we need a way to specify additional compilation flags. However, is OPTFLAGS really a standard? Aren't most developers used to set CFLAGS to specify additional compilation flags?
Bart.
Hi Bart,
Quoted 3 lines · Bart Van Assche
I agree that we need a way to specify additional compilation flags. However, is OPTFLAGS really a standard? Aren't most developers used to set CFLAGS to specify additional compilation flags?
When I created the patch I searched in the source code of other projects after "OPTFLAGS" usage and came to the conclusion that this isn't a standard.
However, my patch shouldn't break any existing use cases.
So my understanding was that "OPTFLAGS" is used like the default set of flags in case the user hasn't set any flags on its own. However, the project may still need to add a special flag which should be set everywhere.
That's why I created the patch the way I did:
1) User can provide own CFLAGS in which case the default set of flags (OPTFLAGS) aren't used.
2) We now extend set CFLAGS by adding our additional flags (-DRUN_DIR..) we want to be set everywhere.
Your patch will do the same but require downstream to unset/negate default flags. I don't really care if we pick your patch or my patch.
Signature · 3 lines
Regards, Thomas Deutschmann / Gentoo Linux Developer C4DD 695F A713 8F24 2AA1 5638 5849 7EE5 1D5D 74A5
Quoted 17 lines · Thomas Deutschmann
Quoted 3 lines · Bart Van Assche
I agree that we need a way to specify additional compilation flags. However, is OPTFLAGS really a standard? Aren't most developers used to set CFLAGS to specify additional compilation flags?
When I created the patch I searched in the source code of other projects after "OPTFLAGS" usage and came to the conclusion that this isn't a standard.
However, my patch shouldn't break any existing use cases.
So my understanding was that "OPTFLAGS" is used like the default set of flags in case the user hasn't set any flags on its own. However, the project may still need to add a special flag which should be set everywhere.
That's why I created the patch the way I did:
Quoted 8 lines
1) User can provide own CFLAGS in which case the default set of flags (OPTFLAGS) aren't used.
2) We now extend set CFLAGS by adding our additional flags (-DRUN_DIR..) we want to be set everywhere.
Your patch will do the same but require downstream to unset/negate default flags. I don't really care if we pick your patch or my patch.
Hello Thomas,
I'm fine with dropping my patch and proceeding with your patch. However, I think that any CFLAGS specified on the make command line or in the environment should be appended at the end of the CFLAGS/OPTFLAGS specified by the Makefile. Otherwise it's not possible to override e.g. the -W... flags specified in the Makefile from the command line.
Thanks,
Bart.
Quoted 27 lines · Bart Van Assche
Quoted 26 lines · Thomas Deutschmann
The
Makefileoverrides standard envvars that control the toolchain flags. This patch should set things right without reducing default behavior.Signed-off-by Thomas Deutschmann <[email protected]>--- Makefile.inc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)Makefile.inc +3
-2@@ -90,11 +90,12 @@ OPTFLAGS = -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \ -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \ --param=ssp-buffer-size=4 -CFLAGS = $(OPTFLAGS) -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" +CFLAGS ?= $(OPTFLAGS) +CFLAGS += -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" BIN_CFLAGS = -fPIE -DPIE LIB_CFLAGS = -fPIC SHARED_FLAGS = -shared -LDFLAGS = -Wl,-z,relro -Wl,-z,now +LDFLAGS += -Wl,-z,relro -Wl,-z,now BIN_LDFLAGS = -pie
Quoted 7 lines
Makefile.inc OPTFLAGS = -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \ · line 101
Quoted 1 line
Makefile.inc +0
-0# Check whether a function with name $1 has been declared in header file $2.Hello Thomas,
I agree that we need a way to specify additional compilation flags. However, is OPTFLAGS really a standard? Aren't most developers used to set CFLAGS to specify additional compilation flags?
OPTFLAGS is used by RPM distributions(Fedora, openSUSE and derivatives).
Quoted 12 lines · Xose Vazquez Perez
Quoted 11 lines · Bart Van Assche
Quoted 7 lines · Thomas Deutschmann
The
Makefileoverrides standard envvars that control the toolchain flags.
This patch should set things right without reducing default behavior.Signed-off-by Thomas Deutschmann <[email protected]>Hello Thomas,
Quoted 8 lines
Quoted 5 lines
I agree that we need a way to specify additional compilation flags. However, is
OPTFLAGS really a standard? Aren't most developers used to set CFLAGS to specify
additional compilation flags?OPTFLAGS is used by RPM
distributions(Fedora, openSUSE and derivatives).
I'm not sure what you mean. At openSUSE, we simply set OPTFLAGS=%{optflags} in the spec file. RPM_OPT_FLAGS aka %{optflags} is a standard for RPM-based distros, but "OPTFLAGS" is not.
Martin
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Quoted 3 lines · Thomas Deutschmann
The
Makefileoverrides standard envvars that control the toolchain flags.
This patch should set things right without reducing default behavior.
I apologize for the very late reply.
I'm not sure what you mean with "standard envvars" here. Is it "CFLAGS" and "LDFLAGS"? If that's what you mean, I disagree.
CFLAGS handling is correct this way - CFLAGS should represent the final list of options passed to the compiler. Typically the Makefile assembles this list from internal project settings and user input.
Currently, setting OPTFLAGS is the preferred way to customize multipath-tools build.
If changes are needed, I'd prefer Bart's suggestion.
Martin
Quoted 29 lines
Signed-off-by Thomas Deutschmann <[email protected]>--- Makefile.inc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)Makefile.inc +3
-5@@ -90,11 +90,12 @@ OPTFLAGS = -O2 -g -pipe -Wall -Wextra -Wformat=2 -Werror=implicit-int \ -Wp,-D_FORTIFY_SOURCE=2 $(STACKPROT) \ --param=ssp-buffer-size=4 -CFLAGS = $(OPTFLAGS) -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" +CFLAGS ?= $(OPTFLAGS) +CFLAGS += -DLIB_STRING=\"${LIB}\" -DRUN_DIR=\"${RUN}\" BIN_CFLAGS = -fPIE -DPIE LIB_CFLAGS = -fPIC SHARED_FLAGS = -shared -LDFLAGS = -Wl,-z,relro -Wl,-z,now +LDFLAGS += -Wl,-z,relro -Wl,-z,now BIN_LDFLAGS = -pie # Check whether a function with name $1 has been declared in headerfile $2.
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Quoted 2 lines · Martin Wilck
I'm not sure what you mean with "standard envvars" here. Is it "CFLAGS" and "LDFLAGS"? If that's what you mean, I disagree.
Yes, I was especially talking about CFLAGS.
Quoted 6 lines
CFLAGS handling is correct this way - CFLAGS should represent the final list of options passed to the compiler. Typically the
Makefileassembles this list from internal project settings and user input.Currently, setting OPTFLAGS is the preferred way to customize multipath-tools build.
And this works for you with the current multipath-tools package? Sorry, maybe I am missing something but from my understanding the Makefile is currently setting OPTFLAGS via
OPTFLAGS = -O2 -g ....
So any OPTFLAGS value you are currently passing should be ignored at the moment. That's why Bart and I independently from each other created this patch.
Quoted 1 line
If changes are needed, I'd prefer Bart's suggestion.
Like said, Bart's variant works for me, too. We can pick his patch.
Signature · 3 lines
Regards, Thomas Deutschmann / Gentoo Linux Developer C4DD 695F A713 8F24 2AA1 5638 5849 7EE5 1D5D 74A5
Quoted 5 lines · Thomas Deutschmann
Quoted 3 lines · Martin Wilck
Currently, setting OPTFLAGS is the preferred way to customize multipath-tools build.
Quoted 7 lines
And this works for you with the current multipath-tools package? Sorry,
maybe I am missing something but from my understanding theMakefileis
currently setting OPTFLAGS viaOPTFLAGS = -O2 -g ....
Yes it works. Your can do e.g.
make OPTFLAGS="-g -O3 -fsanitize=address"
Quoted 5 lines
So any OPTFLAGS value you are currently passing should be ignored at the
moment. That's why Bart and I independently from each other created this
patch.
OPTFLAGS from the environment is ignored, but OPTFLAGS from the command line is honored.
https://www.gnu.org/software/make/manual/make.html#Environment
https://www.gnu.org/software/make/manual/make.html#Overriding
Regards,
Martin
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Hi,
Quoted 1 line · Martin Wilck
make OPTFLAGS="-g -O3 -fsanitize=address"
Thanks, this works for me.
OK, I am now pulling my patch suggestion. No longer required.
Regarding Bart's patch: Still not sure how important things like
-D_FORTIFY_SOURCE=2 $(STACKPROT) --param=ssp-buffer-size=4
are. We (Gentoo) will now probably set
make OPTFLAGS="${CFLAGS}"so we will lose this per default. Bart's patch would preserve these defaults...
Signature · 3 lines
Regards, Thomas Deutschmann / Gentoo Linux Developer C4DD 695F A713 8F24 2AA1 5638 5849 7EE5 1D5D 74A5
Quoted 6 lines · Thomas Deutschmann
Regarding Bart's patch: Still not sure how important things like
-D_FORTIFY_SOURCE=2 $(STACKPROT) --param=ssp-buffer-size=4are.
Most of this came came from Red Hat:
commit 1fce66911f4c15e3a9c09948f4c146d859bc1834
Author: Benjamin Marzinski <[email protected]> Date: Thu May 24 23:57:42 2012 -0500
multipath: Build with standard rpm cflags
This patch makes multipath build with the standard redhat rpm
cflags, which
can help catch some code errors.
I haven't questioned these so far. I don't think they have negative impact, and might help catching errors.
Martin
Signature · 8 lines
Dr. Martin Wilck <[email protected]>, Tel. +49 (0)911 74053 2107 SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel