source: LFS/master.sh@ b217a30

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

Adapt for the cross 2 branch. Note that ICA is broken now. Keeping some old
code to use for fixing ICA, but committing now so that testing can begin!

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