nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0105-Make-it-so-we-can-tell-configure-which-cflags-utils-.patch

5593c8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
5593c8
From: Peter Jones <pjones@redhat.com>
5593c8
Date: Tue, 26 Jun 2018 17:16:06 -0400
5593c8
Subject: [PATCH] Make it so we can tell configure which cflags utils are built
5593c8
 with
5593c8
5593c8
This lets us have kernel.img be built with TARGET_CFLAGS but grub-mkimage and
5593c8
friends built with HOST_CFLAGS.  That in turn lets us build with an ARM compiler
5593c8
that only has hard-float ABI versions of crt*.o and libgcc*, but still use soft
5593c8
float for grub.efi.
5593c8
5593c8
Signed-off-by: Peter Jones <pjones@redhat.com>
5593c8
---
5593c8
 configure.ac         | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
5593c8
 conf/Makefile.common | 23 ++++++++++++-----------
5593c8
 gentpl.py            |  8 ++++----
5593c8
 3 files changed, 64 insertions(+), 16 deletions(-)
5593c8
5593c8
diff --git a/configure.ac b/configure.ac
5593c8
index b4455e4732d..3405348178a 100644
5593c8
--- a/configure.ac
5593c8
+++ b/configure.ac
5593c8
@@ -877,11 +877,23 @@ if ( test "x$target_cpu" = xi386 || test "x$target_cpu" = xx86_64 ) && test "x$p
5593c8
   TARGET_CFLAGS="$TARGET_CFLAGS -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow"
5593c8
 fi
5593c8
 
5593c8
+# Should grub utils get the host CFLAGS, or the target CFLAGS?
5593c8
+AC_ARG_WITH([utils],
5593c8
+            AS_HELP_STRING([--with-utils=host|target|build],
5593c8
+                           [choose which flags to build utilities with. (default=target)]),
5593c8
+	    [have_with_utils=y],
5593c8
+	    [have_with_utils=n])
5593c8
+if test x"$have_with_utils" = xy ; then
5593c8
+  with_utils="$withval"
5593c8
+else
5593c8
+  with_utils=target
5593c8
+fi
5593c8
+
5593c8
 # GRUB doesn't use float or doubles at all. Yet some toolchains may decide
5593c8
 # that floats are a good fit to run instead of what's written in the code.
5593c8
 # Given that floating point unit is disabled (if present to begin with)
5593c8
 # when GRUB is running which may result in various hard crashes.
5593c8
-if test x"$platform" != xemu ; then
5593c8
+if test x"$platform" != xemu -a x"$with_utils" == xtarget ; then
5593c8
   AC_CACHE_CHECK([for options to get soft-float], grub_cv_target_cc_soft_float, [
5593c8
     grub_cv_target_cc_soft_float=no
5593c8
     if test "x$target_cpu" = xarm64; then
5593c8
@@ -2018,6 +2030,41 @@ HOST_CPPFLAGS="$HOST_CPPFLAGS -I\$(top_builddir)/include"
5593c8
 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_srcdir)/include"
5593c8
 TARGET_CPPFLAGS="$TARGET_CPPFLAGS -I\$(top_builddir)/include"
5593c8
 
5593c8
+case "$with_utils" in
5593c8
+  host)
5593c8
+    UTILS_CFLAGS=$HOST_CFLAGS
5593c8
+    UTILS_CPPFLAGS=$HOST_CPPFLAGS
5593c8
+    UTILS_CCASFLAGS=$HOST_CCASFLAGS
5593c8
+    UTILS_LDFLAGS=$HOST_LDFLAGS
5593c8
+    ;;
5593c8
+  target)
5593c8
+    UTILS_CFLAGS=$TARGET_CFLAGS
5593c8
+    UTILS_CPPFLAGS=$TARGET_CPPFLAGS
5593c8
+    UTILS_CCASFLAGS=$TARGET_CCASFLAGS
5593c8
+    UTILS_LDFLAGS=$TARGET_LDFLAGS
5593c8
+    ;;
5593c8
+  build)
5593c8
+    UTILS_CFLAGS=$BUILD_CFLAGS
5593c8
+    UTILS_CPPFLAGS=$BUILD_CPPFLAGS
5593c8
+    UTILS_CCASFLAGS=$BUILD_CCASFLAGS
5593c8
+    UTILS_LDFLAGS=$BUILD_LDFLAGS
5593c8
+    ;;
5593c8
+  *)
5593c8
+    AC_MSG_ERROR([--with-utils must be either host, target, or build])
5593c8
+    ;;
5593c8
+esac
5593c8
+AC_MSG_NOTICE([Using $with_utils flags for utilities.])
5593c8
+
5593c8
+unset CFLAGS
5593c8
+unset CPPFLAGS
5593c8
+unset CCASFLAGS
5593c8
+unset LDFLAGS
5593c8
+
5593c8
+AC_SUBST(UTILS_CFLAGS)
5593c8
+AC_SUBST(UTILS_CPPFLAGS)
5593c8
+AC_SUBST(UTILS_CCASFLAGS)
5593c8
+AC_SUBST(UTILS_LDFLAGS)
5593c8
+
5593c8
 GRUB_TARGET_CPU="${target_cpu}"
5593c8
 GRUB_PLATFORM="${platform}"
5593c8
 
5593c8
diff --git a/conf/Makefile.common b/conf/Makefile.common
5593c8
index 5f0ef969857..2ff9b39357c 100644
5593c8
--- a/conf/Makefile.common
5593c8
+++ b/conf/Makefile.common
5593c8
@@ -40,24 +40,25 @@ CPPFLAGS_KERNEL = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM) -DGRUB_KERNEL=1
5593c8
 CCASFLAGS_KERNEL = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
5593c8
 STRIPFLAGS_KERNEL = -R .eh_frame -R .rel.dyn -R .reginfo -R .note -R .comment -R .drectve -R .note.gnu.gold-version -R .MIPS.abiflags -R .ARM.exidx -R .note.gnu.property -R .gnu.build.attributes
5593c8
 
5593c8
-CFLAGS_MODULE = $(CFLAGS_PLATFORM) -ffreestanding
5593c8
-LDFLAGS_MODULE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d
5593c8
-CPPFLAGS_MODULE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM)
5593c8
-CCASFLAGS_MODULE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
5593c8
+CFLAGS_MODULE = $(TARGET_CFLAGS) $(CFLAGS_PLATFORM) -ffreestanding
5593c8
+LDFLAGS_MODULE = $(TARGET_LDFLAGS) $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-r,-d
5593c8
+CPPFLAGS_MODULE = $(TARGET_CPPFLAGS) $(CPPFLAGS_DEFAULT) $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM)
5593c8
+CCASFLAGS_MODULE = $(TARGET_CCASFLAGS) $(CCASFLAGS_DEFAULT) $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
5593c8
 
5593c8
 CFLAGS_IMAGE = $(CFLAGS_PLATFORM) -fno-builtin
5593c8
 LDFLAGS_IMAGE = $(LDFLAGS_PLATFORM) -nostdlib $(TARGET_LDFLAGS_OLDMAGIC) -Wl,-S
5593c8
 CPPFLAGS_IMAGE = $(CPPFLAGS_CPU) $(CPPFLAGS_PLATFORM)
5593c8
 CCASFLAGS_IMAGE = $(CCASFLAGS_CPU) $(CCASFLAGS_PLATFORM)
5593c8
 
5593c8
-CFLAGS_PROGRAM =
5593c8
-LDFLAGS_PROGRAM =
5593c8
-CPPFLAGS_PROGRAM =
5593c8
-CCASFLAGS_PROGRAM =
5593c8
+CFLAGS_PROGRAM = $(UTILS_CFLAGS)
5593c8
+LDFLAGS_PROGRAM = $(UTILS_LDFLAGS)
5593c8
+CPPFLAGS_PROGRAM = $(UTILS_CPPFLAGS)
5593c8
+CCASFLAGS_PROGRAM = $(UTILS_CCASFLAGS)
5593c8
 
5593c8
-CFLAGS_LIBRARY =
5593c8
-CPPFLAGS_LIBRARY =
5593c8
-CCASFLAGS_LIBRARY =
5593c8
+CFLAGS_LIBRARY = $(UTILS_CFLAGS)
5593c8
+LDFLAGS_LIBRARY = $(UTILS_LDFLAGS)
5593c8
+CPPFLAGS_LIBRARY = $(UTILS_CPPFLAGS)
5593c8
+CCASFLAGS_LIBRARY = $(UTILS_CCASFLAGS)
5593c8
 
5593c8
 # Other variables
5593c8
 
5593c8
diff --git a/gentpl.py b/gentpl.py
5593c8
index 34a4eba2b42..59f62ef9522 100644
5593c8
--- a/gentpl.py
5593c8
+++ b/gentpl.py
5593c8
@@ -697,10 +697,10 @@ def module(defn, platform):
5593c8
     var_set(cname(defn) + "_SOURCES", platform_sources(defn, platform) + " ## platform sources")
5593c8
     var_set("nodist_" + cname(defn) + "_SOURCES", platform_nodist_sources(defn, platform) + " ## platform nodist sources")
5593c8
     var_set(cname(defn) + "_LDADD", platform_ldadd(defn, platform))
5593c8
-    var_set(cname(defn) + "_CFLAGS", "$(AM_CFLAGS) $(CFLAGS_MODULE) " + platform_cflags(defn, platform))
5593c8
-    var_set(cname(defn) + "_LDFLAGS", "$(AM_LDFLAGS) $(LDFLAGS_MODULE) " + platform_ldflags(defn, platform))
5593c8
-    var_set(cname(defn) + "_CPPFLAGS", "$(AM_CPPFLAGS) $(CPPFLAGS_MODULE) " + platform_cppflags(defn, platform))
5593c8
-    var_set(cname(defn) + "_CCASFLAGS", "$(AM_CCASFLAGS) $(CCASFLAGS_MODULE) " + platform_ccasflags(defn, platform))
5593c8
+    var_set(cname(defn) + "_CFLAGS", "$(CFLAGS_MODULE) " + platform_cflags(defn, platform))
5593c8
+    var_set(cname(defn) + "_LDFLAGS", "$(LDFLAGS_MODULE) " + platform_ldflags(defn, platform))
5593c8
+    var_set(cname(defn) + "_CPPFLAGS", "$(CPPFLAGS_MODULE) " + platform_cppflags(defn, platform))
5593c8
+    var_set(cname(defn) + "_CCASFLAGS", "$(CCASFLAGS_MODULE) " + platform_ccasflags(defn, platform))
5593c8
     var_set(cname(defn) + "_DEPENDENCIES", "$(TARGET_OBJ2ELF) " + platform_dependencies(defn, platform))
5593c8
 
5593c8
     gvar_add("dist_noinst_DATA", extra_dist(defn))