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