[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] tools: pass EXTRA_CFLAGS via environment


  • To: xen-devel@xxxxxxxxxxxxxxxxxxx
  • From: Olaf Hering <olaf@xxxxxxxxx>
  • Date: Mon, 04 Jun 2012 23:56:11 +0200
  • Delivery-date: Mon, 04 Jun 2012 21:57:12 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xen.org>

# HG changeset patch
# User Olaf Hering <olaf@xxxxxxxxx>
# Date 1338846793 -7200
# Node ID 92a75908163cb0c5a46f94360d0e5faecf2e5a3a
# Parent  1e2ce970f0f29af4184d975c4f161f11938070cf
tools: pass EXTRA_CFLAGS via environment

Currently qemu-xen will be compiled with CFLAGS only if CFLAGS was
already in the environment during make invocation. If CFLAGS is in
environment then make will append all of the various flags specified in
xen Makefiles to this environment variable, which is then used in qemu
configure. Since qemu-xen is not ready for compiler flags like
"-std=gnu99" compilation will fail. If CFLAGS is not in environment,
then configure will use just its own "-O2 -g" because make does not
export its own CFLAGS variable.

>From a distro perspective, it is required to build libraries and
binaries with certain global cflags (arbitrary gcc options). Up to the
point when qemu-xen was imported it worked as expected by exporting
CFLAGS before 'make tools'.  Now qemu-upstream reuses these CFLAGS, but
it cant deal with the result.

This patch extends the tools Makefiles so that three new environment
variables are recognized:
  EXTRA_CFLAGS_XEN_TOOLS= specifies CFLAGS for the tools build.
  EXTRA_CFLAGS_QEMU_TRADITIONAL= specifies CFLAGS for old qemu.
  EXTRA_CFLAGS_QEMU_XEN= specifies CFLAGS for new qemu.

Special care needs to be taken in tools/firmware because the resulting
binaries are not linked with the hosts runtime libraries. These binaries
run in guest context. To avoid build errors from gcc options like
-fstack-protector, reuse existing practice to unset the new
EXTRA_CFLAGS_XEN_TOOLS for the firmware dirs.


The new feature can be used like this in a rpm xen.spec file:

   export EXTRA_CFLAGS_XEN_TOOLS="${RPM_OPT_FLAGS}"
   export EXTRA_CFLAGS_QEMU_TRADITIONAL="${RPM_OPT_FLAGS}"
   export EXTRA_CFLAGS_QEMU_XEN="${RPM_OPT_FLAGS}"
   ./configure \
        --libdir=%{_libdir} \
        --prefix=/usr
   make


v5:
 - move EXTRA_CFLAGS_XEN_TOOLS back to tools/Rules.mk
 - unset EXTRA_CFLAGS_XEN_TOOLS in tools/firmware/Rules.mk to avoid patching
   every Makefile in the tree

v4:
 - move EXTRA_CFLAGS_QEMU_XEN to existing --extra-cflags option
 - remove all configure related changes, EXTRA_CFLAGS_* will be
   taken from either environment or as make command line.

v3:
 - move EXTRA_CFLAGS_XEN_TOOLS from rules in tools/Rules.mk to every
   Makefile except firmware because it runs in guest context and can not
   deal with gcc options like -fstack-protector. This turns
   EXTRA_CFLAGS_XEN_TOOLS into a HOST_CFLAGS kind of thing.

v2:
 - add new EXTRA_CFLAGS_XEN_TOOLS variable to config/Tools.mk.in instead
   of modifying CFLAGS in this file. Also remove include order change in
   tools/Rules.mk since its now not needed anymore
 - add EXTRA_CFLAGS_XEN_TOOLS to all rules in tools/Rules.mk
 - update help output in tools/configure.ac

Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>

diff -r 1e2ce970f0f2 -r 92a75908163c tools/Makefile
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -122,7 +122,9 @@ subdir-all-qemu-xen-traditional-dir subd
        set -e; \
                $(buildmakevars2shellvars); \
                cd qemu-xen-traditional-dir; \
-               $(QEMU_ROOT)/xen-setup $(IOEMU_CONFIGURE_CROSS); \
+               $(QEMU_ROOT)/xen-setup \
+               --extra-cflags="$(EXTRA_CFLAGS_QEMU_TRADITIONAL)" \
+               $(IOEMU_CONFIGURE_CROSS); \
                $(MAKE) install
 
 subdir-clean-qemu-xen-traditional-dir:
@@ -151,7 +153,8 @@ subdir-all-qemu-xen-dir subdir-install-q
                --extra-cflags="-I$(XEN_ROOT)/tools/include \
                -I$(XEN_ROOT)/tools/libxc \
                -I$(XEN_ROOT)/tools/xenstore \
-               -I$(XEN_ROOT)/tools/xenstore/compat" \
+               -I$(XEN_ROOT)/tools/xenstore/compat \
+               $(EXTRA_CFLAGS_QEMU_XEN)" \
                --extra-ldflags="-L$(XEN_ROOT)/tools/libxc \
                -L$(XEN_ROOT)/tools/xenstore" \
                --bindir=$(LIBEXEC) \
diff -r 1e2ce970f0f2 -r 92a75908163c tools/Rules.mk
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -76,6 +76,8 @@ endif
 CFLAGS-$(CONFIG_X86_32) += $(call cc-option,$(CC),-mno-tls-direct-seg-refs)
 CFLAGS += $(CFLAGS-y)
 
+CFLAGS += $(EXTRA_CFLAGS_XEN_TOOLS)
+
 # Require GCC v3.4+ (to avoid issues with alignment constraints in Xen headers)
 check-$(CONFIG_X86) = $(call cc-ver-check,CC,0x030400,\
                         "Xen requires at least gcc-3.4")
diff -r 1e2ce970f0f2 -r 92a75908163c tools/firmware/Rules.mk
--- a/tools/firmware/Rules.mk
+++ b/tools/firmware/Rules.mk
@@ -3,6 +3,7 @@ override XEN_TARGET_ARCH = x86_32
 
 # User-supplied CFLAGS are not useful here.
 CFLAGS =
+EXTRA_CFLAGS_XEN_TOOLS =
 
 include $(XEN_ROOT)/tools/Rules.mk
 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.