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