Index: common/common-functions
===================================================================
--- common/common-functions	(revision 65d83a612a8ede044d17f1ffa3b5bf9593cfbb11)
+++ common/common-functions	(revision 17c7894389449d0732f4e490a32cc849c3e336e7)
@@ -199,6 +199,4 @@
 
 
-
-
 #----------------------------------#
 wrt_target() {                     # Create target and initialize log file
@@ -260,5 +258,4 @@
 
 
-
 #----------------------------------#
 wrt_target_vars() {                # Target vars for hlfs (cross-build method)
@@ -271,4 +268,34 @@
 ) >> $MKFILE.tmp
 
+}
+
+
+#----------------------------------#
+wrt_optimize() {                   # Apply pkg specific opt's to build
+#----------------------------------#
+  local pkg=$1
+  local optLvl optVal OPT_VAR
+
+  optLvl=`awk -v pkg="$pkg" '$1 == pkg { print $2 }' $JHALFSDIR/opt_override`
+  if [[ "$optLvl" = "" ]] ; then
+    optLvl=$DEF_OPT_LVL;
+  fi
+
+  for OPT_VAR in CFLAGS CXXFLAGS LDFLAGS; do
+    eval optVal=\$${OPT_VAR}_$optLvl
+
+    if [[ "$optVal" != "unset" ]]; then
+     case $pkg in
+       *zlib* ) [[ "$OPT_VAR" != "LDFLAGS" ]] && optVal="$optVal -fPIC" ;;
+     esac
+(
+cat << EOF
+	@echo "export $OPT_VAR=\"$optVal\"" >> envars
+EOF
+) >> $MKFILE.tmp
+    else
+      continue
+    fi
+  done
 }
 
Index: common/config
===================================================================
--- common/config	(revision 65d83a612a8ede044d17f1ffa3b5bf9593cfbb11)
+++ common/config	(revision 17c7894389449d0732f4e490a32cc849c3e336e7)
@@ -11,4 +11,8 @@
 #--- Mount point for the build
 BUILDDIR=/mnt/build_dir
+
+# Create SBU and disk usage report  0(no)/1(yes)
+# NOTE: requires to have bc installed on the host
+REPORT=1
 
 #=== Getting packages ===
@@ -31,4 +35,8 @@
 RUNMAKE=0
 
+#--- Optimize the build? 0(no)/1(yes)
+# Optimization values are set in opt_config and opt_override
+OPTIMIZE=1
+
 #--- Run test suites  [0-3]
 #  0 = none
@@ -41,8 +49,4 @@
 #      (in CLFS, alias to 2)
 TEST=1
-
-# Create SBU and disk usage report  0(no)/1(yes)
-# NOTE: requires to have bc installed on the host
-REPORT=1
 
 #--- Run the stripping phases  0(no)/1(yes)
Index: common/func_validate_configs.sh
===================================================================
--- common/func_validate_configs.sh	(revision 65d83a612a8ede044d17f1ffa3b5bf9593cfbb11)
+++ common/func_validate_configs.sh	(revision 17c7894389449d0732f4e490a32cc849c3e336e7)
@@ -85,8 +85,8 @@
 
   # First internal variables, then the ones that change the book's flavour, and lastly system configuration variables
-  local -r blfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG         DEPEND                TEST"
-  local -r hlfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE MODEL GRSECURITY_HOST TEST REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB             CONFIG KEYMAP         PAGE TIMEZONE LANG LC_ALL"
-  local -r clfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE METHOD  ARCH  TARGET  TEST REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB BOOT_CONFIG CONFIG KEYMAP VIMLANG PAGE TIMEZONE LANG"
-  local -r  lfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE                       TEST REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB             CONFIG        VIMLANG PAGE TIMEZONE LANG"
+  local -r blfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG         DEPEND                TEST OPTIMIZE"
+  local -r hlfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE MODEL GRSECURITY_HOST TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB             CONFIG KEYMAP         PAGE TIMEZONE LANG LC_ALL"
+  local -r clfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE METHOD  ARCH  TARGET  TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB BOOT_CONFIG CONFIG KEYMAP VIMLANG PAGE TIMEZONE LANG"
+  local -r  lfs_PARAM_LIST="BOOK BUILDDIR SRC_ARCHIVE GETPKG RUNMAKE                       TEST OPTIMIZE REPORT COMPARE RUN_ICA RUN_FARCE ITERATIONS STRIP FSTAB             CONFIG        VIMLANG PAGE TIMEZONE LANG"
 
   local -r ERROR_MSG_pt1='The variable \"${L_arrow}${config_param}${R_arrow}\" value ${L_arrow}${BOLD}${!config_param}${R_arrow} is invalid,'
@@ -206,4 +206,5 @@
       ITERATIONS) [[ "$COMPARE" = "1" ]] && validate_against_str "x2x x3x x4x x5x" ;;
       TEST)       validate_against_str "x0x x1x x2x x3x" ;;
+      OPTIMIZE)   validate_against_str "x0x x1x" ;;
       STRIP)      validate_against_str "x0x x1x" ;;
       VIMLANG)    validate_against_str "x0x x1x" ;;
Index: common/opt_config
===================================================================
--- common/opt_config	(revision 17c7894389449d0732f4e490a32cc849c3e336e7)
+++ common/opt_config	(revision 17c7894389449d0732f4e490a32cc849c3e336e7)
@@ -0,0 +1,50 @@
+#####
+#
+# optimization configuration file
+#
+#####
+
+#--- Default optimization level
+#    This level is overridden by definitions in common/def_opt_override;
+#    in this way, packages can be tuned independently.  For example,
+#    if you have trouble building a package at level 3, add it to
+#    common/def_opt_override as an alternate level.
+#
+#    Optimization levels need not be numeric; custom strings
+#    can be defined.
+#      For example: CFLAGS_myLevel="-O3 -pipe"
+#                   cat "fooPkg myLevel" >> common/def_opt_override
+DEF_OPT_LVL=3
+
+#--- Optimization level definitions
+#      Usage: - Apply optimization string at any given level
+#             - "unset" will cause the variable to be not set
+#               instead of set to null
+#--- LEVEL 0
+#      WARNING: Do not edit this level unless you know what you are
+#               doing.  By default, this is set to affect packages
+#               which may have problems with optimization.
+CFLAGS_0="unset"
+CXXFLAGS_0=$CFLAGS_0
+LDFLAGS_0="unset"
+
+
+#--- LEVEL 1
+CFLAGS_1="-O2 -pipe"
+CXXFLAGS_1=$CFLAGS_1
+LDFLAGS_1=""
+
+#--- LEVEL 2
+CFLAGS_2="-O3 -pipe"
+CXXFLAGS_2=$CFLAGS_2
+LDFLAGS_2=""
+
+#--- LEVEL 3
+CFLAGS_3="-O3 -march=pentium4 -pipe -s"
+CXXFLAGS_3=$CFLAGS_3
+LDFLAGS_3="-s"
+
+#--- LEVEL noOpt_noSymbols
+CFLAGS_noOpt_noSymbols="-s"
+CXXFLAGS_noOpt_noSymbols=$CFLAGS_noOpt_noSymbols
+LDFLAGS_noOpt_noSymbols="-s"
Index: common/opt_override
===================================================================
--- common/opt_override	(revision 17c7894389449d0732f4e490a32cc849c3e336e7)
+++ common/opt_override	(revision 17c7894389449d0732f4e490a32cc849c3e336e7)
@@ -0,0 +1,4 @@
+binutils       0
+gcc            0
+glibc          0
+grub           0
