source: LFS/master.sh@ 7f25c70

ablfs-more trunk
Last change on this file since 7f25c70 was 9d665db, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Remove legacy: remove tests in temporary tools

There is no way to run them now since we are in a cross build
configuration

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