From fe195af1ae9df95a5d198c5049858a4bdd4ee742 Mon Sep 17 00:00:00 2001
From: Ivan Davidov <davidov.i@gmail.com>
Date: Mon, 2 May 2016 05:51:53 +0300
Subject: [PATCH] Added more default CFLAGS for better comaptibility with
 Ubuntu toolchain. Added the '-Os' flag which produces smaller output files.
 These changes haven't been tested yet.

---
 src/02_build_kernel.sh  | 4 +++-
 src/04_build_glibc.sh   | 8 +++++++-
 src/07_build_busybox.sh | 4 +++-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/02_build_kernel.sh b/src/02_build_kernel.sh
index 9adf74638..c352b2eae 100755
--- a/src/02_build_kernel.sh
+++ b/src/02_build_kernel.sh
@@ -39,7 +39,9 @@ fi
 # Good explanation of the different kernels:
 # http://unix.stackexchange.com/questions/5518/what-is-the-difference-between-the-following-kernel-makefile-terms-vmlinux-vmlinux
 echo "Building kernel..."
-make bzImage -j $(grep ^processor /proc/cpuinfo | wc -l)
+make \
+  CFLAGS="-Os -fno-stack-protector -U_FORTIFY_SOURCE" \
+  bzImage -j $(grep ^processor /proc/cpuinfo | wc -l)
 
 # Install kernel headers in './usr' (this is not '/usr') which are used later
 # when we build and configure the GNU C library (glibc).
diff --git a/src/04_build_glibc.sh b/src/04_build_glibc.sh
index 9bfcd1239..ced6095ae 100755
--- a/src/04_build_glibc.sh
+++ b/src/04_build_glibc.sh
@@ -30,7 +30,13 @@ cd ../glibc_objects
 # will be installed in '/lib'. Kernel headers are taken from our already prepared
 # kernel header area (see 02_build_kernel.sh). Packages 'gd' and 'selinux' are disabled.
 echo "Configuring glibc..."
-../configure --prefix= --with-headers=$WORK_KERNEL_DIR/usr/include --without-gd --without-selinux --disable-werror
+../configure \
+  --prefix= \
+  --with-headers=$WORK_KERNEL_DIR/usr/include \
+  --without-gd \
+  --without-selinux \
+  --disable-werror \
+  CFLAGS="-Os -fno-stack-protector -U_FORTIFY_SOURCE"
 
 # Compile glibc with optimization for "parallel jobs" = "number of processors".
 echo "Building glibc..."
diff --git a/src/07_build_busybox.sh b/src/07_build_busybox.sh
index 2c4c9ceab..301029e23 100755
--- a/src/07_build_busybox.sh
+++ b/src/07_build_busybox.sh
@@ -50,7 +50,9 @@ sed -i "s/.*CONFIG_SYSROOT.*/CONFIG_SYSROOT=$GLIBC_INSTALLED_ESCAPED/" .config
 
 # Compile busybox with optimization for "parallel jobs" = "number of processors".
 echo "Building BusyBox..."
-make EXTRA_CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0" busybox -j $(grep ^processor /proc/cpuinfo | wc -l)
+make \
+  EXTRA_CFLAGS="-Os -fno-stack-protector -U_FORTIFY_SOURCE" \
+  busybox -j $(grep ^processor /proc/cpuinfo | wc -l)
 
 # Create the symlinks for busybox. The file 'busybox.links' is used for this.
 echo "Generating BusyBox based initramfs area..."