[fbb6b78] | 1 | #!/bin/sh
|
---|
[1236262] | 2 |
|
---|
| 3 | version="
|
---|
[63b2859] | 4 | jhalfs development
|
---|
| 5 |
|
---|
[1236262] | 6 | 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
|
---|
| 18 | -V, --version print version number, then exit
|
---|
| 19 | -L, --LFS-version=VER use VER version of the LFS book
|
---|
| 20 | -d --directory=DIR use DIR directory for building LFS; all files
|
---|
| 21 | jhalfs produces will be in the directory
|
---|
| 22 | DIR/jhalfs
|
---|
| 23 | -D, --download-client=CLIENT use CLIENT as the program for retrieving
|
---|
| 24 | packages
|
---|
[1236262] | 25 | "
|
---|
| 26 |
|
---|
| 27 | help="\
|
---|
| 28 | Try '$0 --help' for more information."
|
---|
| 29 |
|
---|
| 30 | exit_missing_arg="\
|
---|
| 31 | echo \"Option '\$1' requires an argument\" >&2
|
---|
| 32 | echo \"\$help\" >&2
|
---|
| 33 | exit 1"
|
---|
| 34 |
|
---|
| 35 | no_dl_client="\
|
---|
| 36 | echo \"Could not find a way to download the LFS sources.\" >&2
|
---|
| 37 | echo \"Attempting to continue.\" >&2"
|
---|
| 38 |
|
---|
| 39 | while test $# -gt 0 ; do
|
---|
[557fe91] | 40 | case $1 in
|
---|
| 41 | --version | -V )
|
---|
| 42 | echo "$version"
|
---|
| 43 | exit 0
|
---|
| 44 | ;;
|
---|
| 45 |
|
---|
| 46 | --help | -h )
|
---|
| 47 | echo "$usage"
|
---|
| 48 | exit 0
|
---|
| 49 | ;;
|
---|
| 50 |
|
---|
| 51 | --LFS-version | -L )
|
---|
| 52 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 53 | shift
|
---|
| 54 | case $1 in
|
---|
| 55 | dev* | SVN | trunk )
|
---|
| 56 | LFSVRS=development
|
---|
| 57 | ;;
|
---|
| 58 | * )
|
---|
| 59 | echo "$1 is an unsupported version at this time."
|
---|
| 60 | exit 1
|
---|
| 61 | ;;
|
---|
| 62 | esac
|
---|
| 63 | shift
|
---|
| 64 | ;;
|
---|
| 65 |
|
---|
| 66 | --directory | -d )
|
---|
| 67 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 68 | shift
|
---|
| 69 | BUILDDIR=$1
|
---|
| 70 | shift
|
---|
| 71 | ;;
|
---|
| 72 |
|
---|
| 73 | --download-client | -D )
|
---|
| 74 | test $# = 1 && eval "$exit_missing_arg"
|
---|
| 75 | shift
|
---|
| 76 | DL=$1
|
---|
| 77 | shift
|
---|
| 78 | ;;
|
---|
| 79 |
|
---|
| 80 | * )
|
---|
| 81 | echo "$usage"
|
---|
| 82 | exit 1
|
---|
| 83 | ;;
|
---|
| 84 | esac
|
---|
[1236262] | 85 | done
|
---|
| 86 |
|
---|
| 87 | # Test to make sure we're running the build as root
|
---|
| 88 |
|
---|
| 89 | if [ "$UID" != "0" ] ; then
|
---|
[557fe91] | 90 | echo "You must be logged in as root to successfully build LFS."
|
---|
| 91 | exit 1
|
---|
[1236262] | 92 | fi
|
---|
| 93 |
|
---|
| 94 | # Find the download client to use, if not already specified.
|
---|
| 95 |
|
---|
| 96 | if [ -z $DL ] ; then
|
---|
| 97 | if [ `type -p wget` ] ; then
|
---|
[557fe91] | 98 | DL=wget
|
---|
[1236262] | 99 | elif [ `type -p curl` ] ; then
|
---|
[557fe91] | 100 | DL=curl
|
---|
[1236262] | 101 | else
|
---|
[557fe91] | 102 | eval "$no_dl_client"
|
---|
[1236262] | 103 | fi
|
---|
| 104 | fi
|
---|
| 105 |
|
---|
| 106 | SVN="svn://svn.linuxfromscratch.org"
|
---|
| 107 | HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
|
---|
[48d7968] | 108 | if [ -z $BUILDDIR ] ; then BUILDDIR=/mnt/lfs ; fi
|
---|
[4dafc45] | 109 | JHALFSDIR=$BUILDDIR/jhalfs
|
---|
[1236262] | 110 | LOG=build.log
|
---|
[f8de156] | 111 | MKFILE=$JHALFSDIR/Makefile
|
---|
[557fe91] | 112 | XSL=dump-commands.xsl
|
---|
[1236262] | 113 |
|
---|
| 114 | get_book() {
|
---|
| 115 | # Check for Subversion instead of just letting the script hit 'svn' and fail.
|
---|
| 116 | test `type -p svn` || eval "echo \"This feature requires Subversion.\"
|
---|
[557fe91] | 117 | exit 1"
|
---|
[4dafc45] | 118 | cd $JHALFSDIR
|
---|
[fbb6b78] | 119 |
|
---|
[1236262] | 120 | # Test to make sure the LFS version is set
|
---|
| 121 | if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
|
---|
| 122 | echo -n "Downloading the LFS Book, version $LFSVRS... "
|
---|
| 123 |
|
---|
| 124 | # Grab the LFS book fresh if it's missing, otherwise, update it from the
|
---|
| 125 | # repo. If we've already extracted the commands, move on to getting the
|
---|
| 126 | # sources.
|
---|
| 127 | if [ -d lfs-$LFSVRS ] ; then
|
---|
[557fe91] | 128 | cd lfs-$LFSVRS
|
---|
| 129 | if svn up | grep -q At && test -d $JHALFSDIR/commands && \
|
---|
| 130 | test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
|
---|
| 131 | echo -ne "done\n"
|
---|
| 132 | get_sources
|
---|
| 133 | else
|
---|
| 134 | echo -ne "done\n"
|
---|
| 135 | extract_commands
|
---|
| 136 | fi
|
---|
[1236262] | 137 | else
|
---|
[557fe91] | 138 | if [ $LFSVRS = development ] ; then
|
---|
| 139 | svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$JHALFSDIR/$LOG 2>&1
|
---|
| 140 | else
|
---|
| 141 | svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$JHALFSDIR/$LOG 2>&1
|
---|
| 142 | fi
|
---|
| 143 | echo -ne "done\n"
|
---|
| 144 | extract_commands
|
---|
[1236262] | 145 | fi
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | extract_commands() {
|
---|
| 149 | # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
|
---|
| 150 | test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
|
---|
[557fe91] | 151 | exit 1"
|
---|
[4dafc45] | 152 | cd $JHALFSDIR
|
---|
[1236262] | 153 |
|
---|
| 154 | # Start clean
|
---|
| 155 | if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
|
---|
| 156 | echo -n "Extracting commands... "
|
---|
| 157 |
|
---|
[dc2fee8] | 158 | # Dump the commands in shell script form from the LFS book.
|
---|
[557fe91] | 159 | xsltproc --nonet --xinclude -o ./commands/ $XSL \
|
---|
| 160 | lfs-$LFSVRS/index.xml >>$JHALFSDIR/$LOG 2>&1
|
---|
[1236262] | 161 |
|
---|
| 162 | # Grab the patches and package names.
|
---|
[4dafc45] | 163 | cd $JHALFSDIR
|
---|
[1236262] | 164 | for i in patches packages ; do rm -f $i ; done
|
---|
| 165 | grep "\-version" lfs-$LFSVRS/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
|
---|
[557fe91] | 166 | -e '/generic/d' >> packages
|
---|
[1236262] | 167 | grep "ENTITY" lfs-$LFSVRS/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
|
---|
| 168 |
|
---|
| 169 | # Done. Moving on...
|
---|
| 170 | echo -ne "done\n"
|
---|
| 171 | get_sources
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | download() {
|
---|
| 175 | cd $BUILDDIR/sources
|
---|
| 176 |
|
---|
| 177 | # Hackish fix for the bash-doc package that doesn't conform
|
---|
| 178 | # to norms in the URL scheme.
|
---|
| 179 | DIR=`echo $1 | sed 's@-doc@@'`
|
---|
| 180 |
|
---|
| 181 | # Find the md5 sum for this package.
|
---|
| 182 | if [ $2 != MD5SUMS ] ; then MD5=`grep " $2" MD5SUMS` ; fi
|
---|
| 183 |
|
---|
| 184 | if [ ! -f $2 ] ; then
|
---|
[557fe91] | 185 | case $DL in
|
---|
| 186 | wget )
|
---|
| 187 | wget $HTTP/$DIR/$2
|
---|
| 188 | ;;
|
---|
| 189 | curl )
|
---|
| 190 | `curl -# $HTTP/$DIR/$2 -o $2`
|
---|
| 191 | ;;
|
---|
| 192 | * )
|
---|
| 193 | echo "$DL not supported at this time."
|
---|
| 194 | ;;
|
---|
| 195 | esac
|
---|
[1236262] | 196 | elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
|
---|
[557fe91] | 197 | case $DL in
|
---|
| 198 | wget )
|
---|
| 199 | wget -c $HTTP/$DIR/$2
|
---|
| 200 | ;;
|
---|
| 201 | curl )
|
---|
| 202 | `curl -# -C - $HTTP/$DIR/$2 -o $2`
|
---|
| 203 | ;;
|
---|
| 204 | * )
|
---|
| 205 | echo "$DL not supported at this time."
|
---|
| 206 | ;;
|
---|
| 207 | esac
|
---|
[1236262] | 208 | fi
|
---|
| 209 | if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
|
---|
| 210 | exit 1
|
---|
| 211 | fi
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | get_sources() {
|
---|
| 215 |
|
---|
[f8de156] | 216 | # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
|
---|
[1236262] | 217 | # separates each iteration by lines. It is necessary to have the second
|
---|
| 218 | # ' on the next line.
|
---|
| 219 | IFS='
|
---|
| 220 | '
|
---|
| 221 |
|
---|
| 222 | if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
|
---|
| 223 | cd $BUILDDIR/sources
|
---|
| 224 | if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
|
---|
| 225 |
|
---|
| 226 | download "" MD5SUMS
|
---|
| 227 |
|
---|
| 228 | # Iterate through each package and grab it, along with any patches it needs.
|
---|
[4dafc45] | 229 | for i in `cat $JHALFSDIR/packages` ; do
|
---|
[1236262] | 230 | PKG=`echo $i | sed 's/-version.*//'`
|
---|
[fbb6b78] | 231 |
|
---|
[1236262] | 232 | # Someone used some silly entities right next to the valid package entities.
|
---|
| 233 | if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
|
---|
| 234 |
|
---|
| 235 | VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
|
---|
| 236 | if [ "$PKG" = "tcl" ] ; then
|
---|
[557fe91] | 237 | FILE="$PKG$VRS-src.tar.bz2"
|
---|
[1236262] | 238 | else
|
---|
[557fe91] | 239 | FILE="$PKG-$VRS.tar.bz2"
|
---|
[1236262] | 240 | fi
|
---|
| 241 | download $PKG $FILE
|
---|
[4dafc45] | 242 | for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
|
---|
[557fe91] | 243 | PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
|
---|
| 244 | download $PKG $PATCH
|
---|
[fbb6b78] | 245 | done
|
---|
[1236262] | 246 | done
|
---|
| 247 | }
|
---|
| 248 |
|
---|
[f8de156] | 249 | build_Makefile() {
|
---|
[9e406b5] | 250 | echo -n "Creating Makefile... "
|
---|
[f8de156] | 251 | cd $JHALFSDIR/commands
|
---|
[fbb6b78] | 252 |
|
---|
[f8de156] | 253 | # Start with a clean Makefile.tmp file
|
---|
| 254 | >$MKFILE.tmp
|
---|
| 255 |
|
---|
[0bad6ba] | 256 | for file in chapter05/* ; do
|
---|
[63b2859] | 257 | # Keep the script file name
|
---|
| 258 | i=`basename $file`
|
---|
| 259 |
|
---|
| 260 | # First append each name of the script files to a list (this will become
|
---|
[557fe91] | 261 | # the names of the targets in the Makefile
|
---|
[0bad6ba] | 262 | chapter5="$chapter5 $i"
|
---|
[557fe91] | 263 |
|
---|
| 264 | # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
|
---|
| 265 | # and binutils in chapter 5)
|
---|
| 266 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
|
---|
| 267 |
|
---|
| 268 | # Drop in the name of the target on a new line.
|
---|
| 269 | echo -e "\n$i:" >> $MKFILE.tmp
|
---|
| 270 |
|
---|
| 271 | # Find the version of the command files, if it corresponds with the building of
|
---|
| 272 | # a specific package
|
---|
| 273 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
| 274 |
|
---|
| 275 | # If $vrs isn't empty, we've got a package...
|
---|
| 276 | if [ "$vrs" != "" ] ; then
|
---|
| 277 | if [ "$name" = "tcl" ] ; then
|
---|
| 278 | FILE="$name$vrs-src.tar.bz2"
|
---|
| 279 | else
|
---|
| 280 | FILE="$name-$vrs.tar.bz2"
|
---|
| 281 | fi
|
---|
| 282 |
|
---|
| 283 | # Insert instructions for unpacking the package and changing directories
|
---|
[0bad6ba] | 284 | echo -e "\t\$(call unpack-lfs,$FILE) && \\" >> $MKFILE.tmp
|
---|
[557fe91] | 285 | echo -e "\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
[0bad6ba] | 286 | echo -e "\tcd \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
|
---|
[557fe91] | 287 | fi
|
---|
| 288 |
|
---|
[0bad6ba] | 289 | # Insert the script run
|
---|
| 290 | echo -e "\tsu lfs -c \". /home/lfs/.bashrc && $JHALFSDIR/commands/$file\" && \\" >> $MKFILE.tmp
|
---|
[557fe91] | 291 |
|
---|
| 292 | # Include a touch of the target name so make can check if it's already been made.
|
---|
| 293 | echo -e "\ttouch \$@" >> $MKFILE.tmp
|
---|
[f8de156] | 294 | done
|
---|
[9e406b5] | 295 |
|
---|
[fbb6b78] | 296 | # Stick a variable and some defines at the top of the real makefile
|
---|
[9e406b5] | 297 | echo "export SRC := /sources" > $MKFILE
|
---|
| 298 | echo "export LFS := $BUILDDIR" >> $MKFILE
|
---|
[0bad6ba] | 299 | echo "define unpack-lfs" >> $MKFILE
|
---|
| 300 | echo -e "\t@cd \$(LFS)\$(SRC) ; tar -xvjf \$(1) > /tmp/unpacked" >> $MKFILE
|
---|
| 301 | echo -e "endef\n" >> $MKFILE
|
---|
[9e406b5] | 302 | echo "define unpack" >> $MKFILE
|
---|
| 303 | echo -e "\t@cd \$(SRC) ; tar -xvf \$(1) > /tmp/unpacked" >> $MKFILE
|
---|
| 304 | echo -e "endef\n" >> $MKFILE
|
---|
| 305 |
|
---|
[0bad6ba] | 306 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
| 307 | # as a dependency.
|
---|
| 308 | echo -e "all: chapter4 chapter5\n" >> $MKFILE
|
---|
| 309 | echo -e "chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment\n" >> $MKFILE
|
---|
| 310 | echo -e "chapter5: $chapter5\n" >> $MKFILE
|
---|
| 311 |
|
---|
| 312 | # Clean targets
|
---|
| 313 | echo "clean-chapter4:" >> $MKFILE
|
---|
| 314 | echo -e "\tuserdel lfs && \\" >> $MKFILE
|
---|
| 315 | echo -e "\trm -r /home/lfs && \\" >> $MKFILE
|
---|
| 316 | echo -e "\trm -r \$(LFS)/tools && \\" >> $MKFILE
|
---|
| 317 | echo -e "\trm /tools" >> $MKFILE
|
---|
| 318 | echo -e "\trm $JHALFSDIR/02*\n" >> $MKFILE
|
---|
| 319 |
|
---|
| 320 | # The chapter4 sub-targets are hard-coded to can create the lfs user and
|
---|
| 321 | # environment, and to make the scripts executables (as part of 021-addinguser).
|
---|
| 322 | echo "020-creatingtoolsdir:" >> $MKFILE
|
---|
| 323 | echo -e "\tmkdir \$(LFS)/tools && \\" >> $MKFILE
|
---|
| 324 | echo -e "\tln -s \$(LFS)/tools / && \\" >> $MKFILE
|
---|
| 325 | echo -e "\ttouch \$@\n" >> $MKFILE
|
---|
| 326 |
|
---|
| 327 | echo "021-addinguser:" >> $MKFILE
|
---|
| 328 | echo -e "\tgroupadd lfs && \\" >> $MKFILE
|
---|
| 329 | echo -e "\tuseradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\" >> $MKFILE
|
---|
| 330 | echo -e "\tchown lfs \$(LFS)/tools && \\" >> $MKFILE
|
---|
| 331 | echo -e "\tchown lfs \$(LFS)/sources && \\" >> $MKFILE
|
---|
| 332 | # Make the scripts executables
|
---|
| 333 | echo -e "\tchmod -R +x $JHALFSDIR/commands && \\" >> $MKFILE
|
---|
| 334 | echo -e "\ttouch \$@\n" >> $MKFILE
|
---|
| 335 |
|
---|
| 336 | echo "022-settingenvironment:" >> $MKFILE
|
---|
| 337 | echo -e "\techo \"exec env -i HOME=\\\$\$HOME TERM=\\\$\$TERM PS1='\u:\w\$$ ' /bin/bash\" > /home/lfs/.bash_profile && \\" >> $MKFILE
|
---|
| 338 | echo -e "\techo \"set +h\" > /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
| 339 | echo -e "\techo \"umask 022\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
| 340 | echo -e "\techo \"LFS=/mnt/lfs\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
| 341 | echo -e "\techo \"LC_ALL=POSIX\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
| 342 | echo -e "\techo \"PATH=/tools/bin:/bin:/usr/bin\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
| 343 | echo -e "\techo \"export LFS LC_ALL PATH\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
| 344 | echo -e "\tchown lfs /home/lfs/.bash* && \\" >> $MKFILE
|
---|
| 345 | echo -e "\ttouch \$@\n" >> $MKFILE
|
---|
| 346 |
|
---|
[9e406b5] | 347 |
|
---|
| 348 | # Bring over the items from the Makefile.tmp
|
---|
| 349 | cat $MKFILE.tmp >> $MKFILE
|
---|
| 350 | rm $MKFILE.tmp
|
---|
| 351 | echo -ne "done\n"
|
---|
[f8de156] | 352 | }
|
---|
| 353 |
|
---|
[1236262] | 354 |
|
---|
[4dafc45] | 355 | if [ ! -d $JHALFSDIR ] ; then
|
---|
[557fe91] | 356 | mkdir -p $JHALFSDIR
|
---|
[1236262] | 357 | fi
|
---|
| 358 |
|
---|
[4dafc45] | 359 | >$JHALFSDIR/$LOG
|
---|
[409488e] | 360 |
|
---|
| 361 | if [ "$PWD" != "$JHALFSDIR" ] ; then
|
---|
| 362 | cp $0 $XSL $JHALFSDIR/
|
---|
| 363 | fi
|
---|
| 364 |
|
---|
[1236262] | 365 | get_book
|
---|
[f8de156] | 366 | build_Makefile
|
---|