[0170229] | 1 | #!/bin/sh
|
---|
| 2 | set -e # Enable error trapping
|
---|
| 3 |
|
---|
[57ca090] | 4 | # $Id$
|
---|
[0170229] | 5 |
|
---|
| 6 | ###################################
|
---|
| 7 | ### FUNCTIONS ###
|
---|
| 8 | ###################################
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | #----------------------------#
|
---|
[389fe2a] | 12 | chapter3_Makefiles() { # Initialization of the system
|
---|
[0170229] | 13 | #----------------------------#
|
---|
| 14 | local TARGET LOADER
|
---|
| 15 |
|
---|
[e10232b] | 16 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter3${R_arrow}"
|
---|
[0170229] | 17 |
|
---|
| 18 | # Define a few model dependant variables
|
---|
| 19 | if [[ ${MODEL} = "uclibc" ]]; then
|
---|
| 20 | TARGET="tools-linux-uclibc"; LOADER="ld-uClibc.so.0"
|
---|
| 21 | else
|
---|
| 22 | TARGET="tools-linux-gnu"; LOADER="ld-linux.so.2"
|
---|
[5c5a010] | 23 | fi
|
---|
[0170229] | 24 |
|
---|
[5c5a010] | 25 | # NOTE: We use the lfs username and groupname also in HLFS
|
---|
| 26 | # If /home/lfs is already present in the host, we asume that the
|
---|
| 27 | # lfs user and group are also presents in the host, and a backup
|
---|
[0170229] | 28 | # of their bash init files is made.
|
---|
| 29 | (
|
---|
| 30 | cat << EOF
|
---|
| 31 | 020-creatingtoolsdir:
|
---|
| 32 | @\$(call echo_message, Building)
|
---|
[9199a13] | 33 | @mkdir \$(MOUNT_PT)/tools && \\
|
---|
| 34 | rm -f /tools && \\
|
---|
| 35 | ln -s \$(MOUNT_PT)/tools /
|
---|
[0170229] | 36 | @if [ ! -d \$(MOUNT_PT)/sources ]; then \\
|
---|
| 37 | mkdir \$(MOUNT_PT)/sources; \\
|
---|
| 38 | fi;
|
---|
| 39 | @chmod a+wt \$(MOUNT_PT)/sources && \\
|
---|
[9199a13] | 40 | touch \$@ && \\
|
---|
| 41 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
| 42 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
[0170229] | 43 |
|
---|
| 44 | 021-addinguser: 020-creatingtoolsdir
|
---|
| 45 | @\$(call echo_message, Building)
|
---|
| 46 | @if [ ! -d /home/lfs ]; then \\
|
---|
| 47 | groupadd lfs; \\
|
---|
| 48 | useradd -s /bin/bash -g lfs -m -k /dev/null lfs; \\
|
---|
| 49 | else \\
|
---|
| 50 | touch user-lfs-exist; \\
|
---|
| 51 | fi;
|
---|
| 52 | @chown lfs \$(MOUNT_PT)/tools && \\
|
---|
| 53 | chown lfs \$(MOUNT_PT)/sources && \\
|
---|
[9199a13] | 54 | touch \$@ && \\
|
---|
| 55 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
| 56 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
[0170229] | 57 |
|
---|
| 58 | 022-settingenvironment: 021-addinguser
|
---|
| 59 | @\$(call echo_message, Building)
|
---|
| 60 | @if [ -f /home/lfs/.bashrc -a ! -f /home/lfs/.bashrc.XXX ]; then \\
|
---|
[9199a13] | 61 | mv /home/lfs/.bashrc /home/lfs/.bashrc.XXX; \\
|
---|
[0170229] | 62 | fi;
|
---|
| 63 | @if [ -f /home/lfs/.bash_profile -a ! -f /home/lfs/.bash_profile.XXX ]; then \\
|
---|
[9199a13] | 64 | mv /home/lfs/.bash_profile /home/lfs/.bash_profile.XXX; \\
|
---|
[0170229] | 65 | fi;
|
---|
| 66 | @echo "set +h" > /home/lfs/.bashrc && \\
|
---|
| 67 | echo "umask 022" >> /home/lfs/.bashrc && \\
|
---|
| 68 | echo "HLFS=\$(MOUNT_PT)" >> /home/lfs/.bashrc && \\
|
---|
| 69 | echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
|
---|
| 70 | echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
|
---|
| 71 | echo "export HLFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
|
---|
| 72 | echo "" >> /home/lfs/.bashrc && \\
|
---|
| 73 | echo "target=$(uname -m)-${TARGET}" >> /home/lfs/.bashrc && \\
|
---|
| 74 | echo "ldso=/tools/lib/${LOADER}" >> /home/lfs/.bashrc && \\
|
---|
| 75 | echo "export target ldso" >> /home/lfs/.bashrc && \\
|
---|
| 76 | echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
|
---|
| 77 | chown lfs:lfs /home/lfs/.bashrc && \\
|
---|
| 78 | touch envars && \\
|
---|
[9199a13] | 79 | touch \$@ && \\
|
---|
| 80 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
| 81 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
[0170229] | 82 | EOF
|
---|
| 83 | ) >> $MKFILE.tmp
|
---|
| 84 |
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | #----------------------------#
|
---|
| 88 | chapter5_Makefiles() { # Bootstrap or temptools phase
|
---|
| 89 | #----------------------------#
|
---|
| 90 | local file
|
---|
| 91 | local this_script
|
---|
[57ca090] | 92 |
|
---|
[e10232b] | 93 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5${R_arrow}"
|
---|
[0170229] | 94 |
|
---|
| 95 | for file in chapter05/* ; do
|
---|
| 96 | # Keep the script file name
|
---|
| 97 | this_script=`basename $file`
|
---|
| 98 |
|
---|
| 99 | # Skip this script depending on jhalfs.conf flags set.
|
---|
| 100 | case $this_script in
|
---|
| 101 | # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
|
---|
[821a2c6] | 102 | *tcl* ) [[ "$TEST" = "0" ]] && continue; ;;
|
---|
| 103 | *expect* ) [[ "$TEST" = "0" ]] && continue; ;;
|
---|
| 104 | *dejagnu* ) [[ "$TEST" = "0" ]] && continue; ;;
|
---|
[7d018d1] | 105 | # Nothing interestin in this script
|
---|
| 106 | *introduction* ) continue ;;
|
---|
[0170229] | 107 | # Test if the stripping phase must be skipped
|
---|
| 108 | *stripping* ) [[ "$STRIP" = "0" ]] && continue ;;
|
---|
| 109 | *) ;;
|
---|
| 110 | esac
|
---|
| 111 |
|
---|
| 112 | # First append each name of the script files to a list (this will become
|
---|
| 113 | # the names of the targets in the Makefile
|
---|
| 114 | chapter5="$chapter5 $this_script"
|
---|
| 115 |
|
---|
| 116 | # Grab the name of the target (minus the -headers or -cross in the case of gcc
|
---|
| 117 | # and binutils in chapter 5)
|
---|
| 118 | name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-cross@@' -e 's@-headers@@'`
|
---|
| 119 |
|
---|
[5c5a010] | 120 | # Adjust 'name'
|
---|
[0170229] | 121 | case $name in
|
---|
[5c5a010] | 122 | linux-libc) name=linux-libc-headers ;;
|
---|
[0170229] | 123 | esac
|
---|
| 124 |
|
---|
| 125 | # Set the dependency for the first target.
|
---|
| 126 | if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | #--------------------------------------------------------------------#
|
---|
| 130 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
| 131 | #--------------------------------------------------------------------#
|
---|
| 132 | #
|
---|
| 133 | # Drop in the name of the target on a new line, and the previous target
|
---|
| 134 | # as a dependency. Also call the echo_message function.
|
---|
| 135 | wrt_target "$this_script" "$PREV"
|
---|
| 136 |
|
---|
| 137 | # Find the version of the command files, if it corresponds with the building of
|
---|
| 138 | # a specific package
|
---|
| 139 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
| 140 | # If $vrs isn't empty, we've got a package...
|
---|
| 141 | if [ "$vrs" != "" ] ; then
|
---|
| 142 | # Deal with non-standard names
|
---|
| 143 | case $name in
|
---|
[c3c4e1d] | 144 | tcl) FILE="$name$vrs-src.tar.*" ;;
|
---|
| 145 | uclibc) FILE="uClibc-$vrs.tar.*" ;;
|
---|
| 146 | gcc) FILE="gcc-core-$vrs.tar.*" ;;
|
---|
| 147 | *) FILE="$name-$vrs.tar.*" ;;
|
---|
[0170229] | 148 | esac
|
---|
[29f9ec8] | 149 | # Insert instructions for unpacking the package and to set the PKGDIR variable.
|
---|
[460ea63] | 150 | case $this_script in
|
---|
| 151 | *binutils* )
|
---|
[e35e794] | 152 | wrt_unpack "$FILE" 1 ;; # Do not delete an existing package directories
|
---|
| 153 | *)
|
---|
| 154 | wrt_unpack "$FILE" ;;
|
---|
[460ea63] | 155 | esac
|
---|
[e35e794] | 156 | # If the testsuites must be run, initialize the log file
|
---|
| 157 | [[ "$TEST" = "3" ]] && wrt_test_log "${this_script}"
|
---|
| 158 | # If using optimizations, write the instructions
|
---|
[c205656] | 159 | [[ "$OPTIMIZE" = "2" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
|
---|
[29f9ec8] | 160 | fi
|
---|
[0170229] | 161 |
|
---|
| 162 | case $this_script in
|
---|
| 163 | *binutils* ) # Dump the path to sources directory for later removal
|
---|
[2fbc503] | 164 | (
|
---|
| 165 | cat << EOF
|
---|
[460ea63] | 166 | @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
[2fbc503] | 167 | echo "\$(MOUNT_PT)\$(SRC)/\$\$ROOT" >> sources-dir
|
---|
| 168 | EOF
|
---|
| 169 | ) >> $MKFILE.tmp
|
---|
[0170229] | 170 | ;;
|
---|
| 171 | *adjusting* ) # For the Adjusting phase we must to cd to the binutils-build directory.
|
---|
| 172 | echo -e '\t@echo "export PKGDIR=$(MOUNT_PT)$(SRC)/binutils-build" > envars' >> $MKFILE.tmp
|
---|
| 173 | ;;
|
---|
| 174 | esac
|
---|
| 175 |
|
---|
| 176 | # Insert date and disk usage at the top of the log file, the script run
|
---|
| 177 | # and date and disk usage again at the bottom of the log file.
|
---|
| 178 | wrt_run_as_su "${this_script}" "${file}"
|
---|
| 179 |
|
---|
| 180 | # Remove the build directory(ies) except if the package build fails
|
---|
| 181 | # (so we can review config.cache, config.log, etc.)
|
---|
| 182 | # For Binutils the sources must be retained for some time.
|
---|
| 183 | if [ "$vrs" != "" ] ; then
|
---|
[5f4d08f] | 184 | case "${this_script}" in
|
---|
| 185 | *binutils*) : # do NOTHING
|
---|
| 186 | ;;
|
---|
| 187 | *) wrt_remove_build_dirs "$name"
|
---|
| 188 | ;;
|
---|
| 189 | esac
|
---|
[0170229] | 190 | fi
|
---|
| 191 |
|
---|
| 192 | # Remove the Binutils pass 1 sources after a successful Adjusting phase.
|
---|
[5f4d08f] | 193 | case "${this_script}" in
|
---|
| 194 | *adjusting*)
|
---|
[0170229] | 195 | (
|
---|
| 196 | cat << EOF
|
---|
| 197 | @rm -r \`cat sources-dir\` && \\
|
---|
| 198 | rm -r \$(MOUNT_PT)\$(SRC)/binutils-build && \\
|
---|
| 199 | rm sources-dir
|
---|
| 200 | EOF
|
---|
| 201 | ) >> $MKFILE.tmp
|
---|
[5f4d08f] | 202 | ;;
|
---|
| 203 | esac
|
---|
[0170229] | 204 |
|
---|
| 205 | # Include a touch of the target name so make can check if it's already been made.
|
---|
[9199a13] | 206 | wrt_touch
|
---|
[0170229] | 207 | #
|
---|
| 208 | #--------------------------------------------------------------------#
|
---|
| 209 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
| 210 | #--------------------------------------------------------------------#
|
---|
| 211 |
|
---|
| 212 | # Keep the script file name for Makefile dependencies.
|
---|
| 213 | PREV=$this_script
|
---|
| 214 | done # end for file in chapter05/*
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 | #----------------------------#
|
---|
| 219 | chapter6_Makefiles() { # sysroot or chroot build phase
|
---|
| 220 | #----------------------------#
|
---|
| 221 | local TARGET LOADER
|
---|
| 222 | local file
|
---|
| 223 | local this_script
|
---|
[c483858] | 224 | # Set envars and scripts for iteration targets
|
---|
| 225 | LOGS="" # Start with an empty global LOGS envar
|
---|
| 226 | if [[ -z "$1" ]] ; then
|
---|
| 227 | local N=""
|
---|
| 228 | else
|
---|
| 229 | local N=-build_$1
|
---|
| 230 | local chapter6=""
|
---|
| 231 | mkdir chapter06$N
|
---|
| 232 | cp chapter06/* chapter06$N
|
---|
| 233 | for script in chapter06$N/* ; do
|
---|
| 234 | # Overwrite existing symlinks, files, and dirs
|
---|
| 235 | sed -e 's/ln -s /ln -sf /g' \
|
---|
| 236 | -e 's/^mv /&-f/g' -i ${script}
|
---|
| 237 | done
|
---|
| 238 | # Remove Bzip2 binaries before make install
|
---|
| 239 | sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i chapter06$N/*-bzip2
|
---|
| 240 | # Fix how Module-Init-Tools do the install target
|
---|
| 241 | sed -e 's@make install@make INSTALL=install install@' -i chapter06$N/*-module-init-tools
|
---|
| 242 | # Delete *old Readline libraries just after make install
|
---|
| 243 | sed -e 's@make install@&\nrm -v /lib/lib{history,readline}*old@' -i chapter06$N/*-readline
|
---|
| 244 | # Don't readd already existing groups
|
---|
| 245 | sed -e '/groupadd/d' -i chapter06$N/*-udev
|
---|
| 246 | fi
|
---|
[0170229] | 247 |
|
---|
[c483858] | 248 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N${R_arrow}"
|
---|
[0170229] | 249 | #
|
---|
| 250 | # Set these definitions early and only once
|
---|
| 251 | #
|
---|
| 252 | if [[ ${MODEL} = "uclibc" ]]; then
|
---|
| 253 | TARGET="pc-linux-uclibc"; LOADER="ld-uClibc.so.0"
|
---|
| 254 | else
|
---|
| 255 | TARGET="pc-linux-gnu"; LOADER="ld-linux.so.2"
|
---|
| 256 | fi
|
---|
| 257 |
|
---|
[c483858] | 258 | for file in chapter06$N/* ; do
|
---|
[0170229] | 259 | # Keep the script file name
|
---|
| 260 | this_script=`basename $file`
|
---|
| 261 |
|
---|
| 262 | # Skip this script depending on jhalfs.conf flags set.
|
---|
| 263 | case $this_script in
|
---|
| 264 | # We'll run the chroot commands differently than the others, so skip them in the
|
---|
| 265 | # dependencies and target creation.
|
---|
| 266 | *chroot* ) continue ;;
|
---|
| 267 | # Test if the stripping phase must be skipped
|
---|
| 268 | *-stripping* ) [[ "$STRIP" = "0" ]] && continue ;;
|
---|
| 269 | esac
|
---|
| 270 |
|
---|
| 271 | # Grab the name of the target
|
---|
| 272 | name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'`
|
---|
| 273 |
|
---|
[c483858] | 274 | # Find the version of the command files, if it corresponds with the building of
|
---|
| 275 | # a specific package
|
---|
| 276 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
| 277 |
|
---|
| 278 | if [[ "$vrs" = "" ]] && [[ -n "$N" ]] ; then
|
---|
| 279 | case "${this_script}" in
|
---|
| 280 | *stripping*) ;;
|
---|
| 281 | *) continue ;;
|
---|
| 282 | esac
|
---|
| 283 | fi
|
---|
| 284 |
|
---|
| 285 | # Append each name of the script files to a list (this will become
|
---|
| 286 | # the names of the targets in the Makefile
|
---|
| 287 | chapter6="$chapter6 ${this_script}${N}"
|
---|
| 288 |
|
---|
| 289 | # Append each name of the script files to a list (this will become
|
---|
[7635367] | 290 | # the names of the logs to be moved for each iteration)
|
---|
| 291 | LOGS="$LOGS ${this_script}"
|
---|
[c483858] | 292 |
|
---|
[0170229] | 293 | #
|
---|
[582feec] | 294 | # Sed replacement to fix some rm command that could fail.
|
---|
| 295 | # That should be fixed in the book sources.
|
---|
[0170229] | 296 | #
|
---|
| 297 | case $name in
|
---|
[582feec] | 298 | glibc)
|
---|
[c483858] | 299 | sed 's/rm /rm -f /' -i chapter06$N/$this_script
|
---|
[0170229] | 300 | ;;
|
---|
[582feec] | 301 | gcc)
|
---|
[c483858] | 302 | sed 's/rm /rm -f /' -i chapter06$N/$this_script
|
---|
[0170229] | 303 | ;;
|
---|
| 304 | esac
|
---|
| 305 |
|
---|
| 306 | #--------------------------------------------------------------------#
|
---|
| 307 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
| 308 | #--------------------------------------------------------------------#
|
---|
| 309 | #
|
---|
| 310 | # Drop in the name of the target on a new line, and the previous target
|
---|
| 311 | # as a dependency. Also call the echo_message function.
|
---|
[c483858] | 312 | wrt_target "${this_script}${N}" "$PREV"
|
---|
[0170229] | 313 |
|
---|
| 314 | # If $vrs isn't empty, we've got a package...
|
---|
| 315 | # Insert instructions for unpacking the package and changing directories
|
---|
| 316 | if [ "$vrs" != "" ] ; then
|
---|
| 317 | # Deal with non-standard names
|
---|
| 318 | case $name in
|
---|
| 319 | tcl) FILE="$name$vrs-src.tar.*" ;;
|
---|
| 320 | uclibc) FILE="uClibc-$vrs.tar.*" ;;
|
---|
| 321 | gcc) FILE="gcc-core-$vrs.tar.*" ;;
|
---|
| 322 | *) FILE="$name-$vrs.tar.*" ;;
|
---|
| 323 | esac
|
---|
| 324 | wrt_unpack2 "$FILE"
|
---|
| 325 | wrt_target_vars
|
---|
[e35e794] | 326 | # If the testsuites must be run, initialize the log file
|
---|
| 327 | case $name in
|
---|
| 328 | binutils | gcc | glibc )
|
---|
| 329 | [[ "$TEST" != "0" ]] && wrt_test_log2 "${this_script}"
|
---|
| 330 | ;;
|
---|
| 331 | * )
|
---|
| 332 | [[ "$TEST" = "2" ]] || [[ "$TEST" = "3" ]] && wrt_test_log2 "${this_script}"
|
---|
| 333 | ;;
|
---|
| 334 | esac
|
---|
| 335 | # If using optimizations, write the instructions
|
---|
[c205656] | 336 | [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
|
---|
[0170229] | 337 | fi
|
---|
| 338 |
|
---|
| 339 | case $this_script in
|
---|
| 340 | *readjusting*) # For the Re-Adjusting phase we must to cd to the binutils-build directory.
|
---|
| 341 | echo -e '\t@echo "export PKGDIR=$(SRC)/binutils-build" > envars' >> $MKFILE.tmp
|
---|
| 342 | ;;
|
---|
| 343 | esac
|
---|
| 344 |
|
---|
[582feec] | 345 | # In the mount of kernel filesystems we need to set LFS and not to use chroot.
|
---|
[5f4d08f] | 346 | case "${this_script}" in
|
---|
| 347 | *kernfs*)
|
---|
| 348 | wrt_run_as_root "${this_script}" "${file}"
|
---|
| 349 | ;;
|
---|
| 350 | *) # The rest of Chapter06
|
---|
| 351 | wrt_run_as_chroot1 "${this_script}" "${file}"
|
---|
| 352 | ;;
|
---|
| 353 | esac
|
---|
[0170229] | 354 | #
|
---|
| 355 | # Remove the build directory(ies) except if the package build fails.
|
---|
| 356 | if [ "$vrs" != "" ] ; then
|
---|
| 357 | wrt_remove_build_dirs "$name"
|
---|
| 358 | fi
|
---|
| 359 | #
|
---|
| 360 | # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
|
---|
[5f4d08f] | 361 | case "${this_script}" in
|
---|
| 362 | *readjusting*)
|
---|
[0170229] | 363 | (
|
---|
| 364 | cat << EOF
|
---|
| 365 | @rm -r \`cat sources-dir\` && \\
|
---|
| 366 | rm -r \$(MOUNT_PT)\$(SRC)/binutils-build && \\
|
---|
| 367 | rm sources-dir
|
---|
| 368 | EOF
|
---|
| 369 | ) >> $MKFILE.tmp
|
---|
[5f4d08f] | 370 | ;;
|
---|
| 371 | esac
|
---|
[0170229] | 372 |
|
---|
| 373 | # Include a touch of the target name so make can check if it's already been made.
|
---|
[9199a13] | 374 | wrt_touch
|
---|
[0170229] | 375 | #
|
---|
| 376 | #--------------------------------------------------------------------#
|
---|
| 377 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
| 378 | #--------------------------------------------------------------------#
|
---|
| 379 |
|
---|
| 380 | # Keep the script file name for Makefile dependencies.
|
---|
[c483858] | 381 | PREV=${this_script}${N}
|
---|
| 382 | # Set system_build envar for iteration targets
|
---|
| 383 | system_build=$chapter6
|
---|
[0170229] | 384 | done # end for file in chapter06/*
|
---|
| 385 |
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | #----------------------------#
|
---|
| 389 | chapter7_Makefiles() { # Create a bootable system.. kernel, bootscripts..etc
|
---|
| 390 | #----------------------------#
|
---|
| 391 | local file
|
---|
| 392 | local this_script
|
---|
[57ca090] | 393 |
|
---|
[e10232b] | 394 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7${R_arrow}"
|
---|
[0170229] | 395 | for file in chapter07/*; do
|
---|
| 396 | # Keep the script file name
|
---|
| 397 | this_script=`basename $file`
|
---|
| 398 |
|
---|
| 399 | # Grub must be configured manually.
|
---|
| 400 | # The filesystems can't be unmounted via Makefile and the user
|
---|
| 401 | # should enter the chroot environment to create the root
|
---|
| 402 | # password, edit several files and setup Grub.
|
---|
| 403 | case $this_script in
|
---|
[0ac273e] | 404 | *usage) continue ;; # Contains example commands
|
---|
[0170229] | 405 | *grub) continue ;;
|
---|
| 406 | *reboot) continue ;;
|
---|
| 407 | *console) continue ;; # Use the file generated by lfs-bootscripts
|
---|
| 408 |
|
---|
[57ca090] | 409 | *kernel)
|
---|
[821a2c6] | 410 | # If no .config file is supplied, the kernel build is skipped
|
---|
| 411 | [[ -z $CONFIG ]] && continue
|
---|
[1d756b0] | 412 | cp $CONFIG $BUILDDIR/sources/kernel-config
|
---|
[0170229] | 413 | ;;
|
---|
| 414 | esac
|
---|
| 415 |
|
---|
| 416 | # First append then name of the script file to a list (this will become
|
---|
| 417 | # the names of the targets in the Makefile
|
---|
| 418 | chapter7="$chapter7 $this_script"
|
---|
| 419 |
|
---|
| 420 | #--------------------------------------------------------------------#
|
---|
| 421 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
| 422 | #--------------------------------------------------------------------#
|
---|
| 423 | #
|
---|
| 424 | # Drop in the name of the target on a new line, and the previous target
|
---|
| 425 | # as a dependency. Also call the echo_message function.
|
---|
| 426 | wrt_target "$this_script" "$PREV"
|
---|
| 427 |
|
---|
[5f4d08f] | 428 | case "${this_script}" in
|
---|
[db187c74] | 429 | *bootscripts*)
|
---|
[5f4d08f] | 430 | vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
| 431 | FILE="lfs-bootscripts-$vrs.tar.*"
|
---|
| 432 | wrt_unpack2 "$FILE"
|
---|
| 433 | vrs=`grep "^blfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
| 434 | echo -e "\t@echo \"\$(MOUNT_PT)\$(SRC)/blfs-bootscripts-$vrs\" >> sources-dir" >> $MKFILE.tmp
|
---|
| 435 | ;;
|
---|
| 436 | esac
|
---|
[0170229] | 437 |
|
---|
[db187c74] | 438 | case "${this_script}" in
|
---|
[5f4d08f] | 439 | *fstab*) # Check if we have a real /etc/fstab file
|
---|
| 440 | if [[ -n "$FSTAB" ]] ; then
|
---|
| 441 | wrt_copy_fstab "$this_script"
|
---|
| 442 | else # Initialize the log and run the script
|
---|
| 443 | wrt_run_as_chroot2 "${this_script}" "${file}"
|
---|
| 444 | fi
|
---|
| 445 | ;;
|
---|
| 446 | *) # All other scripts
|
---|
| 447 | wrt_run_as_chroot2 "${this_script}" "${file}"
|
---|
| 448 | ;;
|
---|
| 449 | esac
|
---|
[0170229] | 450 |
|
---|
| 451 | # Remove the build directory except if the package build fails.
|
---|
[5f4d08f] | 452 | case "${this_script}" in
|
---|
| 453 | *bootscripts*)
|
---|
[0170229] | 454 | (
|
---|
| 455 | cat << EOF
|
---|
[460ea63] | 456 | @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
[0170229] | 457 | rm -r \$(MOUNT_PT)\$(SRC)/\$\$ROOT
|
---|
| 458 | @rm -r \`cat sources-dir\` && \\
|
---|
| 459 | rm sources-dir
|
---|
| 460 | EOF
|
---|
| 461 | ) >> $MKFILE.tmp
|
---|
[5f4d08f] | 462 | ;;
|
---|
| 463 | esac
|
---|
[0170229] | 464 |
|
---|
| 465 | # Include a touch of the target name so make can check if it's already been made.
|
---|
[9199a13] | 466 | wrt_touch
|
---|
[0170229] | 467 | #
|
---|
| 468 | #--------------------------------------------------------------------#
|
---|
| 469 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
| 470 | #--------------------------------------------------------------------#
|
---|
| 471 |
|
---|
| 472 | # Keep the script file name for Makefile dependencies.
|
---|
| 473 | PREV=$this_script
|
---|
| 474 | done # for file in chapter07/*
|
---|
[9e4b9a1] | 475 |
|
---|
| 476 | # Add SBU-disk_usage report target if required
|
---|
| 477 | if [[ "$REPORT" = "1" ]] ; then wrt_report ; fi
|
---|
[0170229] | 478 | }
|
---|
| 479 |
|
---|
| 480 |
|
---|
| 481 | #----------------------------#
|
---|
| 482 | build_Makefile() { # Construct a Makefile from the book scripts
|
---|
| 483 | #----------------------------#
|
---|
[a702b4d] | 484 | echo "Creating Makefile... ${BOLD}START${OFF}"
|
---|
[0170229] | 485 |
|
---|
| 486 | cd $JHALFSDIR/${PROGNAME}-commands
|
---|
| 487 | # Start with a clean Makefile.tmp file
|
---|
| 488 | >$MKFILE.tmp
|
---|
| 489 |
|
---|
[389fe2a] | 490 | chapter3_Makefiles
|
---|
[0170229] | 491 | chapter5_Makefiles
|
---|
| 492 | chapter6_Makefiles
|
---|
[c483858] | 493 | # Add the iterations targets, if needed
|
---|
| 494 | [[ "$COMPARE" != "0" ]] && wrt_compare_targets
|
---|
[0170229] | 495 | chapter7_Makefiles
|
---|
| 496 |
|
---|
| 497 | # Add a header, some variables and include the function file
|
---|
| 498 | # to the top of the real Makefile.
|
---|
| 499 | (
|
---|
| 500 | cat << EOF
|
---|
| 501 | $HEADER
|
---|
| 502 |
|
---|
| 503 | SRC= /sources
|
---|
| 504 | MOUNT_PT= $BUILDDIR
|
---|
[460ea63] | 505 | PKG_LST= $PKG_LST
|
---|
[0170229] | 506 |
|
---|
| 507 | include makefile-functions
|
---|
| 508 |
|
---|
| 509 | EOF
|
---|
| 510 | ) > $MKFILE
|
---|
| 511 |
|
---|
| 512 |
|
---|
| 513 | # Add chroot commands
|
---|
| 514 | i=1
|
---|
| 515 | for file in chapter06/*chroot* ; do
|
---|
| 516 | chroot=`cat $file | sed -e '/#!\/bin\/sh/d' \
|
---|
| 517 | -e '/^export/d' \
|
---|
| 518 | -e '/^logout/d' \
|
---|
| 519 | -e 's@ \\\@ @g' | tr -d '\n' | sed -e 's/ */ /g' \
|
---|
| 520 | -e 's|\\$|&&|g' \
|
---|
| 521 | -e 's|exit||g' \
|
---|
| 522 | -e 's|$| -c|' \
|
---|
| 523 | -e 's|"$$HLFS"|$(MOUNT_PT)|'\
|
---|
| 524 | -e 's|set -e||'`
|
---|
| 525 | echo -e "CHROOT$i= $chroot\n" >> $MKFILE
|
---|
| 526 | i=`expr $i + 1`
|
---|
| 527 | done
|
---|
| 528 |
|
---|
| 529 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
| 530 | # as a dependency.
|
---|
| 531 | (
|
---|
| 532 | cat << EOF
|
---|
[3a27393] | 533 | all: chapter3 chapter5 chapter6 chapter7 do-housekeeping
|
---|
[0170229] | 534 | @\$(call echo_finished,$VERSION)
|
---|
| 535 |
|
---|
[0ac273e] | 536 | chapter3: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
|
---|
[0170229] | 537 |
|
---|
[0ac273e] | 538 | chapter5: chapter3 $chapter5 restore-lfs-env
|
---|
[0170229] | 539 |
|
---|
| 540 | chapter6: chapter5 $chapter6
|
---|
| 541 |
|
---|
| 542 | chapter7: chapter6 $chapter7
|
---|
| 543 |
|
---|
| 544 | clean-all: clean
|
---|
[bc097cd] | 545 | rm -rf ./{hlfs-commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
|
---|
[0170229] | 546 |
|
---|
[0ac273e] | 547 | clean: clean-chapter7 clean-chapter6 clean-chapter5 clean-chapter3
|
---|
[0170229] | 548 |
|
---|
[0ac273e] | 549 | clean-chapter3:
|
---|
| 550 | -if [ ! -f user-lfs-exist ]; then \\
|
---|
| 551 | userdel lfs; \\
|
---|
| 552 | rm -rf /home/lfs; \\
|
---|
[0170229] | 553 | fi;
|
---|
| 554 | rm -rf \$(MOUNT_PT)/tools
|
---|
| 555 | rm -f /tools
|
---|
[0ac273e] | 556 | rm -f envars user-lfs-exist
|
---|
[0170229] | 557 | rm -f 02* logs/02*.log
|
---|
| 558 |
|
---|
| 559 | clean-chapter5:
|
---|
| 560 | rm -rf \$(MOUNT_PT)/tools/*
|
---|
[0ac273e] | 561 | rm -f $chapter5 restore-lfs-env sources-dir
|
---|
[0170229] | 562 | cd logs && rm -f $chapter5 && cd ..
|
---|
| 563 |
|
---|
| 564 | clean-chapter6:
|
---|
| 565 | -umount \$(MOUNT_PT)/sys
|
---|
| 566 | -umount \$(MOUNT_PT)/proc
|
---|
| 567 | -umount \$(MOUNT_PT)/dev/shm
|
---|
| 568 | -umount \$(MOUNT_PT)/dev/pts
|
---|
| 569 | -umount \$(MOUNT_PT)/dev
|
---|
| 570 | rm -rf \$(MOUNT_PT)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
|
---|
| 571 | rm -f $chapter6
|
---|
| 572 | cd logs && rm -f $chapter6 && cd ..
|
---|
| 573 |
|
---|
| 574 | clean-chapter7:
|
---|
| 575 | rm -f $chapter7
|
---|
| 576 | cd logs && rm -f $chapter7 && cd ..
|
---|
| 577 |
|
---|
[0ac273e] | 578 | restore-lfs-env:
|
---|
[0170229] | 579 | @\$(call echo_message, Building)
|
---|
| 580 | @if [ -f /home/lfs/.bashrc.XXX ]; then \\
|
---|
[9199a13] | 581 | mv -f /home/lfs/.bashrc.XXX /home/lfs/.bashrc; \\
|
---|
[0170229] | 582 | fi;
|
---|
[7d018d1] | 583 | @if [ -f /home/lfs/.bash_profile.XXX ]; then \\
|
---|
[9199a13] | 584 | mv /home/lfs/.bash_profile.XXX /home/lfs/.bash_profile; \\
|
---|
[0170229] | 585 | fi;
|
---|
| 586 | @chown lfs:lfs /home/lfs/.bash* && \\
|
---|
[9199a13] | 587 | touch \$@ && \\
|
---|
| 588 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
| 589 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
[0170229] | 590 |
|
---|
[3a27393] | 591 | do-housekeeping:
|
---|
[9199a13] | 592 | @-umount \$(MOUNT_PT)/dev/pts
|
---|
| 593 | @-umount \$(MOUNT_PT)/dev/shm
|
---|
| 594 | @-umount \$(MOUNT_PT)/dev
|
---|
| 595 | @-umount \$(MOUNT_PT)/sys
|
---|
| 596 | @-umount \$(MOUNT_PT)/proc
|
---|
| 597 | @-if [ ! -f user-lfs-exist ]; then \\
|
---|
[3a27393] | 598 | userdel lfs; \\
|
---|
| 599 | rm -rf /home/lfs; \\
|
---|
| 600 | fi;
|
---|
[460ea63] | 601 |
|
---|
[0170229] | 602 | EOF
|
---|
| 603 | ) >> $MKFILE
|
---|
| 604 |
|
---|
| 605 | # Bring over the items from the Makefile.tmp
|
---|
| 606 | cat $MKFILE.tmp >> $MKFILE
|
---|
| 607 | rm $MKFILE.tmp
|
---|
[a702b4d] | 608 | echo "Creating Makefile... ${BOLD}DONE${OFF}"
|
---|
| 609 |
|
---|
[0170229] | 610 | }
|
---|