Jeremy Byron wrote:
> M.Canales.es wrote:
>> <snip>
>>> It'd be nice to be able to optimize a build and be able to compare ICA
>> <snip>
>> If you want to create such patch, take a look to the wrt_unpack*() functions 
>> inside common/common-functions.
><snip>
> I'll get back to you in a bit.

The test build with my optimization patch of jhalfs-2575 completed
successfully.  Patch is attached.  I can send you the build logs if
they're of any use to you too (only used test level 1 though).

Limitations:
- Doesn't optimize {C,H,B}LFS
  (trivial addition if the other books behave the same as LFS)
- Can't enable/disable optimization from command-line
  (not necessary, would be nice)
- Can't set default optimization level from command-line
  (not necessary, would be nice)
- Doesn't make me coffee. :(
- ?

Bit of an aside, but I'm not sure what the 'wrt_' stands for in the
function names. 'Write,' as in to the makefile, perhaps? Anyhow, I
mimicked it for wrt_optimize() since it performs much the same job as
wrt_unpack*() and such.

Oh.. I changed wrt_target() and LFS/master.sh slightly too.  Not too
sure why you don't end the makefile command in wrt_target() and then in
LFS/master.sh finish it with 'true'.  I don't think makefile command
sequences should continue across functions - just makes headaches.  I
ended the command sequence in wrt_target() and removed the 'true' line
from LFS/master.sh.

Regards,
Jeremy.
diff -Naur jhalfs-X/common/common-functions jhalfs-X-opt/common/common-functions
--- jhalfs-X/common/common-functions    2006-04-25 23:18:39.000000000 -0700
+++ jhalfs-X-opt/common/common-functions        2006-04-25 17:00:03.000000000 
-0700
@@ -201,6 +201,39 @@
 
 
 #----------------------------------#
+wrt_optimize() {                   # Apply pkg specific opt's to build
+#----------------------------------#
+       local pkg=$1
+       if [ "$OPTIMIZE" = "1" -o "$OPTIMIZE" = "yes" ] ; then
+               optLvl=`awk -v pkg="$pkg" '$1 == pkg { print $2 }' \
+                                                       
$JHALFSDIR/def_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
+( cat << EOF
+       @echo "unset $OPT_VAR" >> envars;
+EOF
+) >> $MKFILE.tmp
+                       else
+( cat << EOF
+       @echo "export $OPT_VAR=\"$optVal\"" >> envars;
+EOF
+) >> $MKFILE.tmp
+                       fi
+               done; unset OPT_VAR optVal
+       else
+( cat << EOF
+       @echo "unset CFLAGS CXXFLAGS LDFLAGS" >> envars;
+EOF
+) >> $MKFILE.tmp
+       fi
+}
+
+
+#----------------------------------#
 wrt_target() {                     # Create target and initialize log file
 #----------------------------------#
   local i=$1
@@ -225,7 +258,7 @@
        @\$(call unpack,$FILE)
        @ROOT=\`head -n1 /tmp/unpacked | sed '[EMAIL PROTECTED]/@@;s@/.*@@'\` 
&& \\
        echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
-       chown -R lfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
+       chown -R lfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT
 EOF
 ) >> $MKFILE.tmp
 }
diff -Naur jhalfs-X/common/def_opt_override jhalfs-X-opt/common/def_opt_override
--- jhalfs-X/common/def_opt_override    1969-12-31 16:00:00.000000000 -0800
+++ jhalfs-X-opt/common/def_opt_override        2006-04-25 17:00:03.000000000 
-0700
@@ -0,0 +1,3 @@
+binutils       0
+gcc            0
+glibc          0
diff -Naur jhalfs-X/common/opt_config jhalfs-X-opt/common/opt_config
--- jhalfs-X/common/opt_config  1969-12-31 16:00:00.000000000 -0800
+++ jhalfs-X-opt/common/opt_config      2006-04-25 17:01:22.000000000 -0700
@@ -0,0 +1,52 @@
+#####
+#
+# optimization configuration file
+#
+#####
+
+#--- Enable optimization 0(no)/1(yes)
+OPTIMIZE=0
+
+#--- 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 unset instead of
+#               null
+#--- LEVEL 0
+#      WARNING: Do not edit this level unless you know what you are
+#               doing.  By default, this is set to affect the toolchain
+#               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=athlon-fx -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"
diff -Naur jhalfs-X/LFS/master.sh jhalfs-X-opt/LFS/master.sh
--- jhalfs-X/LFS/master.sh      2006-04-25 23:18:37.000000000 -0700
+++ jhalfs-X-opt/LFS/master.sh  2006-04-25 17:07:09.000000000 -0700
@@ -112,7 +112,10 @@
 
       # Insert instructions for unpacking the package and to set the PKGDIR 
variable.
       wrt_unpack "$FILE"
-      echo -e '\ttrue' >> $MKFILE.tmp
+
+      # Append desired optimizations to envars
+      wrt_optimize "$name"
+
     fi
 
     # Insert date and disk usage at the top of the log file, the script run
@@ -222,6 +225,19 @@
       wrt_unpack2 "$FILE"
     fi
 
+    # Append desired optimization level to envars
+    #   This is hackish and likely not necessary
+    #   provided the makefile is generated properly
+    #   in these non-building sections.
+    case "${this_script}" in
+      *kernfs)                              ;;
+      *creatingdirs)                        ;;
+      *createfiles)                         ;;
+      *readjusting)                         ;;
+      *strippingagain)                      ;;
+      *)               wrt_optimize "$name" ;;
+    esac
+
     # In the mount of kernel filesystems we need to set LFS
     # and not to use chroot.
     case "${this_script}" in
diff -Naur jhalfs-X/master.sh jhalfs-X-opt/master.sh
--- jhalfs-X/master.sh  2006-04-25 23:18:39.000000000 -0700
+++ jhalfs-X-opt/master.sh      2006-04-25 17:00:03.000000000 -0700
@@ -56,6 +56,11 @@
 [[ $? > 0 ]] && echo "$COMMON_DIR/conf did not load.." && exit
 [[ $VERBOSITY > 0 ]] && echo "OK"
 #
+[[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..."
+source $COMMON_DIR/opt_config
+[[ $? > 0 ]] && echo " $COMMON_DIR/opt_config did not load.." && exit
+[[ $VERBOSITY > 0 ]] && echo "OK"
+#
 [[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..."
 source $COMMON_DIR/func_compare.sh
 [[ $? > 0 ]] && echo "$COMMON_DIR/func_compare.sh did not load.." && exit
@@ -485,6 +490,7 @@
 
 if [[ "$PWD" != "$JHALFSDIR" ]]; then
   cp $COMMON_DIR/makefile-functions $JHALFSDIR/
+  cp $COMMON_DIR/def_opt_override $JHALFSDIR/
   if [[ "$COMPARE" != "0" ]] ; then
     mkdir -p $JHALFSDIR/extras
     cp extras/* $JHALFSDIR/extras
-- 
http://linuxfromscratch.org/mailman/listinfo/alfs-discuss
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to