[0170229] | 1 | #!/bin/sh
|
---|
| 2 |
|
---|
[a46ada0] | 3 | # $Id$
|
---|
[0170229] | 4 |
|
---|
| 5 | ###################################
|
---|
| 6 | ### FUNCTIONS ###
|
---|
| 7 | ###################################
|
---|
| 8 |
|
---|
| 9 |
|
---|
[50fb011] | 10 | #############################################################
|
---|
| 11 |
|
---|
| 12 |
|
---|
[0170229] | 13 | #----------------------------#
|
---|
[50fb011] | 14 | chapter4_Makefiles() { #
|
---|
[0170229] | 15 | #----------------------------#
|
---|
[50fb011] | 16 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter4 ( SETUP ) ${R_arrow}"
|
---|
[0170229] | 17 |
|
---|
[30737ea8] | 18 | # If /home/$LUSER is already present in the host, we asume that the
|
---|
[0170229] | 19 | # lfs user and group are also presents in the host, and a backup
|
---|
| 20 | # of their bash init files is made.
|
---|
| 21 | (
|
---|
| 22 | cat << EOF
|
---|
| 23 | 020-creatingtoolsdir:
|
---|
| 24 | @\$(call echo_message, Building)
|
---|
[9199a13] | 25 | @mkdir \$(MOUNT_PT)/tools && \\
|
---|
| 26 | rm -f /tools && \\
|
---|
| 27 | ln -s \$(MOUNT_PT)/tools / && \\
|
---|
| 28 | touch \$@ && \\
|
---|
| 29 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
| 30 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
[0170229] | 31 |
|
---|
| 32 | 021-addinguser: 020-creatingtoolsdir
|
---|
| 33 | @\$(call echo_message, Building)
|
---|
[9485eba] | 34 | @if [ ! -d /home/\$(LUSER) ]; then \\
|
---|
| 35 | groupadd \$(LGROUP); \\
|
---|
| 36 | useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
|
---|
[0170229] | 37 | else \\
|
---|
[30737ea8] | 38 | touch luser-exist; \\
|
---|
[0170229] | 39 | fi;
|
---|
[9485eba] | 40 | @chown \$(LUSER) \$(MOUNT_PT)/tools && \\
|
---|
[50fb011] | 41 | chown -R \$(LUSER) \$(MOUNT_PT)/\$(SCRIPT_ROOT) && \\
|
---|
[dacaa85] | 42 | chmod a+wt \$(MOUNT_PT)/sources && \\
|
---|
[9199a13] | 43 | touch \$@ && \\
|
---|
| 44 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
| 45 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
[0170229] | 46 |
|
---|
| 47 | 022-settingenvironment: 021-addinguser
|
---|
| 48 | @\$(call echo_message, Building)
|
---|
[9485eba] | 49 | @if [ -f /home/\$(LUSER)/.bashrc -a ! -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
|
---|
| 50 | mv /home/\$(LUSER)/.bashrc /home/\$(LUSER)/.bashrc.XXX; \\
|
---|
[0170229] | 51 | fi;
|
---|
[9485eba] | 52 | @if [ -f /home/\$(LUSER)/.bash_profile -a ! -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
|
---|
| 53 | mv /home/\$(LUSER)/.bash_profile /home/\$(LUSER)/.bash_profile.XXX; \\
|
---|
[0170229] | 54 | fi;
|
---|
[9485eba] | 55 | @echo "set +h" > /home/\$(LUSER)/.bashrc && \\
|
---|
| 56 | echo "umask 022" >> /home/\$(LUSER)/.bashrc && \\
|
---|
| 57 | echo "LFS=\$(MOUNT_PT)" >> /home/\$(LUSER)/.bashrc && \\
|
---|
| 58 | echo "LC_ALL=POSIX" >> /home/\$(LUSER)/.bashrc && \\
|
---|
| 59 | echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/\$(LUSER)/.bashrc && \\
|
---|
| 60 | echo "export LFS LC_ALL PATH" >> /home/\$(LUSER)/.bashrc && \\
|
---|
| 61 | echo "source $JHALFSDIR/envars" >> /home/\$(LUSER)/.bashrc && \\
|
---|
| 62 | chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bashrc && \\
|
---|
[0170229] | 63 | touch envars && \\
|
---|
[50fb011] | 64 | chown \$(LUSER) envars && \\
|
---|
[9199a13] | 65 | touch \$@ && \\
|
---|
| 66 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
| 67 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
[0170229] | 68 | EOF
|
---|
[50fb011] | 69 | ) > $MKFILE.tmp
|
---|
| 70 |
|
---|
| 71 | chapter4=" 020-creatingtoolsdir 021-addinguser 022-settingenvironment"
|
---|
[0170229] | 72 | }
|
---|
| 73 |
|
---|
[50fb011] | 74 |
|
---|
| 75 |
|
---|
[0170229] | 76 | #----------------------------#
|
---|
| 77 | chapter5_Makefiles() {
|
---|
| 78 | #----------------------------#
|
---|
[50fb011] | 79 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5 ( LUSER ) ${R_arrow}"
|
---|
[12a5707] | 80 |
|
---|
[0170229] | 81 | for file in chapter05/* ; do
|
---|
| 82 | # Keep the script file name
|
---|
| 83 | this_script=`basename $file`
|
---|
| 84 |
|
---|
| 85 | # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
|
---|
[fed9756] | 86 | # Fix also locales creation when running chapter05 testsuites (ugly)
|
---|
[af4c7b1] | 87 | case "${this_script}" in
|
---|
| 88 | *tcl) [[ "${TEST}" = "0" ]] && continue ;;
|
---|
| 89 | *expect) [[ "${TEST}" = "0" ]] && continue ;;
|
---|
| 90 | *dejagnu) [[ "${TEST}" = "0" ]] && continue ;;
|
---|
[47fddc8] | 91 | *stripping) [[ "${STRIP}" = "n" ]] && continue ;;
|
---|
[fed9756] | 92 | *glibc) [[ "${TEST}" = "3" ]] && \
|
---|
| 93 | sed -i 's@/usr/lib/locale@/tools/lib/locale@' $file ;;
|
---|
[af4c7b1] | 94 | esac
|
---|
[6b1576a] | 95 |
|
---|
[0170229] | 96 | # First append each name of the script files to a list (this will become
|
---|
| 97 | # the names of the targets in the Makefile
|
---|
[50fb011] | 98 | # DO NOT append the changingowner script.
|
---|
| 99 | # A hack is necessary: create script in chap5 BUT run as a dependency for
|
---|
[03b3eba] | 100 | # chap6 CHROOT
|
---|
[50fb011] | 101 | case "${this_script}" in
|
---|
| 102 | *changingowner) : ;;
|
---|
| 103 | *) chapter5="$chapter5 ${this_script}" ;;
|
---|
| 104 | esac
|
---|
[0170229] | 105 |
|
---|
| 106 | # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
|
---|
| 107 | # and binutils in chapter 5)
|
---|
| 108 | name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
|
---|
| 109 |
|
---|
| 110 | # Set the dependency for the first target.
|
---|
| 111 | if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
|
---|
| 112 |
|
---|
[3f858ca] | 113 | #--------------------------------------------------------------------#
|
---|
| 114 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
| 115 | #--------------------------------------------------------------------#
|
---|
| 116 | #
|
---|
[0170229] | 117 | # Drop in the name of the target on a new line, and the previous target
|
---|
| 118 | # as a dependency. Also call the echo_message function.
|
---|
[50fb011] | 119 | LUSER_wrt_target "${this_script}" "$PREV"
|
---|
[0170229] | 120 |
|
---|
| 121 | # Find the version of the command files, if it corresponds with the building of
|
---|
| 122 | # a specific package
|
---|
[3b63c8c] | 123 | pkg_tarball=$(get_package_tarball_name $name)
|
---|
[0170229] | 124 |
|
---|
[3b63c8c] | 125 | # If $pkg_tarball isn't empty, we've got a package...
|
---|
| 126 | if [ "$pkg_tarball" != "" ] ; then
|
---|
[3f858ca] | 127 | # Insert instructions for unpacking the package and to set the PKGDIR variable.
|
---|
[50fb011] | 128 | LUSER_wrt_unpack "$pkg_tarball"
|
---|
[e35e794] | 129 | # If the testsuites must be run, initialize the log file
|
---|
[50fb011] | 130 | [[ "$TEST" = "3" ]] && LUSER_wrt_test_log "${this_script}"
|
---|
[e35e794] | 131 | # If using optimizations, write the instructions
|
---|
[c205656] | 132 | [[ "$OPTIMIZE" = "2" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
|
---|
[0170229] | 133 | fi
|
---|
| 134 |
|
---|
| 135 | # Insert date and disk usage at the top of the log file, the script run
|
---|
| 136 | # and date and disk usage again at the bottom of the log file.
|
---|
[fed9756] | 137 | # The changingowner script must be run as root.
|
---|
| 138 | case "${this_script}" in
|
---|
[9485eba] | 139 | *changingowner) wrt_RunAsRoot "${this_script}" "$file" ;;
|
---|
[50fb011] | 140 | *) LUSER_wrt_RunAsUser "$file" ;;
|
---|
[fed9756] | 141 | esac
|
---|
[0170229] | 142 |
|
---|
| 143 | # Remove the build directory(ies) except if the package build fails
|
---|
| 144 | # (so we can review config.cache, config.log, etc.)
|
---|
[3b63c8c] | 145 | if [ "$pkg_tarball" != "" ] ; then
|
---|
[50fb011] | 146 | LUSER_RemoveBuildDirs "$name"
|
---|
[0170229] | 147 | fi
|
---|
| 148 |
|
---|
| 149 | # Include a touch of the target name so make can check
|
---|
| 150 | # if it's already been made.
|
---|
[9199a13] | 151 | wrt_touch
|
---|
[3f858ca] | 152 | #
|
---|
| 153 | #--------------------------------------------------------------------#
|
---|
| 154 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
| 155 | #--------------------------------------------------------------------#
|
---|
[0170229] | 156 |
|
---|
| 157 | # Keep the script file name for Makefile dependencies.
|
---|
| 158 | PREV=${this_script}
|
---|
| 159 | done # end for file in chapter05/*
|
---|
| 160 | }
|
---|
| 161 |
|
---|
[50fb011] | 162 |
|
---|
[0170229] | 163 | #----------------------------#
|
---|
| 164 | chapter6_Makefiles() {
|
---|
| 165 | #----------------------------#
|
---|
[50fb011] | 166 |
|
---|
[615e37d] | 167 | # Set envars and scripts for iteration targets
|
---|
[4edbc92] | 168 | LOGS="" # Start with an empty global LOGS envar
|
---|
[b242136] | 169 | if [[ -z "$1" ]] ; then
|
---|
[aa08925] | 170 | local N=""
|
---|
| 171 | else
|
---|
| 172 | local N=-build_$1
|
---|
| 173 | local chapter6=""
|
---|
[615e37d] | 174 | mkdir chapter06$N
|
---|
| 175 | cp chapter06/* chapter06$N
|
---|
| 176 | for script in chapter06$N/* ; do
|
---|
[7aee0dd] | 177 | # Overwrite existing symlinks, files, and dirs
|
---|
[615e37d] | 178 | sed -e 's/ln -sv/&f/g' \
|
---|
| 179 | -e 's/mv -v/&f/g' \
|
---|
[7aee0dd] | 180 | -e 's/mkdir -v/&p/g' -i ${script}
|
---|
[615e37d] | 181 | done
|
---|
[3135831] | 182 | # Remove Bzip2 binaries before make install
|
---|
[c2fdc03] | 183 | sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i chapter06$N/*-bzip2
|
---|
[aa08925] | 184 | fi
|
---|
| 185 |
|
---|
[50fb011] | 186 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N ( CHROOT ) ${R_arrow}"
|
---|
[af4c7b1] | 187 |
|
---|
[615e37d] | 188 | for file in chapter06$N/* ; do
|
---|
[0170229] | 189 | # Keep the script file name
|
---|
| 190 | this_script=`basename $file`
|
---|
| 191 |
|
---|
| 192 | # We'll run the chroot commands differently than the others, so skip them in the
|
---|
| 193 | # dependencies and target creation.
|
---|
[af4c7b1] | 194 | case "${this_script}" in
|
---|
| 195 | *chroot) continue ;;
|
---|
[47fddc8] | 196 | *stripping*) [[ "${STRIP}" = "n" ]] && continue ;;
|
---|
[af4c7b1] | 197 | esac
|
---|
[0170229] | 198 |
|
---|
[b242136] | 199 | # Grab the name of the target
|
---|
| 200 | name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@'`
|
---|
| 201 |
|
---|
| 202 | # Find the version of the command files, if it corresponds with the building of
|
---|
| 203 | # a specific package. We need this here to can skip scripts not needed for
|
---|
| 204 | # iterations rebuilds
|
---|
[3b63c8c] | 205 | pkg_tarball=$(get_package_tarball_name $name)
|
---|
[b242136] | 206 |
|
---|
[3b63c8c] | 207 | if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
|
---|
[b242136] | 208 | case "${this_script}" in
|
---|
| 209 | *stripping*) ;;
|
---|
| 210 | *) continue ;;
|
---|
| 211 | esac
|
---|
| 212 | fi
|
---|
| 213 |
|
---|
[4edbc92] | 214 | # Append each name of the script files to a list (this will become
|
---|
| 215 | # the names of the targets in the Makefile)
|
---|
[aa08925] | 216 | chapter6="$chapter6 ${this_script}${N}"
|
---|
[0170229] | 217 |
|
---|
[4edbc92] | 218 | # Append each name of the script files to a list (this will become
|
---|
| 219 | # the names of the logs to be moved for each iteration)
|
---|
| 220 | LOGS="$LOGS ${this_script}"
|
---|
| 221 |
|
---|
[3f858ca] | 222 | #--------------------------------------------------------------------#
|
---|
| 223 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
| 224 | #--------------------------------------------------------------------#
|
---|
| 225 | #
|
---|
[0170229] | 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.
|
---|
[50fb011] | 228 | CHROOT_wrt_target "${this_script}${N}" "$PREV"
|
---|
[0170229] | 229 |
|
---|
[3b63c8c] | 230 | # If $pkg_tarball isn't empty, we've got a package...
|
---|
[0170229] | 231 | # Insert instructions for unpacking the package and changing directories
|
---|
[3b63c8c] | 232 | if [ "$pkg_tarball" != "" ] ; then
|
---|
[50fb011] | 233 | CHROOT_Unpack "$pkg_tarball"
|
---|
[e35e794] | 234 | # If the testsuites must be run, initialize the log file
|
---|
| 235 | case $name in
|
---|
| 236 | binutils | gcc | glibc )
|
---|
[50fb011] | 237 | [[ "$TEST" != "0" ]] && CHROOT_wrt_test_log "${this_script}"
|
---|
[e35e794] | 238 | ;;
|
---|
| 239 | * )
|
---|
[50fb011] | 240 | [[ "$TEST" = "2" ]] || [[ "$TEST" = "3" ]] && CHROOT_wrt_test_log "${this_script}"
|
---|
[e35e794] | 241 | ;;
|
---|
| 242 | esac
|
---|
| 243 | # If using optimizations, write the instructions
|
---|
[c205656] | 244 | [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
|
---|
[0170229] | 245 | fi
|
---|
| 246 |
|
---|
| 247 | # In the mount of kernel filesystems we need to set LFS
|
---|
| 248 | # and not to use chroot.
|
---|
[af4c7b1] | 249 | case "${this_script}" in
|
---|
[9485eba] | 250 | *kernfs) wrt_RunAsRoot "${this_script}" "$file" ;;
|
---|
[50fb011] | 251 | *) CHROOT_wrt_RunAsRoot "$file" ;;
|
---|
[af4c7b1] | 252 | esac
|
---|
[0170229] | 253 |
|
---|
| 254 | # Remove the build directory(ies) except if the package build fails.
|
---|
[3b63c8c] | 255 | if [ "$pkg_tarball" != "" ] ; then
|
---|
[50fb011] | 256 | CHROOT_wrt_RemoveBuildDirs "$name"
|
---|
[0170229] | 257 | fi
|
---|
| 258 |
|
---|
| 259 | # Include a touch of the target name so make can check
|
---|
| 260 | # if it's already been made.
|
---|
[9199a13] | 261 | wrt_touch
|
---|
[3f858ca] | 262 | #
|
---|
| 263 | #--------------------------------------------------------------------#
|
---|
| 264 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
| 265 | #--------------------------------------------------------------------#
|
---|
[0170229] | 266 |
|
---|
| 267 | # Keep the script file name for Makefile dependencies.
|
---|
[aa08925] | 268 | PREV=${this_script}${N}
|
---|
| 269 | # Set system_build envar for iteration targets
|
---|
| 270 | system_build=$chapter6
|
---|
[0170229] | 271 | done # end for file in chapter06/*
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | #----------------------------#
|
---|
| 275 | chapter789_Makefiles() {
|
---|
| 276 | #----------------------------#
|
---|
[50fb011] | 277 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8/9 ( BOOT ) ${R_arrow}"
|
---|
[af4c7b1] | 278 |
|
---|
[0170229] | 279 | for file in chapter0{7,8,9}/* ; do
|
---|
| 280 | # Keep the script file name
|
---|
| 281 | this_script=`basename $file`
|
---|
| 282 |
|
---|
| 283 | # Grub must be configured manually.
|
---|
| 284 | # The filesystems can't be unmounted via Makefile and the user
|
---|
| 285 | # should enter the chroot environment to create the root
|
---|
| 286 | # password, edit several files and setup Grub.
|
---|
[0271c0c] | 287 | #
|
---|
[0170229] | 288 | # If no .config file is supplied, the kernel build is skipped
|
---|
[0271c0c] | 289 | #
|
---|
| 290 | case ${this_script} in
|
---|
| 291 | *grub) continue ;;
|
---|
| 292 | *reboot) continue ;;
|
---|
[6b1576a] | 293 | *console) continue ;; # Use the file generated by lfs-bootscripts
|
---|
[50fb011] | 294 | *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
|
---|
[0271c0c] | 295 | *kernel) [[ -z ${CONFIG} ]] && continue
|
---|
| 296 | cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
|
---|
| 297 | esac
|
---|
[0170229] | 298 |
|
---|
| 299 | # First append each name of the script files to a list (this will become
|
---|
| 300 | # the names of the targets in the Makefile
|
---|
| 301 | chapter789="$chapter789 ${this_script}"
|
---|
| 302 |
|
---|
[3f858ca] | 303 | #--------------------------------------------------------------------#
|
---|
| 304 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
| 305 | #--------------------------------------------------------------------#
|
---|
| 306 | #
|
---|
[0170229] | 307 | # Drop in the name of the target on a new line, and the previous target
|
---|
| 308 | # as a dependency. Also call the echo_message function.
|
---|
[50fb011] | 309 | CHROOT_wrt_target "${this_script}" "$PREV"
|
---|
[0170229] | 310 |
|
---|
| 311 | # Find the bootscripts and kernel package names
|
---|
[af4c7b1] | 312 | case "${this_script}" in
|
---|
| 313 | *bootscripts)
|
---|
[3b63c8c] | 314 | name="lfs-bootscripts"
|
---|
| 315 | pkg_tarball=$(get_package_tarball_name $name)
|
---|
[50fb011] | 316 | CHROOT_Unpack "$pkg_tarball"
|
---|
[af4c7b1] | 317 | ;;
|
---|
| 318 | *kernel)
|
---|
[3b63c8c] | 319 | name="linux"
|
---|
| 320 | pkg_tarball=$(get_package_tarball_name $name)
|
---|
[50fb011] | 321 | CHROOT_Unpack "$pkg_tarball"
|
---|
[af4c7b1] | 322 | ;;
|
---|
| 323 | esac
|
---|
[6b1576a] | 324 |
|
---|
[0170229] | 325 | # Check if we have a real /etc/fstab file
|
---|
[af4c7b1] | 326 | case "${this_script}" in
|
---|
| 327 | *fstab) if [[ -n $FSTAB ]]; then
|
---|
[50fb011] | 328 | CHROOT_wrt_CopyFstab
|
---|
[af4c7b1] | 329 | else
|
---|
[50fb011] | 330 | CHROOT_wrt_RunAsRoot "$file"
|
---|
[af4c7b1] | 331 | fi
|
---|
| 332 | ;;
|
---|
[50fb011] | 333 | *) CHROOT_wrt_RunAsRoot "$file"
|
---|
[af4c7b1] | 334 | ;;
|
---|
| 335 | esac
|
---|
[0170229] | 336 |
|
---|
[af4c7b1] | 337 | case "${this_script}" in
|
---|
[50fb011] | 338 | *bootscripts) CHROOT_wrt_RemoveBuildDirs "dummy" ;;
|
---|
| 339 | *kernel) CHROOT_wrt_RemoveBuildDirs "dummy" ;;
|
---|
[af4c7b1] | 340 | esac
|
---|
[6b1576a] | 341 |
|
---|
[0170229] | 342 | # Include a touch of the target name so make can check
|
---|
| 343 | # if it's already been made.
|
---|
[9199a13] | 344 | wrt_touch
|
---|
[3f858ca] | 345 | #
|
---|
| 346 | #--------------------------------------------------------------------#
|
---|
| 347 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
| 348 | #--------------------------------------------------------------------#
|
---|
[0170229] | 349 |
|
---|
| 350 | # Keep the script file name for Makefile dependencies.
|
---|
| 351 | PREV=${this_script}
|
---|
| 352 | done # for file in chapter0{7,8,9}/*
|
---|
[9e4b9a1] | 353 |
|
---|
| 354 | # Add SBU-disk_usage report target if required
|
---|
[47fddc8] | 355 | if [[ "$REPORT" = "y" ]] ; then wrt_report ; fi
|
---|
[0170229] | 356 | }
|
---|
| 357 |
|
---|
| 358 |
|
---|
[50fb011] | 359 |
|
---|
[0170229] | 360 | #----------------------------#
|
---|
[50fb011] | 361 | build_Makefile() { #
|
---|
[0170229] | 362 | #----------------------------#
|
---|
[50fb011] | 363 |
|
---|
[a702b4d] | 364 | echo "Creating Makefile... ${BOLD}START${OFF}"
|
---|
[03b3eba] | 365 |
|
---|
[0170229] | 366 | cd $JHALFSDIR/${PROGNAME}-commands
|
---|
| 367 |
|
---|
| 368 | # Start with a clean Makefile.tmp file
|
---|
[50fb011] | 369 | >$MKFILE
|
---|
[03b3eba] | 370 |
|
---|
[0170229] | 371 | chapter4_Makefiles
|
---|
| 372 | chapter5_Makefiles
|
---|
| 373 | chapter6_Makefiles
|
---|
[4edbc92] | 374 | # Add the iterations targets, if needed
|
---|
[47fddc8] | 375 | [[ "$COMPARE" = "y" ]] && wrt_compare_targets
|
---|
[0170229] | 376 | chapter789_Makefiles
|
---|
| 377 |
|
---|
| 378 | # Add a header, some variables and include the function file
|
---|
| 379 | # to the top of the real Makefile.
|
---|
| 380 | (
|
---|
| 381 | cat << EOF
|
---|
| 382 | $HEADER
|
---|
| 383 |
|
---|
[50fb011] | 384 |
|
---|
[398a037] | 385 | SRC = /sources
|
---|
| 386 | MOUNT_PT = $BUILDDIR
|
---|
| 387 | PKG_LST = $PKG_LST
|
---|
| 388 | LUSER = $LUSER
|
---|
| 389 | LGROUP = $LGROUP
|
---|
| 390 | SCRIPT_ROOT = $SCRIPT_ROOT
|
---|
| 391 |
|
---|
| 392 | BASEDIR = \$(MOUNT_PT)
|
---|
| 393 | SRCSDIR = \$(BASEDIR)/sources
|
---|
| 394 | CMDSDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$PROGNAME-commands
|
---|
| 395 | LOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/logs
|
---|
| 396 | TESTLOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/test-logs
|
---|
| 397 |
|
---|
| 398 | crSRCSDIR = /sources
|
---|
| 399 | crCMDSDIR = /\$(SCRIPT_ROOT)/$PROGNAME-commands
|
---|
| 400 | crLOGDIR = /\$(SCRIPT_ROOT)/logs
|
---|
| 401 | crTESTLOGDIR = /\$(SCRIPT_ROOT)/test-logs
|
---|
| 402 |
|
---|
| 403 | SU_LUSER = su - \$(LUSER) -c
|
---|
| 404 | LUSER_HOME = /home/\$(LUSER)
|
---|
[50fb011] | 405 | PRT_DU = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) \$(MOUNT_PT) \`\n"
|
---|
| 406 | PRT_DU_CR = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) / \`\n"
|
---|
[398a037] | 407 |
|
---|
[0170229] | 408 |
|
---|
| 409 | include makefile-functions
|
---|
| 410 |
|
---|
| 411 | EOF
|
---|
| 412 | ) > $MKFILE
|
---|
| 413 |
|
---|
| 414 | # Add chroot commands
|
---|
[8381f6e] | 415 | CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
|
---|
[0170229] | 416 | i=1
|
---|
| 417 | for file in chapter06/*chroot* ; do
|
---|
[8381f6e] | 418 | chroot=`cat $file | \
|
---|
| 419 | sed -e "s@chroot@$CHROOT_LOC@" \
|
---|
| 420 | -e '/#!\/bin\/sh/d' \
|
---|
| 421 | -e 's@ \\\@ @g' | \
|
---|
| 422 | tr -d '\n' | \
|
---|
| 423 | sed -e 's/ */ /g' \
|
---|
| 424 | -e 's|\\$|&&|g' \
|
---|
| 425 | -e 's|exit||g' \
|
---|
| 426 | -e 's|$| -c|' \
|
---|
| 427 | -e 's|"$$LFS"|$(MOUNT_PT)|' \
|
---|
| 428 | -e 's|set -e||'`
|
---|
[0170229] | 429 | echo -e "CHROOT$i= $chroot\n" >> $MKFILE
|
---|
| 430 | i=`expr $i + 1`
|
---|
| 431 | done
|
---|
| 432 |
|
---|
| 433 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
| 434 | # as a dependency.
|
---|
| 435 | (
|
---|
| 436 | cat << EOF
|
---|
[50fb011] | 437 |
|
---|
| 438 | all: mk_SETUP mk_LUSER mk_CHROOT mk_BOOT
|
---|
[0170229] | 439 | @\$(call echo_finished,$VERSION)
|
---|
| 440 |
|
---|
| 441 |
|
---|
[50fb011] | 442 | mk_SETUP:
|
---|
| 443 | @\$(call echo_SU_request)
|
---|
| 444 | @sudo make SETUP
|
---|
| 445 | @touch \$@
|
---|
[03b3eba] | 446 |
|
---|
[50fb011] | 447 | mk_LUSER: mk_SETUP
|
---|
| 448 | @\$(call echo_SULUSER_request)
|
---|
| 449 | @( \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make LUSER" )
|
---|
| 450 | @touch \$@
|
---|
| 451 | #
|
---|
| 452 | # The convoluted piece of code below is necessary to provide 'make' with a valid shell in the
|
---|
| 453 | # chroot environment. (Unless someone knows a different way)
|
---|
| 454 | # Manually create the /bin directory and provide link to the /tools dir.
|
---|
[03b3eba] | 455 | # Also change the original symlink creation to include (f)orce to prevent failure due to
|
---|
[50fb011] | 456 | # pre-existing links.
|
---|
| 457 | #
|
---|
| 458 | mk_CHROOT: mk_LUSER 057-changingowner 059-kernfs
|
---|
| 459 | @mkdir \$(MOUNT_PT)/bin && \\
|
---|
| 460 | cd \$(MOUNT_PT)/bin && \\
|
---|
| 461 | ln -sf /tools/bin/bash bash; ln -sf bash sh
|
---|
| 462 | @sed -e 's|^ln -sv|ln -svf|' -i \$(CMDSDIR)/chapter06/063-createfiles
|
---|
| 463 | @\$(call echo_CHROOT_request)
|
---|
| 464 | @( sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make CHROOT")
|
---|
| 465 | @touch \$@
|
---|
| 466 |
|
---|
[03b3eba] | 467 | mk_BOOT: mk_CHROOT
|
---|
[50fb011] | 468 | @\$(call echo_CHROOT_request)
|
---|
| 469 | @( sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BOOT")
|
---|
| 470 | @touch \$@
|
---|
[03b3eba] | 471 |
|
---|
[50fb011] | 472 |
|
---|
| 473 | SETUP: $chapter4
|
---|
| 474 |
|
---|
| 475 | LUSER: $chapter5
|
---|
| 476 |
|
---|
| 477 | CHROOT: $chapter6
|
---|
| 478 |
|
---|
| 479 | BOOT: $chapter789
|
---|
[0170229] | 480 |
|
---|
| 481 |
|
---|
[9199a13] | 482 | restart: restart_code all
|
---|
| 483 |
|
---|
[30737ea8] | 484 | restore-luser-env:
|
---|
[0170229] | 485 | @\$(call echo_message, Building)
|
---|
[9485eba] | 486 | @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
|
---|
| 487 | mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
|
---|
[0170229] | 488 | fi;
|
---|
[9485eba] | 489 | @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
|
---|
| 490 | mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
|
---|
[0170229] | 491 | fi;
|
---|
[9485eba] | 492 | @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
|
---|
[9199a13] | 493 | touch \$@ && \\
|
---|
| 494 | echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
| 495 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
[460ea63] | 496 |
|
---|
[3a27393] | 497 | do_housekeeping:
|
---|
[9199a13] | 498 | @-umount \$(MOUNT_PT)/sys
|
---|
| 499 | @-umount \$(MOUNT_PT)/proc
|
---|
| 500 | @-umount \$(MOUNT_PT)/dev/shm
|
---|
| 501 | @-umount \$(MOUNT_PT)/dev/pts
|
---|
| 502 | @-umount \$(MOUNT_PT)/dev
|
---|
[30737ea8] | 503 | @-if [ ! -f luser-exist ]; then \\
|
---|
[9485eba] | 504 | userdel \$(LUSER); \\
|
---|
| 505 | rm -rf /home/\$(LUSER); \\
|
---|
[3a27393] | 506 | fi;
|
---|
[460ea63] | 507 |
|
---|
[9199a13] | 508 | restart_code:
|
---|
| 509 | @echo ">>> This feature is experimental, BUGS may exist"
|
---|
| 510 |
|
---|
| 511 | @if [ ! -L /tools ]; then \\
|
---|
| 512 | echo -e "\\nERROR::\\n /tools is NOT a symlink.. /tools must point to \$(MOUNT_PT)/tools\\n" && false;\\
|
---|
| 513 | fi;
|
---|
| 514 |
|
---|
| 515 | @if [ ! -e /tools ]; then \\
|
---|
| 516 | echo -e "\\nERROR::\\nThe target /tools points to does not exist.\\nVerify the target.. \$(MOUNT_PT)/tools\\n" && false;\\
|
---|
| 517 | fi;
|
---|
| 518 |
|
---|
| 519 | @if ! stat -c %N /tools | grep "\$(MOUNT_PT)/tools" >/dev/null ; then \\
|
---|
| 520 | echo -e "\\nERROR::\\nThe symlink \\"/tools\\" does not point to \\"\$(MOUNT_PT)/tools\\".\\nCorrect the problem and rerun\\n" && false;\\
|
---|
| 521 | fi;
|
---|
| 522 |
|
---|
| 523 | @if [ -f ???-kernfs ]; then \\
|
---|
| 524 | mkdir -pv \$(MOUNT_PT)/{dev,proc,sys};\\
|
---|
| 525 | if [ ! -e \$(MOUNT_PT)/dev/console ]; then \\
|
---|
| 526 | mknod -m 600 \$(MOUNT_PT)/dev/console c 5 1;\\
|
---|
| 527 | fi;\\
|
---|
| 528 | if [ ! -e \$(MOUNT_PT)/dev/null ]; then \\
|
---|
| 529 | mknod -m 666 \$(MOUNT_PT)/dev/null c 1 3;\\
|
---|
| 530 | fi;\\
|
---|
| 531 | if ! mount -l | grep bind >/dev/null ; then \\
|
---|
| 532 | mount --bind /dev \$(MOUNT_PT)/dev;\\
|
---|
| 533 | fi;\\
|
---|
| 534 | if ! mount -l | grep "\$(MOUNT_PT)/dev/pts" >/dev/null ; then \\
|
---|
| 535 | mount -vt devpts devpts \$(MOUNT_PT)/dev/pts;\\
|
---|
| 536 | fi;\\
|
---|
| 537 | if ! mount -l | grep "\$(MOUNT_PT)/dev/shm" >/dev/null ; then \\
|
---|
| 538 | mount -vt tmpfs shm \$(MOUNT_PT)/dev/shm;\\
|
---|
| 539 | fi;\\
|
---|
| 540 | if ! mount -l | grep "\$(MOUNT_PT)/proc" >/dev/null ; then \\
|
---|
| 541 | mount -vt proc proc \$(MOUNT_PT)/proc;\\
|
---|
| 542 | fi;\\
|
---|
[3b63c8c] | 543 | if ! mount -l | grep "\$(MOUNT_PT)/sys" >/dev/null ; then \\
|
---|
[9199a13] | 544 | mount -vt sysfs sysfs \$(MOUNT_PT)/sys;\\
|
---|
| 545 | fi;\\
|
---|
| 546 | fi;
|
---|
| 547 |
|
---|
[50fb011] | 548 |
|
---|
| 549 |
|
---|
[42346b2] | 550 | EOF
|
---|
| 551 | ) >> $MKFILE
|
---|
| 552 |
|
---|
[50fb011] | 553 |
|
---|
| 554 |
|
---|
[0170229] | 555 | # Bring over the items from the Makefile.tmp
|
---|
| 556 | cat $MKFILE.tmp >> $MKFILE
|
---|
| 557 | rm $MKFILE.tmp
|
---|
[a702b4d] | 558 | echo "Creating Makefile... ${BOLD}DONE${OFF}"
|
---|
| 559 | }
|
---|
[0170229] | 560 |
|
---|