diff mbox series

[v5,1/2] meson: add per package optional compiler/linker flags

Message ID 20190408204321.18620-1-ps.report@gmx.net
State Superseded
Headers show
Series [v5,1/2] meson: add per package optional compiler/linker flags | expand

Commit Message

Peter Seiderer April 8, 2019, 8:43 p.m. UTC
Add LIBFOO_MESON_CFLAGS, LIBFOO_MESON_LDFLAGS and LIBFOO_MESON_CXXFLAGS
variables to allow per package additional compiler/linker flags.

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
---
Notes:
  - documentation change for the new flags variables is missing

Changes v4:
  - new patch (base on the original '[RFC v3 2/4] meson: change from
    global to per package  cross-compilation.conf', see [1])

Changes v4 -> v5:
  - no changes
[1] http://lists.busybox.net/pipermail/buildroot/2018-July/226313.html
---
 package/meson/cross-compilation.conf.in | 8 ++++----
 package/meson/meson.mk                  | 3 +++
 package/pkg-meson.mk                    | 7 +++++++
 3 files changed, 14 insertions(+), 4 deletions(-)

--
2.21.0

Comments

Thomas Petazzoni April 13, 2019, 4:49 p.m. UTC | #1
Hello Peter,

On Mon,  8 Apr 2019 22:43:20 +0200
Peter Seiderer <ps.report@gmx.net> wrote:

> Add LIBFOO_MESON_CFLAGS, LIBFOO_MESON_LDFLAGS and LIBFOO_MESON_CXXFLAGS
> variables to allow per package additional compiler/linker flags.
> 
> Signed-off-by: Peter Seiderer <ps.report@gmx.net>

I did a bit of research. Meson does accept -Dc_args and a bunch of
other options on the command line, but they are ignored when a
cross-file is used. http://mesonbuild.com/Builtin-options.html says it
clearly: "c_args, cpp_args, c_link_args, and cpp_link_args only affect
native builds, when cross compiling they will not be applied to
binaries or libraries targeting the host system, only those being run
on the build system."

There is some on-going discussion upstream about this. See
https://github.com/mesonbuild/meson/issues/4767.

A cross_pkg_config_path option was merged:

  https://github.com/mesonbuild/meson/commit/91b2475e30d7659dad24eb35b47e4d098c716792

Aparently, they are talking about possibly adding cross_c_args.

What do we do ? Wait until upstream solves the problem ? Use an
intermediate solution like yours, and later one move to another one if
upstream provides one ?

Could you at least raise the fact that the Buildroot project would also
be interested in being able to pass addition cflags/cxxflags/ldflags on
the command line, as well as passing the path of tools like
libgcrypt-config ? (See my reply to Jörg Krause's patch on this topic,
on which you are Cc'ed).

Best regards,

Thomas
Peter Seiderer April 23, 2019, 6:45 p.m. UTC | #2
Hello Thomas,

On Sat, 13 Apr 2019 18:49:17 +0200, Thomas Petazzoni <thomas.petazzoni@bootlin.com> wrote:

> Hello Peter,
> 
> On Mon,  8 Apr 2019 22:43:20 +0200
> Peter Seiderer <ps.report@gmx.net> wrote:
> 
> > Add LIBFOO_MESON_CFLAGS, LIBFOO_MESON_LDFLAGS and LIBFOO_MESON_CXXFLAGS
> > variables to allow per package additional compiler/linker flags.
> > 
> > Signed-off-by: Peter Seiderer <ps.report@gmx.net>  
> 
> I did a bit of research. Meson does accept -Dc_args and a bunch of
> other options on the command line, but they are ignored when a
> cross-file is used. http://mesonbuild.com/Builtin-options.html says it
> clearly: "c_args, cpp_args, c_link_args, and cpp_link_args only affect
> native builds, when cross compiling they will not be applied to
> binaries or libraries targeting the host system, only those being run
> on the build system."
> 
> There is some on-going discussion upstream about this. See
> https://github.com/mesonbuild/meson/issues/4767.
> 
> A cross_pkg_config_path option was merged:
> 
>   https://github.com/mesonbuild/meson/commit/91b2475e30d7659dad24eb35b47e4d098c716792
> 
> Aparently, they are talking about possibly adding cross_c_args.
> 
> What do we do ? Wait until upstream solves the problem ? Use an
> intermediate solution like yours, and later one move to another one if
> upstream provides one ?

Use the per package cross-compilation.conf with the enhanced flags setting
solution ;-), maybe it is the canonical solution because the compiler etc.
binaries and other settings for cross compile are already given via this
config file, why not all other settings (maybe unfamiliar for long term
autotools users, used to the 'easy' (1) way of quick overwrite some compile
flags/parameters)? 

> 
> Could you at least raise the fact that the Buildroot project would also
> be interested in being able to pass addition cflags/cxxflags/ldflags on
> the command line, as well as passing the path of tools like
> libgcrypt-config ? (See my reply to Jörg Krause's patch on this topic,
> on which you are Cc'ed).

O.k., will try to give some input on the upstream discussion...

Regards,
Peter

(1) maybe newbies would call it magic

> 
> Best regards,
> 
> Thomas
Peter Seiderer May 1, 2019, 9:03 p.m. UTC | #3
Hello Thomas,

On Tue, 23 Apr 2019 20:45:55 +0200, Peter Seiderer <ps.report@gmx.net> wrote:

> Hello Thomas,
> 
> On Sat, 13 Apr 2019 18:49:17 +0200, Thomas Petazzoni <thomas.petazzoni@bootlin.com> wrote:
> 
> > Hello Peter,
> > 
> > On Mon,  8 Apr 2019 22:43:20 +0200
> > Peter Seiderer <ps.report@gmx.net> wrote:
> >   
> > > Add LIBFOO_MESON_CFLAGS, LIBFOO_MESON_LDFLAGS and LIBFOO_MESON_CXXFLAGS
> > > variables to allow per package additional compiler/linker flags.
> > > 
> > > Signed-off-by: Peter Seiderer <ps.report@gmx.net>    
> > 
> > I did a bit of research. Meson does accept -Dc_args and a bunch of
> > other options on the command line, but they are ignored when a
> > cross-file is used. http://mesonbuild.com/Builtin-options.html says it
> > clearly: "c_args, cpp_args, c_link_args, and cpp_link_args only affect
> > native builds, when cross compiling they will not be applied to
> > binaries or libraries targeting the host system, only those being run
> > on the build system."
> > 
> > There is some on-going discussion upstream about this. See
> > https://github.com/mesonbuild/meson/issues/4767.
> > 
> > A cross_pkg_config_path option was merged:
> > 
> >   https://github.com/mesonbuild/meson/commit/91b2475e30d7659dad24eb35b47e4d098c716792
> > 
> > Aparently, they are talking about possibly adding cross_c_args.
> > 
> > What do we do ? Wait until upstream solves the problem ? Use an
> > intermediate solution like yours, and later one move to another one if
> > upstream provides one ?  
> 
> Use the per package cross-compilation.conf with the enhanced flags setting
> solution ;-), maybe it is the canonical solution because the compiler etc.
> binaries and other settings for cross compile are already given via this
> config file, why not all other settings (maybe unfamiliar for long term
> autotools users, used to the 'easy' (1) way of quick overwrite some compile
> flags/parameters)? 
> 
> > 
> > Could you at least raise the fact that the Buildroot project would also
> > be interested in being able to pass addition cflags/cxxflags/ldflags on
> > the command line, as well as passing the path of tools like
> > libgcrypt-config ? (See my reply to Jörg Krause's patch on this topic,
> > on which you are Cc'ed).  
> 
> O.k., will try to give some input on the upstream discussion...

Finally done, see [1]

Regards,
Peter

[1] https://github.com/mesonbuild/meson/issues/4767#issuecomment-488424402

> 
> Regards,
> Peter
> 
> (1) maybe newbies would call it magic
> 
> > 
> > Best regards,
> > 
> > Thomas  
> 
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
diff mbox series

Patch

diff --git a/package/meson/cross-compilation.conf.in b/package/meson/cross-compilation.conf.in
index fc8e27f7eb..4056c2b2f4 100644
--- a/package/meson/cross-compilation.conf.in
+++ b/package/meson/cross-compilation.conf.in
@@ -12,10 +12,10 @@  pkgconfig = '@HOST_DIR@/usr/bin/pkg-config'

 [properties]
 needs_exe_wrapper = true
-c_args = [@TARGET_CFLAGS@]
-c_link_args = [@TARGET_LDFLAGS@]
-cpp_args = [@TARGET_CXXFLAGS@]
-cpp_link_args = [@TARGET_LDFLAGS@]
+c_args = [@TARGET_CFLAGS@@PKG_TARGET_CFLAGS@]
+c_link_args = [@TARGET_LDFLAGS@@PKG_TARGET_LDFLAGS@]
+cpp_args = [@TARGET_CXXFLAGS@@PKG_TARGET_CXXFLAGS@]
+cpp_link_args = [@TARGET_LDFLAGS@@PKG_TARGET_LDFLAGS@]

 [host_machine]
 system = 'linux'
diff --git a/package/meson/meson.mk b/package/meson/meson.mk
index 49e27f5527..70128f6bad 100644
--- a/package/meson/meson.mk
+++ b/package/meson/meson.mk
@@ -60,6 +60,9 @@  define HOST_MESON_INSTALL_CROSS_CONF
 	    -e "s%@TARGET_CFLAGS@%$(HOST_MESON_SED_CFLAGS)%g" \
 	    -e "s%@TARGET_LDFLAGS@%$(HOST_MESON_SED_LDFLAGS)%g" \
 	    -e "s%@TARGET_CXXFLAGS@%$(HOST_MESON_SED_CXXFLAGS)%g" \
+	    -e "s%@PKG_TARGET_CFLAGS@%%g" \
+	    -e "s%@PKG_TARGET_LDFLAGS@%%g" \
+	    -e "s%@PKG_TARGET_CXXFLAGS@%%g" \
 	    -e "s%@HOST_DIR@%$(HOST_DIR)%g" \
 	    $(HOST_MESON_PKGDIR)/cross-compilation.conf.in \
 	    > $(HOST_DIR)/etc/meson/cross-compilation.conf
diff --git a/package/pkg-meson.mk b/package/pkg-meson.mk
index 886fcf7205..9974b1e513 100644
--- a/package/pkg-meson.mk
+++ b/package/pkg-meson.mk
@@ -57,6 +57,10 @@  $(2)_NINJA_ENV		?=
 ifndef $(2)_CONFIGURE_CMDS
 ifeq ($(4),target)

+$(2)_MESON_SED_CFLAGS = $(if $($(2)_MESON_CFLAGS),`printf '"%s"$(comma) ' $($(2)_MESON_CFLAGS)`)
+$(2)_MESON_SED_LDFLAGS = $(if $($(2)_MESON_LDFLAGS),`printf '"%s"$(comma) ' $($(2)_MESON_LDFLAGS)`)
+$(2)_MESON_SED_CXXFLAGS = $(if $($(2)_MESON_CXXFLAGS),`printf '"%s"$(comma) ' $$($$(2)_MESON_CXXFLAGS)`)
+
 # Configure package for target
 #
 #
@@ -70,6 +74,9 @@  define $(2)_CONFIGURE_CMDS
 	    -e "s%@TARGET_CFLAGS@%$$(HOST_MESON_SED_CFLAGS)%g" \
 	    -e "s%@TARGET_LDFLAGS@%$$(HOST_MESON_SED_LDFLAGS)%g" \
 	    -e "s%@TARGET_CXXFLAGS@%$$(HOST_MESON_SED_CXXFLAGS)%g" \
+	    -e "s%@PKG_TARGET_CFLAGS@%$$($$(PKG)_MESON_SED_CFLAGS)%g" \
+	    -e "s%@PKG_TARGET_LDFLAGS@%$$($$(PKG)_MESON_SED_LDFLAGS)%g" \
+	    -e "s%@PKG_TARGET_CXXFLAGS@%$$($$(PKG)_MESON_SED_CXXFLAGS)%g" \
 	    -e "s%@HOST_DIR@%$$(HOST_DIR)%g" \
 	    package/meson/cross-compilation.conf.in \
 	    > $$($$(PKG)_SRCDIR)/build/cross-compilation.conf