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

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