source: LFS/master.sh@ 9440e4a

ablfs-more trunk
Last change on this file since 9440e4a was 04a608b, checked in by Pierre Labastie <pierre.labastie@…>, 12 months ago

Pass NINJAJOBS if N_PARALLEL is defined

Now that MAKEFLAGS is defined at the beginning of the scriptlet,
there is no need to pass MAKEFLAGS as an envar to the scriptlet.
But still NINJAJOBS is not defined. In most cases, when we want
to use all cores, this is not a problem. But if N_PARALLEL is
defined, it needs to be passed. Note that we also pass
MAKEFLAGS in this case, because we use the old "wrt_xxx" function,
but it is not used.

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