distcc setup in lunar

Couannette couannette at free.fr
Tue Jun 10 13:24:33 GMT 2003


I created a new file :
/var/lib/lunar/functions/distcc.lunar
which export a new function "distcc_setup"

I modified /var/lib/lunar/functions/optimize.lunar.

Now you have to install distcc, and setup is included in Lunar "Optimize 
architecture" menu.

The reason for this fix is that DistCC is very VERY slow if hosts not 
alive are not removed from its list before starting lin.

Couannette (au taquet de la couanne)
-------------- next part --------------
############################################################
#                                                          #
# This code is written for Lunar Linux, see                #
# http://www.lunar-linux.org                               #
#                                                          #
############################################################
#                                                          #
# $FUNCTIONS/distcc.lunar                                  #
# includes distcc_setup function                           #
#                                                          #
# 20030610                                                 #
#                                                          #
############################################################
#                                                          #
# Copyrighted Michel Briand 2003 under GPLv2               #
#                                                          #
############################################################

function test_host() {
    fping -q $1 2>/dev/null
}

function distcc_setup() {
    unset DISTCC_HOSTS
    unset DISTCC_VERBOSE
    unset DISTCC_LOG
    
    . /etc/lunar/local/distcc.config
    
    AHOSTS=""
    for i in $DISTCCHOSTS; do
	test_host $i && AHOSTS="$AHOSTS $i"
    done
    
    export DISTCC_HOSTS="$AHOSTS"
    echo "$AHOSTS" >> /root/lin.distcchosts
    
    export PATH=$DISTCCPATH:$PATH
}


-------------- next part --------------
#Copyrighted Jason Johnston  2002 under GPLv2

# All specified optimizations are system wide,
#  and apply to any module built using lin.

# All settings in this function may be adjusted
#  in each modules BUILD script.

# $PLATFORM  = This sets the platform (x86, Sparc, PPC, etc..)
#         specific optimizations for the machine
# $BOPT = This sets the base optimizations (the -O level)
#         it is applicable to all platforms and cpu types.
# $CPU  = This sets the specific cpu and arch type.
# $SPD  = This sets options that can increase the speed
#         of compiled binaries.
# $XTRA = This specifies what type of extra instructions
#         to use for the specified cpu and platform.
# $FPM  = This sets the Floating Point Math use
#         of SSE instructions.
# $LDF  = This sets the system wide linking optimizations.

# Source in the optimization settings if it exists.
if [[ -s /etc/lunar/local/optimizations ]]; then
   . /etc/lunar/local/optimizations
else
  verbose_msg "initializing optimizations with hard-coded defaults"
  echo -e PLATFOM=x86             '\n'    \
          BUILD=i386-pc-linux-gnu '\n'    \
	  MAKES=                  '\n'    \
	  COPT=                   '\n'    \
	  CCOPT=                  '\n'    \
          BOPT=-O0                '\n'    \
          CPU=i386                '\n'    \
          SPD=( )                 '\n'    \
	  STACK=                  '\n'    \
          XTRA=( )                '\n'    \
          FPM=                    '\n'    \
	  CC_WARN=( )             '\n'    \
	  CCC_WARN=( )            '\n'    \
          LDF=( )                 '\n'    \
          ADDON=( ) > /etc/lunar/local/optimizations
fi

optimize_make() {
  if [[ $PSAFE == "no" ]]; then
   unset MAKES
  fi
  if [[ $MAKES == "1" ]]; then
   unset MAKES
  fi
  if module_installed linux-openmosix; then
    alias make="mosrun -h make"
    if [[ $MAKES > 1 ]]; then
      alias make="mosrun -h make -j$MAKES"
    fi
  elif [[ $MAKES > 1 ]]; then
    alias make="make -j$MAKES"
  fi
  verbose_msg "make=\"$(which make)\", MAKES=\"$MAKES\""
}
 
optimize_base() {
   if ! [[ $1 ]]; then
      BOPT="None"
   fi

   if [[ $CFLAGS ]]; then
      unset CFLAGS CXXFLAGS 
   fi

   case $1 in
      None)    CFLAGS="-O0"
               CXXFLAGS="-O0"
               ;;
      Fast)    CFLAGS="-O1"
               CXXFLAGS="-O1"
               ;;
      Faster)  CFLAGS="-O2"
               CXXFLAGS="-O2"
               ;;
      Fastest) CFLAGS="-O3"
               CXXFLAGS="-O3"
               ;;
      Smaller) CFLAGS="-Os"
               CXXFLAGS="-Os"
               ;;
   esac
}

optimize_cpu()  {
   if ! [[ $1 ]]; then
      if   [[ $PLATFORM == "Alpha" ]];   then
         CPU="ev4"
      elif [[ $PLATFORM == "PowerPC" ]]; then
         CPU="powerpc"
      elif [[ $PLATFORM == "SPARC" ]];   then
         CPU="ultrasparc"
      else
         CPU="I386"
      fi
   fi

# Begin x86 options
   case $1 in
      I386)         CFLAGS="$CFLAGS -mcpu=i386 -march=i386"
                    CXXFLAGS="$CXXFLAGS -mcpu=i386 -march=i386"
                    BUILD="i386-pc-linux-gnu"
                    ;;
      I486)         CFLAGS="$CFLAGS -mcpu=i486 -march=i486"
                    CXXFLAGS="$CXXFLAGS -mcpu=i486 -march=i486"
                    BUILD="i486-pc-linux-gnu"
                    ;;
      I586)         CFLAGS="$CFLAGS -mcpu=i586 -march=i586"
                    CXXFLAGS="$CXXFLAGS -mcpu=i586 -march=i586"
                    BUILD="i586-pc-linux-gnu"
                    ;;
      I686)         CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
                    CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
                    BUILD="i686-pc-linux-gnu"
                    ;;
      Pentium)      CFLAGS="$CFLAGS -mcpu=pentium -march=pentium"
                    CXXFLAGS="$CXXFLAGS -mcpu=pentium -march=pentium"
                    BUILD="i586-pc-linux-gnu"
                    ;;
      PentiumMMX)   CFLAGS="$CFLAGS -mcpu=pentium-mmx -march=pentium-mmx"
                    CXXFLAGS="$CXXFLAGS -mcpu=pentium-mmx -march=pentium-mmx"
                    BUILD="i586-pc-linux-gnu"
                    ;;
      PentiumPro)   CFLAGS="$CFLAGS -mcpu=pentiumpro -march=pentiumpro"
                    CXXFLAGS="$CXXFLAGS -mcpu=pentiumpro -march=pentiumpro"
                    BUILD="i686-pc-linux-gnu"
                    ;;
      Pentium2)     if [[ $GCCVER == "3" ]];  then
                       CFLAGS="$CFLAGS -mcpu=pentium2 -march=pentium2"
                       CXXFLAGS="$CXXFLAGS -mcpu=pentium2 -march=pentium2"
                       BUILD="i686-pc-linux-gnu"
                    else
                       CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
                       CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
                       BUILD="i686-pc-linux-gnu"
                    fi
                    ;;
      Pentium3)     if [[ $GCCVER == "3" ]];  then
                       CFLAGS="$CFLAGS -mcpu=pentium3 -march=pentium3"
                       CXXFLAGS="$CXXFLAGS -mcpu=pentium3 -march=pentium3"
                       BUILD="i686-pc-linux-gnu"
                    else
                       CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
                       CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
                       BUILD="i686-pc-linux-gnu"
                    fi
                    ;;
      Pentium4)     if [[ $GCCVER == "3" ]];  then
                       CFLAGS="$CFLAGS -mcpu=pentium4 -march=pentium4"
                       CXXFLAGS="$CXXFLAGS -mcpu=pentium4 -march=pentium4"
                       BUILD="i686-pc-linux-gnu"
                    else
                       CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
                       CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
                       BUILD="i686-pc-linux-gnu"
                    fi
                    ;;
      K6)           if [[ $GCCVER == "3" ]];  then
                       CFLAGS="$CFLAGS -mcpu=k6 -march=k6"
                       CXXFLAGS="$CXXFLAGS -mcpu=k6 -march=k6"
                       BUILD="i586-pc-linux-gnu"
                    else
                       CFLAGS="$CFLAGS -mcpu=i586 -march=i586"
                       CXXFLAGS="$CXXFLAGS -mcpu=k6 -march=k6"
                       BUILD="i586-pc-linux-gnu"
                    fi
                    ;;
      K62)          if [[ $GCCVER == "3" ]];  then
                       CFLAGS="$CFLAGS -mcpu=k6-2 -march=k6-2"
                       CXXFLAGS="$CXXFLAGS -mcpu=k6-2 -march=k6-2"
                       BUILD="i586-pc-linux-gnu"
                    else
                       CFLAGS="$CFLAGS -mcpu=i686 -march=i586"
                       CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i586"
                       BUILD="i586-pc-linux-gnu"
                    fi
                    ;;
      K63)          if [[ $GCCVER == "3" ]];  then
                       CFLAGS="$CFLAGS -mcpu=k6-3 -march=k6-3"
                       CXXFLAGS="$CXXFLAGS -mcpu=k6-3 -march=k6-3"
                       BUILD="i586-pc-linux-gnu"
                    else
                       CFLAGS="$CFLAGS -mcpu=i686 -march=i586"
                       CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i586"
                       BUILD="i586-pc-linux-gnu"
                    fi
                    ;;
      Athlon)       if [[ $GCCVER == "3" ]];  then
                       CFLAGS="$CFLAGS -mcpu=athlon -march=athlon"
                       CXXFLAGS="$CXXFLAGS -mcpu=athlon -march=athlon"
                       BUILD="i686-pc-linux-gnu"
                    else
                       CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
                       CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
                       BUILD="i686-pc-linux-gnu"
                    fi
                    ;;
      AthlonTBird) if [[ $GCCVER == "3" ]];  then
                       CFLAGS="$CFLAGS -mcpu=athlon-tbird -march=athlon-tbird"
                       CXXFLAGS="$CXXFLAGS -mcpu=athlon-tbird -march=athlon-tbird"
                       BUILD="i686-pc-linux-gnu"
                    else
                       CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
                       CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
                       BUILD="i686-pc-linux-gnu"
                    fi
                    ;;
      Athlon4)     if [[ $GCCVER == "3" ]];  then
                       CFLAGS="$CFLAGS -mcpu=athlon-4 -march=athlon-4"
                       CXXFLAGS="$CXXFLAGS -mcpu=athlon-4 -march=athlon-4"
                       BUILD="i686-pc-linux-gnu"
                    else
                       CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
                       CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
                       BUILD="i686-pc-linux-gnu"
                    fi
                    ;;
      AthlonXP)    if [[ $GCCVER == "3" ]];  then
                       CFLAGS="$CFLAGS -mcpu=athlon-xp -march=athlon-xp"
                       CXXFLAGS="$CXXFLAGS -mcpu=athlon-xp -march=athlon-xp"
                       BUILD="i686-pc-linux-gnu"
                    else
                       CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
                       CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
                       BUILD="i686-pc-linux-gnu"
                    fi
                    ;;
      AthlonMP)    if [[ $GCCVER == "3" ]];  then
                       CFLAGS="$CFLAGS -mcpu=athlon-mp -march=athlon-mp"
                       CXXFLAGS="$CXXFLAGS -mcpu=athlon-mp -march=athlon-mp"
                       BUILD="i686-pc-linux-gnu"
                    else
                       CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
                       CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
                       BUILD="i686-pc-linux-gnu"
                    fi
                    ;;

# Begin PowerPC options
      common)  CFLAGS="$CFLAGS -mcpu=common"
               CXXFLAGS="$CXXFLAGS -mcpu=common"
               BUILD="power-linux"
               ;;
      rios)    CFLAGS="$CFLAGS -mcpu=rios"
               CXXFLAGS="$CXXFLAGS -mcpu=rios"
               BUILD="power-linux"
               ;;
      rios1)   CFLAGS="$CFLAGS -mcpu=rios1"
               CXXFLAGS="$CXXFLAGS -mcpu=rios1"
               BUILD="power-linux"
               ;;
      rsc)     CFLAGS="$CFLAGS -mcpu=rsc"
               CXXFLAGS="$CXXFLAGS -mcpu=rsc"
               BUILD="power-linux"
               ;;
      rios2)   CFLAGS="$CFLAGS -mcpu=rios2"
               CXXFLAGS="$CXXFLAGS -mcpu=rios2"
               BUILD="power-linux"
               ;;
      rs64a)   CFLAGS="$CFLAGS -mcpu=rs64a"
               CXXFLAGS="$CXXFLAGS -mcpu=rs64a"
               BUILD="powerpc64-linux"
               ;;
      403)    CFLAGS="$CFLAGS -mcpu=403"
               CXXFLAGS="$CXXFLAGS -mcpu=403"
               BUILD="powerpc-linux"
               ;;
      505)    CFLAGS="$CFLAGS -mcpu=505"
               CXXFLAGS="$CXXFLAGS -mcpu=505"
               BUILD="powerpc-linux"
               ;;
      601)    CFLAGS="$CFLAGS -mcpu=601"
               CXXFLAGS="$CXXFLAGS -mcpu=601"
               BUILD="powerpc-linux"
               ;;
      602)    CFLAGS="$CFLAGS -mcpu=602"
               CXXFLAGS="$CXXFLAGS -mcpu=602"
               BUILD="powerpc-linux"
               ;;
      603)    CFLAGS="$CFLAGS -mcpu=603"
               CXXFLAGS="$CXXFLAGS -mcpu=603"
               BUILD="powerpc-linux"
               ;;
      603e)   CFLAGS="$CFLAGS -mcpu=603e"
               CXXFLAGS="$CXXFLAGS -mcpu=603e"
               BUILD="powerpc-linux"
               ;;
      604)    CFLAGS="$CFLAGS -mcpu=604"
               CXXFLAGS="$CXXFLAGS -mcpu=604"
               BUILD="powerpc-linux"
               ;;
      604e)   CFLAGS="$CFLAGS -mcpu=604e"
               CXXFLAGS="$CXXFLAGS -mcpu=604e"
               BUILD="powerpc-linux"
               ;;
      620)    CFLAGS="$CFLAGS -mcpu=620"
               CXXFLAGS="$CXXFLAGS -mcpu=620"
               BUILD="powerpc64-linux"
               ;;
      630)    CFLAGS="$CFLAGS -mcpu=630"
               CXXFLAGS="$CXXFLAGS -mcpu=630"
               BUILD="powerpc-linux"
               ;;
      740)    CFLAGS="$CFLAGS -mcpu=740"
               CXXFLAGS="$CXXFLAGS -mcpu=740"
               BUILD="powerpc-linux"
               ;;
      7400)   CFLAGS="$CFLAGS -mcpu=7400"
               CXXFLAGS="$CXXFLAGS -mcpu=7400"
               BUILD="powerpc-linux"
               ;;
      7450)   CFLAGS="$CFLAGS -mcpu=7450"
               CXXFLAGS="$CXXFLAGS -mcpu=7450"
               BUILD="powerpc-linux"
               ;;
      750)    CFLAGS="$CFLAGS -mcpu=750"
               CXXFLAGS="$CXXFLAGS -mcpu=750"
               BUILD="powerpc-linux"
               ;;
      801)    CFLAGS="$CFLAGS -mcpu=801"
               CXXFLAGS="$CXXFLAGS -mcpu=801"
               BUILD="powerpc-linux"
               ;;
      821)    CFLAGS="$CFLAGS -mcpu=821"
               CXXFLAGS="$CXXFLAGS -mcpu=821"
               BUILD="powerpc-linux"
               ;;
      823)    CFLAGS="$CFLAGS -mcpu=823"
               CXXFLAGS="$CXXFLAGS -mcpu=823"
               BUILD="powerpc-linux"
               ;;
      860)    CFLAGS="$CFLAGS -mcpu=860"
               CXXFLAGS="$CXXFLAGS -mcpu=860"
               BUILD="powerpc-linux"
               ;;
      power)   CFLAGS="$CFLAGS -mcpu=power"
               CXXFLAGS="$CXXFLAGS -mcpu=power"
               BUILD="power-linux"
               ;;
      power2)  CFLAGS="$CFLAGS -mcpu=power2"
               CXXFLAGS="$CXXFLAGS -mcpu=power2"
               BUILD="power-linux"
               ;;
      PowerPC) CFLAGS="$CFLAGS -mcpu=powerpc"
               CXXFLAGS="$CXXFLAGS -mcpu=powerpc"
               BUILD="powerpc-linux"
               ;;





# Begin Alpha options
      ev4)     CFLAGS="$CFLAGS -mcpu=ev4"
               CXXFLAGS="$CXXFLAGS -mcpu=ev4"
               BUILD="alpha-linux"
               ;;
      ev45)    CFLAGS="$CFLAGS -mcpu=ev4"
               CXXFLAGS="$CXXFLAGS -mcpu=ev4"
               BUILD="alpha-linux"
               ;;
      ev5)     CFLAGS="$CFLAGS -mcpu=ev5"
               CXXFLAGS="$CXXFLAGS -mcpu=ev5"
               BUILD="alpha-linux"
               ;;
      ev56)    CFLAGS="$CFLAGS -mcpu=ev56"
               CXXFLAGS="$CXXFLAGS -mcpu=ev56"
               BUILD="alpha-linux"
               ;;
      pca56)   CFLAGS="$CFLAGS -mcpu=pca56"
               CXXFLAGS="$CXXFLAGS -mcpu=pca56"
               BUILD="alpha-linux"
               ;;
      ev6)     CFLAGS="$CFLAGS -mcpu=ev6"
               CXXFLAGS="$CXXFLAGS -mcpu=ev6"
               BUILD="alpha-linux"
               ;;
      ev67)    CFLAGS="$CFLAGS -mcpu=ev67"
               CXXFLAGS="$CXXFLAGS -mcpu=ev67"
               BUILD="alpha-linux"
               ;;
      ev68)    CFLAGS="$CFLAGS -mcpu=ev67"
               CXXFLAGS="$CXXFLAGS -mcpu=ev67"
	       BUILD="alpha-linux"
               ;;
# Begin SPARC options
      v7)            CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                     BUILD=""
                     ;;
      cypress)       CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                     BUILD=""
                     ;;
      v8)            CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                     BUILD=""
                     ;;
      super-sparc)   CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                     BUILD=""
                     ;;
      sparclite)     CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                     BUILD=""
                     ;;
      hypersparc)    CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                     BUILD=""
                     ;;
      sparclite86x)  CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                     BUILD=""
                     ;;
      f930)          CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                     BUILD=""
                     ;;
      f934)          CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                     BUILD=""
                     ;;
      sparclet)      CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                     BUILD=""
                     ;;
      tsc701)        CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                     BUILD=""
                     ;;
      v9)            CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                     BUILD=""
                     ;;
      ultrasparc)    CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                     BUILD=""
                     ;;
   esac
}

optimize_speed() {
   for A in ${SPD[@]}; do
      case $A in
             None) CFLAGS="$CFLAGS"
                   CXXFLAGS="$CXXFLAGS"
                 ;;
           Speedy) CFLAGS="$CFLAGS -funroll-loops"
                   CXXFLAGS="$CXXFLAGS -funroll-loops"
                 ;;
            Risky) CFLAGS="$CFLAGS -ffast-math"
                   CXXFLAGS="$CXXFLAGS -ffast-math"
                 ;;
         Pointers) if [[ $GCCVER == "3" ]] ; then
                     CFLAGS="$CFLAGS -fomit-frame-pointer"
                     CXXFLAGS="$CXXFLAGS -fomit-frame-pointer"
                   else
                     CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                   fi
                 ;;
         Siblings) if [[ $GCCVER == "3" ]] ; then
                     CFLAGS="$CFLAGS -foptimize-sibling-calls"
                     CXXFLAGS="$CXXFLAGS"
                   else
                     CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                   fi
                 ;;
        Profiling) if [[ $GCCVER == "3" ]] ; then
                     CFLAGS="$CFLAGS -fprofile-arcs"
                     CXXFLAGS="$CXXFLAGS -fprofile-arcs"
		     if ! [[ `grep KEEP_SOURCE=on /etc/lunar/local/config` ]]; then
		       echo "KEEP_SOURCE=yes" >> /etc/lunar/local/config
		     elif [[ `grep KEEP_SOURCE=off /etc/lunar/local/config` ]]; then
		       sedit "s/KEEP_SOURCE=off/KEEP_SOURCE=on/" /etc/lunar/local/config
		     fi
                   else
                     CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                   fi
                 ;;
        Branching) if [[ $GCCVER == "3" ]] ; then
                     CFLAGS="$CFLAGS -fbranch-probabilities"
                     CXXFLAGS="$CXXFLAGS -fbranch-probabilities"
                   else
                     CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                   fi
                 ;; 
         Aliasing) if [[ $GCCVER == "3" ]] ; then
                      CFLAGS="$CFLAGS -fstrict-aliasing"
                      CXXFLAGS="$CXXFLAGS -fstrict-aliasing"
                    else
                      CFLAGS="$CFLAGS"
                      CXXFLAGS="$CXXFLAGS"
                    fi
                 ;;
            Cprop) if [[ $GCCVER == "3" ]] ; then
                     CFLAGS="$CFLAGS -fno-cprop-registers"
                     CXXFLAGS="$CXXFLAGS -fno-cprop-registers"
                   else
                     CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                   fi
                 ;;
            Float) if [[ $GCCVER == "3" ]] ; then
                     CFLAGS="$CFLAGS -ffloat-store"
                     CXXFLAGS="$CXXFLAGS -ffloat-store"
                   else
                     CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                   fi
                 ;;
          Address) if [[ $GCCVER == "3" ]] ; then
                     CFLAGS="$CFLAGS -fforce-addr"
                     CXXFLAGS="$CXXFLAGS -fforce-addr"
                   else
                     CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                   fi
                 ;;
            Align) if [[ $GCCVER == "3" ]] ; then
                     CFLAGS="$CFLAGS -falign-functions -falign-loops -falign-jumps"
                     CXXFLAGS="$CXXFLAGS -falign-functions -falign-loops -falign-jumps"
                   else
                     CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                   fi
                 ;;
        Expensive) if [[ $GCCVER == "3" ]] ; then
                     CFLAGS="$CFLAGS -fexpensive-optimizations"
                     CXXFLAGS="$CXXFLAGS -fexpensive-optimizations"
                   else
                     CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                   fi
                 ;;
          Doubles) if [[ $GCCVER == "3" ]] ; then
                     CFLAGS="$CFLAGS -malign-double"
                     CXXFLAGS="$CXXFLAGS -malign-double"
                   else
                     CFLAGS="$CFLAGS"
                     CXXFLAGS="$CXXFLAGS"
                   fi
                 ;;

      esac
   done
}

optimize_stack() {
  if [[ $STACK > 0 ]]; then
    if [[ $PLATFORM == "x86" ]]; then
      STACK="-mpreferred-stack-boundary=$STACK" 
    fi
      CFLAGS="$CFLAGS $STACK"
      CXXFLAGS="$CXXFLAGS $STACK"
      CPPFLAGS="$CPPFLAGS $STACK"
  fi
}

optimize_extra() {
 for A in ${XTRA[@]}; do
   case $A in
     None)     CFLAGS="$CFLAGS"
               CXXFLAGS="$CXXFLAGS"
               ;;
      MMX)     if [[ $GCCVER == "3" ]];  then
                  CFLAGS="$CFLAGS -mmmx"
                  CXXFLAGS="$CXXFLAGS -mmmx"
               fi
	       ;;
      SSE)     if [[ $GCCVER == "3" ]];  then
                  CFLAGS="$CFLAGS -msse"
                  CXXFLAGS="$CXXFLAGS -msse"
               fi
	       ;;
      SSE2)    if [[ $GCCVER == "3" ]];  then
                  CFLAGS="$CFLAGS -msse2"
                  CXXFLAGS="$CXXFLAGS -msse2"
               fi
	       ;;
      dnow)   if [[ $GCCVER == "3" ]];  then
                  CFLAGS="$CFLAGS -m3dnow"
                  CXXFLAGS="$CXXFLAGS -m3dnow"
               fi
	       ;;
      Altivec) if [[ $GCCVER == "3" ]];  then
                  CFLAGS="$CFLAGS -maltivec"
                  CXXFLAGS="$CXXFLAGS -maltivec"
               fi
	       ;;
   esac
 done
}

# Set how floating point math is done
optimize_fp() {
   case $1 in
      x387) if [[ $GCCVER == "3" ]];  then
              CFLAGS="$CFLAGS -mfpmath=387"
              CXXFLAGS="$CXXFLAGS -mfpmath=387"
            fi
	    ;;
       SSE) if [[ $GCCVER == "3" ]];  then
              CFLAGS="$CFLAGS -mfpmath=sse"
              CXXFLAGS="$CXXFLAGS -mfpmath=sse"
            fi
	    ;;
      Both) if [[ $GCCVER == "3" ]];  then
              CFLAGS="$CFLAGS -mfpmath=sse,387"
              CXXFLAGS="$CXXFLAGS -mfpmath=sse,387"
            fi
	    ;;
      None) CFLAGS="$CFLAGS"
            CXXFLAGS="$CXXFLAGS"
            ;;
   esac
}

# Set up the Linker optimizations
optimize_ld() {
   if [[ $LDFLAGS ]]; then
      unset LDFLAGS
   fi

   for A in ${LDF[@]}; do
      case $A in
         Strip)     LDFLAGS="$LDFLAGS -s"
                    ;;
# The Debug option breaks some modules (eg: tar and gzip, just to mention a
# few), so this option should either be removed, or remain "deactivated"
# untill this has been resolved but the hatch is that we don't know how many
# modules is affected by it... See bug No. 75. Or contact me (Niki Guldbran
# <nikig at vip.cybercity.dk>)
#
#         Debug)     LDFLAGS="$LDFLAGS -S"
#                    ;;
         Combreloc) LDFLAGS="$LDFLAGS -z combreloc"
                    ;;
      esac
   done
}

optimize_addon() {
  if ! [[ `grep ADDON /etc/lunar/local/optimizations` ]]; then
    echo ADDON=( None ) >> /etc/lunar/local/optimizations
    ADDON=( None )
  fi

  for A in ${ADDON[@]}; do
    case $A in
      DistCC) if module_installed distcc; then
                CC_EXT="$CC_EXT distcc"
                CXX_EXT="$CXX_EXT distcc"		
		message "Testing hosts for distributed compilation & setup DISTCC PATH"
		distcc_setup
		message "DISTCC_HOSTS=$DISTCC_HOSTS"
		message "PATH=$PATH"
              else
                CC_EXT="$CC_EXT"
                CXX_EXT="$CXX_EXT"
              fi
              ;;
      CCache) if module_installed ccache; then
                CC_EXT="ccache $CC_EXT"
                CXX_EXT="ccache $CXX_EXT"
              else
                CC_EXT="$CC_EXT"
                CXX_EXT="$CXX_EXT"
              fi
              ;;
        GECC) CC_EXT="gecc"
              CXX_EXT="gecc"
              ;;
    esac
  done
  verbose_msg "CC_EXT=\"$CC_EXT\", CXX_EXT=\"$CXX_EXT\""
}

optimize_cc_warn() {
  for W in ${CC_WARN[@]}; do
    case $W in
    Deprecated)
      CFLAGS="$CFLAGS -Wno-deprecated"
      ;;
    esac
  done
}

optimize_ccc_warn() {
  for W in ${CCC_WARN[@]}; do
    case $W in
    Deprecated)
      CXXFLAGS="$CXXFLAGS -Wno-deprecated"
      CPPFLAGS="$CPPFLAGS -Wno-deprecated"
      ;;
    esac
  done
}

optimize_platform() {
   unset CFLAGS CXXFLAGS LDFLAGS
   GCCVER="$1"

   case $PLATFORM in
      x86)      optimize_make     $MAKES     &&
                optimize_base     $BOPT      &&
                optimize_cpu      $CPU       &&
                optimize_speed    ${SPD[@]}  &&
                optimize_extra    ${XTRA[@]} &&
		optimize_stack               &&
                optimize_fp       $FPM       &&
		optimize_cc_warn             &&
		optimize_ccc_warn            &&
                optimize_ld       ${LDF[@]}  &&
		optimize_addon
                ;;
      Alpha)    optimize_make  $MAKES     &&
                optimize_base  $BOPT      &&
                optimize_cpu   $CPU       &&
                optimize_speed ${SPD[@]}  &&
                optimize_extra ${XTRA[@]} &&
                optimize_fp    $FPM       &&
		optimize_cc_warn             &&
		optimize_ccc_warn            &&
                optimize_ld    ${LDF[@]}  &&
		optimize_addon
                ;;
      PowerPC)  optimize_make  $MAKES     &&
                optimize_base  $BOPT      &&
                optimize_cpu   $CPU       &&
                optimize_speed ${SPD[@]}  &&
                optimize_extra ${XTRA[@]} &&
                optimize_fp    $FPM       &&
		optimize_cc_warn             &&
		optimize_ccc_warn            &&
                optimize_ld    ${LDF[@]}  &&
		optimize_addon
                ;;
      SPARC)    optimize_make  $MAKES     &&
                optimize_base  $BOPT      &&
                optimize_cpu   $CPU       &&
                optimize_speed ${SPD[@]}  &&
                optimize_extra ${XTRA[@]} &&
                optimize_fp    $FPM       &&
		optimize_cc_warn             &&
		optimize_ccc_warn            &&
                optimize_ld    ${LDF[@]}  &&
		optimize_addon
                ;;
   esac

  export CC_EXT
  export CXX_EXT
  export CFLAGS
  export COPT
  export CCOPT
  export CXXFLAGS
  export LDFLAGS

  verbose_msg "CFLAGS=\"$CFLAGS\""
  verbose_msg "CXXFLAGS=\"$CXXFLAGS\""
  verbose_msg "LDFLAGS=\"$LDFLAGS\""

}

# This is the flow control and error checking for the menus.
optimize_architecture()  {
  # Make sure optimizations file exists, if not create it.
  if ! [[ -f /etc/lunar/local/optimizations ]]; then
    touch /etc/lunar/local/optimizations
  fi

  # Make sure our menu script exists and source it in, or exit.
  if [[ -f /var/lib/lunar/menu/optimize.menu ]]; then
    . /var/lib/lunar/menu/optimize.menu
  else
    exit 0
  fi

# Flow control for the menus. This will also check for gcc3,
# if it exists it will allow more options.
  TITLE="Lunar Optimizations"

  help compiler_help          &&
  compiler_options            &&
  menu radiolist              &&
  COMPILER=$RESULT
  
  help cc_help                &&
  cc_options                  &&
  menu checklist              &&
  COPT=$RESULT

  help ccc_help               &&
  ccc_options                 &&
  menu checklist              &&
  CCOPT=$RESULT

  help platform_help          &&
  platform_options            &&
  menu radiolist              &&
  PLATFORM=$RESULT

  help bopt_help              &&
  bopt_options                &&
  menu radiolist              &&
  BOPT=$RESULT

  help cpu_help $PLATFORM     &&
  cpu_options $PLATFORM       &&
  menu radiolist              &&
  CPU=$RESULT
  optimize_cpu $CPU           &&
  BUILD=$BUILD

  help spd_help               &&
  spd_options                 &&
  menu checklist              &&
  SPD=( $RESULT )

  help xtra_help              &&
  xtra_options                &&
  menu checklist              &&
  XTRA=( $RESULT )

  help fpm_help               &&
  fpm_options                 &&
  menu radiolist              &&
  FPM=$RESULT

  help cc_warn_help           &&
  cc_warn             &&
  menu checklist              &&
  CC_WARN=$RESULT

  help ccc_warn_help          &&
  ccc_warn            &&
  menu checklist              &&
  CCC_WARN=$RESULT  

  help ldf_help               &&
  ldf_options                 &&
  menu checklist              &&
  LDF=( $RESULT )
  
  help addon_help             &&
  addon_options               &&
  menu checklist              &&
  ADDON=( $RESULT )

  MAKES=`dialog --title "Make - parallellizing" \
                --nocancel                       \
		--stdout                         \
		--inputbox                       \
		"Enter the number of concurrent makes ( >= 1 ). Hint: how many CPU's do you have?"  \
		0 55 $MAKES`

  STACK=`dialog --title "Set stack parameters. (WARNING! Best left empty!)" \
                --nocancel                       \
		--stdout                         \
		--inputbox                       \
		"Enter the number to set the stack to, leave empty for default."  \
		0 55 $STACK`

  for A in ${ADDON[@]}; do
    case $A in
      DistCC) if module_installed distcc; then

  	DISTCCHOSTS=`dialog --title "DistCC - hosts" \
                --nocancel                       \
                --stdout                         \
                --inputbox                       \
                "Enter the hosts to distribute work to"  \
                0 55 $DISTCCHOSTS`

  	DISTCCPATH=`dialog --title "DistCC - masquerading directory" \
                --nocancel                       \
                --stdout                         \
                --inputbox                       \
                "Enter the path for DistCC masquerading directory or leave empty for no masquerading"  \
                0 55 $DISTCCPATH`

	echo -e DISTCCHOSTS=\"$DISTCCHOSTS\"		'\n'\
		DISTCCPATH=$DISTCCPATH	> /etc/lunar/local/distcc.config

	      fi
	      ;;
    esac
  done

  optimize
}


More information about the Lunar mailing list