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