source: LFS/master.sh@ 0fa52f2

ablfs-more trunk
Last change on this file since 0fa52f2 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
Line 
1#!/bin/bash
2
3###################################
4### FUNCTIONS ###
5###################################
6
7
8#############################################################
9
10
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
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}"
43
44 for file in ${dir}$N/* ; do
45 # Keep the script file name
46 this_script=`basename $file`
47
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
52 # - do not reinstall linux-headers when rebuilding
53 # - grub config: must be done manually; skip it
54 # - handle fstab and .config. Skip kernel if .config not supplied
55 case "${this_script}" in
56 *strippingagain) [[ "${STRIP}" = "n" ]] && continue ;;
57 *stripping) [[ "${STRIP}" = "n" ]] && continue ;;
58 *linux-headers*) [[ -n "$N" ]] && continue ;;
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 ;;
67 esac
68 # Grab the name of the target
69 # This is only used to check the name in "opt_override" or "BLACKIST"
70 name=`echo ${this_script} | sed -e 's@[0-9]\{3,4\}-@@' \
71 -e 's@-pass[0-9]\{1\}@@' \
72 -e 's@-libstdc++@@' \
73 -e 's,'$N',,' \
74 -e 's@-32@@'`
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
84 *stripping*|*cleanup*|*revised*) ;;
85 *) continue ;;
86 esac
87 fi
88
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
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.
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.
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
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
128
129 # If using optimizations, write the instructions
130 case "${OPTIMIZE}$1${nb_chaps}${this_script}${REALSBU}" in
131 0* | *binutils-pass1y | 15* | 167* | 177*) ;;
132 *kernel*) wrt_makeflags "$name" ;; # No CFLAGS for kernel
133 *) wrt_optimize "$name" && wrt_makeflags "$name" ;;
134 esac
135 fi
136
137# Some scriptlet have a special treatment; otherwise standard
138 case "${this_script}" in
139 *addinguser)
140(
141# /var/lib may already exist and be owned by root if blfs tools
142# have been installed.
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 @if [ -d "\$(MOUNT_PT)/var/lib" ]; then \\
154 chown \$(LUSER):\$(LGROUP) \$(MOUNT_PT)/var/lib; \\
155 fi
156 @chmod -R a+wt $JHALFSDIR
157 @chmod a+wt \$(SRCSDIR)
158EOF
159) >> $MKFILE.tmp
160 ;;
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
181 *)
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 ;;
190 esac
191
192 # Write installed files log and remove the build directory(ies)
193 # except if the package build fails.
194 if [ "$pkg_tarball" != "" ] ; then
195 if [ "${INSTALL_LOG}" = "y" ] &&
196 (( 1+nb_chaps <= $1 )) &&
197 [ "x${N}" = "x" ] ; then
198 CHROOT_wrt_LogNewFiles "${this_script}"
199 fi
200 fi
201
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}
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
217 done # end for file in $dir/*
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
223}
224
225#----------------------------#
226build_Makefile() { #
227#----------------------------#
228
229 echo "Creating Makefile... ${BOLD}START${OFF}"
230
231 cd $JHALFSDIR/${PROGNAME}-commands
232
233 # Start with empty files
234 >$MKFILE
235 >$MKFILE.tmp
236
237 # Ensure the first dependency is empty
238 unset PREV
239
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
246 chaps=($(echo chapter*))
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
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
264 done
265 # Add the CUSTOM_TOOLS targets, if needed
266 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
267
268 # Add a header, some variables and include the function file
269 # to the top of the real Makefile.
270 wrt_Makefile_header
271
272 # Add chroot commands
273 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
274 i=1
275 for file in ../chroot-scripts/*chroot* ; do
276 chroot=`cat $file | \
277 perl -pe 's|\\\\\n||g' | \
278 tr -s [:space:] | \
279 grep chroot | \
280 sed -e "s|chroot|$CHROOT_LOC|" \
281 -e 's|\\$|&&|g' \
282 -e 's|"$$LFS"|$(MOUNT_PT)|'`
283 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
284 i=`expr $i + 1`
285 done
286
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' \
293 -e 's|\$|; \\\\|' \
294 -e 's|then|& :|' \
295 -e 's|\$\$LFS|$(MOUNT_PT)|g'`
296 teardown=`cat ../kernfs-scripts/teardown.sh | \
297 sed -e 's|^| |' \
298 -e 's|umount|-sudo &|' \
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)|'`
304 # Drop in the main target 'all:' and the chapter targets with each sub-target
305 # as a dependency.
306(
307 cat << EOF
308
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
310$teardownat
311 @sudo make do_housekeeping
312 @echo $VERSION > lfs-release && \\
313 sudo mv lfs-release \$(MOUNT_PT)/etc && \\
314 sudo chown root:root \$(MOUNT_PT)/etc/lfs-release
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
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
332 @\$(call echo_finished,$VERSION)
333
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
342ck_terminal:
343 @stty size | ( read L C; \\
344 if (( L < 24 )) || (( C < 80 )) ; then \\
345 echo "--------------------------------------------------"; \\
346 echo "Terminal too small: \$\$C columns x \$\$L lines";\\
347 echo "Minimum: 80 columns x 24 lines";\\
348 echo "--------------------------------------------------"; \\
349 exit 1; \\
350 fi )
351
352mk_SETUP:
353 @\$(call echo_SU_request)
354 @sudo make save-luser
355 @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
356 @touch \$@
357
358mk_LUSER: mk_SETUP
359 @\$(call echo_SULUSER_request)
360 @\$(SU_LUSER) "make -C \$(MOUNT_PT)/\$(SCRIPT_ROOT) BREAKPOINT=\$(BREAKPOINT) LUSER"
361 @sudo make restore-luser
362 @touch \$@
363
364mk_SUDO: mk_LUSER
365 @sudo rm -f envars
366 @sudo make BREAKPOINT=\$(BREAKPOINT) SUDO
367 @touch \$@
368
369mk_CHROOT: mk_SUDO
370 @\$(call echo_CHROOT_request)
371 @( sudo \$(CHROOT1) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CHROOT")
372 @touch \$@
373
374mk_BOOT: mk_CHROOT
375 @\$(call echo_CHROOT_request)
376 @( sudo \$(CHROOT1) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BOOT")
377 @touch \$@
378
379mk_BLFS_TOOL: create-sbu_du-report
380 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
381 \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
382 (sudo \$(CHROOT1) -c "make -C $BLFS_ROOT/work"); \\
383 fi;
384 @touch \$@
385
386mk_CUSTOM_TOOLS: mk_BLFS_TOOL
387 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
388 \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
389 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
390 (sudo \$(CHROOT1) -c "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
391 fi;
392 @touch \$@
393
394devices: ck_UID
395$devices
396EOF
397) >> $MKFILE
398if [ "$INITSYS" = systemd ]; then
399(
400 cat << EOF
401 sudo mkdir -pv \$(MOUNT_PT)/run/systemd/resolve
402 sudo cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve
403EOF
404) >> $MKFILE
405fi
406(
407 cat << EOF
408
409teardown:
410$teardown
411
412chroot1: devices
413 sudo \$(CHROOT1)
414 \$(MAKE) teardown
415
416chroot: devices
417 sudo \$(CHROOT1)
418 \$(MAKE) teardown
419
420SETUP: $SETUP_TGT
421LUSER: $LUSER_TGT
422SUDO: $SUDO_TGT
423EOF
424) >> $MKFILE
425if [ "$INITSYS" = systemd ]; then
426(
427 cat << EOF
428 mkdir -pv \$(MOUNT_PT)/run/systemd/resolve
429 cp -v /etc/resolv.conf \$(MOUNT_PT)/run/systemd/resolve
430
431EOF
432) >> $MKFILE
433fi
434(
435 cat << EOF
436CHROOT: SHELL=\$(filter %bash,\$(CHROOT1))
437CHROOT: $CHROOT_TGT
438BOOT: $BOOT_TGT
439CUSTOM_TOOLS: $custom_list
440
441create-sbu_du-report: mk_BOOT
442 @\$(call echo_message, Building)
443 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
444 sudo ./create-sbu_du-report.sh logs $VERSION $(date --iso-8601); \\
445 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
446 fi
447 @touch \$@
448
449save-luser:
450 @\$(call echo_message, Building)
451 @LUSER_ID=\$\$(grep '^\$(LUSER):' /etc/passwd | cut -d: -f3); \\
452 if [ -n "\$\$LUSER_ID" ]; then \\
453 if [ ! -d \$(LUSER_HOME).XXX ]; then \\
454 mv \$(LUSER_HOME){,.XXX}; \\
455 mkdir \$(LUSER_HOME); \\
456 chown \$(LUSER):\$(LGROUP) \$(LUSER_HOME); \\
457 fi; \\
458 echo "\$\$LUSER_ID" > luser-id; \\
459 echo User \$(LUSER) exists with ID \$\$LUSER_ID; \\
460 else \\
461 rm -f luser-id; \\
462 echo User \$(LUSER) does not exist; \\
463 echo It will be created with book instructions.; \\
464 fi
465 @\$(call housekeeping)
466
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 \\
474 userdel \$(LUSER); \\
475 groupdel \$(LGROUP); \\
476 rm -rf \$(LUSER_HOME); \\
477 fi
478 @\$(call housekeeping)
479
480do_housekeeping:
481 @-rm -f /tools
482
483EOF
484) >> $MKFILE
485
486 # Bring over the items from the Makefile.tmp
487 cat $MKFILE.tmp >> $MKFILE
488 rm $MKFILE.tmp
489 echo "Creating Makefile... ${BOLD}DONE${OFF}"
490}
Note: See TracBrowser for help on using the repository browser.