[877cc6a] | 1 | #!/bin/sh
|
---|
| 2 |
|
---|
| 3 | # $Id$
|
---|
| 4 |
|
---|
| 5 | ###################################
|
---|
| 6 | ### FUNCTIONS ###
|
---|
| 7 | ###################################
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | #----------------------------#
|
---|
| 12 | chapter4_Makefiles() {
|
---|
| 13 | #----------------------------#
|
---|
| 14 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter4${R_arrow}"
|
---|
| 15 |
|
---|
| 16 | # If /home/lfs is already present in the host, we asume that the
|
---|
| 17 | # lfs user and group are also presents in the host, and a backup
|
---|
| 18 | # of their bash init files is made.
|
---|
| 19 | (
|
---|
| 20 | cat << EOF
|
---|
| 21 | 020-creatingtoolsdir:
|
---|
| 22 | @\$(call echo_message, Building)
|
---|
| 23 | @mkdir -v \$(MOUNT_PT)/tools && \\
|
---|
| 24 | rm -fv /tools && \\
|
---|
| 25 | ln -sv \$(MOUNT_PT)/tools / && \\
|
---|
| 26 | touch \$@
|
---|
| 27 |
|
---|
| 28 | 021-addinguser: 020-creatingtoolsdir
|
---|
| 29 | @\$(call echo_message, Building)
|
---|
| 30 | @if [ ! -d /home/lfs ]; then \\
|
---|
| 31 | groupadd lfs; \\
|
---|
| 32 | useradd -s /bin/bash -g lfs -m -k /dev/null lfs; \\
|
---|
| 33 | else \\
|
---|
| 34 | touch user-lfs-exist; \\
|
---|
| 35 | fi;
|
---|
| 36 | @chown lfs \$(MOUNT_PT)/tools && \\
|
---|
| 37 | chmod a+wt \$(MOUNT_PT)/sources && \\
|
---|
| 38 | touch \$@
|
---|
| 39 |
|
---|
| 40 | 022-settingenvironment: 021-addinguser
|
---|
| 41 | @\$(call echo_message, Building)
|
---|
| 42 | @if [ -f /home/lfs/.bashrc -a ! -f /home/lfs/.bashrc.XXX ]; then \\
|
---|
| 43 | mv -v /home/lfs/.bashrc /home/lfs/.bashrc.XXX; \\
|
---|
| 44 | fi;
|
---|
| 45 | @if [ -f /home/lfs/.bash_profile -a ! -f /home/lfs/.bash_profile.XXX ]; then \\
|
---|
| 46 | mv -v /home/lfs/.bash_profile /home/lfs/.bash_profile.XXX; \\
|
---|
| 47 | fi;
|
---|
| 48 | @echo "set +h" > /home/lfs/.bashrc && \\
|
---|
| 49 | echo "umask 022" >> /home/lfs/.bashrc && \\
|
---|
| 50 | echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
|
---|
| 51 | echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
|
---|
| 52 | echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
|
---|
| 53 | echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
|
---|
| 54 | echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
|
---|
| 55 | chown lfs:lfs /home/lfs/.bashrc && \\
|
---|
| 56 | touch envars && \\
|
---|
| 57 | touch \$@
|
---|
| 58 | EOF
|
---|
| 59 | ) >> $MKFILE.tmp
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | #----------------------------#
|
---|
| 63 | chapter5_Makefiles() {
|
---|
| 64 | #----------------------------#
|
---|
| 65 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5${R_arrow}"
|
---|
| 66 |
|
---|
| 67 | for file in chapter05/* ; do
|
---|
| 68 | # Keep the script file name
|
---|
| 69 | this_script=`basename $file`
|
---|
| 70 |
|
---|
| 71 | # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
|
---|
[a241c33] | 72 | # Fix also locales creation when running chapter05 testsuites (ugly)
|
---|
[877cc6a] | 73 | case "${this_script}" in
|
---|
| 74 | *tcl) [[ "${TEST}" = "0" ]] && continue ;;
|
---|
| 75 | *expect) [[ "${TEST}" = "0" ]] && continue ;;
|
---|
| 76 | *dejagnu) [[ "${TEST}" = "0" ]] && continue ;;
|
---|
| 77 | *stripping) [[ "${STRIP}" = "0" ]] && continue ;;
|
---|
[a241c33] | 78 | *glibc) [[ "${TEST}" = "3" ]] && \
|
---|
[d46a46e] | 79 | sed -i 's@/usr/lib/locale@/tools/lib/locale@' $file ;;
|
---|
[877cc6a] | 80 | esac
|
---|
| 81 |
|
---|
| 82 | # First append each name of the script files to a list (this will become
|
---|
| 83 | # the names of the targets in the Makefile
|
---|
| 84 | chapter5="$chapter5 ${this_script}"
|
---|
| 85 |
|
---|
| 86 | # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
|
---|
| 87 | # and binutils in chapter 5)
|
---|
| 88 | name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
|
---|
| 89 |
|
---|
| 90 | # Set the dependency for the first target.
|
---|
| 91 | if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
|
---|
| 92 |
|
---|
| 93 | #--------------------------------------------------------------------#
|
---|
| 94 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
| 95 | #--------------------------------------------------------------------#
|
---|
| 96 | #
|
---|
| 97 | # Drop in the name of the target on a new line, and the previous target
|
---|
| 98 | # as a dependency. Also call the echo_message function.
|
---|
| 99 | wrt_target "${this_script}" "$PREV"
|
---|
| 100 |
|
---|
| 101 | # Find the version of the command files, if it corresponds with the building of
|
---|
| 102 | # a specific package
|
---|
| 103 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
| 104 |
|
---|
| 105 | # If $vrs isn't empty, we've got a package...
|
---|
| 106 | if [ "$vrs" != "" ] ; then
|
---|
| 107 | if [ "$name" = "tcl" ] ; then
|
---|
| 108 | FILE="$name$vrs-src.tar.*"
|
---|
| 109 | else
|
---|
| 110 | FILE="$name-$vrs.tar.*"
|
---|
| 111 | fi
|
---|
| 112 |
|
---|
| 113 | # Insert instructions for unpacking the package and to set the PKGDIR variable.
|
---|
| 114 | wrt_unpack "$FILE"
|
---|
| 115 | fi
|
---|
| 116 |
|
---|
| 117 | # Insert date and disk usage at the top of the log file, the script run
|
---|
| 118 | # and date and disk usage again at the bottom of the log file.
|
---|
[a241c33] | 119 | # The changingowner script must be run as root.
|
---|
| 120 | case "${this_script}" in
|
---|
| 121 | *changingowner) wrt_run_as_root "${this_script}" "$file" ;;
|
---|
| 122 | *) wrt_run_as_su "${this_script}" "$file" ;;
|
---|
| 123 | esac
|
---|
[877cc6a] | 124 |
|
---|
| 125 | # Remove the build directory(ies) except if the package build fails
|
---|
| 126 | # (so we can review config.cache, config.log, etc.)
|
---|
| 127 | if [ "$vrs" != "" ] ; then
|
---|
| 128 | wrt_remove_build_dirs "$name"
|
---|
| 129 | fi
|
---|
| 130 |
|
---|
| 131 | # Include a touch of the target name so make can check
|
---|
| 132 | # if it's already been made.
|
---|
| 133 | echo -e '\t@touch $@' >> $MKFILE.tmp
|
---|
| 134 | #
|
---|
| 135 | #--------------------------------------------------------------------#
|
---|
| 136 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
| 137 | #--------------------------------------------------------------------#
|
---|
| 138 |
|
---|
| 139 | # Keep the script file name for Makefile dependencies.
|
---|
| 140 | PREV=${this_script}
|
---|
| 141 | done # end for file in chapter05/*
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | #----------------------------#
|
---|
| 145 | chapter6_Makefiles() {
|
---|
| 146 | #----------------------------#
|
---|
| 147 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6${R_arrow}"
|
---|
| 148 |
|
---|
| 149 | for file in chapter06/* ; do
|
---|
| 150 | # Keep the script file name
|
---|
| 151 | this_script=`basename $file`
|
---|
| 152 |
|
---|
| 153 | # We'll run the chroot commands differently than the others, so skip them in the
|
---|
| 154 | # dependencies and target creation.
|
---|
| 155 | case "${this_script}" in
|
---|
| 156 | *chroot) continue ;;
|
---|
| 157 | *stripping*) [[ "${STRIP}" = "0" ]] && continue ;;
|
---|
| 158 | esac
|
---|
| 159 |
|
---|
| 160 | # First append each name of the script files to a list (this will become
|
---|
| 161 | # the names of the targets in the Makefile
|
---|
| 162 | chapter6="$chapter6 ${this_script}"
|
---|
| 163 |
|
---|
| 164 | # Grab the name of the target
|
---|
| 165 | name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@'`
|
---|
| 166 |
|
---|
| 167 | #--------------------------------------------------------------------#
|
---|
| 168 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
| 169 | #--------------------------------------------------------------------#
|
---|
| 170 | #
|
---|
| 171 | # Drop in the name of the target on a new line, and the previous target
|
---|
| 172 | # as a dependency. Also call the echo_message function.
|
---|
| 173 | wrt_target "${this_script}" "$PREV"
|
---|
| 174 |
|
---|
| 175 | # Find the version of the command files, if it corresponds with the building of
|
---|
| 176 | # a specific package
|
---|
| 177 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
| 178 |
|
---|
| 179 | # If $vrs isn't empty, we've got a package...
|
---|
| 180 | # Insert instructions for unpacking the package and changing directories
|
---|
| 181 | if [ "$vrs" != "" ] ; then
|
---|
| 182 | FILE="$name-$vrs.tar.*"
|
---|
| 183 | wrt_unpack2 "$FILE"
|
---|
| 184 | fi
|
---|
| 185 |
|
---|
| 186 | # In the mount of kernel filesystems we need to set LFS
|
---|
| 187 | # and not to use chroot.
|
---|
| 188 | case "${this_script}" in
|
---|
| 189 | *kernfs) wrt_run_as_root "${this_script}" "$file" ;;
|
---|
| 190 | *) wrt_run_as_chroot1 "${this_script}" "$file" ;;
|
---|
| 191 | esac
|
---|
| 192 |
|
---|
| 193 | # Remove the build directory(ies) except if the package build fails.
|
---|
| 194 | if [ "$vrs" != "" ] ; then
|
---|
| 195 | wrt_remove_build_dirs "$name"
|
---|
| 196 | fi
|
---|
| 197 |
|
---|
| 198 | # Include a touch of the target name so make can check
|
---|
| 199 | # if it's already been made.
|
---|
| 200 | echo -e '\t@touch $@' >> $MKFILE.tmp
|
---|
| 201 | #
|
---|
| 202 | #--------------------------------------------------------------------#
|
---|
| 203 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
| 204 | #--------------------------------------------------------------------#
|
---|
| 205 |
|
---|
| 206 | # Keep the script file name for Makefile dependencies.
|
---|
| 207 | PREV=${this_script}
|
---|
| 208 | done # end for file in chapter06/*
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | #----------------------------#
|
---|
| 212 | chapter789_Makefiles() {
|
---|
| 213 | #----------------------------#
|
---|
| 214 | echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8/9${R_arrow}"
|
---|
| 215 |
|
---|
| 216 | for file in chapter0{7,8,9}/* ; do
|
---|
| 217 | # Keep the script file name
|
---|
| 218 | this_script=`basename $file`
|
---|
| 219 |
|
---|
| 220 | # Grub must be configured manually.
|
---|
| 221 | # The filesystems can't be unmounted via Makefile and the user
|
---|
| 222 | # should enter the chroot environment to create the root
|
---|
| 223 | # password, edit several files and setup Grub.
|
---|
| 224 | #
|
---|
| 225 | # If no .config file is supplied, the kernel build is skipped
|
---|
| 226 | #
|
---|
| 227 | case ${this_script} in
|
---|
| 228 | *grub) continue ;;
|
---|
| 229 | *reboot) continue ;;
|
---|
| 230 | *console) continue ;; # Use the file generated by lfs-bootscripts
|
---|
| 231 | *kernel) [[ -z ${CONFIG} ]] && continue
|
---|
| 232 | cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
|
---|
| 233 | esac
|
---|
| 234 |
|
---|
| 235 | # First append each name of the script files to a list (this will become
|
---|
| 236 | # the names of the targets in the Makefile
|
---|
| 237 | chapter789="$chapter789 ${this_script}"
|
---|
| 238 |
|
---|
| 239 | #--------------------------------------------------------------------#
|
---|
| 240 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
| 241 | #--------------------------------------------------------------------#
|
---|
| 242 | #
|
---|
| 243 | # Drop in the name of the target on a new line, and the previous target
|
---|
| 244 | # as a dependency. Also call the echo_message function.
|
---|
| 245 | wrt_target "${this_script}" "$PREV"
|
---|
| 246 |
|
---|
| 247 | # Find the bootscripts and kernel package names
|
---|
| 248 | case "${this_script}" in
|
---|
| 249 | *bootscripts)
|
---|
| 250 | vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
| 251 | FILE="lfs-bootscripts-$vrs.tar.*"
|
---|
| 252 | wrt_unpack2 "$FILE"
|
---|
| 253 | ;;
|
---|
| 254 | *kernel)
|
---|
| 255 | vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
| 256 | FILE="linux-$vrs.tar.*"
|
---|
| 257 | wrt_unpack2 "$FILE"
|
---|
| 258 | ;;
|
---|
| 259 | esac
|
---|
| 260 |
|
---|
| 261 | # Check if we have a real /etc/fstab file
|
---|
| 262 | case "${this_script}" in
|
---|
| 263 | *fstab) if [[ -n $FSTAB ]]; then
|
---|
| 264 | wrt_copy_fstab "${this_script}"
|
---|
| 265 | else
|
---|
| 266 | wrt_run_as_chroot2 "$this_script" "$file"
|
---|
| 267 | fi
|
---|
| 268 | ;;
|
---|
| 269 | *) wrt_run_as_chroot2 "$this_script" "$file"
|
---|
| 270 | ;;
|
---|
| 271 | esac
|
---|
| 272 |
|
---|
| 273 | case "${this_script}" in
|
---|
| 274 | *bootscripts) wrt_remove_build_dirs "dummy" ;;
|
---|
| 275 | *kernel) wrt_remove_build_dirs "dummy" ;;
|
---|
| 276 | esac
|
---|
| 277 |
|
---|
| 278 | # Include a touch of the target name so make can check
|
---|
| 279 | # if it's already been made.
|
---|
| 280 | echo -e '\t@touch $@' >> $MKFILE.tmp
|
---|
| 281 | #
|
---|
| 282 | #--------------------------------------------------------------------#
|
---|
| 283 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
| 284 | #--------------------------------------------------------------------#
|
---|
| 285 |
|
---|
| 286 | # Keep the script file name for Makefile dependencies.
|
---|
| 287 | PREV=${this_script}
|
---|
| 288 | done # for file in chapter0{7,8,9}/*
|
---|
[453bef0] | 289 |
|
---|
| 290 | # Add SBU-disk_usage report target if required
|
---|
| 291 | if [[ "$REPORT" = "1" ]] ; then wrt_report ; fi
|
---|
[877cc6a] | 292 | }
|
---|
| 293 |
|
---|
| 294 |
|
---|
| 295 | #----------------------------#
|
---|
| 296 | build_Makefile() {
|
---|
| 297 | #----------------------------#
|
---|
[c7c5a53] | 298 | echo "Creating Makefile... ${BOLD}START${OFF}"
|
---|
[877cc6a] | 299 | cd $JHALFSDIR/${PROGNAME}-commands
|
---|
| 300 |
|
---|
| 301 | # Start with a clean Makefile.tmp file
|
---|
| 302 | >$MKFILE.tmp
|
---|
| 303 |
|
---|
| 304 | chapter4_Makefiles
|
---|
| 305 | chapter5_Makefiles
|
---|
| 306 | chapter6_Makefiles
|
---|
| 307 | chapter789_Makefiles
|
---|
| 308 |
|
---|
| 309 |
|
---|
| 310 | # Add a header, some variables and include the function file
|
---|
| 311 | # to the top of the real Makefile.
|
---|
| 312 | (
|
---|
| 313 | cat << EOF
|
---|
| 314 | $HEADER
|
---|
| 315 |
|
---|
| 316 | SRC= /sources
|
---|
| 317 | MOUNT_PT= $BUILDDIR
|
---|
| 318 |
|
---|
| 319 | include makefile-functions
|
---|
| 320 |
|
---|
| 321 | EOF
|
---|
| 322 | ) > $MKFILE
|
---|
| 323 |
|
---|
| 324 |
|
---|
| 325 | # Add chroot commands
|
---|
| 326 | i=1
|
---|
| 327 | for file in chapter06/*chroot* ; do
|
---|
| 328 | chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
|
---|
| 329 | -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
|
---|
| 330 | -e 's|"$$LFS"|$(MOUNT_PT)|' -e 's|set -e||'`
|
---|
| 331 | echo -e "CHROOT$i= $chroot\n" >> $MKFILE
|
---|
| 332 | i=`expr $i + 1`
|
---|
| 333 | done
|
---|
| 334 |
|
---|
| 335 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
| 336 | # as a dependency.
|
---|
| 337 | (
|
---|
| 338 | cat << EOF
|
---|
| 339 | all: chapter4 chapter5 chapter6 chapter789
|
---|
| 340 | @\$(call echo_finished,$VERSION)
|
---|
| 341 |
|
---|
| 342 | chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
|
---|
| 343 |
|
---|
| 344 | chapter5: chapter4 $chapter5 restore-lfs-env
|
---|
| 345 |
|
---|
| 346 | chapter6: chapter5 $chapter6
|
---|
| 347 |
|
---|
| 348 | chapter789: chapter6 $chapter789
|
---|
| 349 |
|
---|
| 350 | clean-all: clean
|
---|
| 351 | rm -rf ./{lfs-commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
|
---|
| 352 |
|
---|
| 353 | clean: clean-chapter789 clean-chapter6 clean-chapter5 clean-chapter4
|
---|
| 354 |
|
---|
| 355 | clean-chapter4:
|
---|
| 356 | -if [ ! -f user-lfs-exist ]; then \\
|
---|
| 357 | userdel lfs; \\
|
---|
| 358 | rm -rf /home/lfs; \\
|
---|
| 359 | fi;
|
---|
| 360 | rm -rf \$(MOUNT_PT)/tools
|
---|
| 361 | rm -f /tools
|
---|
| 362 | rm -f envars user-lfs-exist
|
---|
| 363 | rm -f 02* logs/02*.log
|
---|
| 364 |
|
---|
| 365 | clean-chapter5:
|
---|
| 366 | rm -rf \$(MOUNT_PT)/tools/*
|
---|
| 367 | rm -f $chapter5 restore-lfs-env sources-dir
|
---|
| 368 | cd logs && rm -f $chapter5 && cd ..
|
---|
| 369 |
|
---|
| 370 | clean-chapter6:
|
---|
| 371 | -umount \$(MOUNT_PT)/sys
|
---|
| 372 | -umount \$(MOUNT_PT)/proc
|
---|
| 373 | -umount \$(MOUNT_PT)/dev/shm
|
---|
| 374 | -umount \$(MOUNT_PT)/dev/pts
|
---|
| 375 | -umount \$(MOUNT_PT)/dev
|
---|
| 376 | rm -rf \$(MOUNT_PT)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
|
---|
| 377 | rm -f $chapter6
|
---|
| 378 | cd logs && rm -f $chapter6 && cd ..
|
---|
| 379 |
|
---|
| 380 | clean-chapter789:
|
---|
| 381 | rm -f $chapter789
|
---|
| 382 | cd logs && rm -f $chapter789 && cd ..
|
---|
| 383 |
|
---|
| 384 | restore-lfs-env:
|
---|
| 385 | @\$(call echo_message, Building)
|
---|
| 386 | @if [ -f /home/lfs/.bashrc.XXX ]; then \\
|
---|
| 387 | mv -fv /home/lfs/.bashrc.XXX /home/lfs/.bashrc; \\
|
---|
| 388 | fi;
|
---|
| 389 | @if [ -f /home/lfs/.bash_profile.XXX ]; then \\
|
---|
| 390 | mv -v /home/lfs/.bash_profile.XXX /home/lfs/.bash_profile; \\
|
---|
| 391 | fi;
|
---|
| 392 | @chown lfs:lfs /home/lfs/.bash* && \\
|
---|
| 393 | touch \$@
|
---|
| 394 |
|
---|
| 395 | EOF
|
---|
| 396 | ) >> $MKFILE
|
---|
| 397 |
|
---|
| 398 | # Bring over the items from the Makefile.tmp
|
---|
| 399 | cat $MKFILE.tmp >> $MKFILE
|
---|
| 400 | rm $MKFILE.tmp
|
---|
[c7c5a53] | 401 | echo "Creating Makefile... ${BOLD}DONE${OFF}"
|
---|
[877cc6a] | 402 |
|
---|
[c7c5a53] | 403 | }
|
---|
[877cc6a] | 404 |
|
---|