[fbb6b78] | 1 | #!/bin/sh
|
---|
[1236262] | 2 |
|
---|
| 3 | version="
|
---|
[63b2859] | 4 | jhalfs development
|
---|
| 5 |
|
---|
[db9cec6] | 6 | Originally written by Jeremy Huntwork.
|
---|
[557fe91] | 7 | Maintained by Manuel Canales Esparcia.
|
---|
[1236262] | 8 |
|
---|
| 9 | This program is published under the \
|
---|
[557fe91] | 10 | Gnu General Public License, Version 2.
|
---|
| 11 | "
|
---|
[1236262] | 12 |
|
---|
| 13 | usage="\
|
---|
| 14 | Usage: $0 [OPTION]
|
---|
| 15 |
|
---|
| 16 | Options:
|
---|
[557fe91] | 17 | -h, --help print this help, then exit
|
---|
[24530379] | 18 |
|
---|
[557fe91] | 19 | -V, --version print version number, then exit
|
---|
[24530379] | 20 |
|
---|
[557fe91] | 21 | -d --directory=DIR use DIR directory for building LFS; all files
|
---|
| 22 | jhalfs produces will be in the directory
|
---|
| 23 | DIR/jhalfs
|
---|
[24530379] | 24 |
|
---|
| 25 | -P, --get-packages download the packages and patches
|
---|
| 26 |
|
---|
[557fe91] | 27 | -D, --download-client=CLIENT use CLIENT as the program for retrieving
|
---|
[24530379] | 28 | packages (for use in conjunction with -P)
|
---|
| 29 |
|
---|
| 30 | -W, --working-copy=DIR use the local working copy placed in DIR
|
---|
| 31 | as the LFS book
|
---|
| 32 |
|
---|
| 33 | -L, --LFS-version=VER ckeckout VER version of the LFS book
|
---|
| 34 |
|
---|
| 35 | -T, --testsuites add support to run the optional testsuites
|
---|
| 36 |
|
---|
[d310939] | 37 | -M, --run-make run make on the generated Makefile
|
---|
[1236262] | 38 | "
|
---|
| 39 |
|
---|
| 40 | help="\
|
---|
| 41 | Try '$0 --help' for more information."
|
---|
| 42 |
|
---|
| 43 | exit_missing_arg="\
|
---|
| 44 | echo \"Option '\$1' requires an argument\" >&2
|
---|
| 45 | echo \"\$help\" >&2
|
---|
| 46 | exit 1"
|
---|
| 47 |
|
---|
| 48 | no_dl_client="\
|
---|
| 49 | echo \"Could not find a way to download the LFS sources.\" >&2
|
---|
| 50 | echo \"Attempting to continue.\" >&2"
|
---|
| 51 |
|
---|
| 52 | while test $# -gt 0 ; do
|
---|
[557fe91] | 53 | case $1 in
|
---|
| 54 | --version | -V )
|
---|
| 55 | echo "$version"
|
---|
| 56 | exit 0
|
---|
| 57 | ;;
|
---|
| 58 |
|
---|
| 59 | --help | -h )
|
---|
| 60 | echo "$usage"
|
---|
| 61 | exit 0
|
---|
| 62 | ;;
|
---|
| 63 |
|
---|
| 64 | --LFS-version | -L )
|
---|
| 65 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 66 | shift
|
---|
| 67 | case $1 in
|
---|
| 68 | dev* | SVN | trunk )
|
---|
| 69 | LFSVRS=development
|
---|
| 70 | ;;
|
---|
| 71 | * )
|
---|
| 72 | echo "$1 is an unsupported version at this time."
|
---|
| 73 | exit 1
|
---|
| 74 | ;;
|
---|
| 75 | esac
|
---|
| 76 | shift
|
---|
| 77 | ;;
|
---|
| 78 |
|
---|
| 79 | --directory | -d )
|
---|
| 80 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 81 | shift
|
---|
| 82 | BUILDDIR=$1
|
---|
| 83 | shift
|
---|
| 84 | ;;
|
---|
| 85 |
|
---|
| 86 | --download-client | -D )
|
---|
| 87 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 88 | shift
|
---|
| 89 | DL=$1
|
---|
| 90 | shift
|
---|
| 91 | ;;
|
---|
| 92 |
|
---|
[24530379] | 93 | --working-copy | -W )
|
---|
| 94 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 95 | shift
|
---|
| 96 | WC=1
|
---|
| 97 | BOOK=$1
|
---|
| 98 | shift
|
---|
| 99 | ;;
|
---|
| 100 |
|
---|
[d310939] | 101 | --testsuites | -T )
|
---|
[db9cec6] | 102 | TEST=1
|
---|
| 103 | shift
|
---|
| 104 | ;;
|
---|
| 105 |
|
---|
[d310939] | 106 | --get-packages | -P )
|
---|
[07f47df] | 107 | HPKG=1
|
---|
| 108 | shift
|
---|
| 109 | ;;
|
---|
| 110 |
|
---|
[d310939] | 111 | --run-make | -M )
|
---|
| 112 | RUNMAKE=1
|
---|
| 113 | shift
|
---|
| 114 | ;;
|
---|
| 115 |
|
---|
[557fe91] | 116 | * )
|
---|
| 117 | echo "$usage"
|
---|
| 118 | exit 1
|
---|
| 119 | ;;
|
---|
| 120 | esac
|
---|
[1236262] | 121 | done
|
---|
| 122 |
|
---|
| 123 | # Test to make sure we're running the build as root
|
---|
| 124 |
|
---|
| 125 | if [ "$UID" != "0" ] ; then
|
---|
[557fe91] | 126 | echo "You must be logged in as root to successfully build LFS."
|
---|
| 127 | exit 1
|
---|
[1236262] | 128 | fi
|
---|
| 129 |
|
---|
| 130 | # Find the download client to use, if not already specified.
|
---|
| 131 |
|
---|
| 132 | if [ -z $DL ] ; then
|
---|
| 133 | if [ `type -p wget` ] ; then
|
---|
[557fe91] | 134 | DL=wget
|
---|
[1236262] | 135 | elif [ `type -p curl` ] ; then
|
---|
[557fe91] | 136 | DL=curl
|
---|
[1236262] | 137 | else
|
---|
[557fe91] | 138 | eval "$no_dl_client"
|
---|
[1236262] | 139 | fi
|
---|
| 140 | fi
|
---|
| 141 |
|
---|
| 142 | SVN="svn://svn.linuxfromscratch.org"
|
---|
| 143 | HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
|
---|
[48d7968] | 144 | if [ -z $BUILDDIR ] ; then BUILDDIR=/mnt/lfs ; fi
|
---|
[4dafc45] | 145 | JHALFSDIR=$BUILDDIR/jhalfs
|
---|
[4c62c61] | 146 | LOGDIR=$JHALFSDIR/logs
|
---|
[a5e49c6] | 147 | LOG=000-jhalfs.log
|
---|
[f8de156] | 148 | MKFILE=$JHALFSDIR/Makefile
|
---|
[3cfe871] | 149 | XSL=dump-lfs-scripts.xsl
|
---|
[0fc4c75] | 150 | FNC=functions
|
---|
[db9cec6] | 151 | if [ -z $TEST ] ; then TEST=0 ; fi
|
---|
[1236262] | 152 |
|
---|
[8bb92e7] | 153 | HEADER="# This file is automatically generated by jhalfs
|
---|
| 154 | # DO NOT EDIT THIS FILE MANUALLY
|
---|
| 155 | #
|
---|
| 156 | # Generated on `date \"+%F %X %Z\"`"
|
---|
| 157 |
|
---|
[1236262] | 158 | get_book() {
|
---|
| 159 | # Check for Subversion instead of just letting the script hit 'svn' and fail.
|
---|
| 160 | test `type -p svn` || eval "echo \"This feature requires Subversion.\"
|
---|
[557fe91] | 161 | exit 1"
|
---|
[4dafc45] | 162 | cd $JHALFSDIR
|
---|
[fbb6b78] | 163 |
|
---|
[1236262] | 164 | # Test to make sure the LFS version is set
|
---|
| 165 | if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
|
---|
[24530379] | 166 |
|
---|
[56dd1e2] | 167 | # Set the book's sources directory
|
---|
[24530379] | 168 | if [ -z $BOOK ] ; then BOOK=lfs-$LFSVRS ; fi
|
---|
| 169 |
|
---|
| 170 | if [ -z $WC ] ; then
|
---|
| 171 | echo -n "Downloading the LFS Book, version $LFSVRS... "
|
---|
| 172 |
|
---|
| 173 | # Grab the LFS book fresh if it's missing, otherwise, update it from the
|
---|
| 174 | # repo. If we've already extracted the commands, move on to getting the
|
---|
| 175 | # sources.
|
---|
| 176 | if [ -d lfs-$LFSVRS ] ; then
|
---|
| 177 | cd lfs-$LFSVRS
|
---|
| 178 | if svn up | grep -q At && test -d $JHALFSDIR/commands && \
|
---|
| 179 | test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
|
---|
| 180 | echo -ne "done\n"
|
---|
| 181 | get_sources
|
---|
| 182 | else
|
---|
| 183 | echo -ne "done\n"
|
---|
| 184 | extract_commands
|
---|
| 185 | fi
|
---|
[557fe91] | 186 | else
|
---|
[24530379] | 187 | if [ $LFSVRS = development ] ; then
|
---|
[4c62c61] | 188 | svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1
|
---|
[24530379] | 189 | else
|
---|
[4c62c61] | 190 | svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1
|
---|
[24530379] | 191 | fi
|
---|
[557fe91] | 192 | echo -ne "done\n"
|
---|
| 193 | extract_commands
|
---|
| 194 | fi
|
---|
[1236262] | 195 | else
|
---|
[24530379] | 196 | echo -ne "Using $BOOK as book's sources ...\n"
|
---|
[557fe91] | 197 | extract_commands
|
---|
[1236262] | 198 | fi
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | extract_commands() {
|
---|
| 202 | # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
|
---|
| 203 | test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
|
---|
[557fe91] | 204 | exit 1"
|
---|
[4dafc45] | 205 | cd $JHALFSDIR
|
---|
[1236262] | 206 |
|
---|
| 207 | # Start clean
|
---|
| 208 | if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
|
---|
| 209 | echo -n "Extracting commands... "
|
---|
| 210 |
|
---|
[dc2fee8] | 211 | # Dump the commands in shell script form from the LFS book.
|
---|
[db9cec6] | 212 | xsltproc --nonet --xinclude --stringparam testsuite $TEST -o ./commands/ \
|
---|
[4c62c61] | 213 | $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
[1236262] | 214 |
|
---|
| 215 | # Grab the patches and package names.
|
---|
[4dafc45] | 216 | cd $JHALFSDIR
|
---|
[1236262] | 217 | for i in patches packages ; do rm -f $i ; done
|
---|
[24530379] | 218 | grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
|
---|
[557fe91] | 219 | -e '/generic/d' >> packages
|
---|
[24530379] | 220 | grep "ENTITY" $BOOK/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
|
---|
[1236262] | 221 |
|
---|
| 222 | # Done. Moving on...
|
---|
| 223 | echo -ne "done\n"
|
---|
| 224 | get_sources
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | download() {
|
---|
| 228 | cd $BUILDDIR/sources
|
---|
| 229 |
|
---|
| 230 | # Hackish fix for the bash-doc package that doesn't conform
|
---|
| 231 | # to norms in the URL scheme.
|
---|
| 232 | DIR=`echo $1 | sed 's@-doc@@'`
|
---|
| 233 |
|
---|
| 234 | # Find the md5 sum for this package.
|
---|
| 235 | if [ $2 != MD5SUMS ] ; then MD5=`grep " $2" MD5SUMS` ; fi
|
---|
| 236 |
|
---|
| 237 | if [ ! -f $2 ] ; then
|
---|
[557fe91] | 238 | case $DL in
|
---|
| 239 | wget )
|
---|
| 240 | wget $HTTP/$DIR/$2
|
---|
| 241 | ;;
|
---|
| 242 | curl )
|
---|
| 243 | `curl -# $HTTP/$DIR/$2 -o $2`
|
---|
| 244 | ;;
|
---|
| 245 | * )
|
---|
| 246 | echo "$DL not supported at this time."
|
---|
| 247 | ;;
|
---|
| 248 | esac
|
---|
[1236262] | 249 | elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
|
---|
[557fe91] | 250 | case $DL in
|
---|
| 251 | wget )
|
---|
| 252 | wget -c $HTTP/$DIR/$2
|
---|
| 253 | ;;
|
---|
| 254 | curl )
|
---|
| 255 | `curl -# -C - $HTTP/$DIR/$2 -o $2`
|
---|
| 256 | ;;
|
---|
| 257 | * )
|
---|
| 258 | echo "$DL not supported at this time."
|
---|
| 259 | ;;
|
---|
| 260 | esac
|
---|
[1236262] | 261 | fi
|
---|
| 262 | if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
|
---|
| 263 | exit 1
|
---|
| 264 | fi
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | get_sources() {
|
---|
| 268 |
|
---|
[07f47df] | 269 | # Test if the packages must be downloaded
|
---|
[d310939] | 270 | if [ "$HPKG" = "1" ] ; then
|
---|
[1236262] | 271 |
|
---|
[07f47df] | 272 | # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
|
---|
| 273 | # separates each iteration by lines. It is necessary to have the second
|
---|
| 274 | # ' on the next line.
|
---|
| 275 | IFS='
|
---|
| 276 | '
|
---|
[1236262] | 277 |
|
---|
[07f47df] | 278 | if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
|
---|
| 279 | cd $BUILDDIR/sources
|
---|
| 280 | if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
|
---|
| 281 |
|
---|
| 282 | download "" MD5SUMS
|
---|
| 283 |
|
---|
| 284 | # Iterate through each package and grab it, along with any patches it needs.
|
---|
| 285 | for i in `cat $JHALFSDIR/packages` ; do
|
---|
| 286 | PKG=`echo $i | sed 's/-version.*//'`
|
---|
| 287 |
|
---|
| 288 | # Someone used some silly entities right next to the valid package entities.
|
---|
| 289 | if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
|
---|
| 290 |
|
---|
| 291 | VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
|
---|
| 292 | if [ "$PKG" = "tcl" ] ; then
|
---|
| 293 | FILE="$PKG$VRS-src.tar.bz2"
|
---|
| 294 | else
|
---|
| 295 | FILE="$PKG-$VRS.tar.bz2"
|
---|
| 296 | fi
|
---|
| 297 | download $PKG $FILE
|
---|
| 298 | for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
|
---|
| 299 | PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
|
---|
| 300 | download $PKG $PATCH
|
---|
| 301 | done
|
---|
[fbb6b78] | 302 | done
|
---|
[07f47df] | 303 | fi
|
---|
[1236262] | 304 | }
|
---|
| 305 |
|
---|
[f8de156] | 306 | build_Makefile() {
|
---|
[9e406b5] | 307 | echo -n "Creating Makefile... "
|
---|
[f8de156] | 308 | cd $JHALFSDIR/commands
|
---|
[fbb6b78] | 309 |
|
---|
[f8de156] | 310 | # Start with a clean Makefile.tmp file
|
---|
| 311 | >$MKFILE.tmp
|
---|
| 312 |
|
---|
[0bad6ba] | 313 | for file in chapter05/* ; do
|
---|
[71642ef] | 314 | # Keep the script file name
|
---|
| 315 | i=`basename $file`
|
---|
[63b2859] | 316 |
|
---|
[71642ef] | 317 | # First append each name of the script files to a list (this will become
|
---|
| 318 | # the names of the targets in the Makefile
|
---|
| 319 | chapter5="$chapter5 $i"
|
---|
[557fe91] | 320 |
|
---|
[71642ef] | 321 | # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
|
---|
| 322 | # and binutils in chapter 5)
|
---|
| 323 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
|
---|
[557fe91] | 324 |
|
---|
[e909d9d] | 325 | # Set the dependency for the first target.
|
---|
| 326 | if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
|
---|
| 327 |
|
---|
| 328 | # Drop in the name of the target on a new line, and the previous target
|
---|
[0fc4c75] | 329 | # as a dependency. Also call the echo_message function.
|
---|
[3f990d1] | 330 | (
|
---|
| 331 | cat << EOF
|
---|
| 332 |
|
---|
| 333 | $i: $PREV
|
---|
| 334 | @\$(call echo_message, Building)
|
---|
| 335 | EOF
|
---|
| 336 | ) >> $MKFILE.tmp
|
---|
[557fe91] | 337 |
|
---|
[71642ef] | 338 | # Find the version of the command files, if it corresponds with the building of
|
---|
| 339 | # a specific package
|
---|
| 340 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
[557fe91] | 341 |
|
---|
[71642ef] | 342 | # If $vrs isn't empty, we've got a package...
|
---|
| 343 | if [ "$vrs" != "" ] ; then
|
---|
| 344 | if [ "$name" = "tcl" ] ; then
|
---|
| 345 | FILE="$name$vrs-src.tar.bz2"
|
---|
| 346 | else
|
---|
| 347 | FILE="$name-$vrs.tar.bz2"
|
---|
| 348 | fi
|
---|
[557fe91] | 349 |
|
---|
[71642ef] | 350 | # Insert instructions for unpacking the package and to set
|
---|
| 351 | # the PKGDIR variable.
|
---|
[3f990d1] | 352 | (
|
---|
| 353 | cat << EOF
|
---|
| 354 | @\$(call unpack,$FILE)
|
---|
| 355 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\
|
---|
| 356 | chown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
| 357 | echo "PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT" > envars && \\
|
---|
| 358 | echo "export PKGDIR" >> envars && \\
|
---|
| 359 | EOF
|
---|
| 360 | ) >> $MKFILE.tmp
|
---|
| 361 |
|
---|
[71642ef] | 362 | fi
|
---|
[557fe91] | 363 |
|
---|
[4c62c61] | 364 | # Dump the path to the Binutils or TCL sources directory.
|
---|
| 365 | if [ "$i" = "027-binutils-pass1" -o "$i" = "032-tcl" -o "$i" = "036-binutils-pass2" ] ; then
|
---|
[3f990d1] | 366 | (
|
---|
| 367 | cat << EOF
|
---|
| 368 | echo "\$(LFS)\$(SRC)/\$\$ROOT" > sources-dir
|
---|
| 369 | EOF
|
---|
| 370 | ) >> $MKFILE.tmp
|
---|
[88dcce5] | 371 |
|
---|
[71642ef] | 372 | # For the Adjusting phase we must to cd to the binutils-build directory.
|
---|
[0fc4c75] | 373 | elif [ "$i" = "031-adjusting" ] ; then
|
---|
[3f990d1] | 374 | (
|
---|
| 375 | cat << EOF
|
---|
| 376 | @echo "PKGDIR=\$(LFS)\$(SRC)/binutils-build" > envars && \\
|
---|
| 377 | echo "export PKGDIR" >> envars
|
---|
| 378 | EOF
|
---|
| 379 | ) >> $MKFILE.tmp
|
---|
[0209bb7] | 380 |
|
---|
[97a3ffc] | 381 | # For the Expect build we need to set the TCLPATH envar.
|
---|
[0fc4c75] | 382 | elif [ "$i" = "033-expect" ] ; then
|
---|
[3f990d1] | 383 | (
|
---|
| 384 | cat << EOF
|
---|
| 385 | echo "TCLPATH=\`cat sources-dir\`" >> envars && \\
|
---|
| 386 | echo "export TCLPATH" >> envars
|
---|
| 387 | EOF
|
---|
| 388 | ) >> $MKFILE.tmp
|
---|
[0fc4c75] | 389 |
|
---|
| 390 | # Everything else, add a true statment so we don't confuse make
|
---|
| 391 | else
|
---|
[3f990d1] | 392 | (
|
---|
| 393 | cat << EOF
|
---|
| 394 | true
|
---|
| 395 | EOF
|
---|
| 396 | ) >> $MKFILE.tmp
|
---|
[71642ef] | 397 | fi
|
---|
[557fe91] | 398 |
|
---|
[3f990d1] | 399 | # Insert date and disk usage at the top of the log file, the script run
|
---|
| 400 | # and date and disk usage again at the bottom of the log file.
|
---|
| 401 | (
|
---|
| 402 | cat << EOF
|
---|
| 403 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
| 404 | su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/commands/$file" >>logs/$i 2>&1 && \\
|
---|
| 405 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\n" >>logs/$i
|
---|
| 406 | EOF
|
---|
| 407 | ) >> $MKFILE.tmp
|
---|
[71642ef] | 408 |
|
---|
| 409 | # Remove the build directory(ies) even if the package build fails, except for
|
---|
[d310939] | 410 | # Binutils and TCL. In that cases the sources directories are removed
|
---|
[71642ef] | 411 | # only if the build fails.
|
---|
| 412 | if [ "$vrs" != "" ] ; then
|
---|
[d310939] | 413 | if [ "$i" != "027-binutils-pass1" ] && [ "$i" != "032-tcl" ] && [ "$i" != "036-binutils-pass2" ] ; then
|
---|
[3f990d1] | 414 | (
|
---|
| 415 | cat << EOF
|
---|
| 416 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\
|
---|
| 417 | rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
| 418 | if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
|
---|
| 419 | rm -r \$(LFS)\$(SRC)/$name-build; \\
|
---|
| 420 | fi;
|
---|
| 421 | EOF
|
---|
| 422 | ) >> $MKFILE.tmp
|
---|
[71642ef] | 423 | fi
|
---|
| 424 | fi
|
---|
[7bbd436] | 425 |
|
---|
| 426 | # Remove the Binutils pass 1 sources after a successful Adjusting phase.
|
---|
| 427 | if [ "$i" = "031-adjusting" ] ; then
|
---|
[3f990d1] | 428 | (
|
---|
| 429 | cat << EOF
|
---|
| 430 | @rm -r \`cat sources-dir\` && \\
|
---|
| 431 | rm -r \$(LFS)\$(SRC)/binutils-build && \\
|
---|
| 432 | rm sources-dir
|
---|
| 433 | EOF
|
---|
| 434 | ) >> $MKFILE.tmp
|
---|
[7bbd436] | 435 | fi
|
---|
| 436 |
|
---|
| 437 | # Remove the TCL sources after a successful Expect build.
|
---|
| 438 | if [ "$i" = "033-expect" ] ; then
|
---|
[3f990d1] | 439 | (
|
---|
| 440 | cat << EOF
|
---|
| 441 | @rm -r \`cat sources-dir\` && \\
|
---|
| 442 | rm sources-dir
|
---|
| 443 | EOF
|
---|
| 444 | ) >> $MKFILE.tmp
|
---|
[7bbd436] | 445 | fi
|
---|
| 446 |
|
---|
| 447 | # Include a touch of the target name so make can check
|
---|
| 448 | # if it's already been made.
|
---|
[3f990d1] | 449 | (
|
---|
| 450 | cat << EOF
|
---|
| 451 | @touch \$@
|
---|
| 452 | EOF
|
---|
| 453 | ) >> $MKFILE.tmp
|
---|
[7bbd436] | 454 |
|
---|
| 455 | # The next two "if" must be after the touch to can check if the sources
|
---|
| 456 | # directories should be retained or deleted.
|
---|
[d310939] | 457 | if [ "$i" = "027-binutils-pass1" -o "$i" = "036-binutils-pass2" ] ; then
|
---|
[3f990d1] | 458 | (
|
---|
| 459 | cat << EOF
|
---|
| 460 | @if [ ! -e \$@ ] ; then \\
|
---|
| 461 | ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\
|
---|
| 462 | rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
| 463 | rm -r \$(LFS)\$(SRC)/binutils-build; \\
|
---|
| 464 | fi;
|
---|
| 465 | EOF
|
---|
| 466 | ) >> $MKFILE.tmp
|
---|
[d310939] | 467 | fi
|
---|
[3f990d1] | 468 |
|
---|
[d310939] | 469 | if [ "$i" = "032-tcl" ] ; then
|
---|
[3f990d1] | 470 | (
|
---|
| 471 | cat << EOF
|
---|
| 472 | @if [ ! -e \$@ ] ; then \\
|
---|
| 473 | ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\
|
---|
| 474 | rm -r \$(LFS)\$(SRC)/\$\$ROOT; \\
|
---|
| 475 | fi;
|
---|
| 476 | EOF
|
---|
| 477 | ) >> $MKFILE.tmp
|
---|
[71642ef] | 478 | fi
|
---|
[44f88e3] | 479 |
|
---|
[e909d9d] | 480 | # Keep the script file name for Makefile dependencies.
|
---|
| 481 | PREV=$i
|
---|
[f8de156] | 482 | done
|
---|
[9e406b5] | 483 |
|
---|
[97a3ffc] | 484 | for file in chapter06/* ; do
|
---|
| 485 | # Keep the script file name
|
---|
| 486 | i=`basename $file`
|
---|
| 487 |
|
---|
[16c67ed] | 488 | # We'll run the chroot commands differently than the others, so skip them in the
|
---|
| 489 | # dependencies and target creation.
|
---|
| 490 | if echo $i | grep -q "chroot" ; then
|
---|
| 491 | continue
|
---|
| 492 | fi
|
---|
| 493 |
|
---|
[97a3ffc] | 494 | # First append each name of the script files to a list (this will become
|
---|
| 495 | # the names of the targets in the Makefile
|
---|
| 496 | chapter6="$chapter6 $i"
|
---|
| 497 |
|
---|
| 498 | # Grab the name of the target
|
---|
| 499 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@'`
|
---|
| 500 |
|
---|
| 501 | # Set the dependency for the first target.
|
---|
| 502 | if [ -z $PREV ] ; then PREV=055-stripping ; fi
|
---|
| 503 |
|
---|
| 504 | # Drop in the name of the target on a new line, and the previous target
|
---|
[4c62c61] | 505 | # as a dependency. Also call the echo_message function.
|
---|
[3f990d1] | 506 | (
|
---|
| 507 | cat << EOF
|
---|
| 508 |
|
---|
| 509 | $i: $PREV
|
---|
| 510 | @\$(call echo_message, Building)
|
---|
| 511 | EOF
|
---|
| 512 | ) >> $MKFILE.tmp
|
---|
[97a3ffc] | 513 |
|
---|
| 514 | # Find the version of the command files, if it corresponds with the building of
|
---|
| 515 | # a specific package
|
---|
| 516 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
| 517 |
|
---|
| 518 | # If $vrs isn't empty, we've got a package...
|
---|
[3f990d1] | 519 | # Insert instructions for unpacking the package and changing directories
|
---|
[97a3ffc] | 520 | if [ "$vrs" != "" ] ; then
|
---|
| 521 | FILE="$name-$vrs.tar.bz2"
|
---|
[3f990d1] | 522 | (
|
---|
| 523 | cat << EOF
|
---|
| 524 | @\$(call unpack,$FILE)
|
---|
| 525 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\
|
---|
| 526 | echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
|
---|
[2e51f44] | 527 | echo "export PKGDIR" >> envars
|
---|
[3f990d1] | 528 | EOF
|
---|
| 529 | ) >> $MKFILE.tmp
|
---|
[97a3ffc] | 530 | fi
|
---|
| 531 |
|
---|
| 532 | # For the Re-Adjusting phase we must to cd to the binutils-build directory.
|
---|
| 533 | if [ "$i" = "067-readjusting" ] ; then
|
---|
[3f990d1] | 534 | (
|
---|
| 535 | cat << EOF
|
---|
| 536 | @echo "PKGDIR=\$(SRC)/binutils-build" > envars && \\
|
---|
| 537 | echo "export PKGDIR" >> envars
|
---|
| 538 | EOF
|
---|
| 539 | ) >> $MKFILE.tmp
|
---|
[4c62c61] | 540 | fi
|
---|
[97a3ffc] | 541 |
|
---|
[80c00fc] | 542 | # In the mount of kernel filesystems we need to set LFS for CHROOT1
|
---|
| 543 | # and not to use chroot.
|
---|
[4c62c61] | 544 | if [ "$i" = "057-kernfs" ] ; then
|
---|
[3f990d1] | 545 | (
|
---|
| 546 | cat << EOF
|
---|
| 547 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
[ad5f7f7] | 548 | commands/$file >>logs/$i 2>&1 && \\
|
---|
[3f990d1] | 549 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\n" >>logs/$i
|
---|
| 550 | EOF
|
---|
[a7d20b8] | 551 | ) >> $MKFILE.tmp
|
---|
| 552 |
|
---|
| 553 | # The rest of Chapter06
|
---|
[7ecd166] | 554 | else
|
---|
[3f990d1] | 555 | (
|
---|
| 556 | cat << EOF
|
---|
[80c00fc] | 557 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=0??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
[2e51f44] | 558 | \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
|
---|
[3f990d1] | 559 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=0??-* \$(LFS)\`\n" >>logs/$i
|
---|
| 560 | EOF
|
---|
| 561 | ) >> $MKFILE.tmp
|
---|
| 562 |
|
---|
[7ecd166] | 563 | fi
|
---|
[97a3ffc] | 564 |
|
---|
[6299c11] | 565 | # Remove the build directory(ies) even if the package build fails.
|
---|
[97a3ffc] | 566 | if [ "$vrs" != "" ] ; then
|
---|
[3f990d1] | 567 | (
|
---|
| 568 | cat << EOF
|
---|
| 569 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\
|
---|
| 570 | rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
| 571 | if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
|
---|
| 572 | rm -r \$(LFS)\$(SRC)/$name-build; \\
|
---|
| 573 | fi;
|
---|
| 574 | EOF
|
---|
| 575 | ) >> $MKFILE.tmp
|
---|
[97a3ffc] | 576 | fi
|
---|
| 577 |
|
---|
[4e4a8d5] | 578 | # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
|
---|
[6299c11] | 579 | if [ "$i" = "067-readjusting" ] ; then
|
---|
[3f990d1] | 580 | (
|
---|
| 581 | cat << EOF
|
---|
| 582 | @rm -r \`cat sources-dir\` && \\
|
---|
| 583 | rm -r \$(LFS)\$(SRC)/binutils-build && \\
|
---|
| 584 | rm sources-dir
|
---|
| 585 | EOF
|
---|
| 586 | ) >> $MKFILE.tmp
|
---|
[97a3ffc] | 587 | fi
|
---|
| 588 |
|
---|
[732d1f1] | 589 | # Include a touch of the target name so make can check
|
---|
| 590 | # if it's already been made.
|
---|
[3f990d1] | 591 | (
|
---|
| 592 | cat << EOF
|
---|
| 593 | @touch \$@
|
---|
| 594 | EOF
|
---|
| 595 | ) >> $MKFILE.tmp
|
---|
[732d1f1] | 596 |
|
---|
[97a3ffc] | 597 | # Keep the script file name for Makefile dependencies.
|
---|
| 598 | PREV=$i
|
---|
| 599 | done
|
---|
| 600 |
|
---|
[3f990d1] | 601 | # Add a header, some variables and include the function file
|
---|
| 602 | # to the top of the real Makefile.
|
---|
| 603 | (
|
---|
| 604 | cat << EOF
|
---|
| 605 | $HEADER
|
---|
| 606 |
|
---|
| 607 | SRC= /sources
|
---|
| 608 | LFS= $BUILDDIR
|
---|
| 609 |
|
---|
| 610 | include functions
|
---|
| 611 |
|
---|
| 612 | EOF
|
---|
| 613 | ) > $MKFILE
|
---|
[8bb92e7] | 614 |
|
---|
[c08d23b] | 615 |
|
---|
| 616 | # Add chroot commands
|
---|
| 617 | i=1
|
---|
| 618 | for file in chapter06/*chroot* ; do
|
---|
| 619 | chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
|
---|
[002f8a7] | 620 | -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|&&exit||g' -e 's|$| -c|' -e 's|"$$LFS"|$(LFS)|'`
|
---|
[d7fd195] | 621 | echo -e "CHROOT$i= $chroot\n" >> $MKFILE
|
---|
[c08d23b] | 622 | i=`expr $i + 1`
|
---|
| 623 | done
|
---|
[9e406b5] | 624 |
|
---|
[0bad6ba] | 625 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
| 626 | # as a dependency.
|
---|
[3f990d1] | 627 | (
|
---|
| 628 | cat << EOF
|
---|
[16c67ed] | 629 | all: chapter4 chapter5 chapter6
|
---|
[3f990d1] | 630 | @echo -e "\n\tYour new LFS system has been successfully built"
|
---|
| 631 |
|
---|
| 632 | chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
|
---|
| 633 |
|
---|
| 634 | chapter5: chapter4 $chapter5
|
---|
| 635 |
|
---|
| 636 | chapter6: chapter5 $chapter6
|
---|
| 637 |
|
---|
| 638 | clean-all: clean
|
---|
| 639 | rm -rf ./*
|
---|
| 640 |
|
---|
| 641 | clean: clean-chapter5 clean-chapter4
|
---|
| 642 |
|
---|
| 643 | clean-chapter4:
|
---|
| 644 | -userdel lfs
|
---|
| 645 | rm -rf /home/lfs
|
---|
| 646 | rm -rf \$(LFS)/tools
|
---|
| 647 | rm -f /tools
|
---|
| 648 | rm -f envars
|
---|
| 649 | rm -f 02* logs/02*.log
|
---|
| 650 |
|
---|
| 651 | clean-chapter5:
|
---|
| 652 | rm -rf \$(LFS)/tools/*
|
---|
| 653 | rm -f envars
|
---|
| 654 | rm -f $chapter5
|
---|
| 655 | cd logs && rm -f $chapter5 && cd ..
|
---|
| 656 |
|
---|
| 657 | 020-creatingtoolsdir:
|
---|
| 658 | @\$(call echo_message, Building)
|
---|
| 659 | @mkdir -v \$(LFS)/tools && \\
|
---|
| 660 | ln -sv \$(LFS)/tools / && \\
|
---|
| 661 | touch \$@
|
---|
| 662 |
|
---|
| 663 | 021-addinguser: 020-creatingtoolsdir
|
---|
| 664 | @\$(call echo_message, Building)
|
---|
| 665 | @groupadd lfs && \\
|
---|
| 666 | useradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\
|
---|
| 667 | chown lfs \$(LFS)/tools && \\
|
---|
| 668 | chown lfs \$(LFS)/sources && \\
|
---|
| 669 | chmod -R +x $JHALFSDIR/commands && \\
|
---|
| 670 | touch \$@
|
---|
| 671 |
|
---|
| 672 | 022-settingenvironment: 021-addinguser
|
---|
| 673 | @\$(call echo_message, Building)
|
---|
| 674 | @echo "exec env -i HOME=\\\$\$HOME TERM=\\\$\$TERM PS1='\u:\w\$$ ' /bin/bash" > /home/lfs/.bash_profile && \\
|
---|
| 675 | echo "set +h" > /home/lfs/.bashrc && \\
|
---|
| 676 | echo "umask 022" >> /home/lfs/.bashrc && \\
|
---|
| 677 | echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
|
---|
| 678 | echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
|
---|
| 679 | echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
|
---|
| 680 | echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
|
---|
| 681 | echo ". $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
|
---|
| 682 | chown lfs:lfs /home/lfs/.bash* && \\
|
---|
| 683 | touch envars && \\
|
---|
| 684 | touch \$@
|
---|
| 685 | EOF
|
---|
| 686 | ) >> $MKFILE
|
---|
[0bad6ba] | 687 |
|
---|
[9e406b5] | 688 | # Bring over the items from the Makefile.tmp
|
---|
| 689 | cat $MKFILE.tmp >> $MKFILE
|
---|
| 690 | rm $MKFILE.tmp
|
---|
| 691 | echo -ne "done\n"
|
---|
[f8de156] | 692 | }
|
---|
| 693 |
|
---|
[88dcce5] | 694 | run_make() {
|
---|
[d310939] | 695 | # Test if make must be run.
|
---|
| 696 | if [ "$RUNMAKE" = "1" ] ; then
|
---|
| 697 | # Build the system
|
---|
| 698 | if [ -e $MKFILE ] ; then
|
---|
[e3e1db0] | 699 | echo -ne "Building the LFS system...\n"
|
---|
[d310939] | 700 | cd $JHALFSDIR && make
|
---|
| 701 | echo -ne "done\n"
|
---|
| 702 | fi
|
---|
[88dcce5] | 703 | fi
|
---|
| 704 | }
|
---|
[1236262] | 705 |
|
---|
[4dafc45] | 706 | if [ ! -d $JHALFSDIR ] ; then
|
---|
[557fe91] | 707 | mkdir -p $JHALFSDIR
|
---|
[1236262] | 708 | fi
|
---|
| 709 |
|
---|
[4c62c61] | 710 | if [ ! -d $LOGDIR ] ; then
|
---|
| 711 | mkdir $LOGDIR
|
---|
[a5e49c6] | 712 | fi
|
---|
| 713 |
|
---|
[4c62c61] | 714 | >$LOGDIR/$LOG
|
---|
[409488e] | 715 |
|
---|
| 716 | if [ "$PWD" != "$JHALFSDIR" ] ; then
|
---|
[0fc4c75] | 717 | cp $0 $XSL $FNC $JHALFSDIR/
|
---|
[409488e] | 718 | fi
|
---|
| 719 |
|
---|
[1236262] | 720 | get_book
|
---|
[f8de156] | 721 | build_Makefile
|
---|
[71642ef] | 722 | run_make
|
---|