Permalink
Browse files

Reworked build scripts to reduce boilerplate and simplify cleanup.

  • Loading branch information...
1 parent db26533 commit 4488ed08019c2e434e9b8fd9b556e1f80ca35a25 @Vultaire committed May 29, 2011
View
@@ -3,15 +3,12 @@
# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/gcc-pass1.html
-set -o nounset
-set -o errexit
+source package_build.sh
+TARBALL=gcc-4.5.2.tar.bz2
+SRC_DIR=gcc-4.5.2
+BUILD_DIR=gcc-build
-source shared.sh
-match_user "lfs" || die 'This script must be run as the "lfs" user.'
-
-cd $LFS/sources
-tar -xf gcc-4.5.2.tar.bz2
-cd gcc-4.5.2
+prep_build "lfs"
tar -jxf ../mpfr-3.0.0.tar.bz2
mv -v mpfr-3.0.0 mpfr
@@ -37,6 +34,4 @@ make install
ln -vs libgcc.a `$LFS_TGT-gcc -print-libgcc-file-name | \
sed 's/libgcc/&_eh/'`
-# Cleanup
-cd $LFS/sources
-rm -rf gcc-4.5.2 gcc-build
+cleanup_build
@@ -3,22 +3,17 @@
# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/linux-headers.html
-set -o nounset
-set -o errexit
+source package_build.sh
+TARBALL=linux-2.6.37.tar.bz2
+SRC_DIR=linux-2.6.37
+BUILD_DIR=
-source shared.sh
-match_user "lfs" || die 'This script must be run as the "lfs" user.'
-
-cd $LFS/sources
-tar -xf linux-2.6.37.tar.bz2
-cd linux-2.6.37
+prep_build "lfs"
make mrproper
make headers_check
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /tools/include
-# Cleanup
-cd $LFS/sources
-rm -rf linux-2.6.37
+cleanup_build
View
@@ -3,15 +3,12 @@
# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/glibc.html
-set -o nounset
-set -o errexit
+source package_build.sh
+TARBALL=glibc-2.13.tar.bz2
+SRC_DIR=glibc-2.13
+BUILD_DIR=glibc-build
-source shared.sh
-match_user "lfs" || die 'This script must be run as the "lfs" user.'
-
-cd $LFS/sources
-tar -xf glibc-2.13.tar.bz2
-cd glibc-2.13
+prep_build "lfs"
patch -Np1 -i ../glibc-2.13-gcc_fix-1.patch
@@ -30,6 +27,4 @@ esac
make
make install
-# Cleanup
-cd $LFS/sources
-rm -rf glibc-2.13 glibc-build
+cleanup_build
@@ -3,15 +3,12 @@
# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/binutils-pass2.html
-set -o nounset
-set -o errexit
+source package_build.sh
+TARBALL=binutils-2.21.tar.bz2
+SRC_DIR=binutils-2.21
+BUILD_DIR=binutils-build
-source shared.sh
-match_user "lfs" || die 'This script must be run as the "lfs" user.'
-
-cd $LFS/sources
-tar -xf binutils-2.21.tar.bz2
-cd binutils-2.21
+prep_build "lfs"
mkdir -v ../binutils-build
cd ../binutils-build
@@ -27,6 +24,4 @@ make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib
cp -v ld/ld-new /tools/bin
-# Cleanup
-cd $LFS/sources
-rm -rf binutils-2.21 binutils-build
+cleanup_build
View
@@ -3,15 +3,12 @@
# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/gcc-pass2.html
-set -o nounset
-set -o errexit
+source package_build.sh
+TARBALL=gcc-4.5.2.tar.bz2
+SRC_DIR=gcc-4.5.2
+BUILD_DIR=gcc-build
-source shared.sh
-match_user "lfs" || die 'This script must be run as the "lfs" user.'
-
-cd $LFS/sources
-tar -xf gcc-4.5.2.tar.bz2
-cd gcc-4.5.2
+prep_build "lfs"
patch -Np1 -i ../gcc-4.5.2-startfiles_fix-1.patch
@@ -73,6 +70,4 @@ readelf -l a.out | grep ': /tools'
rm -v dummy.c a.out
-# Cleanup
-cd $LFS/sources
-rm -rf gcc-4.5.2 gcc-build
+cleanup_build
View
@@ -3,15 +3,12 @@
# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/tcl.html
-set -o nounset
-set -o errexit
+source package_build.sh
+TARBALL=tcl8.5.9-src.tar.gz
+SRC_DIR=tcl8.5.9
+BUILD_DIR=
-source shared.sh
-match_user "lfs" || die 'This script must be run as the "lfs" user.'
-
-cd $LFS/sources
-tar -xf tcl8.5.9-src.tar.gz
-cd tcl8.5.9
+prep_build "lfs"
cd unix
./configure --prefix=/tools
@@ -22,6 +19,4 @@ chmod -v u+w /tools/lib/libtcl8.5.so
make install-private-headers
ln -sv tclsh8.5 /tools/bin/tclsh
-# Cleanup
-cd $LFS/sources
-rm -rf tcl8.5.9
+cleanup_build
View
@@ -3,15 +3,12 @@
# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/expect.html
-set -o nounset
-set -o errexit
+source package_build.sh
+TARBALL=expect5.45.tar.gz
+SRC_DIR=expect5.45
+BUILD_DIR=
-source shared.sh
-match_user "lfs" || die 'This script must be run as the "lfs" user.'
-
-cd $LFS/sources
-tar -xf expect5.45.tar.gz
-cd expect5.45
+prep_build "lfs"
cp -v configure{,.orig}
sed 's:/usr/local/bin:/bin:' configure.orig > configure
@@ -22,6 +19,4 @@ make
#make test
make SCRIPTS="" install
-# Cleanup
-cd $LFS/sources
-rm -rf expect5.45
+cleanup_build
View
@@ -3,21 +3,16 @@
# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/dejagnu.html
-set -o nounset
-set -o errexit
+source package_build.sh
+TARBALL=dejagnu-1.4.4.tar.gz
+SRC_DIR=dejagnu-1.4.4
+BUILD_DIR=
-source shared.sh
-match_user "lfs" || die 'This script must be run as the "lfs" user.'
-
-cd $LFS/sources
-tar -xf dejagnu-1.4.4.tar.gz
-cd dejagnu-1.4.4
+prep_build "lfs"
patch -Np1 -i ../dejagnu-1.4.4-consolidated-1.patch
./configure --prefix=/tools
make install
make check
-# Cleanup
-cd $LFS/sources
-rm -rf dejagnu-1.4.4
+cleanup_build
View
@@ -3,21 +3,16 @@
# LFS Reference:
# http://www.linuxfromscratch.org/lfs/view/stable/chapter05/ncurses.html
-set -o nounset
-set -o errexit
+source package_build.sh
+TARBALL=ncurses-5.7.tar.gz
+SRC_DIR=ncurses-5.7
+BUILD_DIR=
-source shared.sh
-match_user "lfs" || die 'This script must be run as the "lfs" user.'
-
-cd $LFS/sources
-tar -xf ncurses-5.7.tar.gz
-cd ncurses-5.7
+prep_build "lfs"
./configure --prefix=/tools --with-shared \
--without-debug --without-ada --enable-overwrite
make
make install
-# Cleanup
-cd $LFS/sources
-rm -rf ncurses-5.7
+cleanup_build
View
@@ -0,0 +1,40 @@
+# Functions for package building
+#
+# If you use these functions, you need to define the following
+# variables:
+#
+# - TARBALL: The tarball's file name. No path component.
+# - SRC_DIR: The tarball's extracted directory name.
+# - BUILD_DIR: If a separate build directory is used, specify it. If
+# not, define but leave blank.
+#
+# So as not to require touching the original LFS procedures, the
+# BUILD_DIR is not auto-created. It is used purely for
+# cleanup_build().
+
+source shared.sh
+
+function forgive_nothing () {
+ set -o nounset
+ set -o errexit
+}
+
+function prep_build () {
+ user="$1"
+ forgive_nothing
+
+ source shared.sh
+ match_user "$user" || die "This script must be run as the \"$user\" user."
+
+ cd $LFS/sources
+ tar -xf "$TARBALL"
+ cd "$SRC_DIR"
+}
+
+function cleanup_build () {
+ cd $LFS/sources
+ rm -rf "$SRC_DIR"
+ if [ ! -z "$BUILD_DIR" ]; then
+ rm -rf "$BUILD_DIR"
+ fi
+}
View
@@ -1,5 +1,8 @@
#!/bin/bash
+# Shared constants
+LFS=/mnt/lfs
+
# Shared functions
function die () {
echo "$@" > /dev/stdout
@@ -14,6 +17,3 @@ function match_user () {
user=$1
[ "$(id -un)" == "$user" ]
}
-
-# Shared constants
-LFS=/mnt/lfs

0 comments on commit 4488ed0

Please sign in to comment.