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