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