I'm building against LFS-latest SVN on a 64-bit system. I use the "More Control and Package User" package management system and have, over the years, developed a build script for each {,B}LFS package. Today I'm working on Chapter 6.9, GlibC-2.11.2. Currently the build of GlibC is cooking merrily along with a successful "configure" and is currently "Building," but I'd like some help with what I call an "error trap" that didn't work in the script. I've attached a copy of the script itself.

CAVEAT: This may be another example of Occam's Razor in which the simplest solution is most often the best.

But I've got to try.

What I wanted to do was write a set of generic instructions that would assign a value to the name of a build directory, create the directory, change to it and then test to see if I was in that directory. If I wasn't, I wanted the script to "bail" so that I could check to see what went wrong. At Line 184, instead of what's there now, the following sequence started:

    BUILD=$HOME/$package-build
    cd $BUILD
#Double sanity check--visual and logical
    pwd
    if [ $(pwd) -ne $BUILD ]
    echo Check the build directory creation
    exit Status 1

When I ran it this way it failed with the message "Line [greater than the last line of the script" syntax error: unexpected end of file

I suspected that the problem was the "trap" and changed to what is in the script now. It's, as I said, "cooking away." If someone has the time and desire, I'd like to see what logic or syntax errors I committed in the trap. I know what I want it to say and can't see the forest for the trees.

If you follow the script the maybe not so clear variables are:

$(whoami) = glibc-2.11.2
packagedir = glibc-2.11.2
$HOME = glibc-2.11.2

The only real "problem" I have now is that I'll have to remove the glibc-build directory by hand. I'd really like to make a generic script for any package that needs a build directory.

As a comment on the script as you see it now, the build of glibc has moved to the testing phase.

I sure would appreciate any pointers, comments or questions.

Thanks,
Dan
#! /bin/bash

# Begin Build for <PACKAGE>

# The basis for this script, and actually the meat of it, came from
# Matthias Benkman's "More Control and Package Users" package management
# system.  The "hint" for this is found at the Linux From Scratch "Hints"
# web page.

# This version of the scripotcame from a CLFS build, by Dan McGhee in September
# of 2009 using "CLFS-SVN-<snapshot date>-x86_64-Multilib" book.  I owe a large
# debt of gratitude to Ken Moffat, an LFS developer, from whom I took
# a large portion of the "start_commands."  

# Run this script from the package user's home directory by invoking it with
# the `./build $package_name--ex. vim-7.2.  It will find the tarball in
# $PACKAGES, untar it, change to the created directory and "configure, make,
# make install."  Then it will "clean up" by creating a list of the installed
# files and remove the source tree.

# It will also recover from, start from where it left off, on failed configure
# make or install steps.

# It will create 6 log files in the $HOME directory:
#   configure.log: All messages output during configure
#   configure.err: Just the errors output during configure
#   make.log: All messages output during make
#   make.err: Just the errors output during make
#   install.log: All messages output during make install
#   install.err: Just the errors output during make install

# On many LFS packages there are commands and edits that occur outside the
# "configure, make, make install" process.  These commands can be added to this 
# script before the appropriate configure, make or make install section.  
Please# note that if the are placed outside of
# <{configure,make,make install}_commands ()>, any results sent to standard
# output will not be captured by a log but will appear on the screen as the
# operation takes place.

# Now, let's go with the rest of the script!

# variables
package=$@
logdir=$package-logs
PACKAGES=/sources
CURRENT=$package

# Begin function definitions
start_commands () {

# Make a log directory
mkdir -v $logdir
        # determine type of tar, and name of its directory
        # enter with current set to version name
        # returns with current set with tar/type,
        # directory set, and tarcmd set
        if [ -r ${PACKAGES}/${CURRENT}.tar.bz2 ]; then
                CURRENT=${CURRENT}.tar.bz2
                TARCMD='-j'
        elif [ -r ${PACKAGES}/${CURRENT}.tar.gz ]; then
                CURRENT=${CURRENT}.tar.gz
                TARCMD='-z'
        elif [ -r ${PACKAGES}/${CURRENT}.tgz ]; then
                CURRENT=${CURRENT}.tgz
                TARCMD='-z'
        elif [ -r ${PACKAGES}/${CURRENT}.tar ]; then
                CURRENT=${CURRENT}.tar
                TARCMD=
        elif [ -r ${PACKAGES}/${CURRENT}.tbz2 ]; then
                CURRENT=${CURRENT}.tbz2
                TARCMD='-j'
        else
                echo "identify: unable to identify tar for $CURRENT"
                exit 1
        fi

        echo "testing ${CURRENT}"
        # /dev/null may not exist at start of ch6
        # changed to test for character special file instead of file
        #if [ -c /dev/null ]; then
        #       NUL='2>/dev/null'
        #fi
        # util-linux uses ./ at start of directory names
        #DIRECTORY=`tar -tv $TARCMD -f ${PACKAGES}/${CURRENT} $NUL | head -n 1 
| awk '{ print $6}' | sed s'@^./@@' | \
        # making NUL defined causes tar to try to look for 2>/dev/null in the 
tarball. 
        DIRECTORY=`tar -tv $TARCMD -f ${PACKAGES}/${CURRENT}  | head -n 1 | awk 
'{ print $6}' | sed s'@^./@@' | \
                cut -d '/' -f 1`
        if [ -z $DIRECTORY ]; then
                echo "indentify: error in trying to determine directory name"
                exit 1
        fi
echo "identify: directory is $DIRECTORY"

# Untar
echo "Untarring $CURRENT"
tar -x $TARCMD -f $PACKAGES/$CURRENT
echo "Entering source tree"
cd $DIRECTORY
packagedir=$DIRECTORY
echo $packagedir
}

configure_commands()
{ :
         ../glibc-2.11.2/configure --prefix=/usr \
                 --disable-profile --enable-add-ons \
                 --enable-kernel=2.6.22.5 --libexecdir=/usr/lib/glibc
}

make_commands()
{ :
  make
}

install_commands()
{ :
  make install
}

test_pipe()
{
  for i in "${pipestat...@]}" 
  do
    test $i != 0 && { echo FAILED! ; exit 1 ; }
  done
  echo successful!
  return 0
}

# End Functions

# Begin tests and function calls for fresh and failed builds.

# This one recovers from failed "make."
if [ -e $logdir/make-`echo $package`.err ] && \
[ ! -e $logdir/install-`echo $package`.err ]; then #Now build

        cd $packagedir
        echo -n Building `echo $package`...
        { make_commands 3>&1 1>&2 2>&3 | tee "$Home/$logdir/make-`echo 
$package`.err" ;} &>"$HOME/$logdir/make-`echo $package`.log"
        test_pipe && echo -n Installing `echo $package`... #Now build

        cd $packagedir
        { install_commands 3>&1 1>&2 2>&3 | tee "$HOME/$logdir/install-`echo 
$package`.err" ;} &>"$HOME/$logdir/install-`echo $package`.log"
        test_pipe
        cd $HOME
        list_package $(whoami) > $package-files.list
        echo Cleaning up by removing the source tree
        rm -rf $packagedir
        echo "Congratulations!!! You're finally done with $package"     
fi

# This one recovers from a failed install
if [ -e $logdir/make-`echo $package`.log ] && \
[ ! -e $HOME/$package-files.list ]; then
        cd $packagedir
         echo -n Installing `echo $package`...
        { install_commands 3>&1 1>&2 2>&3 | tee "$HOME/$logdir/install-`echo 
$package`.err" ;} &>"$HOME/$logdir/install-`echo $package`.log"
        test_pipe
        cd $HOME
        list_package $(whoami) > $package-files.list
        echo Cleaning up by removing the source tree
        rm -rf $packagedir
        echo "Congratulations!! You're finally done with ${package}"
fi 

# This one does everything through configure, make, make install
if [ ! -e $logdir ];  then 
         start_commands

# Point GlibC internal scripts to the "right" GlibC according to
# LFS Chapter6.9
         DL=$(readelf -l /bin/sh | sed -n 
's...@.*interpret.*/tools\(.*\)]...@\1@p')
         sed -i "s|libs -o|libs -L/usr/lib -Wl,-dynamic-linker=$DL -o|" \
                scripts/test-installation.pl
         unset DL

# Change the 'ldd'shell script to '/bin/bash' even though '/bin/sh' is
# installed according to LFS Chapter 6.9.
         sed -i 's|@BASH@|/bin/bash|' elf/ldd.bash.in

# Now apply the patch
         patch -Np1 -i $PACKAGES/glibc-2.11.2-gcc_fix-1.patch

# Create and enter the build directory
        mkdir -v ../glibc-build
        echo Entering build directory
        cd ../glibc-build
        pwd

# Optimize the library for the gcc compiler and speed by setting CFLAGS
# according to LFS Chapter 6.9
         case `uname -m` in
            i?86) echo "CFLAGS += -march=i486 -mtune=native -O3 -pipe" > 
configparms ;;
         esac

# Let's get on with it now.
         echo -n Configuring `echo $package`...
         { configure_commands 3>&1 1>&2 2>&3 | tee 
"$HOME/$logdir/configure-`echo $(whoami)`.err" ;} 
&>"$HOME/$logdir/configure-`echo $(whoami)`.log"
         test_pipe
         pwd

         echo -n Building `echo $package`...
        { make_commands 3>&1 1>&2 2>&3 | tee "$HOME/$logdir/make-`echo 
$package`.err" ;} &>"$HOME/$logdir/make-`echo $package`.log"
        test_pipe

# If you want to run the test suite, uncomment the following
        echo Testing...$package
# For GlibC
        cp -v ../glibc-2.11.2/iconvdata/gconv-modules iconvdata
# For GlibC and everything else
        make -k check 2>&1 | tee $HOME/$(whoami)-tests.log \
        grep Error $HOME/$(whoami)-tests.log > $HOME/$(whoami)-test_errors.log

        echo -n Installing `echo $package`...
        { install_commands 3>&1 1>&2 2>&3 | tee "$HOME/$logdir/install-`echo 
$package`.err" ;} &>"$HOME/$logdir/install-`echo $package`.log"
        test_pipe
        mkdir -pv /usr/lib/locale
        localedef -i cs_CZ -f UTF-8 cs_CZ.UTF-8
        localedef -i de_DE -f ISO-8859-1 de_DE
        localedef -i de...@euro -f ISO-8859-15 de...@euro
        localedef -i de_DE -f UTF-8 de_DE.UTF-8
        localedef -i en_HK -f ISO-8859-1 en_HK
        localedef -i en_PH -f ISO-8859-1 en_PH
        localedef -i en_US -f ISO-8859-1 en_US
        localedef -i en_US -f UTF-8 en_US.UTF-8
        localedef -i es_MX -f ISO-8859-1 es_MX
        localedef -i fa_IR -f UTF-8 fa_IR
        localedef -i fr_FR -f ISO-8859-1 fr_FR
        localedef -i fr...@euro -f ISO-8859-15 fr...@euro
        localedef -i fr_FR -f UTF-8 fr_FR.UTF-8
        localedef -i it_IT -f ISO-8859-1 it_IT
        localedef -i ja_JP -f EUC-JP ja_JP
        localedef -i tr_TR -f UTF-8 tr_TR.UTF-8
        localedef -i zh_CN -f GB18030 zh_CN.GB18030

# Clean-up and exit

        echo Going home
        cd $HOME
        echo Listing package files
        list_package $(whoami) >  $package-files.list
        echo Removing source tree
        rm -rf $packagedir
        echo Congratulations you are done with $package!!!!
fi

# NOTE: Simply using && instead of test_pipe would not work, because &&
# only tests the exit status of the last command in the pipe, which is tee.




# End Build
-- 
http://linuxfromscratch.org/mailman/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/lfs/faq.html
Unsubscribe: See the above information page

Reply via email to