source: LFS/master.sh@ 0a0753d

ablfs-more legacy trunk
Last change on this file since 0a0753d was 0a0753d, checked in by Pierre Labastie <pierre@…>, 4 years ago

Remove spaces at the end of lines

  • Property mode set to 100644
File size: 27.9 KB
Line 
1#!/bin/bash
2
3# $Id$
4
5###################################
6### FUNCTIONS ###
7###################################
8
9
10#############################################################
11
12
13#-------------------------#
14chapter_targets() { #
15#-------------------------#
16# $1 is the chapter number. Pad it with 0 to the left to obtain a 2-digit
17# number:
18 printf -v dir chapter%02d $1
19
20# $2 contains the build number if rebuilding for ICA
21 if [[ -z "$2" ]] ; then
22 local N=""
23 else
24 local N=-build_$2
25 local CHROOT_TGT=""
26 mkdir ${dir}$N
27 cp ${dir}/* ${dir}$N
28 for script in ${dir}$N/* ; do
29 # Overwrite existing symlinks, files, and dirs
30 sed -e 's/ln *-sv/&f/g' \
31 -e 's/mv *-v/&f/g' \
32 -e 's/mkdir *-v/&p/g' -i ${script}
33 # Rename the scripts
34 mv ${script} ${script}$N
35 done
36 # Remove Bzip2 binaries before make install (LFS-6.2 compatibility)
37 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i ${dir}$N/*-bzip2$N
38 # Remove openssl-<version> from /usr/share/doc (LFS-9.x), because
39 # otherwise the mv command creates an openssl directory.
40 sed -e 's@mv -v@rm -rfv /usr/share/doc/openssl-*\n&@' \
41 -i ${dir}$N/*-openssl$N
42 fi
43
44 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter $1$N${R_arrow}"
45
46 for file in ${dir}$N/* ; do
47 # Keep the script file name
48 this_script=`basename $file`
49
50 # Some scripts need peculiar actions:
51 # - glibc chap 5: fix locales creation when running chapter05 testsuites
52 # - Stripping at the end of system build: lfs.xsl does not generate
53 # correct commands if the user does not want to strip, so skip it
54 # in this case
55 # - do not reinstall linux-headers when rebuilding
56 # - grub config: must be done manually; skip it
57 # - handle fstab and .config. Skip kernel if .config not supplied
58 case "${this_script}" in
59 5*glibc) [[ "${TEST}" = "3" ]] && \
60 sed -i 's@/usr/lib/locale@/tools/lib/locale@' $file ;;
61 *strippingagain) [[ "${STRIP}" = "n" ]] && continue ;;
62 *linux-headers*) [[ -n "$N" ]] && continue ;;
63 8*grub) (( nb_chaps == 5 )) && continue ;;
64 10*grub) continue ;;
65 *fstab) [[ -z "${FSTAB}" ]] ||
66 [[ ${FSTAB} == $BUILDDIR/sources/fstab ]] ||
67 cp ${FSTAB} $BUILDDIR/sources/fstab ;;
68 *kernel) [[ -z ${CONFIG} ]] && continue
69 [[ ${CONFIG} == $BUILDDIR/sources/kernel-config ]] ||
70 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
71 esac
72 # Grab the name of the target
73 name=`echo ${this_script} | sed -e 's@[0-9]\{3,4\}-@@' \
74 -e 's@-pass[0-9]\{1\}@@' \
75 -e 's@-libstdc++@@' \
76 -e 's,'$N',,'`
77
78 # Find the name of the tarball and the version of the package
79 # If it doesn't exist, we skip it in iterations rebuilds (except stripping
80 # and revisedchroot, where .a and .la files are removed).
81 pkg_tarball=$(sed -n 's/tar -xf \(.*\)/\1/p' $file)
82 pkg_version=$(sed -n 's/VERSION=\(.*\)/\1/p' $file)
83
84 if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
85 case "${this_script}" in
86 *stripping*|*revised*) ;;
87 *) continue ;;
88 esac
89 fi
90
91 # Append the name of the script to a list. The name of the
92 # list is contained in the variable Makefile_target. We adjust this
93 # variable at various points. Note that it is initialized to "SETUP"
94 # in the main function, before calling this function for the first time.
95 case "${this_script}" in
96 *settingenvironment) Makefile_target=LUSER_TGT ;;
97 *changingowner ) Makefile_target=SUDO_TGT ;;
98 *creatingdirs ) Makefile_target=CHROOT_TGT ;;
99 *bootscripts ) Makefile_target=BOOT_TGT ;; # case of sysv book
100 *network ) Makefile_target=BOOT_TGT ;; # case of systemd book
101 esac
102 eval $Makefile_target=\"\$$Makefile_target ${this_script}\"
103
104 #--------------------------------------------------------------------#
105 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
106 #--------------------------------------------------------------------#
107
108 # Drop in the name of the target on a new line, and the previous target
109 # as a dependency. Also call the echo_message function.
110 case $Makefile_target in
111 CHROOT_TGT) CHROOT_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
112 *) LUSER_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
113 esac
114
115 # If $pkg_tarball isn't empty, we've got a package...
116 if [ "$pkg_tarball" != "" ] ; then
117 # Touch timestamp file if installed files logs shall be created.
118 # But only for the final install chapter and not when rebuilding it
119 if [ "${INSTALL_LOG}" = "y" ] &&
120 (( 1+nb_chaps <= $1 )) &&
121 [ "x$N" = x ] ; then
122 CHROOT_wrt_TouchTimestamp
123 fi
124 # Always initialize the test log file, since the test instructions may
125 # be "uncommented" by the user
126 case $Makefile_target in
127 CHROOT_TGT) CHROOT_wrt_test_log "${this_script}" "$pkg_version" ;;
128 LUSER_TGT ) LUSER_wrt_test_log "${this_script}" "$pkg_version" ;;
129 esac
130
131 # If using optimizations, write the instructions
132 case "${OPTIMIZE}$1${nb_chaps}${this_script}${REALSBU}" in
133 0* | *binutils-pass1y | 15* | 167* | 177*) ;;
134 *kernel*) wrt_makeflags "$name" ;; # No CFLAGS for kernel
135 *) wrt_optimize "$name" && wrt_makeflags "$name" ;;
136 esac
137 fi
138
139# Some scriptlet have a special treatment; otherwise standard
140 case "${this_script}" in
141 *addinguser)
142(
143cat << EOF
144 @if [ -f luser-id ]; then \\
145 function useradd() { true; }; \\
146 function groupadd() { true; }; \\
147 export -f useradd groupadd; \\
148 fi; \\
149 export LFS=\$(MOUNT_PT) && \\
150 \$(CMDSDIR)/`dirname $file`/\$@ >> \$(LOGDIR)/\$@ 2>&1; \\
151 \$(PRT_DU) >>logs/\$@
152 @chown \$(LUSER):\$(LGROUP) envars
153 @chmod -R a+wt $JHALFSDIR
154 @chmod a+wt \$(SRCSDIR)
155EOF
156) >> $MKFILE.tmp
157 ;;
158 *settingenvironment)
159(
160cat << EOF
161 @cd && \\
162 function source() { true; } && \\
163 export -f source && \\
164 \$(CMDSDIR)/`dirname $file`/\$@ >> \$(LOGDIR)/\$@ 2>&1 && \\
165 sed 's|/mnt/lfs|\$(MOUNT_PT)|' -i .bashrc && \\
166 echo source $JHALFSDIR/envars >> .bashrc
167 @\$(PRT_DU) >>logs/\$@
168EOF
169) >> $MKFILE.tmp
170 ;;
171 *fstab) if [[ -n "$FSTAB" ]]; then
172 CHROOT_wrt_CopyFstab
173 else
174 CHROOT_wrt_RunAsRoot "$file"
175 fi
176 ;;
177
178 *)
179 # Insert date and disk usage at the top of the log file, the script
180 # run and date and disk usage again at the bottom of the log file.
181 case "${Makefile_target}" in
182 SETUP_TGT | SUDO_TGT) wrt_RunAsRoot "$file" "$pkg_version" ;;
183 LUSER_TGT) LUSER_wrt_RunAsUser "$file" "$pkg_version" ;;
184 CHROOT_TGT | BOOT_TGT) CHROOT_wrt_RunAsRoot "$file" "$pkg_version" ;;
185 esac
186 ;;
187 esac
188
189 # Write installed files log and remove the build directory(ies)
190 # except if the package build fails.
191 if [ "$pkg_tarball" != "" ] ; then
192 if [ "${INSTALL_LOG}" = "y" ] &&
193 (( 1+nb_chaps <= $1 )) &&
194 [ "x${N}" = "x" ] ; then
195 CHROOT_wrt_LogNewFiles "$name"
196 fi
197 fi
198
199 # Include a touch of the target name so make can check
200 # if it's already been made.
201 wrt_touch
202 #
203 #--------------------------------------------------------------------#
204 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
205 #--------------------------------------------------------------------#
206
207 # Keep the script file name for Makefile dependencies.
208 PREV=${this_script}
209 # Set "system_build" var for iteration targets
210 if [ -z "$N" ] && (( 1+nb_chaps == $1 )); then
211 system_build="$system_build $this_script"
212 fi
213
214 done # end for file in $dir/*
215 # Set "system_build" when rebuilding: note the CHROOT_TGT is local
216 # in that case.
217 if [ -n "$N" ]; then
218 system_build="$CHROOT_TGT"
219 fi
220}
221
222# NOT USED -- NOT USED
223#----------------------------#
224chapter5_Makefiles() {
225#----------------------------#
226 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5 ( LUSER ) ${R_arrow}"
227
228# Initialize the Makefile target: it'll change during chapter
229# For vanilla lfs, the "changingowner" script should be run as root. So
230# it belongs to the "SUDO" target, with list in the "runasroot" variable.
231# For new lfs, changingowner and kernfs are in "runasroot", then the following,
232# starting at creatingdirs, are in the "CHROOT" target, in variable "chapter6".
233# Makefile_target records the variable, not really the target!
234# We use a case statement on that variable, because instructions in the
235# Makefile change according to the phase of the build (LUSER, SUDO, CHROOT).
236 Makefile_target=chapter5
237
238# Start loop
239 for file in chapter05/* ; do
240 # Keep the script file name
241 this_script=`basename $file`
242
243 # Append each name of the script files to a list that Makefile_target
244 # points to. But before that, change Makefile_target at the first script
245 # of each target.
246 case "${this_script}" in
247 *changingowner) Makefile_target=runasroot ;;
248 *creatingdirs ) Makefile_target=chapter6 ;; # only run for new lfs
249 esac
250 eval $Makefile_target=\"\$$Makefile_target ${this_script}\"
251
252 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
253 # and binutils in chapter 5)
254 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' \
255 -e 's@-pass[0-9]\{1\}@@' \
256 -e 's@-libstdc++@@'`
257
258 #--------------------------------------------------------------------#
259 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
260 #--------------------------------------------------------------------#
261 #
262 # Find the name of the tarball and the version of the package
263 pkg_tarball=$(sed -n 's/tar -xf \(.*\)/\1/p' $file)
264 pkg_version=$(sed -n 's/VERSION=\(.*\)/\1/p' $file)
265
266 # Drop in the name of the target on a new line, and the previous target
267 # as a dependency. Also call the echo_message function.
268 case $Makefile_target in
269 chapter6) CHROOT_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
270 *) LUSER_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
271 esac
272
273 # If $pkg_tarball isn't empty, we've got a package...
274 if [ "$pkg_tarball" != "" ] ; then
275 # Always initialize the log file, since the test instructions may be
276 # "uncommented" by the user
277 case $Makefile_target in
278 chapter6) CHROOT_wrt_test_log "${this_script}" "$pkg_version" ;;
279 *) LUSER_wrt_test_log "${this_script}" "$pkg_version" ;;
280 esac
281
282 # If using optimizations, write the instructions
283 case "${OPTIMIZE}${this_script}${REALSBU}" in
284 *binutils-pass1y) ;;
285 2*) wrt_optimize "$name" && wrt_makeflags "$name" ;;
286 *) ;;
287 esac
288 fi
289
290 # Insert date and disk usage at the top of the log file, the script run
291 # and date and disk usage again at the bottom of the log file.
292 # The changingowner script must be run as root.
293 case "${Makefile_target}" in
294 runasroot) wrt_RunAsRoot "$file" "$pkg_version" ;;
295 chapter5) LUSER_wrt_RunAsUser "$file" "$pkg_version" ;;
296 chapter6) CHROOT_wrt_RunAsRoot "$file" "$pkg_version" ;;
297 esac
298
299 # Include a touch of the target name so make can check
300 # if it's already been made.
301 wrt_touch
302 #
303 #--------------------------------------------------------------------#
304 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
305 #--------------------------------------------------------------------#
306
307 # Keep the script file name for Makefile dependencies.
308 PREV=${this_script}
309 done # end for file in chapter05/*
310}
311
312# NOT USED -- NOT USED keep for ICA code
313#----------------------------#
314chapter6_Makefiles() {
315#----------------------------#
316
317 # Set envars and scripts for iteration targets
318 if [[ -z "$1" ]] ; then
319 local N=""
320 else
321 local N=-build_$1
322 local chapter6=""
323 mkdir chapter06$N
324 cp chapter06/* chapter06$N
325 for script in chapter06$N/* ; do
326 # Overwrite existing symlinks, files, and dirs
327 sed -e 's/ln *-sv/&f/g' \
328 -e 's/mv *-v/&f/g' \
329 -e 's/mkdir *-v/&p/g' -i ${script}
330 # Suppress the mod of "test-installation.pl" because now
331 # the library path points to /usr/lib
332 if [[ ${script} =~ glibc ]]; then
333 sed '/DL=/,/unset DL/d' -i ${script}
334 fi
335 # Rename the scripts
336 mv ${script} ${script}$N
337 done
338 # Remove Bzip2 binaries before make install (LFS-6.2 compatibility)
339 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i chapter06$N/*-bzip2$N
340 # Remove openssl-<version> from /usr/share/doc (LFS-9.x), because
341 # otherwise the mv command creates an openssl directory.
342 sed -e 's@mv -v@rm -rfv /usr/share/doc/openssl-*\n&@' \
343 -i chapter06$N/*-openssl$N
344 fi
345
346 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N ( CHROOT ) ${R_arrow}"
347
348# Initialize the Makefile target. In vanilla lfs, kernfs should be run as root,
349# then the others are run in chroot. If in new lfs, we should start in chroot.
350# this will be changed later because man-pages is the first script in
351# chapter 6. Note that this Makefile_target business is not really needed here
352# but we do it to have a similar structure to chapter 5 (we may merge all
353# those functions at some point).
354 case "$N" in
355 -build*) Makefile_target=chapter6 ;;
356 *) Makefile_target=runasroot ;;
357 esac
358
359# Start loop
360 for file in chapter06$N/* ; do
361 # Keep the script file name
362 this_script=`basename $file`
363
364 # Skip the "stripping" scripts if the user does not want to strip.
365 # Skip also linux-headers in iterative builds.
366 case "${this_script}" in
367 *stripping*) [[ "${STRIP}" = "n" ]] && continue ;;
368 *linux-headers*) [[ -n "$N" ]] && continue ;;
369 esac
370
371 # Grab the name of the target.
372 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's,'$N',,'`
373
374 # Find the tarball corresponding to our script.
375 # If it doesn't exist, we skip it in iterations rebuilds (except stripping
376 # and revisedchroot, where .a and .la files are removed).
377 pkg_tarball=$(sed -n 's/tar -xf \(.*\)/\1/p' $file)
378 pkg_version=$(sed -n 's/VERSION=\(.*\)/\1/p' $file)
379
380 if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
381 case "${this_script}" in
382 *stripping*|*revised*) ;;
383 *) continue ;;
384 esac
385 fi
386
387 # Append each name of the script files to a list (this will become
388 # the names of the targets in the Makefile)
389 # The kernfs script must be run as part of SUDO target.
390 case "${this_script}" in
391 *creatingdirs) Makefile_target=chapter6 ;;
392 *man-pages ) Makefile_target=chapter6 ;;
393 esac
394 eval $Makefile_target=\"\$$Makefile_target ${this_script}\"
395
396 #--------------------------------------------------------------------#
397 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
398 #--------------------------------------------------------------------#
399 #
400 # Drop in the name of the target on a new line, and the previous target
401 # as a dependency. Also call the echo_message function.
402 # In the mount of kernel filesystems we need to set LFS
403 # and not to use chroot.
404 case "${Makefile_target}" in
405 runasroot) LUSER_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
406 *) CHROOT_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
407 esac
408
409 # If $pkg_tarball isn't empty, we've got a package...
410 # Insert instructions for unpacking the package and changing directories
411 if [ "$pkg_tarball" != "" ] ; then
412 # Touch timestamp file if installed files logs will be created.
413 # But only for the firt build when running iterative builds.
414 if [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
415 CHROOT_wrt_TouchTimestamp
416 fi
417 # Always initialize the log file, so that the user may reinstate a
418 # commented out test
419 CHROOT_wrt_test_log "${this_script}" "$pkg_version"
420 # If using optimizations, write the instructions
421 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
422 fi
423
424 # In the mount of kernel filesystems we need to set LFS
425 # and not to use chroot.
426 case "${Makefile_target}" in
427 runasroot) wrt_RunAsRoot "$file" "$pkg_version" ;;
428 *) CHROOT_wrt_RunAsRoot "$file" "$pkg_version" ;;
429 esac
430
431 # Write installed files log and remove the build directory(ies)
432 # except if the package build fails.
433 if [ "$pkg_tarball" != "" ] ; then
434 if [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
435 CHROOT_wrt_LogNewFiles "$name"
436 fi
437 fi
438
439 # Include a touch of the target name so make can check
440 # if it's already been made.
441 wrt_touch
442 #
443 #--------------------------------------------------------------------#
444 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
445 #--------------------------------------------------------------------#
446
447 # Keep the script file name for Makefile dependencies.
448 PREV=${this_script}
449 # Set system_build envar for iteration targets
450 if [ -z "$N" ]; then
451 system_build="$system_build $this_script"
452 fi
453 done # end for file in chapter06/*
454 if [ -n "$N" ]; then
455 system_build="$chapter6"
456 fi
457}
458# NOT USED -- NOT USED
459#----------------------------#
460chapter78_Makefiles() {
461#----------------------------#
462 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8 ( BOOT ) ${R_arrow}"
463
464 for file in chapter0{7,8}/* ; do
465 # Keep the script file name
466 this_script=`basename $file`
467
468 # Grub must be configured manually.
469 # Handle fstab creation.
470 # If no .config file is supplied, the kernel build is skipped
471 case ${this_script} in
472 *grub) continue ;;
473 *fstab) [[ -z "${FSTAB}" ]] ||
474 [[ ${FSTAB} == $BUILDDIR/sources/fstab ]] ||
475 cp ${FSTAB} $BUILDDIR/sources/fstab ;;
476 *kernel) [[ -z ${CONFIG} ]] && continue
477 [[ ${CONFIG} == $BUILDDIR/sources/kernel-config ]] ||
478 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
479 esac
480
481 # First append each name of the script files to a list (this will become
482 # the names of the targets in the Makefile
483 chapter78="$chapter78 ${this_script}"
484
485 #--------------------------------------------------------------------#
486 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
487 #--------------------------------------------------------------------#
488 #
489 # Drop in the name of the target on a new line, and the previous target
490 # as a dependency. Also call the echo_message function.
491 CHROOT_wrt_target "${this_script}" "$PREV"
492
493 # Find the bootscripts or networkscripts (for systemd)
494 # and kernel package names
495 case "${this_script}" in
496 *bootscripts)
497 name="lfs-bootscripts"
498 if [ "${INSTALL_LOG}" = "y" ] ; then
499 CHROOT_wrt_TouchTimestamp
500 fi
501 ;;
502 *network-scripts)
503 name="lfs-network-scripts"
504 if [ "${INSTALL_LOG}" = "y" ] ; then
505 CHROOT_wrt_TouchTimestamp
506 fi
507 ;;
508 *kernel)
509 name="linux"
510 if [ "${INSTALL_LOG}" = "y" ] ; then
511 CHROOT_wrt_TouchTimestamp
512 fi
513 # If using optimizations, use MAKEFLAGS (unless blacklisted)
514 # no setting of CFLAGS and friends.
515 [[ "$OPTIMIZE" != "0" ]] && wrt_makeflags "$name"
516 ;;
517 esac
518
519 # Check if we have a real /etc/fstab file
520 case "${this_script}" in
521 *fstab) if [[ -n "$FSTAB" ]]; then
522 CHROOT_wrt_CopyFstab
523 else
524 CHROOT_wrt_RunAsRoot "$file"
525 fi
526 ;;
527 *) CHROOT_wrt_RunAsRoot "$file"
528 ;;
529 esac
530
531 case "${this_script}" in
532 *bootscripts|*network-scripts|*kernel)
533 if [ "${INSTALL_LOG}" = "y" ] ; then
534 CHROOT_wrt_LogNewFiles "$name"
535 fi ;;
536 esac
537 # Include a touch of the target name so make can check
538 # if it's already been made.
539 wrt_touch
540 #
541 #--------------------------------------------------------------------#
542 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
543 #--------------------------------------------------------------------#
544
545 # Keep the script file name for Makefile dependencies.
546 PREV=${this_script}
547 done # for file in chapter0{7,8}/*
548
549}
550
551#----------------------------#
552build_Makefile() { #
553#----------------------------#
554
555 echo "Creating Makefile... ${BOLD}START${OFF}"
556
557 cd $JHALFSDIR/${PROGNAME}-commands
558
559 # Start with empty files
560 >$MKFILE
561 >$MKFILE.tmp
562
563 # Ensure the first dependency is empty
564 unset PREV
565
566 # We begin with the SETUP target; successive targets will be assigned in
567 # the chapter_targets function.
568 Makefile_target=SETUP_TGT
569
570 # We need to know the chapter numbering, which depends on the version
571 # of the book. Use the number of subdirs to know which version we have
572 chaps=($(echo *))
573 nb_chaps=${#chaps[*]} # 5 if classical version, 7 if new version
574# DEBUG
575# echo chaps: ${chaps[*]}
576# echo nb_chaps: $nb_chaps
577# end DEBUG
578
579 # Make a temporary file with all script targets
580 for (( i = 4; i < nb_chaps+4; i++ )); do
581 chapter_targets $i
582 if (( i == nb_chaps )); then : # we have finished temporary tools
583 # Add the save target, if needed
584 [[ "$SAVE_CH5" = "y" ]] && wrt_save_target $Makefile_target
585 fi
586 if (( i == 1+nb_chaps )); then : # we have finished final system
587 # Add the iterations targets, if needed
588 [[ "$COMPARE" = "y" ]] && wrt_compare_targets $i
589 fi
590 done
591 # Add the CUSTOM_TOOLS targets, if needed
592 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
593
594 # Add a header, some variables and include the function file
595 # to the top of the real Makefile.
596 wrt_Makefile_header
597
598 # Add chroot commands
599 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
600 i=1
601 for file in ../chroot-scripts/*chroot* ; do
602 chroot=`cat $file | \
603 perl -pe 's|\\\\\n||g' | \
604 tr -s [:space:] | \
605 grep chroot | \
606 sed -e "s|chroot|$CHROOT_LOC|" \
607 -e 's|\\$|&&|g' \
608 -e 's|"$$LFS"|$(MOUNT_PT)|'`
609 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
610 i=`expr $i + 1`
611 done
612
613 # Store virtual kernel file systems commands:
614 devices=`cat ../kernfs-scripts/devices.sh | \
615 sed -e 's|^| |' \
616 -e 's|mount|sudo &|' \
617 -e 's|mkdir|sudo &|' \
618 -e 's|\\$|&&|g' \
619 -e 's|\$|; \\\\|' \
620 -e 's|then|& :|' \
621 -e 's|\$\$LFS|$(MOUNT_PT)|g'`
622 teardown=`cat ../kernfs-scripts/teardown.sh | \
623 sed -e 's|^| |' \
624 -e 's|umount|sudo &|' \
625 -e 's|\$LFS|$(MOUNT_PT)|'`
626 teardownat=`cat ../kernfs-scripts/teardown.sh | \
627 sed -e 's|^| |' \
628 -e 's|umount|@-sudo &|' \
629 -e 's|\$LFS|$(MOUNT_PT)|'`
630 # Drop in the main target 'all:' and the chapter targets with each sub-target
631 # as a dependency.
632(
633 cat << EOF
634
635all: ck_UID ck_terminal mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_BLFS_TOOL mk_CUSTOM_TOOLS
636$teardownat
637 @sudo make do_housekeeping
638EOF
639) >> $MKFILE
640if [ "$INITSYS" = systemd ]; then
641(
642 cat << EOF
643 @/bin/echo -e -n \\
644 NAME=\\"Linux From Scratch\\"\\\\n\\
645 VERSION=\\"$VERSION\\"\\\\n\\
646 ID=lfs\\\\n\\
647 PRETTY_NAME=\\"Linux From Scratch $VERSION\\"\\\\n\\
648 VERSION_CODENAME=\\"$(whoami)-jhalfs\\"\\\\n\\
649 > os-release && \\
650 sudo mv os-release \$(MOUNT_PT)/etc && \\
651 sudo chown root:root \$(MOUNT_PT)/etc/os-release
652EOF
653) >> $MKFILE
654fi
655(
656 cat << EOF
657 @echo $VERSION > lfs-release && \\
658 sudo mv lfs-release \$(MOUNT_PT)/etc && \\
659 sudo chown root:root \$(MOUNT_PT)/etc/lfs-release
660 @/bin/echo -e -n \\
661 DISTRIB_ID=\\"Linux From Scratch\\"\\\\n\\
662 DISTRIB_RELEASE=\\"$VERSION\\"\\\\n\\
663 DISTRIB_CODENAME=\\"$(whoami)-jhalfs\\"\\\\n\\
664 DISTRIB_DESCRIPTION=\\"Linux From Scratch\\"\\\\n\\
665 > lsb-release && \\
666 sudo mv lsb-release \$(MOUNT_PT)/etc && \\
667 sudo chown root:root \$(MOUNT_PT)/etc/lsb-release
668 @\$(call echo_finished,$VERSION)
669
670ck_UID:
671 @if [ \`id -u\` = "0" ]; then \\
672 echo "--------------------------------------------------"; \\
673 echo "You cannot run this makefile from the root account"; \\
674 echo "--------------------------------------------------"; \\
675 exit 1; \\
676 fi
677
678ck_terminal:
679 @stty size | ( read L C; \\
680 if (( L < 24 )) || (( C < 80 )) ; then \\
681 echo "--------------------------------------------------"; \\
682 echo "Terminal too small: \$\$C columns x \$\$L lines";\\
683 echo "Minimum: 80 columns x 24 lines";\\
684 echo "--------------------------------------------------"; \\
685 exit 1; \\
686 fi )
687
688mk_SETUP:
689 @\$(call echo_SU_request)
690 @sudo make save-luser
691 @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
692 @touch \$@
693
694mk_LUSER: mk_SETUP
695 @\$(call echo_SULUSER_request)
696 @\$(SU_LUSER) "make -C \$(MOUNT_PT)/\$(SCRIPT_ROOT) BREAKPOINT=\$(BREAKPOINT) LUSER"
697 @sudo make restore-luser
698 @touch \$@
699
700mk_SUDO: mk_LUSER
701 @sudo rm -f envars
702 @sudo make BREAKPOINT=\$(BREAKPOINT) SUDO
703 @touch \$@
704
705mk_CHROOT: mk_SUDO
706 @\$(call echo_CHROOT_request)
707 @( sudo \$(CHROOT1) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CHROOT")
708 @touch \$@
709
710mk_BOOT: mk_CHROOT
711 @\$(call echo_CHROOT_request)
712 @( sudo \$(CHROOT2) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BOOT")
713 @touch \$@
714
715mk_BLFS_TOOL: create-sbu_du-report
716 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
717 \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
718 (sudo \$(CHROOT2) -c "make -C $BLFS_ROOT/work"); \\
719 fi;
720 @touch \$@
721
722mk_CUSTOM_TOOLS: mk_BLFS_TOOL
723 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
724 \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
725 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
726 (sudo \$(CHROOT2) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
727 fi;
728 @touch \$@
729
730devices: ck_UID
731$devices
732EOF
733) >> $MKFILE
734if [ "$INITSYS" = systemd ]; then
735(
736 cat << EOF
737 sudo mkdir -pv \$(MOUNT_PT)/run/systemd/resolve
738 sudo cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve
739EOF
740) >> $MKFILE
741fi
742(
743 cat << EOF
744
745teardown:
746$teardown
747
748chroot1: devices
749 sudo \$(CHROOT1)
750 \$(MAKE) teardown
751
752chroot: devices
753 sudo \$(CHROOT2)
754 \$(MAKE) teardown
755
756SETUP: $SETUP_TGT
757LUSER: $LUSER_TGT
758SUDO: $SUDO_TGT
759EOF
760) >> $MKFILE
761if [ "$INITSYS" = systemd ]; then
762(
763 cat << EOF
764 mkdir -pv \$(MOUNT_PT)/run/systemd/resolve
765 cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve
766
767EOF
768) >> $MKFILE
769fi
770(
771 cat << EOF
772CHROOT: SHELL=\$(filter %bash,\$(CHROOT1))
773CHROOT: $CHROOT_TGT
774BOOT: $BOOT_TGT
775CUSTOM_TOOLS: $custom_list
776
777create-sbu_du-report: mk_BOOT
778 @\$(call echo_message, Building)
779 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
780 sudo ./create-sbu_du-report.sh logs $VERSION $(date --iso-8601); \\
781 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
782 fi
783 @touch \$@
784
785save-luser:
786 @\$(call echo_message, Building)
787 @LUSER_ID=\$\$(grep '^\$(LUSER):' /etc/passwd | cut -d: -f3); \\
788 if [ -n "\$\$LUSER_ID" ]; then \\
789 if [ ! -d \$(LUSER_HOME).XXX ]; then \\
790 mv \$(LUSER_HOME){,.XXX}; \\
791 mkdir \$(LUSER_HOME); \\
792 chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME); \\
793 fi; \\
794 echo "\$\$LUSER_ID" > luser-id; \\
795 echo User \$(LUSER) exists with ID \$\$LUSER_ID; \\
796 else \\
797 rm -f luser-id; \\
798 echo User \$(LUSER) does not exist; \\
799 echo It will be created with book instructions.; \\
800 fi
801 @\$(call housekeeping)
802
803restore-luser:
804 @\$(call echo_message, Building)
805 @if [ -f luser-id ]; then \\
806 rm -rf \$(LUSER_HOME); \\
807 mv \$(LUSER_HOME){.XXX,}; \\
808 rm luser-id; \\
809 else \\
810 userdel \$(LUSER); \\
811 groupdel \$(LGROUP); \\
812 rm -rf \$(LUSER_HOME); \\
813 fi
814 @\$(call housekeeping)
815
816do_housekeeping:
817 @-rm /tools
818
819EOF
820) >> $MKFILE
821
822 # Bring over the items from the Makefile.tmp
823 cat $MKFILE.tmp >> $MKFILE
824 rm $MKFILE.tmp
825 echo "Creating Makefile... ${BOLD}DONE${OFF}"
826}
Note: See TracBrowser for help on using the repository browser.