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