source: LFS/master.sh@ b8e5cad

ablfs-more legacy trunk
Last change on this file since b8e5cad was fd4a798, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Remove $Id$ comments, they are useless with git

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