]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/commitdiff
Merge branch 'sudo-without-pam' into next
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 26 May 2014 21:46:20 +0000 (23:46 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 26 May 2014 21:46:20 +0000 (23:46 +0200)
lfs/Config
lfs/linux
make.sh
tools/make-functions

index fb0f2e9a2f92c2f2238e14e8b0e9b10164db1396..415766d123da4b2bbd5ab7c87fa8ffda8b4b906b 100644 (file)
@@ -57,8 +57,6 @@ DIR_CONF    = $(LFS_BASEDIR)/config
 DIR_INFO    = $(LFS_BASEDIR)/log
 DIR_TMP     = /tmp
 
-KGCC = gcc
-
 ###############################################################################
 # Common Macro Definitions
 ###############################################################################
index 5dd5cc04846e646dc312b46090d6694ea4a9450f..9146ad935f2ab2c79cde397a17fa523b0d13d612 100644 (file)
--- a/lfs/linux
+++ b/lfs/linux
@@ -253,26 +253,26 @@ else
 
        # Cleanup kernel source
        cp $(DIR_SRC)/config/kernel/kernel.config.$(MACHINE)-$(VERSUFIX) $(DIR_APP)/.config
-       cd $(DIR_APP) && make CC="$(KGCC)" oldconfig
-       cd $(DIR_APP) && make CC="$(KGCC)" clean
+       cd $(DIR_APP) && make oldconfig
+       cd $(DIR_APP) && make clean
        cd $(DIR_APP) && sed -i -e 's/EXTRAVERSION\ =.*/EXTRAVERSION\ =\ -$(VERSUFIX)/' Makefile
 
 ifeq "$(KCFG)" "-kirkwood"
-       cd $(DIR_APP) && make $(MAKETUNING) CC="$(KGCC)" uImage modules
+       cd $(DIR_APP) && make $(MAKETUNING) uImage modules
        cd $(DIR_APP) && cp -v arch/arm/boot/uImage /boot/vmlinuz-$(VER)-$(VERSUFIX)
        cd $(DIR_APP) && cp -v arch/arm/boot/uImage /boot/uImage-$(VERSUFIX)
 else
 ifeq "$(KCFG)" "-multi"
-       cd $(DIR_APP) && make $(MAKETUNING) CC="$(KGCC)" zImage modules
+       cd $(DIR_APP) && make $(MAKETUNING) zImage modules
        cd $(DIR_APP) && cp -v arch/arm/boot/zImage /boot/vmlinuz-$(VER)-$(VERSUFIX)
        cd $(DIR_APP) && cp -v arch/arm/boot/zImage /boot/zImage-$(VERSUFIX)
 else
 ifeq "$(KCFG)" "-rpi"
-       cd $(DIR_APP) && make $(MAKETUNING) CC="$(KGCC)" zImage modules
+       cd $(DIR_APP) && make $(MAKETUNING) zImage modules
        cd $(DIR_APP) && cp -v arch/arm/boot/zImage /boot/vmlinuz-$(VER)-$(VERSUFIX)
        cd $(DIR_APP) && cp -v arch/arm/boot/zImage /boot/kernel.img
 else
-       cd $(DIR_APP) && make $(MAKETUNING) CC="$(KGCC)" bzImage modules
+       cd $(DIR_APP) && make $(MAKETUNING) bzImage modules
        cd $(DIR_APP) && cp -v arch/i386/boot/bzImage /boot/vmlinuz-$(VER)-$(VERSUFIX)
        ln -sf vmlinuz-$(VER)-$(VERSUFIX) /boot/vmlinuz-$(VERSUFIX)
 endif
@@ -281,11 +281,11 @@ endif
        cd $(DIR_APP) && cp -v System.map /boot/System.map-$(VER)-$(VERSUFIX)
        cd $(DIR_APP) && cp -v .config /boot/config-$(VER)-$(VERSUFIX)
        ln -sf System.map-$(VER)-$(VERSUFIX) /boot/System.map-$(VERSUFIX)
-       cd $(DIR_APP) && make CC="$(KGCC)" $(MAKETUNING) modules_install
-       cd $(DIR_APP) && make CC="$(KGCC)" $(MAKETUNING) firmware_install
+       cd $(DIR_APP) && make $(MAKETUNING) modules_install
+       cd $(DIR_APP) && make $(MAKETUNING) firmware_install
 
 ifeq "$(MACHINE_TYPE)" "arm"
-       cd $(DIR_APP) && make CC="$(KGCC)" $(MAKETUNING) dtbs
+       cd $(DIR_APP) && make $(MAKETUNING) dtbs
        cd $(DIR_APP) && for f in $$(find arch/arm/boot/dts/ -name *.dtb); do \
                                mkdir -p /boot/dtb-$(VER)-$(VERSUFIX) ; \
                                install -m 644 $$f /boot/dtb-$(VER)-$(VERSUFIX)/ ; \
diff --git a/make.sh b/make.sh
index 398c91c930c78c150cd8439f7303e1292741f7e0..37339edc63b9d5963277f78ab811b83fbb63e88a 100755 (executable)
--- a/make.sh
+++ b/make.sh
@@ -34,16 +34,13 @@ NICE=10                                                             # Nice level
 MAX_RETRIES=1                                                  # prefetch/check loop
 BUILD_IMAGES=1                                                 # Flash and Xen Downloader
 KVER=`grep --max-count=1 VER lfs/linux | awk '{ print $3 }'`
-MACHINE=`uname -m`
 GIT_TAG=$(git tag | tail -1)                                   # Git Tag
 GIT_LASTCOMMIT=$(git log | head -n1 | cut -d" " -f2 |head -c8) # Last commit
 TOOLCHAINVER=7
 
-BUILDMACHINE=$MACHINE
-    if [ "$MACHINE" = "x86_64" ]; then
-        BUILDMACHINE="i686";
-    fi
-
+# New architecture variables
+BUILD_ARCH="$(uname -m)"
+BUILDMACHINE="${BUILD_ARCH}"
 
 # Debian specific settings
 if [ ! -e /etc/debian_version ]; then
@@ -68,6 +65,8 @@ mkdir $BASEDIR/log/ 2>/dev/null
 # Include funtions
 . tools/make-functions
 
+configure_target "default"
+
 if [ -f .config ]; then
        . .config
 fi
@@ -241,7 +240,7 @@ prepareenv() {
 
 buildtoolchain() {
     local error=false
-    case "${MACHINE}:$(uname -m)" in
+    case "${TARGET_ARCH}:${BUILD_ARCH}" in
         # x86
         i586:i586|i586:i686|i586:x86_64)
             # These are working.
@@ -399,61 +398,62 @@ buildipfire() {
   ipfiremake bc
   ipfiremake u-boot
 
-  if [ "${MACHINE_TYPE}" != "arm" ]; then
-
-    # x86-pae (Native and new XEN) kernel build
-    ipfiremake linux                   KCFG="-pae"
-#    ipfiremake kvm-kmod                       KCFG="-pae"
-#    ipfiremake v4l-dvb                        KCFG="-pae"
-#    ipfiremake mISDN                  KCFG="-pae"
-    ipfiremake cryptodev               KCFG="-pae"
-#    ipfiremake compat-drivers         KCFG="-pae"
-#    ipfiremake r8169                  KCFG="-pae"
-#    ipfiremake r8168                  KCFG="-pae"
-#    ipfiremake r8101                  KCFG="-pae"
-    ipfiremake e1000e                  KCFG="-pae"
-    ipfiremake igb                     KCFG="-pae"
-
-    # x86 kernel build
-    ipfiremake linux                   KCFG=""
-#    ipfiremake kvm-kmod                       KCFG=""
-#    ipfiremake v4l-dvb                        KCFG=""
-#    ipfiremake mISDN                  KCFG=""
-    ipfiremake cryptodev               KCFG=""
-#    ipfiremake compat-drivers         KCFG=""
-#    ipfiremake r8169                  KCFG=""
-#    ipfiremake r8168                  KCFG=""
-#    ipfiremake r8101                  KCFG=""
-    ipfiremake e1000e                  KCFG=""
-    ipfiremake igb                     KCFG=""
-
-  else
-    # arm-rpi (Raspberry Pi) kernel build
-    ipfiremake linux                   KCFG="-rpi"
-#    ipfiremake v4l-dvb                        KCFG="-rpi"
-#    ipfiremake mISDN                  KCFG="-rpi" NOPCI=1
-    ipfiremake cryptodev               KCFG="-rpi"
-#    ipfiremake compat-drivers         KCFG="-rpi"
-
-    # arm multi platform (Panda, Wandboard ...) kernel build
-    ipfiremake linux                   KCFG="-multi"
-    ipfiremake cryptodev               KCFG="-multi"
-    ipfiremake e1000e                  KCFG="-multi"
-    ipfiremake igb                     KCFG="-multi"
-
-    # arm-kirkwood (Dreamplug, ICY-Box ...) kernel build
-    ipfiremake linux                   KCFG="-kirkwood"
-#    ipfiremake v4l-dvb                        KCFG="-kirkwood"
-#    ipfiremake mISDN                  KCFG="-kirkwood"
-    ipfiremake cryptodev               KCFG="-kirkwood"
-#    ipfiremake compat-drivers         KCFG="-kirkwood"
-#    ipfiremake r8169                  KCFG="-kirkwood"
-#    ipfiremake r8168                  KCFG="-kirkwood"
-#    ipfiremake r8101                  KCFG="-kirkwood"
-#    ipfiremake e1000e                 KCFG="-kirkwood"
-    ipfiremake igb                     KCFG="-kirkwood"
+  case "${TARGET_ARCH}" in
+       i586)
+               # x86-pae (Native and new XEN) kernel build
+               ipfiremake linux                        KCFG="-pae"
+#              ipfiremake kvm-kmod                     KCFG="-pae"
+#              ipfiremake v4l-dvb                      KCFG="-pae"
+#              ipfiremake mISDN                        KCFG="-pae"
+               ipfiremake cryptodev                    KCFG="-pae"
+#              ipfiremake compat-drivers               KCFG="-pae"
+#              ipfiremake r8169                        KCFG="-pae"
+#              ipfiremake r8168                        KCFG="-pae"
+#              ipfiremake r8101                        KCFG="-pae"
+               ipfiremake e1000e                       KCFG="-pae"
+               ipfiremake igb                          KCFG="-pae"
+
+               # x86 kernel build
+               ipfiremake linux                        KCFG=""
+#              ipfiremake kvm-kmod                     KCFG=""
+#              ipfiremake v4l-dvb                      KCFG=""
+#              ipfiremake mISDN                        KCFG=""
+               ipfiremake cryptodev                    KCFG=""
+#              ipfiremake compat-drivers               KCFG=""
+#              ipfiremake r8169                        KCFG=""
+#              ipfiremake r8168                        KCFG=""
+#              ipfiremake r8101                        KCFG=""
+               ipfiremake e1000e                       KCFG=""
+               ipfiremake igb                          KCFG=""
+               ;;
 
-  fi
+       armv5tel)
+               # arm-rpi (Raspberry Pi) kernel build
+               ipfiremake linux                        KCFG="-rpi"
+#              ipfiremake v4l-dvb                      KCFG="-rpi"
+#              ipfiremake mISDN                        KCFG="-rpi" NOPCI=1
+               ipfiremake cryptodev                    KCFG="-rpi"
+#              ipfiremake compat-drivers               KCFG="-rpi"
+
+               # arm multi platform (Panda, Wandboard ...) kernel build
+               ipfiremake linux                        KCFG="-multi"
+               ipfiremake cryptodev                    KCFG="-multi"
+               ipfiremake e1000e                       KCFG="-multi"
+               ipfiremake igb                          KCFG="-multi"
+
+               # arm-kirkwood (Dreamplug, ICY-Box ...) kernel build
+               ipfiremake linux                        KCFG="-kirkwood"
+#              ipfiremake v4l-dvb                      KCFG="-kirkwood"
+#              ipfiremake mISDN                        KCFG="-kirkwood"
+               ipfiremake cryptodev                    KCFG="-kirkwood"
+#              ipfiremake compat-drivers               KCFG="-kirkwood"
+#              ipfiremake r8169                        KCFG="-kirkwood"
+#              ipfiremake r8168                        KCFG="-kirkwood"
+#              ipfiremake r8101                        KCFG="-kirkwood"
+#              ipfiremake e1000e                       KCFG="-kirkwood"
+               ipfiremake igb                          KCFG="-kirkwood"
+               ;;
+  esac
   ipfiremake pkg-config
   ipfiremake linux-atm
   ipfiremake cpio
@@ -897,6 +897,22 @@ ipfirepackages() {
   rm -rf  $BASEDIR/build/install/packages/*
 }
 
+while [ $# -gt 0 ]; do
+       case "${1}" in
+               --target=*)
+                       configure_target "${1#--target=}"
+                       ;;
+               -*)
+                       exiterror "Unknown configuration option: ${1}"
+                       ;;
+               *)
+                       # Found a command, so exit options parsing.
+                       break
+                       ;;
+       esac
+       shift
+done
+
 # See what we're supposed to do
 case "$1" in 
 build)
index 48fc6d434dd5ef0e7c5535800f73df6d383edb8a..6e9ad6c3302cdc0e693d2759f28577e8cfd859b5 100644 (file)
@@ -60,6 +60,67 @@ WARN="\\033[1;35m"
 FAIL="\\033[1;31m"
 NORMAL="\\033[0;39m"
 
+configure_target() {
+       local target_arch="${1}"
+
+       if [ "${target_arch}" = "default" ]; then
+               target_arch="$(configure_target_guess)"
+       fi
+
+       case "${target_arch}" in
+               i586)
+                       BUILDTARGET="${TARGET_ARCH}-pc-linux-gnu"
+                       CROSSTARGET="${BUILD_ARCH}-cross-linux-gnu"
+                       CFLAGS_ARCH="-march=i586 -fomit-frame-pointer"
+                       ;;
+
+               armv5tel)
+                       BUILDTARGET="${TARGET_ARCH}-unknown-linux-gnueabi"
+                       CROSSTARGET="${BUILD_ARCH}-cross-linux-gnueabi"
+                       CFLAGS_ARCH="-march=armv5te -mfloat-abi=soft -fomit-frame-pointer"
+                       MACHINE_TYPE="arm"
+                       ;;
+
+               *)
+                       exiterror "Cannot build for architure ${target_arch}"
+                       ;;
+       esac
+
+       # Check if the QEMU helper is available if needed.
+       if qemu_is_required "${target_arch}"; then
+               local qemu_target_helper="$(qemu_find_target_helper_name "${target_arch}")"
+
+               if [ -n "${qemu_target_helper}" ]; then
+                       QEMU_TARGET_HELPER="${qemu_target_helper}"
+               else
+                       exiterror "Could not find a binfmt_misc helper entry for ${target_arch}"
+               fi
+       fi
+
+       TARGET_ARCH="${target_arch}"
+
+       # Old variable names
+       MACHINE="${TARGET_ARCH}"
+
+       CFLAGS="-O2 -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fPIC"
+       CFLAGS="${CFLAGS} -fstack-protector-all --param=ssp-buffer-size=4 ${CFLAGS_ARCH}"
+       CXXFLAGS="${CFLAGS}"
+}
+
+configure_target_guess() {
+       case "${BUILD_ARCH}" in
+               x86_64|i686|i586)
+                       echo "i586"
+                       ;;
+               armv7*|armv6*|armv5*)
+                       echo "armv5tel"
+                       ;;
+               *)
+                       exiterror "Cannot guess target architecture"
+                       ;;
+       esac
+}
+
 evaluate() {
        if [ "$?" -eq "0" ]; then
                beautify message DONE
@@ -217,30 +278,6 @@ get_pkg_ver()
        echo "$PKG_VER"
 } # End of get_pkg_ver()
 
-if [ 'x86_64' = $MACHINE -o 'i686' = $MACHINE -o 'i586' = $MACHINE ]; then
-       echo "`date -u '+%b %e %T'`: Machine is iX86 (or equivalent)" >> $LOGFILE
-       MACHINE=i586
-       CROSSTARGET=${MACHINE}-cross-linux-gnu
-       BUILDTARGET=i586-pc-linux-gnu
-       CFLAGS_ARCH="${GLOBAL_CFLAGS} -march=i586 -fomit-frame-pointer"
-elif [ 'armv5tejl' = $MACHINE -o 'armv5tel' = $MACHINE -o 'armv6l' = $MACHINE -o 'armv7l' = $MACHINE ]; then
-       echo "`date -u '+%b %e %T'`: Machine is ARM (or equivalent)" >> $LOGFILE
-       MACHINE=armv5tel
-       MACHINE_TYPE=arm
-       CROSSTARGET=${MACHINE}-cross-linux-gnueabi
-       BUILDTARGET=${MACHINE}-unknown-linux-gnueabi
-       CFLAGS_ARCH="-march=armv5te -mfloat-abi=soft -fomit-frame-pointer"
-else
-       echo "`date -u '+%b %e %T'`: Can't determine your architecture - $MACHINE"
-       exit 1
-fi
-
-CFLAGS="-O2 -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fPIC"
-CFLAGS="${CFLAGS} -fstack-protector-all --param=ssp-buffer-size=4 ${CFLAGS_ARCH}"
-CXXFLAGS="${CFLAGS}"
-C2FLAGS="${CFLAGS}"
-CXX2FLAGS="${CXXFLAGS}"
-
 # Define immediately
 stdumount() {
        umount $BASEDIR/build/sys                       2>/dev/null;
@@ -282,22 +319,136 @@ fake_environ() {
        env="${env} UTS_RELEASE=${KVER}"
 
        # Fake machine version.
-       env="${env} UTS_MACHINE=${MACHINE}"
+       env="${env} UTS_MACHINE=${TARGET_ARCH}"
+
+       echo "${env}"
+}
+
+qemu_environ() {
+       local env
+
+       # Don't add anything if qemu is not used.
+       if ! qemu_is_required; then
+               return
+       fi
+
+       # Set default qemu options
+       case "${TARGET_ARCH}" in
+               arm*)
+                       QEMU_CPU="${QEMU_CPU:-cortex-a9}"
+
+                       env="${env} QEMU_CPU=${QEMU_CPU}"
+                       ;;
+       esac
+
+       # Enable QEMU strace
+       #env="${env} QEMU_STRACE=1"
 
        echo "${env}"
 }
 
+qemu_is_required() {
+       local target_arch="${1}"
+
+       if [ -z "${target_arch}" ]; then
+               target_arch="${TARGET_ARCH}"
+       fi
+
+       case "${BUILD_ARCH},${target_arch}" in
+               x86_64,arm*|i?86,arm*)
+                       return 0
+                       ;;
+               *)
+                       return 1
+                       ;;
+       esac
+}
+
+qemu_install_helper() {
+       # Do nothing, if qemu is not required
+       if ! qemu_is_required; then
+               return 0
+       fi
+
+       if [ -z "${QEMU_TARGET_HELPER}" ]; then
+               exiterror "QEMU_TARGET_HELPER not set"
+       fi
+
+       # Check if the helper is already installed.
+       if [ -x "${LFS}${QEMU_TARGET_HELPER}" ]; then
+               return 0
+       fi
+
+       # Try to find a suitable binary that we can install
+       # to the build environment.
+       local file
+       for file in "${QEMU_TARGET_HELPER}" "${QEMU_TARGET_HELPER}-static"; do
+               # file must exist and be executable.
+               [ -x "${file}" ] || continue
+
+               # Must be static.
+               file_is_static "${file}" || continue
+
+               local dirname="${LFS}$(dirname "${file}")"
+               mkdir -p "${dirname}"
+
+               install -m 755 "${file}" "${LFS}${QEMU_TARGET_HELPER}"
+               return 0
+       done
+
+       exiterror "Could not find a statically-linked QEMU emulator: ${QEMU_TARGET_HELPER}"
+}
+
+qemu_find_target_helper_name() {
+       local target_arch="${1}"
+
+       local magic
+       case "${target_arch}" in
+               arm*)
+                       magic="7f454c4601010100000000000000000002002800"
+                       ;;
+       esac
+
+       [ -z "${magic}" ] && return 1
+
+       local file
+       for file in /proc/sys/fs/binfmt_misc/*; do
+               # Search for the file with the correct magic value.
+               grep -qE "^magic ${magic}$" "${file}" || continue
+
+               local interpreter="$(grep "^interpreter" "${file}" | awk '{ print $2 }')"
+
+               [ -n "${interpreter}" ] || continue
+               [ "${interpreter:0:1}" = "/" ] || continue
+               [ -x "${interpreter}" ] || continue
+
+               echo "${interpreter}"
+               return 0
+       done
+
+       return 1
+}
+
+file_is_static() {
+       local file="${1}"
+
+       file ${file} 2>/dev/null | grep -q "statically linked"
+}
+
 entershell() {
        if [ ! -e $BASEDIR/build/usr/src/lfs/ ]; then
                exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/"
        fi
 
+       # Install QEMU helper, if needed
+       qemu_install_helper
+
        echo "Entering to a shell inside LFS chroot, go out with exit"
-       chroot $LFS /tools/bin/env -i HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
+       chroot $LFS /tools/bin/env -i HOME=/root TERM=$TERM PS1='ipfire build chroot ($(uname -m)) \u:\w\$ ' \
                PATH=/tools/ccache/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
                VERSION=$VERSION CONFIG_ROOT=$CONFIG_ROOT \
                NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
-               CFLAGS="$CF2LAGS" CXXFLAGS="$CXX2FLAGS" \
+               CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" \
                CCACHE_DIR=/usr/src/ccache \
                CCACHE_COMPRESS=1 \
                CCACHE_COMPILERCHECK="none" \
@@ -306,9 +457,9 @@ entershell() {
                CROSSTARGET="${CROSSTARGET}" \
                MACHINE="$MACHINE" \
                MACHINE_TYPE="$MACHINE_TYPE" \
-               KGCC="ccache /usr/bin/gcc" \
                $(fake_environ) \
-               /tools/bin/bash
+               $(qemu_environ) \
+               /tools/bin/bash -i
        if [ $? -ne 0 ]; then
                        beautify message FAIL
                        exiterror "chroot error"
@@ -410,6 +561,9 @@ lfsmake2() {
        lfsmakecommoncheck $*
        [ $? == 1 ] && return 0
 
+       # Install QEMU helper, if needed
+       qemu_install_helper
+
        local PKG_TIME_START=`date +%s`
        chroot $LFS /tools/bin/env -i   HOME=/root \
                                                TERM=$TERM PS1='\u:\w\$ ' \
@@ -418,7 +572,7 @@ lfsmake2() {
                                                SYSTEM_RELEASE="${SYSTEM_RELEASE}" \
                                                CONFIG_ROOT=$CONFIG_ROOT \
                                                NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
-                                               CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \
+                                               CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" \
                                                CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 \
                                                CCACHE_COMPILERCHECK="none" \
                                                KVER=$KVER MAKETUNING=$MAKETUNING \
@@ -426,6 +580,7 @@ lfsmake2() {
                                                CROSSTARGET="${CROSSTARGET}" \
                                                MACHINE="$MACHINE" \
                                                MACHINE_TYPE="$MACHINE_TYPE" \
+                                               $(qemu_environ) \
                                                $(fake_environ) \
                                                /tools/bin/bash -x -c "cd /usr/src/lfs && \
                                                make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
@@ -446,6 +601,9 @@ ipfiremake() {
        lfsmakecommoncheck $*
        [ $? == 1 ] && return 0
 
+       # Install QEMU helper, if needed
+       qemu_install_helper
+
        local PKG_TIME_START=`date +%s`
        chroot $LFS /tools/bin/env -i   HOME=/root \
                                                TERM=$TERM PS1='\u:\w\$ ' \
@@ -455,7 +613,7 @@ ipfiremake() {
                                                CONFIG_ROOT=$CONFIG_ROOT \
                                                NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
                                                SYSTEM_RELEASE="$SYSTEM_RELEASE" \
-                                               CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \
+                                               CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" \
                                                CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 \
                                                CCACHE_COMPILERCHECK="none" \
                                                KVER=$KVER MAKETUNING=$MAKETUNING \
@@ -463,6 +621,7 @@ ipfiremake() {
                                                CROSSTARGET="${CROSSTARGET}" \
                                                MACHINE="$MACHINE" \
                                                MACHINE_TYPE="$MACHINE_TYPE" \
+                                               $(qemu_environ) \
                                                $(fake_environ) \
                                                /bin/bash -x -c "cd /usr/src/lfs && \
                                                make -f $* LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
@@ -483,6 +642,9 @@ ipfiredist() {
        lfsmakecommoncheck $*
        [ $? == 1 ] && return 0
        
+       # Install QEMU helper, if needed
+       qemu_install_helper
+
        local PKG_TIME_START=`date +%s`
        chroot $LFS /tools/bin/env -i   HOME=/root \
                                        TERM=$TERM PS1='\u:\w\$ ' \
@@ -490,7 +652,7 @@ ipfiredist() {
                                        VERSION=$VERSION \
                                        CONFIG_ROOT=$CONFIG_ROOT \
                                        NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
-                                       CFLAGS="$C2FLAGS" CXXFLAGS="$CXX2FLAGS" \
+                                       CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" \
                                        CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 \
                                        CCACHE_COMPILERCHECK="none" \
                                        KVER=$KVER \
@@ -498,6 +660,7 @@ ipfiredist() {
                                        CROSSTARGET="${CROSSTARGET}" \
                                        MACHINE="$MACHINE" \
                                        MACHINE_TYPE="$MACHINE_TYPE" \
+                                       $(qemu_environ) \
                                        $(fake_environ) \
                                        /bin/bash -x -c "cd /usr/src/lfs && \
                                        make -f $1 LFS_BASEDIR=/usr/src dist" >>$LOGFILE 2>&1
@@ -518,6 +681,9 @@ installmake() {
        lfsmakecommoncheck $*
        [ $? == 1 ] && return 0
 
+       # Install QEMU helper, if needed
+       qemu_install_helper
+
        local PKG_TIME_START=`date +%s`
        chroot $LFS /tools/bin/env -i   HOME=/root \
                                                TERM=$TERM PS1='\u:\w\$ ' \
@@ -526,7 +692,7 @@ installmake() {
                                                SYSTEM_RELEASE="${SYSTEM_RELEASE}" \
                                                CONFIG_ROOT=$CONFIG_ROOT \
                                                NAME="$NAME" SNAME="$SNAME" SLOGAN="$SLOGAN" \
-                                               CFLAGS="-Os" CXXFLAGS="-Os" \
+                                               CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" \
                                                CCACHE_DIR=/usr/src/ccache CCACHE_COMPRESS=1 CCACHE_HASHDIR=1 \
                                                KVER=$KVER \
                                                BUILDTARGET="$BUILDTARGET" \