source: LFS/master.sh@ 3ac3ae1

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

Various small fixes/improvements:

  • Prefer SysV over Sys V in Config.in
  • do not generate the package list for lfs, it is not needed anymore
  • prevent an (ignored) error in LFS/master.sh
  • log new files under the scriptlet name (allows to log files for the same package from different builds)
  • keep the full name in log_new_file functions (fix a undetected bug in CLFS/HLFS)
  • Property mode set to 100644
File size: 15.6 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
[706e5bf]73 # This is only use to check the name in "opt_override" or "BLACKIST"
[3da8c49]74 name=`echo ${this_script} | sed -e 's@[0-9]\{3,4\}-@@' \
75 -e 's@-pass[0-9]\{1\}@@' \
76 -e 's@-libstdc++@@' \
[706e5bf]77 -e 's,'$N',,' \
78 -e 's@-32@@'`
[3da8c49]79
80 # Find the name of the tarball and the version of the package
81 # If it doesn't exist, we skip it in iterations rebuilds (except stripping
82 # and revisedchroot, where .a and .la files are removed).
83 pkg_tarball=$(sed -n 's/tar -xf \(.*\)/\1/p' $file)
84 pkg_version=$(sed -n 's/VERSION=\(.*\)/\1/p' $file)
85
86 if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
87 case "${this_script}" in
88 *stripping*|*revised*) ;;
89 *) continue ;;
90 esac
91 fi
[877cc6a]92
[ebe1ba6]93 # Append the name of the script to a list. The name of the
94 # list is contained in the variable Makefile_target. We adjust this
95 # variable at various points. Note that it is initialized to "SETUP"
96 # in the main function, before calling this function for the first time.
97 case "${this_script}" in
98 *settingenvironment) Makefile_target=LUSER_TGT ;;
99 *changingowner ) Makefile_target=SUDO_TGT ;;
100 *creatingdirs ) Makefile_target=CHROOT_TGT ;;
101 *bootscripts ) Makefile_target=BOOT_TGT ;; # case of sysv book
102 *network ) Makefile_target=BOOT_TGT ;; # case of systemd book
103 esac
104 eval $Makefile_target=\"\$$Makefile_target ${this_script}\"
105
[903eefd]106 #--------------------------------------------------------------------#
107 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
108 #--------------------------------------------------------------------#
109
110 # Drop in the name of the target on a new line, and the previous target
111 # as a dependency. Also call the echo_message function.
[ebe1ba6]112 case $Makefile_target in
113 CHROOT_TGT) CHROOT_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
114 *) LUSER_wrt_target "${this_script}" "$PREV" "$pkg_version" ;;
115 esac
116
117 # If $pkg_tarball isn't empty, we've got a package...
118 if [ "$pkg_tarball" != "" ] ; then
119 # Touch timestamp file if installed files logs shall be created.
[3da8c49]120 # But only for the final install chapter and not when rebuilding it
121 if [ "${INSTALL_LOG}" = "y" ] &&
122 (( 1+nb_chaps <= $1 )) &&
123 [ "x$N" = x ] ; then
[ebe1ba6]124 CHROOT_wrt_TouchTimestamp
125 fi
126 # Always initialize the test log file, since the test instructions may
127 # be "uncommented" by the user
128 case $Makefile_target in
129 CHROOT_TGT) CHROOT_wrt_test_log "${this_script}" "$pkg_version" ;;
130 LUSER_TGT ) LUSER_wrt_test_log "${this_script}" "$pkg_version" ;;
131 esac
[903eefd]132
[ebe1ba6]133 # If using optimizations, write the instructions
134 case "${OPTIMIZE}$1${nb_chaps}${this_script}${REALSBU}" in
135 0* | *binutils-pass1y | 15* | 167* | 177*) ;;
[b33c6ee]136 *kernel*) wrt_makeflags "$name" ;; # No CFLAGS for kernel
[ebe1ba6]137 *) wrt_optimize "$name" && wrt_makeflags "$name" ;;
138 esac
139 fi
140
141# Some scriptlet have a special treatment; otherwise standard
[903eefd]142 case "${this_script}" in
143 *addinguser)
144(
145cat << EOF
146 @if [ -f luser-id ]; then \\
147 function useradd() { true; }; \\
148 function groupadd() { true; }; \\
149 export -f useradd groupadd; \\
150 fi; \\
151 export LFS=\$(MOUNT_PT) && \\
152 \$(CMDSDIR)/`dirname $file`/\$@ >> \$(LOGDIR)/\$@ 2>&1; \\
153 \$(PRT_DU) >>logs/\$@
154 @chown \$(LUSER):\$(LGROUP) envars
155 @chmod -R a+wt $JHALFSDIR
156 @chmod a+wt \$(SRCSDIR)
[877cc6a]157EOF
[903eefd]158) >> $MKFILE.tmp
159 ;;
[ebe1ba6]160 *settingenvironment)
161(
162cat << EOF
163 @cd && \\
164 function source() { true; } && \\
165 export -f source && \\
166 \$(CMDSDIR)/`dirname $file`/\$@ >> \$(LOGDIR)/\$@ 2>&1 && \\
167 sed 's|/mnt/lfs|\$(MOUNT_PT)|' -i .bashrc && \\
168 echo source $JHALFSDIR/envars >> .bashrc
169 @\$(PRT_DU) >>logs/\$@
170EOF
171) >> $MKFILE.tmp
172 ;;
173 *fstab) if [[ -n "$FSTAB" ]]; then
174 CHROOT_wrt_CopyFstab
175 else
176 CHROOT_wrt_RunAsRoot "$file"
177 fi
178 ;;
179
[0a0753d]180 *)
[ebe1ba6]181 # Insert date and disk usage at the top of the log file, the script
182 # run and date and disk usage again at the bottom of the log file.
183 case "${Makefile_target}" in
184 SETUP_TGT | SUDO_TGT) wrt_RunAsRoot "$file" "$pkg_version" ;;
185 LUSER_TGT) LUSER_wrt_RunAsUser "$file" "$pkg_version" ;;
186 CHROOT_TGT | BOOT_TGT) CHROOT_wrt_RunAsRoot "$file" "$pkg_version" ;;
187 esac
188 ;;
[903eefd]189 esac
[045b2dc]190
[ebe1ba6]191 # Write installed files log and remove the build directory(ies)
192 # except if the package build fails.
193 if [ "$pkg_tarball" != "" ] ; then
[3da8c49]194 if [ "${INSTALL_LOG}" = "y" ] &&
195 (( 1+nb_chaps <= $1 )) &&
196 [ "x${N}" = "x" ] ; then
[706e5bf]197 CHROOT_wrt_LogNewFiles "${this_script}"
[ebe1ba6]198 fi
199 fi
200
[903eefd]201 # Include a touch of the target name so make can check
202 # if it's already been made.
203 wrt_touch
204 #
205 #--------------------------------------------------------------------#
206 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
207 #--------------------------------------------------------------------#
208
209 # Keep the script file name for Makefile dependencies.
210 PREV=${this_script}
[3da8c49]211 # Set "system_build" var for iteration targets
212 if [ -z "$N" ] && (( 1+nb_chaps == $1 )); then
213 system_build="$system_build $this_script"
214 fi
215
[ebe1ba6]216 done # end for file in $dir/*
[3da8c49]217 # Set "system_build" when rebuilding: note the CHROOT_TGT is local
218 # in that case.
219 if [ -n "$N" ]; then
220 system_build="$CHROOT_TGT"
221 fi
[877cc6a]222}
223
224#----------------------------#
[045b2dc]225build_Makefile() { #
[877cc6a]226#----------------------------#
[045b2dc]227
[c7c5a53]228 echo "Creating Makefile... ${BOLD}START${OFF}"
[045b2dc]229
[877cc6a]230 cd $JHALFSDIR/${PROGNAME}-commands
231
[ebe1ba6]232 # Start with empty files
[045b2dc]233 >$MKFILE
[ebe1ba6]234 >$MKFILE.tmp
235
236 # Ensure the first dependency is empty
237 unset PREV
[877cc6a]238
[ebe1ba6]239 # We begin with the SETUP target; successive targets will be assigned in
240 # the chapter_targets function.
241 Makefile_target=SETUP_TGT
242
243 # We need to know the chapter numbering, which depends on the version
244 # of the book. Use the number of subdirs to know which version we have
245 chaps=($(echo *))
246 nb_chaps=${#chaps[*]} # 5 if classical version, 7 if new version
247# DEBUG
248# echo chaps: ${chaps[*]}
249# echo nb_chaps: $nb_chaps
250# end DEBUG
251
252 # Make a temporary file with all script targets
253 for (( i = 4; i < nb_chaps+4; i++ )); do
254 chapter_targets $i
255 if (( i == nb_chaps )); then : # we have finished temporary tools
256 # Add the save target, if needed
257 [[ "$SAVE_CH5" = "y" ]] && wrt_save_target $Makefile_target
258 fi
[3da8c49]259 if (( i == 1+nb_chaps )); then : # we have finished final system
260 # Add the iterations targets, if needed
261 [[ "$COMPARE" = "y" ]] && wrt_compare_targets $i
262 fi
[ebe1ba6]263 done
[3e7ceed]264 # Add the CUSTOM_TOOLS targets, if needed
265 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
[877cc6a]266
267 # Add a header, some variables and include the function file
268 # to the top of the real Makefile.
[195ed9f]269 wrt_Makefile_header
[877cc6a]270
271 # Add chroot commands
[6ad5a2f]272 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
[877cc6a]273 i=1
[d68eb1b]274 for file in ../chroot-scripts/*chroot* ; do
[6ad5a2f]275 chroot=`cat $file | \
[abc8b27]276 perl -pe 's|\\\\\n||g' | \
277 tr -s [:space:] | \
278 grep chroot | \
279 sed -e "s|chroot|$CHROOT_LOC|" \
[6ad5a2f]280 -e 's|\\$|&&|g' \
[abc8b27]281 -e 's|"$$LFS"|$(MOUNT_PT)|'`
[877cc6a]282 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
283 i=`expr $i + 1`
284 done
285
[13c475b]286 # Store virtual kernel file systems commands:
287 devices=`cat ../kernfs-scripts/devices.sh | \
288 sed -e 's|^| |' \
289 -e 's|mount|sudo &|' \
290 -e 's|mkdir|sudo &|' \
291 -e 's|\\$|&&|g' \
[a659e46]292 -e 's|\$|; \\\\|' \
293 -e 's|then|& :|' \
[13c475b]294 -e 's|\$\$LFS|$(MOUNT_PT)|g'`
295 teardown=`cat ../kernfs-scripts/teardown.sh | \
296 sed -e 's|^| |' \
297 -e 's|umount|sudo &|' \
298 -e 's|\$LFS|$(MOUNT_PT)|'`
299 teardownat=`cat ../kernfs-scripts/teardown.sh | \
300 sed -e 's|^| |' \
301 -e 's|umount|@-sudo &|' \
302 -e 's|\$LFS|$(MOUNT_PT)|'`
[877cc6a]303 # Drop in the main target 'all:' and the chapter targets with each sub-target
304 # as a dependency.
305(
306 cat << EOF
[045b2dc]307
[9728b23]308all: 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]309$teardownat
[045b2dc]310 @sudo make do_housekeeping
[df97e68]311EOF
312) >> $MKFILE
313if [ "$INITSYS" = systemd ]; then
314(
315 cat << EOF
316 @/bin/echo -e -n \\
317 NAME=\\"Linux From Scratch\\"\\\\n\\
318 VERSION=\\"$VERSION\\"\\\\n\\
319 ID=lfs\\\\n\\
320 PRETTY_NAME=\\"Linux From Scratch $VERSION\\"\\\\n\\
321 VERSION_CODENAME=\\"$(whoami)-jhalfs\\"\\\\n\\
322 > os-release && \\
323 sudo mv os-release \$(MOUNT_PT)/etc && \\
324 sudo chown root:root \$(MOUNT_PT)/etc/os-release
325EOF
326) >> $MKFILE
327fi
328(
329 cat << EOF
[e1fc855]330 @echo $VERSION > lfs-release && \\
[9096853]331 sudo mv lfs-release \$(MOUNT_PT)/etc && \\
332 sudo chown root:root \$(MOUNT_PT)/etc/lfs-release
[e1fc855]333 @/bin/echo -e -n \\
334 DISTRIB_ID=\\"Linux From Scratch\\"\\\\n\\
335 DISTRIB_RELEASE=\\"$VERSION\\"\\\\n\\
336 DISTRIB_CODENAME=\\"$(whoami)-jhalfs\\"\\\\n\\
337 DISTRIB_DESCRIPTION=\\"Linux From Scratch\\"\\\\n\\
338 > lsb-release && \\
339 sudo mv lsb-release \$(MOUNT_PT)/etc && \\
340 sudo chown root:root \$(MOUNT_PT)/etc/lsb-release
[877cc6a]341 @\$(call echo_finished,$VERSION)
342
[045b2dc]343ck_UID:
344 @if [ \`id -u\` = "0" ]; then \\
345 echo "--------------------------------------------------"; \\
346 echo "You cannot run this makefile from the root account"; \\
347 echo "--------------------------------------------------"; \\
348 exit 1; \\
349 fi
350
[9728b23]351ck_terminal:
[7e0a1b8]352 @stty size | ( read L C; \\
353 if (( L < 24 )) || (( C < 80 )) ; then \\
[9728b23]354 echo "--------------------------------------------------"; \\
[7e0a1b8]355 echo "Terminal too small: \$\$C columns x \$\$L lines";\\
[9728b23]356 echo "Minimum: 80 columns x 24 lines";\\
357 echo "--------------------------------------------------"; \\
358 exit 1; \\
[7e0a1b8]359 fi )
[9728b23]360
[045b2dc]361mk_SETUP:
362 @\$(call echo_SU_request)
[dd7e0f67]363 @sudo make save-luser
[dbcdfd7]364 @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
[045b2dc]365 @touch \$@
366
367mk_LUSER: mk_SETUP
368 @\$(call echo_SULUSER_request)
[903eefd]369 @\$(SU_LUSER) "make -C \$(MOUNT_PT)/\$(SCRIPT_ROOT) BREAKPOINT=\$(BREAKPOINT) LUSER"
370 @sudo make restore-luser
[045b2dc]371 @touch \$@
372
373mk_SUDO: mk_LUSER
[a73ed74]374 @sudo rm -f envars
[dbcdfd7]375 @sudo make BREAKPOINT=\$(BREAKPOINT) SUDO
[1330ebc]376 @touch \$@
377
[045b2dc]378mk_CHROOT: mk_SUDO
379 @\$(call echo_CHROOT_request)
[d68eb1b]380 @( sudo \$(CHROOT1) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CHROOT")
[045b2dc]381 @touch \$@
[877cc6a]382
[045b2dc]383mk_BOOT: mk_CHROOT
384 @\$(call echo_CHROOT_request)
[d68eb1b]385 @( sudo \$(CHROOT2) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BOOT")
[045b2dc]386 @touch \$@
[877cc6a]387
[ac9bdc7]388mk_BLFS_TOOL: create-sbu_du-report
389 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
390 \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
[d68eb1b]391 (sudo \$(CHROOT2) -c "make -C $BLFS_ROOT/work"); \\
[ac9bdc7]392 fi;
393 @touch \$@
394
395mk_CUSTOM_TOOLS: mk_BLFS_TOOL
[3e7ceed]396 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
[3bc6078]397 \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
[3e7ceed]398 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
[d68eb1b]399 (sudo \$(CHROOT2) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
[3e7ceed]400 fi;
401 @touch \$@
402
[f60a8b7]403devices: ck_UID
[13c475b]404$devices
[d39252b]405EOF
406) >> $MKFILE
407if [ "$INITSYS" = systemd ]; then
408(
409 cat << EOF
410 sudo mkdir -pv \$(MOUNT_PT)/run/systemd/resolve
[426c618]411 sudo cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve
[d39252b]412EOF
413) >> $MKFILE
414fi
415(
416 cat << EOF
[13c475b]417
[2e1c1c3]418teardown:
[13c475b]419$teardown
[d39252b]420
421chroot1: devices
422 sudo \$(CHROOT1)
423 \$(MAKE) teardown
[7c17066]424
425chroot: devices
[d68eb1b]426 sudo \$(CHROOT2)
[7c17066]427 \$(MAKE) teardown
[877cc6a]428
[ebe1ba6]429SETUP: $SETUP_TGT
430LUSER: $LUSER_TGT
431SUDO: $SUDO_TGT
[13c475b]432EOF
433) >> $MKFILE
434if [ "$INITSYS" = systemd ]; then
435(
436 cat << EOF
[c6506aea]437 mkdir -pv \$(MOUNT_PT)/run/systemd/resolve
438 cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve
[13c475b]439
440EOF
441) >> $MKFILE
442fi
443(
444 cat << EOF
[a73ed74]445CHROOT: SHELL=\$(filter %bash,\$(CHROOT1))
[ebe1ba6]446CHROOT: $CHROOT_TGT
447BOOT: $BOOT_TGT
[3e7ceed]448CUSTOM_TOOLS: $custom_list
[fe24ca6]449
[1838bc7]450create-sbu_du-report: mk_BOOT
451 @\$(call echo_message, Building)
452 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
[c57747d]453 sudo ./create-sbu_du-report.sh logs $VERSION $(date --iso-8601); \\
[1838bc7]454 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
[903eefd]455 fi
[1838bc7]456 @touch \$@
[045b2dc]457
[903eefd]458save-luser:
[877cc6a]459 @\$(call echo_message, Building)
[49e2745]460 @LUSER_ID=\$\$(grep '^\$(LUSER):' /etc/passwd | cut -d: -f3); \\
[dd7e0f67]461 if [ -n "\$\$LUSER_ID" ]; then \\
[903eefd]462 if [ ! -d \$(LUSER_HOME).XXX ]; then \\
463 mv \$(LUSER_HOME){,.XXX}; \\
464 mkdir \$(LUSER_HOME); \\
465 chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME); \\
466 fi; \\
[dd7e0f67]467 echo "\$\$LUSER_ID" > luser-id; \\
468 echo User \$(LUSER) exists with ID \$\$LUSER_ID; \\
[903eefd]469 else \\
[49e2745]470 rm -f luser-id; \\
[dd7e0f67]471 echo User \$(LUSER) does not exist; \\
472 echo It will be created with book instructions.; \\
[903eefd]473 fi
[dbcdfd7]474 @\$(call housekeeping)
[a858a78]475
[903eefd]476restore-luser:
477 @\$(call echo_message, Building)
478 @if [ -f luser-id ]; then \\
479 rm -rf \$(LUSER_HOME); \\
480 mv \$(LUSER_HOME){.XXX,}; \\
481 rm luser-id; \\
482 else \\
[6ad5a2f]483 userdel \$(LUSER); \\
[903eefd]484 groupdel \$(LGROUP); \\
[962793a]485 rm -rf \$(LUSER_HOME); \\
[903eefd]486 fi
487 @\$(call housekeeping)
488
489do_housekeeping:
[706e5bf]490 @-rm -f /tools
[a858a78]491
[877cc6a]492EOF
493) >> $MKFILE
494
495 # Bring over the items from the Makefile.tmp
496 cat $MKFILE.tmp >> $MKFILE
497 rm $MKFILE.tmp
[c7c5a53]498 echo "Creating Makefile... ${BOLD}DONE${OFF}"
499}
Note: See TracBrowser for help on using the repository browser.