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