Fakeroot

From CBLFS
Jump to: navigation, search

This page gives a step-by-step case study of building a package using a fakeroot method. In our example we will be building Coreutils.

Contents

Before the Build

I always recommend setting a variable for our temporary directory, and one for our binary directory. I use IMAGE_DIR and PKG_DIR. So I would issue the following commands:

 export IMAGE_DIR=/home/clfs/build
 export PKG_DIR=/home/clfs/binary

Build the Package

Follow the book's instructions for the build, except do not do the install command:

 rm -rf ${IMAGE_DIR}
 cd /usr/src
 tar xvf /home/clfs/sources/coreutils-6.12.tar.gz
 cd coreutils-6.12
 CC="gcc ${BUILD64}" ./configure --prefix=/usr \
   --enable-no-install-program=kill,uptime \
   --enable-install-program=hostname
 make

Installation of the Package

Now we will need to prepare our build directory. As you know with Coreutils we move files from /usr/bin to /bin, so we need to prep for these changes.

 install -d ${IMAGE_DIR}/bin
 install -d ${IMAGE_DIR}/usr/sbin

Now we can install the build into our Image Directory. We do this by passing the DESTDIR=${IMAGE_DIR} to the install command.

 make DESTDIR=${IMAGE_DIR} install

Now lets copy the files so our binary package will be correct.

 mv ${IMAGE_DIR}/usr/bin/{cat,chgrp,chmod,chown,cp,date} ${IMAGE_DIR}/bin
 mv ${IMAGE_DIR}/usr/bin/{dd,df,echo,false,hostname,ln,ls,mkdir,mknod} ${IMAGE_DIR}/bin
 mv ${IMAGE_DIR}/usr/bin/{mv,pwd,rm,rmdir,stty,true,uname} ${IMAGE_DIR}/bin
 mv ${IMAGE_DIR}/usr/bin/chroot ${IMAGE_DIR}/usr/sbin
 mv ${IMAGE_DIR}/usr/bin/{[,basename,head,install,nice} ${IMAGE_DIR}/bin
 mv ${IMAGE_DIR}/usr/bin/{readlink,sleep,sync,test,touch} ${IMAGE_DIR}/bin

Now lets create any needed symlinks.

 ln -sf ../../bin/install ${IMAGE_DIR}/usr/bin

Create a Tarball of the Package

Now lets create a tarball of our package so we can install it later.

 cd ${IMAGE_DIR}
 sync
 cd /tmp
 tar cvf ${PKG_DIR}/coreutils-6.12.tar ${IMAGE_DIR}/*

How to install Package

Now you have your nice tarball of your package, how do you install it.

 rm -f ${IMAGE_DIR}
 tar xvf ${PKG_DIR}/coreutils-6.12.tar
 cd ${IMAGE_DIR}
 for dir in in $(find . -type d | sed -e 's@./@@'); do
   install -d /${dir}
 done
 for file in $(find . ! -type d | sed -e 's@./@@'); do
   cp -dpf ${file} /${file}
 done

Specific Issues with Coreutils

The reason I picked Coreutils for this example is to show an error that always occurs. Since we are installing Coreutils that has cp being used, it has a conflict. You may encounter this with other builds. The simple workaround for this is to duplicate the file that is going to give you an issue. Here is a correct version that will work with Coreutils.

 rm -f ${IMAGE_DIR}
 tar xvf ${PKG_DIR}/coreutils-6.12.tar
 cd ${IMAGE_DIR}
 for dir in in $(find . -type d | sed -e 's@./@@'); do
   install -d /${dir}
 done
 cp /bin/cp /tmp/cp
 for file in $(find . ! -type d | sed -e 's@./@@'); do
   /tmp/cp -dpf ${file} /${file}
 done
 rm -f /tmp/cp
Personal tools