devtools: reset compilation flags for each target

Message ID 1570035347-18360-1-git-send-email-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series devtools: reset compilation flags for each target |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-compilation success Compile Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

David Marchand Oct. 2, 2019, 4:55 p.m. UTC
  Same idea than overriding PATH and PKG_CONFIG_PATH, it can be quite
useful to override compilation flags like CFLAGS, CPPFLAGS and LDFLAGS
for cross compilation or libraries that won't provide a pkg-config file.

Fixes: 272236741258 ("devtools: load target-specific compilation environment")

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 devtools/test-meson-builds.sh | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Bruce Richardson Oct. 3, 2019, 9:21 a.m. UTC | #1
On Wed, Oct 02, 2019 at 06:55:47PM +0200, David Marchand wrote:
> Same idea than overriding PATH and PKG_CONFIG_PATH, it can be quite
> useful to override compilation flags like CFLAGS, CPPFLAGS and LDFLAGS
> for cross compilation or libraries that won't provide a pkg-config file.
> 
> Fixes: 272236741258 ("devtools: load target-specific compilation environment")
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---

No strong objection to this change, but for meson the better way to handle
this may be to put these flags into the cross-file used for the build. By
explicitly passing CFLAGS etc. to the build, I'm not sure what the
behaviour is with regards to passing those flags to cross-built vs
native-built components. For a cross-compile, not all CFLAGS should be
passed to the build of pmdinfogen, for instance.

/Bruce
  
David Marchand Oct. 3, 2019, 10:08 a.m. UTC | #2
On Thu, Oct 3, 2019 at 11:21 AM Bruce Richardson
<bruce.richardson@intel.com> wrote:
>
> On Wed, Oct 02, 2019 at 06:55:47PM +0200, David Marchand wrote:
> > Same idea than overriding PATH and PKG_CONFIG_PATH, it can be quite
> > useful to override compilation flags like CFLAGS, CPPFLAGS and LDFLAGS
> > for cross compilation or libraries that won't provide a pkg-config file.
> >
> > Fixes: 272236741258 ("devtools: load target-specific compilation environment")
> >
> > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > ---
>
> No strong objection to this change, but for meson the better way to handle
> this may be to put these flags into the cross-file used for the build. By
> explicitly passing CFLAGS etc. to the build, I'm not sure what the
> behaviour is with regards to passing those flags to cross-built vs
> native-built components. For a cross-compile, not all CFLAGS should be
> passed to the build of pmdinfogen, for instance.

Ok, I see.

Then the only usecase would be for locally built libraries that meson
can't find by itself.
A bit hackish too.

Mm, is there a way to tell meson "library X (CFLAGS, LDFLAGS) is (xx, yy)" ?
I could write some local .pc files and override PKG_CONFIG_PATH...
Any better idea ?
  
Bruce Richardson Oct. 3, 2019, 10:35 a.m. UTC | #3
On Thu, Oct 03, 2019 at 12:08:30PM +0200, David Marchand wrote:
> On Thu, Oct 3, 2019 at 11:21 AM Bruce Richardson
> <bruce.richardson@intel.com> wrote:
> >
> > On Wed, Oct 02, 2019 at 06:55:47PM +0200, David Marchand wrote:
> > > Same idea than overriding PATH and PKG_CONFIG_PATH, it can be quite
> > > useful to override compilation flags like CFLAGS, CPPFLAGS and LDFLAGS
> > > for cross compilation or libraries that won't provide a pkg-config file.
> > >
> > > Fixes: 272236741258 ("devtools: load target-specific compilation environment")
> > >
> > > Signed-off-by: David Marchand <david.marchand@redhat.com>
> > > ---
> >
> > No strong objection to this change, but for meson the better way to handle
> > this may be to put these flags into the cross-file used for the build. By
> > explicitly passing CFLAGS etc. to the build, I'm not sure what the
> > behaviour is with regards to passing those flags to cross-built vs
> > native-built components. For a cross-compile, not all CFLAGS should be
> > passed to the build of pmdinfogen, for instance.
> 
> Ok, I see.
> 
> Then the only usecase would be for locally built libraries that meson
> can't find by itself.
> A bit hackish too.
> 
> Mm, is there a way to tell meson "library X (CFLAGS, LDFLAGS) is (xx, yy)" ?
> I could write some local .pc files and override PKG_CONFIG_PATH...
> Any better idea ?
>
If the scheme here using CFLAGS/LDFLAGS works just go with it for now.

Ideally for cross compiles, we could consider taking the stored
cross-compile files and copying them to /tmp and then adding the additional
flags there.  However, for just passing flags to help find library X or Y,
its probably not worth doing, so let's keep it simple until we need
something more powerful. I was just pointing out that this could cause
issues in the future if we do start using it for something more fancy...
  
Thomas Monjalon Nov. 27, 2019, 11:07 p.m. UTC | #4
02/10/2019 18:55, David Marchand:
> Same idea than overriding PATH and PKG_CONFIG_PATH, it can be quite
> useful to override compilation flags like CFLAGS, CPPFLAGS and LDFLAGS
> for cross compilation or libraries that won't provide a pkg-config file.
> 
> Fixes: 272236741258 ("devtools: load target-specific compilation environment")
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Applied, thanks
  

Patch

diff --git a/devtools/test-meson-builds.sh b/devtools/test-meson-builds.sh
index 08e83eb..6091347 100755
--- a/devtools/test-meson-builds.sh
+++ b/devtools/test-meson-builds.sh
@@ -36,12 +36,18 @@  fi
 
 default_path=$PATH
 default_pkgpath=$PKG_CONFIG_PATH
+default_cflags=$CFLAGS
+default_cppflags=$CPPFLAGS
+default_ldflags=$LDFLAGS
 
 load_env () # <target compiler>
 {
 	targetcc=$1
 	export PATH=$default_path
 	export PKG_CONFIG_PATH=$default_pkgpath
+	export CFLAGS=$default_cflags
+	export CPPFLAGS=$default_cppflags
+	export LDFLAGS=$default_ldflags
 	unset DPDK_MESON_OPTIONS
 	command -v $targetcc >/dev/null 2>&1 || return 1
 	DPDK_TARGET=$($targetcc -v 2>&1 | sed -n 's,^Target: ,,p')