source: LFS/master.sh@ e4b7aa8

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

Update ICA for new LFS/master.sh

  • Property mode set to 100644
File size: 27.9 KB
RevLine 
[91ff6a9]1#!/bin/bash
[877cc6a]2
3# $Id$
4
5###################################
6### FUNCTIONS ###
7###################################
8
9
[045b2dc]10#############################################################
11
12
[ebe1ba6]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
[3da8c49]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}"
[877cc6a]45
[3da8c49]46 for file in ${dir}$N/* ; do
[903eefd]47 # Keep the script file name
48 this_script=`basename $file`
[877cc6a]49
[ebe1ba6]50 # Some scripts need peculiar actions:
[3da8c49]51 # - glibc chap 5: fix locales creation when running chapter05 testsuites
[ebe1ba6]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
[3da8c49]55 # - do not reinstall linux-headers when rebuilding
[ebe1ba6]56 # - grub config: must be done manually; skip it
57 # - handle fstab and .config. Skip kernel if .config not supplied
[903eefd]58 case "${this_script}" in
[ebe1ba6]59 5*glibc) [[ "${TEST}" = "3" ]] && \
60 sed -i 's@/usr/lib/locale@/tools/lib/locale@' $file ;;
61 *strippingagain) [[ "${STRIP}" = "n" ]] && continue ;;
[3da8c49]62 *linux-headers*) [[ -n "$N" ]] && continue ;;
[ebe1ba6]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 ;;
[903eefd]71 esac
[3da8c49]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
[877cc6a]90
[ebe1ba6]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
[903eefd]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.
[ebe1ba6]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.
[3da8c49]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
[ebe1ba6]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
[903eefd]130
[ebe1ba6]131 # If using optimizations, write the instructions
132 case "${OPTIMIZE}$1${nb_chaps}${this_script}${REALSBU}" in
133 0* | *binutils-pass1y | 15* | 167* | 177*) ;;
[b33c6ee]134 *kernel*) wrt_makeflags "$name" ;; # No CFLAGS for kernel
[ebe1ba6]135 *) wrt_optimize "$name" && wrt_makeflags "$name" ;;
136 esac
137 fi
138
139# Some scriptlet have a special treatment; otherwise standard
[903eefd]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)
[877cc6a]155EOF
[903eefd]156) >> $MKFILE.tmp
157 ;;
[ebe1ba6]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 ;;
[903eefd]187 esac
[045b2dc]188
[ebe1ba6]189 # Write installed files log and remove the build directory(ies)
190 # except if the package build fails.
191 if [ "$pkg_tarball" != "" ] ; then
[3da8c49]192 if [ "${INSTALL_LOG}" = "y" ] &&
193 (( 1+nb_chaps <= $1 )) &&
194 [ "x${N}" = "x" ] ; then
[ebe1ba6]195 CHROOT_wrt_LogNewFiles "$name"
196 fi
197 fi
198
[903eefd]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}
[3da8c49]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
[ebe1ba6]214 done # end for file in $dir/*
[3da8c49]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
[877cc6a]220}
221
[ebe1ba6]222# NOT USED -- NOT USED
[877cc6a]223#----------------------------#
224chapter5_Makefiles() {
225#----------------------------#
[045b2dc]226 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5 ( LUSER ) ${R_arrow}"
[877cc6a]227
[3261fe7]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.
[f5ecc28]231# For new lfs, changingowner and kernfs are in "runasroot", then the following,
[3261fe7]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
[877cc6a]239 for file in chapter05/* ; do
240 # Keep the script file name
241 this_script=`basename $file`
242
[3261fe7]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.
[045b2dc]246 case "${this_script}" in
[3261fe7]247 *changingowner) Makefile_target=runasroot ;;
248 *creatingdirs ) Makefile_target=chapter6 ;; # only run for new lfs
[045b2dc]249 esac
[3261fe7]250 eval $Makefile_target=\"\$$Makefile_target ${this_script}\"
[877cc6a]251
252 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
253 # and binutils in chapter 5)
[1849935]254 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' \
255 -e 's@-pass[0-9]\{1\}@@' \
256 -e 's@-libstdc++@@'`
[877cc6a]257
258 #--------------------------------------------------------------------#
259 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
260 #--------------------------------------------------------------------#
261 #
[3cb4ef5b]262 # Find the name of the tarball and the version of the package
[2758d94]263 pkg_tarball=$(sed -n 's/tar -xf \(.*\)/\1/p' $file)
264 pkg_version=$(sed -n 's/VERSION=\(.*\)/\1/p' $file)
[3cb4ef5b]265
[877cc6a]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.
[3261fe7]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
[b7faa5a]272
[a160d86]273 # If $pkg_tarball isn't empty, we've got a package...
274 if [ "$pkg_tarball" != "" ] ; then
[5a8939e]275 # Always initialize the log file, since the test instructions may be
276 # "uncommented" by the user
[3261fe7]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
[a229600]282 # If using optimizations, write the instructions
[84a3fda]283 case "${OPTIMIZE}${this_script}${REALSBU}" in
284 *binutils-pass1y) ;;
285 2*) wrt_optimize "$name" && wrt_makeflags "$name" ;;
286 *) ;;
287 esac
[877cc6a]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.
[a241c33]292 # The changingowner script must be run as root.
[3261fe7]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" ;;
[a241c33]297 esac
[877cc6a]298
299 # Include a touch of the target name so make can check
300 # if it's already been made.
[e2ef100]301 wrt_touch
[877cc6a]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
[ebe1ba6]312# NOT USED -- NOT USED keep for ICA code
[877cc6a]313#----------------------------#
314chapter6_Makefiles() {
315#----------------------------#
[045b2dc]316
[45f82718]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
[93fd2d0]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
[10c8b78]335 # Rename the scripts
336 mv ${script} ${script}$N
[45f82718]337 done
[a5f52ba]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
[709eb74]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
[45f82718]344 fi
345
[045b2dc]346 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N ( CHROOT ) ${R_arrow}"
[45f82718]347
[3261fe7]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).
[7b7b5e9]354 case "$N" in
355 -build*) Makefile_target=chapter6 ;;
356 *) Makefile_target=runasroot ;;
357 esac
[3261fe7]358
359# Start loop
[45f82718]360 for file in chapter06$N/* ; do
[877cc6a]361 # Keep the script file name
362 this_script=`basename $file`
363
[d68eb1b]364 # Skip the "stripping" scripts if the user does not want to strip.
[8426d1f]365 # Skip also linux-headers in iterative builds.
[877cc6a]366 case "${this_script}" in
[401f81e]367 *stripping*) [[ "${STRIP}" = "n" ]] && continue ;;
[8426d1f]368 *linux-headers*) [[ -n "$N" ]] && continue ;;
[877cc6a]369 esac
370
[4eba1ea]371 # Grab the name of the target.
[10c8b78]372 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's,'$N',,'`
[877cc6a]373
[d68eb1b]374 # Find the tarball corresponding to our script.
[bdb0761]375 # If it doesn't exist, we skip it in iterations rebuilds (except stripping
376 # and revisedchroot, where .a and .la files are removed).
[2758d94]377 pkg_tarball=$(sed -n 's/tar -xf \(.*\)/\1/p' $file)
378 pkg_version=$(sed -n 's/VERSION=\(.*\)/\1/p' $file)
[45f82718]379
[a160d86]380 if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
[45f82718]381 case "${this_script}" in
[bdb0761]382 *stripping*|*revised*) ;;
[45f82718]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)
[4eba1ea]389 # The kernfs script must be run as part of SUDO target.
390 case "${this_script}" in
[3261fe7]391 *creatingdirs) Makefile_target=chapter6 ;;
392 *man-pages ) Makefile_target=chapter6 ;;
[4eba1ea]393 esac
[3261fe7]394 eval $Makefile_target=\"\$$Makefile_target ${this_script}\"
[45f82718]395
[877cc6a]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.
[8bea2c8]402 # In the mount of kernel filesystems we need to set LFS
403 # and not to use chroot.
[3261fe7]404 case "${Makefile_target}" in
405 runasroot) LUSER_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
406 *) CHROOT_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
[8bea2c8]407 esac
[877cc6a]408
[a160d86]409 # If $pkg_tarball isn't empty, we've got a package...
[877cc6a]410 # Insert instructions for unpacking the package and changing directories
[a160d86]411 if [ "$pkg_tarball" != "" ] ; then
[38d2de6]412 # Touch timestamp file if installed files logs will be created.
[81fca31]413 # But only for the firt build when running iterative builds.
414 if [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
[93346ee]415 CHROOT_wrt_TouchTimestamp
416 fi
[3261fe7]417 # Always initialize the log file, so that the user may reinstate a
[5a8939e]418 # commented out test
419 CHROOT_wrt_test_log "${this_script}" "$pkg_version"
[a229600]420 # If using optimizations, write the instructions
[1b65a84]421 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
[877cc6a]422 fi
423
424 # In the mount of kernel filesystems we need to set LFS
425 # and not to use chroot.
[3261fe7]426 case "${Makefile_target}" in
427 runasroot) wrt_RunAsRoot "$file" "$pkg_version" ;;
428 *) CHROOT_wrt_RunAsRoot "$file" "$pkg_version" ;;
[877cc6a]429 esac
430
[93346ee]431 # Write installed files log and remove the build directory(ies)
432 # except if the package build fails.
[a160d86]433 if [ "$pkg_tarball" != "" ] ; then
[81fca31]434 if [ "${INSTALL_LOG}" = "y" ] && [ "x${N}" = "x" ] ; then
[93346ee]435 CHROOT_wrt_LogNewFiles "$name"
436 fi
[877cc6a]437 fi
438
439 # Include a touch of the target name so make can check
440 # if it's already been made.
[e2ef100]441 wrt_touch
[877cc6a]442 #
443 #--------------------------------------------------------------------#
444 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
445 #--------------------------------------------------------------------#
446
447 # Keep the script file name for Makefile dependencies.
[10c8b78]448 PREV=${this_script}
[45f82718]449 # Set system_build envar for iteration targets
[7b7b5e9]450 if [ -z "$N" ]; then
451 system_build="$system_build $this_script"
452 fi
[877cc6a]453 done # end for file in chapter06/*
[7b7b5e9]454 if [ -n "$N" ]; then
455 system_build="$chapter6"
456 fi
[877cc6a]457}
[ebe1ba6]458# NOT USED -- NOT USED
[877cc6a]459#----------------------------#
[14eaa9f]460chapter78_Makefiles() {
[877cc6a]461#----------------------------#
[b11c10b]462 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8 ( BOOT ) ${R_arrow}"
[877cc6a]463
[14eaa9f]464 for file in chapter0{7,8}/* ; do
[877cc6a]465 # Keep the script file name
466 this_script=`basename $file`
467
468 # Grub must be configured manually.
[14eaa9f]469 # Handle fstab creation.
[877cc6a]470 # If no .config file is supplied, the kernel build is skipped
471 case ${this_script} in
472 *grub) continue ;;
[d601cfc]473 *fstab) [[ -z "${FSTAB}" ]] ||
[85506da]474 [[ ${FSTAB} == $BUILDDIR/sources/fstab ]] ||
475 cp ${FSTAB} $BUILDDIR/sources/fstab ;;
[877cc6a]476 *kernel) [[ -z ${CONFIG} ]] && continue
[85506da]477 [[ ${CONFIG} == $BUILDDIR/sources/kernel-config ]] ||
[877cc6a]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
[14eaa9f]483 chapter78="$chapter78 ${this_script}"
[877cc6a]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.
[045b2dc]491 CHROOT_wrt_target "${this_script}" "$PREV"
[877cc6a]492
[532ede6]493 # Find the bootscripts or networkscripts (for systemd)
494 # and kernel package names
[877cc6a]495 case "${this_script}" in
496 *bootscripts)
[a160d86]497 name="lfs-bootscripts"
[93346ee]498 if [ "${INSTALL_LOG}" = "y" ] ; then
499 CHROOT_wrt_TouchTimestamp
500 fi
[877cc6a]501 ;;
[532ede6]502 *network-scripts)
503 name="lfs-network-scripts"
504 if [ "${INSTALL_LOG}" = "y" ] ; then
505 CHROOT_wrt_TouchTimestamp
506 fi
507 ;;
[877cc6a]508 *kernel)
[a160d86]509 name="linux"
[93346ee]510 if [ "${INSTALL_LOG}" = "y" ] ; then
511 CHROOT_wrt_TouchTimestamp
512 fi
[93fd2d0]513 # If using optimizations, use MAKEFLAGS (unless blacklisted)
514 # no setting of CFLAGS and friends.
515 [[ "$OPTIMIZE" != "0" ]] && wrt_makeflags "$name"
[877cc6a]516 ;;
517 esac
518
519 # Check if we have a real /etc/fstab file
520 case "${this_script}" in
[d601cfc]521 *fstab) if [[ -n "$FSTAB" ]]; then
[045b2dc]522 CHROOT_wrt_CopyFstab
[877cc6a]523 else
[045b2dc]524 CHROOT_wrt_RunAsRoot "$file"
[877cc6a]525 fi
526 ;;
[045b2dc]527 *) CHROOT_wrt_RunAsRoot "$file"
[877cc6a]528 ;;
529 esac
530
531 case "${this_script}" in
[2758d94]532 *bootscripts|*network-scripts|*kernel)
[532ede6]533 if [ "${INSTALL_LOG}" = "y" ] ; then
534 CHROOT_wrt_LogNewFiles "$name"
535 fi ;;
[877cc6a]536 esac
537 # Include a touch of the target name so make can check
538 # if it's already been made.
[e2ef100]539 wrt_touch
[877cc6a]540 #
541 #--------------------------------------------------------------------#
542 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
543 #--------------------------------------------------------------------#
544
545 # Keep the script file name for Makefile dependencies.
546 PREV=${this_script}
[14eaa9f]547 done # for file in chapter0{7,8}/*
[453bef0]548
[877cc6a]549}
550
551#----------------------------#
[045b2dc]552build_Makefile() { #
[877cc6a]553#----------------------------#
[045b2dc]554
[c7c5a53]555 echo "Creating Makefile... ${BOLD}START${OFF}"
[045b2dc]556
[877cc6a]557 cd $JHALFSDIR/${PROGNAME}-commands
558
[ebe1ba6]559 # Start with empty files
[045b2dc]560 >$MKFILE
[ebe1ba6]561 >$MKFILE.tmp
562
563 # Ensure the first dependency is empty
564 unset PREV
[877cc6a]565
[ebe1ba6]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
[3da8c49]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
[ebe1ba6]590 done
[3e7ceed]591 # Add the CUSTOM_TOOLS targets, if needed
592 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
[877cc6a]593
594 # Add a header, some variables and include the function file
595 # to the top of the real Makefile.
[195ed9f]596 wrt_Makefile_header
[877cc6a]597
598 # Add chroot commands
[6ad5a2f]599 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
[877cc6a]600 i=1
[d68eb1b]601 for file in ../chroot-scripts/*chroot* ; do
[6ad5a2f]602 chroot=`cat $file | \
[abc8b27]603 perl -pe 's|\\\\\n||g' | \
604 tr -s [:space:] | \
605 grep chroot | \
606 sed -e "s|chroot|$CHROOT_LOC|" \
[6ad5a2f]607 -e 's|\\$|&&|g' \
[abc8b27]608 -e 's|"$$LFS"|$(MOUNT_PT)|'`
[877cc6a]609 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
610 i=`expr $i + 1`
611 done
612
[13c475b]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' \
[a659e46]619 -e 's|\$|; \\\\|' \
620 -e 's|then|& :|' \
[13c475b]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)|'`
[877cc6a]630 # Drop in the main target 'all:' and the chapter targets with each sub-target
631 # as a dependency.
632(
633 cat << EOF
[045b2dc]634
[9728b23]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
[13c475b]636$teardownat
[045b2dc]637 @sudo make do_housekeeping
[df97e68]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
[e1fc855]657 @echo $VERSION > lfs-release && \\
[9096853]658 sudo mv lfs-release \$(MOUNT_PT)/etc && \\
659 sudo chown root:root \$(MOUNT_PT)/etc/lfs-release
[e1fc855]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
[877cc6a]668 @\$(call echo_finished,$VERSION)
669
[045b2dc]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
[9728b23]678ck_terminal:
[7e0a1b8]679 @stty size | ( read L C; \\
680 if (( L < 24 )) || (( C < 80 )) ; then \\
[9728b23]681 echo "--------------------------------------------------"; \\
[7e0a1b8]682 echo "Terminal too small: \$\$C columns x \$\$L lines";\\
[9728b23]683 echo "Minimum: 80 columns x 24 lines";\\
684 echo "--------------------------------------------------"; \\
685 exit 1; \\
[7e0a1b8]686 fi )
[9728b23]687
[045b2dc]688mk_SETUP:
689 @\$(call echo_SU_request)
[dd7e0f67]690 @sudo make save-luser
[dbcdfd7]691 @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
[045b2dc]692 @touch \$@
693
694mk_LUSER: mk_SETUP
695 @\$(call echo_SULUSER_request)
[903eefd]696 @\$(SU_LUSER) "make -C \$(MOUNT_PT)/\$(SCRIPT_ROOT) BREAKPOINT=\$(BREAKPOINT) LUSER"
697 @sudo make restore-luser
[045b2dc]698 @touch \$@
699
700mk_SUDO: mk_LUSER
[a73ed74]701 @sudo rm -f envars
[dbcdfd7]702 @sudo make BREAKPOINT=\$(BREAKPOINT) SUDO
[1330ebc]703 @touch \$@
704
[045b2dc]705mk_CHROOT: mk_SUDO
706 @\$(call echo_CHROOT_request)
[d68eb1b]707 @( sudo \$(CHROOT1) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CHROOT")
[045b2dc]708 @touch \$@
[877cc6a]709
[045b2dc]710mk_BOOT: mk_CHROOT
711 @\$(call echo_CHROOT_request)
[d68eb1b]712 @( sudo \$(CHROOT2) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BOOT")
[045b2dc]713 @touch \$@
[877cc6a]714
[ac9bdc7]715mk_BLFS_TOOL: create-sbu_du-report
716 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
717 \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
[d68eb1b]718 (sudo \$(CHROOT2) -c "make -C $BLFS_ROOT/work"); \\
[ac9bdc7]719 fi;
720 @touch \$@
721
722mk_CUSTOM_TOOLS: mk_BLFS_TOOL
[3e7ceed]723 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
[3bc6078]724 \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
[3e7ceed]725 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
[d68eb1b]726 (sudo \$(CHROOT2) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
[3e7ceed]727 fi;
728 @touch \$@
729
[f60a8b7]730devices: ck_UID
[13c475b]731$devices
[d39252b]732EOF
733) >> $MKFILE
734if [ "$INITSYS" = systemd ]; then
735(
736 cat << EOF
737 sudo mkdir -pv \$(MOUNT_PT)/run/systemd/resolve
[426c618]738 sudo cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve
[d39252b]739EOF
740) >> $MKFILE
741fi
742(
743 cat << EOF
[13c475b]744
[2e1c1c3]745teardown:
[13c475b]746$teardown
[d39252b]747
748chroot1: devices
749 sudo \$(CHROOT1)
750 \$(MAKE) teardown
[7c17066]751
752chroot: devices
[d68eb1b]753 sudo \$(CHROOT2)
[7c17066]754 \$(MAKE) teardown
[877cc6a]755
[ebe1ba6]756SETUP: $SETUP_TGT
757LUSER: $LUSER_TGT
758SUDO: $SUDO_TGT
[13c475b]759EOF
760) >> $MKFILE
761if [ "$INITSYS" = systemd ]; then
762(
763 cat << EOF
[c6506aea]764 mkdir -pv \$(MOUNT_PT)/run/systemd/resolve
765 cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve
[13c475b]766
767EOF
768) >> $MKFILE
769fi
770(
771 cat << EOF
[a73ed74]772CHROOT: SHELL=\$(filter %bash,\$(CHROOT1))
[ebe1ba6]773CHROOT: $CHROOT_TGT
774BOOT: $BOOT_TGT
[3e7ceed]775CUSTOM_TOOLS: $custom_list
[fe24ca6]776
[1838bc7]777create-sbu_du-report: mk_BOOT
778 @\$(call echo_message, Building)
779 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
[c57747d]780 sudo ./create-sbu_du-report.sh logs $VERSION $(date --iso-8601); \\
[1838bc7]781 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
[903eefd]782 fi
[1838bc7]783 @touch \$@
[045b2dc]784
[903eefd]785save-luser:
[877cc6a]786 @\$(call echo_message, Building)
[49e2745]787 @LUSER_ID=\$\$(grep '^\$(LUSER):' /etc/passwd | cut -d: -f3); \\
[dd7e0f67]788 if [ -n "\$\$LUSER_ID" ]; then \\
[903eefd]789 if [ ! -d \$(LUSER_HOME).XXX ]; then \\
790 mv \$(LUSER_HOME){,.XXX}; \\
791 mkdir \$(LUSER_HOME); \\
792 chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME); \\
793 fi; \\
[dd7e0f67]794 echo "\$\$LUSER_ID" > luser-id; \\
795 echo User \$(LUSER) exists with ID \$\$LUSER_ID; \\
[903eefd]796 else \\
[49e2745]797 rm -f luser-id; \\
[dd7e0f67]798 echo User \$(LUSER) does not exist; \\
799 echo It will be created with book instructions.; \\
[903eefd]800 fi
[dbcdfd7]801 @\$(call housekeeping)
[a858a78]802
[903eefd]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 \\
[6ad5a2f]810 userdel \$(LUSER); \\
[903eefd]811 groupdel \$(LGROUP); \\
[962793a]812 rm -rf \$(LUSER_HOME); \\
[903eefd]813 fi
814 @\$(call housekeeping)
815
816do_housekeeping:
817 @-rm /tools
[a858a78]818
[877cc6a]819EOF
820) >> $MKFILE
821
822 # Bring over the items from the Makefile.tmp
823 cat $MKFILE.tmp >> $MKFILE
824 rm $MKFILE.tmp
[c7c5a53]825 echo "Creating Makefile... ${BOLD}DONE${OFF}"
826}
Note: See TracBrowser for help on using the repository browser.