source: LFS/master.sh@ 3366dfd

2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 3366dfd was cbc8ba2, checked in by George Boudreau <georgeb@…>, 18 years ago

Corrections to blfs-tools scripts. Added missing tidy_docs download and code

  • Property mode set to 100755
File size: 18.0 KB
Line 
1#!/bin/sh
2
3# $Id$
4
5###################################
6### FUNCTIONS ###
7###################################
8
9
10#############################################################
11
12
13#----------------------------#
14chapter4_Makefiles() { #
15#----------------------------#
16 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter4 ( SETUP ) ${R_arrow}"
17
18# If /home/$LUSER is already present in the host, we asume that the
19# lfs user and group are also presents in the host, and a backup
20# of their bash init files is made.
21(
22 cat << EOF
23020-creatingtoolsdir:
24 @\$(call echo_message, Building)
25 @mkdir \$(MOUNT_PT)/tools && \\
26 rm -f /tools && \\
27 ln -s \$(MOUNT_PT)/tools / && \\
28 touch \$@ && \\
29 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
30 echo --------------------------------------------------------------------------------\$(WHITE)
31
32021-addinguser: 020-creatingtoolsdir
33 @\$(call echo_message, Building)
34 @if [ ! -d /home/\$(LUSER) ]; then \\
35 groupadd \$(LGROUP); \\
36 useradd -s /bin/bash -g \$(LGROUP) -m -k /dev/null \$(LUSER); \\
37 else \\
38 touch luser-exist; \\
39 fi;
40 @chown \$(LUSER) \$(MOUNT_PT)/tools && \\
41 chown -R \$(LUSER) \$(MOUNT_PT)/\$(SCRIPT_ROOT) && \\
42 chmod -R a+wt \$(MOUNT_PT) && \\
43 touch \$@ && \\
44 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
45 echo --------------------------------------------------------------------------------\$(WHITE)
46
47022-settingenvironment: 021-addinguser
48 @\$(call echo_message, Building)
49 @if [ -f /home/\$(LUSER)/.bashrc -a ! -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
50 mv /home/\$(LUSER)/.bashrc /home/\$(LUSER)/.bashrc.XXX; \\
51 fi;
52 @if [ -f /home/\$(LUSER)/.bash_profile -a ! -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
53 mv /home/\$(LUSER)/.bash_profile /home/\$(LUSER)/.bash_profile.XXX; \\
54 fi;
55 @echo "set +h" > /home/\$(LUSER)/.bashrc && \\
56 echo "umask 022" >> /home/\$(LUSER)/.bashrc && \\
57 echo "LFS=\$(MOUNT_PT)" >> /home/\$(LUSER)/.bashrc && \\
58 echo "LC_ALL=POSIX" >> /home/\$(LUSER)/.bashrc && \\
59 echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/\$(LUSER)/.bashrc && \\
60 echo "export LFS LC_ALL PATH" >> /home/\$(LUSER)/.bashrc && \\
61 echo "source $JHALFSDIR/envars" >> /home/\$(LUSER)/.bashrc && \\
62 chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bashrc && \\
63 touch envars && \\
64 chown \$(LUSER) envars && \\
65 touch \$@ && \\
66 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
67 echo --------------------------------------------------------------------------------\$(WHITE)
68EOF
69) > $MKFILE.tmp
70
71 chapter4=" 020-creatingtoolsdir 021-addinguser 022-settingenvironment"
72}
73
74
75
76#----------------------------#
77chapter5_Makefiles() {
78#----------------------------#
79 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5 ( LUSER ) ${R_arrow}"
80
81 for file in chapter05/* ; do
82 # Keep the script file name
83 this_script=`basename $file`
84
85 # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
86 # Fix also locales creation when running chapter05 testsuites (ugly)
87 case "${this_script}" in
88 *tcl) [[ "${TEST}" = "0" ]] && continue ;;
89 *expect) [[ "${TEST}" = "0" ]] && continue ;;
90 *dejagnu) [[ "${TEST}" = "0" ]] && continue ;;
91 *stripping) [[ "${STRIP}" = "n" ]] && continue ;;
92 *glibc) [[ "${TEST}" = "3" ]] && \
93 sed -i 's@/usr/lib/locale@/tools/lib/locale@' $file ;;
94 esac
95
96 # First append each name of the script files to a list (this will become
97 # the names of the targets in the Makefile
98 # DO NOT append the changingowner script.
99 # A hack is necessary: create script in chap5 BUT run as a dependency for
100 # chap6 CHROOT
101 case "${this_script}" in
102 *changingowner) : ;;
103 *) chapter5="$chapter5 ${this_script}" ;;
104 esac
105
106 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
107 # and binutils in chapter 5)
108 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
109
110 # Set the dependency for the first target.
111 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
112
113 #--------------------------------------------------------------------#
114 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
115 #--------------------------------------------------------------------#
116 #
117 # Drop in the name of the target on a new line, and the previous target
118 # as a dependency. Also call the echo_message function.
119 LUSER_wrt_target "${this_script}" "$PREV"
120
121 # Find the version of the command files, if it corresponds with the building of
122 # a specific package
123 pkg_tarball=$(get_package_tarball_name $name)
124
125 # If $pkg_tarball isn't empty, we've got a package...
126 if [ "$pkg_tarball" != "" ] ; then
127 # Insert instructions for unpacking the package and to set the PKGDIR variable.
128 LUSER_wrt_unpack "$pkg_tarball"
129 # If the testsuites must be run, initialize the log file
130 [[ "$TEST" = "3" ]] && LUSER_wrt_test_log "${this_script}"
131 # If using optimizations, write the instructions
132 [[ "$OPTIMIZE" = "2" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
133 fi
134
135 # Insert date and disk usage at the top of the log file, the script run
136 # and date and disk usage again at the bottom of the log file.
137 # The changingowner script must be run as root.
138 case "${this_script}" in
139 *changingowner) wrt_RunAsRoot "${this_script}" "$file" ;;
140 *) LUSER_wrt_RunAsUser "$file" ;;
141 esac
142
143 # Remove the build directory(ies) except if the package build fails
144 # (so we can review config.cache, config.log, etc.)
145 if [ "$pkg_tarball" != "" ] ; then
146 LUSER_RemoveBuildDirs "$name"
147 fi
148
149 # Include a touch of the target name so make can check
150 # if it's already been made.
151 wrt_touch
152 #
153 #--------------------------------------------------------------------#
154 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
155 #--------------------------------------------------------------------#
156
157 # Keep the script file name for Makefile dependencies.
158 PREV=${this_script}
159 done # end for file in chapter05/*
160}
161
162
163#----------------------------#
164chapter6_Makefiles() {
165#----------------------------#
166
167 # Set envars and scripts for iteration targets
168 LOGS="" # Start with an empty global LOGS envar
169 if [[ -z "$1" ]] ; then
170 local N=""
171 else
172 local N=-build_$1
173 local chapter6=""
174 mkdir chapter06$N
175 cp chapter06/* chapter06$N
176 for script in chapter06$N/* ; do
177 # Overwrite existing symlinks, files, and dirs
178 sed -e 's/ln -sv/&f/g' \
179 -e 's/mv -v/&f/g' \
180 -e 's/mkdir -v/&p/g' -i ${script}
181 done
182 # Remove Bzip2 binaries before make install
183 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i chapter06$N/*-bzip2
184 fi
185
186 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N ( CHROOT ) ${R_arrow}"
187
188 for file in chapter06$N/* ; do
189 # Keep the script file name
190 this_script=`basename $file`
191
192 # We'll run the chroot commands differently than the others, so skip them in the
193 # dependencies and target creation.
194 case "${this_script}" in
195 *chroot) continue ;;
196 *stripping*) [[ "${STRIP}" = "n" ]] && continue ;;
197 esac
198
199 # Grab the name of the target
200 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@'`
201
202 # Find the version of the command files, if it corresponds with the building of
203 # a specific package. We need this here to can skip scripts not needed for
204 # iterations rebuilds
205 pkg_tarball=$(get_package_tarball_name $name)
206
207 if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
208 case "${this_script}" in
209 *stripping*) ;;
210 *) continue ;;
211 esac
212 fi
213
214 # Append each name of the script files to a list (this will become
215 # the names of the targets in the Makefile)
216 chapter6="$chapter6 ${this_script}${N}"
217
218 # Append each name of the script files to a list (this will become
219 # the names of the logs to be moved for each iteration)
220 LOGS="$LOGS ${this_script}"
221
222 #--------------------------------------------------------------------#
223 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
224 #--------------------------------------------------------------------#
225 #
226 # Drop in the name of the target on a new line, and the previous target
227 # as a dependency. Also call the echo_message function.
228 CHROOT_wrt_target "${this_script}${N}" "$PREV"
229
230 # If $pkg_tarball isn't empty, we've got a package...
231 # Insert instructions for unpacking the package and changing directories
232 if [ "$pkg_tarball" != "" ] ; then
233 CHROOT_Unpack "$pkg_tarball"
234 # If the testsuites must be run, initialize the log file
235 case $name in
236 binutils | gcc | glibc )
237 [[ "$TEST" != "0" ]] && CHROOT_wrt_test_log "${this_script}"
238 ;;
239 * )
240 [[ "$TEST" = "2" ]] || [[ "$TEST" = "3" ]] && CHROOT_wrt_test_log "${this_script}"
241 ;;
242 esac
243 # If using optimizations, write the instructions
244 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
245 fi
246
247 # In the mount of kernel filesystems we need to set LFS
248 # and not to use chroot.
249 case "${this_script}" in
250 *kernfs) wrt_RunAsRoot "${this_script}" "$file" ;;
251 *) CHROOT_wrt_RunAsRoot "$file" ;;
252 esac
253
254 # Remove the build directory(ies) except if the package build fails.
255 if [ "$pkg_tarball" != "" ] ; then
256 CHROOT_wrt_RemoveBuildDirs "$name"
257 fi
258
259 # Include a touch of the target name so make can check
260 # if it's already been made.
261 wrt_touch
262 #
263 #--------------------------------------------------------------------#
264 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
265 #--------------------------------------------------------------------#
266
267 # Keep the script file name for Makefile dependencies.
268 PREV=${this_script}${N}
269 # Set system_build envar for iteration targets
270 system_build=$chapter6
271 done # end for file in chapter06/*
272}
273
274#----------------------------#
275chapter789_Makefiles() {
276#----------------------------#
277 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8/9 ( BOOT ) ${R_arrow}"
278
279 for file in chapter0{7,8,9}/* ; do
280 # Keep the script file name
281 this_script=`basename $file`
282
283 # Grub must be configured manually.
284 # The filesystems can't be unmounted via Makefile and the user
285 # should enter the chroot environment to create the root
286 # password, edit several files and setup Grub.
287 #
288 # If no .config file is supplied, the kernel build is skipped
289 #
290 case ${this_script} in
291 *grub) continue ;;
292 *reboot) continue ;;
293 *console) continue ;; # Use the file generated by lfs-bootscripts
294 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
295 *kernel) [[ -z ${CONFIG} ]] && continue
296 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
297 esac
298
299 # First append each name of the script files to a list (this will become
300 # the names of the targets in the Makefile
301 chapter789="$chapter789 ${this_script}"
302
303 #--------------------------------------------------------------------#
304 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
305 #--------------------------------------------------------------------#
306 #
307 # Drop in the name of the target on a new line, and the previous target
308 # as a dependency. Also call the echo_message function.
309 CHROOT_wrt_target "${this_script}" "$PREV"
310
311 # Find the bootscripts and kernel package names
312 case "${this_script}" in
313 *bootscripts)
314 name="lfs-bootscripts"
315 pkg_tarball=$(get_package_tarball_name $name)
316 CHROOT_Unpack "$pkg_tarball"
317 ;;
318 *kernel)
319 name="linux"
320 pkg_tarball=$(get_package_tarball_name $name)
321 CHROOT_Unpack "$pkg_tarball"
322 ;;
323 esac
324
325 # Check if we have a real /etc/fstab file
326 case "${this_script}" in
327 *fstab) if [[ -n $FSTAB ]]; then
328 CHROOT_wrt_CopyFstab
329 else
330 CHROOT_wrt_RunAsRoot "$file"
331 fi
332 ;;
333 *) CHROOT_wrt_RunAsRoot "$file"
334 ;;
335 esac
336
337 case "${this_script}" in
338 *bootscripts) CHROOT_wrt_RemoveBuildDirs "dummy" ;;
339 *kernel) CHROOT_wrt_RemoveBuildDirs "dummy" ;;
340 esac
341
342 # Include a touch of the target name so make can check
343 # if it's already been made.
344 wrt_touch
345 #
346 #--------------------------------------------------------------------#
347 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
348 #--------------------------------------------------------------------#
349
350 # Keep the script file name for Makefile dependencies.
351 PREV=${this_script}
352 done # for file in chapter0{7,8,9}/*
353
354}
355
356
357
358#----------------------------#
359build_Makefile() { #
360#----------------------------#
361
362 echo "Creating Makefile... ${BOLD}START${OFF}"
363
364 cd $JHALFSDIR/${PROGNAME}-commands
365
366 # Start with a clean Makefile.tmp file
367 >$MKFILE
368
369 chapter4_Makefiles
370 chapter5_Makefiles
371 chapter6_Makefiles
372 # Add the iterations targets, if needed
373 [[ "$COMPARE" = "y" ]] && wrt_compare_targets
374 chapter789_Makefiles
375 # Add the BLFS_TOOL targets, if needed
376 [[ "$BLFS_TOOL" = "y" ]] && wrt_blfs_tool_targets
377
378 # Add a header, some variables and include the function file
379 # to the top of the real Makefile.
380(
381 cat << EOF
382$HEADER
383
384
385SRC = /sources
386MOUNT_PT = $BUILDDIR
387PKG_LST = $PKG_LST
388LUSER = $LUSER
389LGROUP = $LGROUP
390SCRIPT_ROOT = $SCRIPT_ROOT
391
392BASEDIR = \$(MOUNT_PT)
393SRCSDIR = \$(BASEDIR)/sources
394CMDSDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/$PROGNAME-commands
395LOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/logs
396TESTLOGDIR = \$(BASEDIR)/\$(SCRIPT_ROOT)/test-logs
397
398crSRCSDIR = /sources
399crCMDSDIR = /\$(SCRIPT_ROOT)/$PROGNAME-commands
400crLOGDIR = /\$(SCRIPT_ROOT)/logs
401crTESTLOGDIR = /\$(SCRIPT_ROOT)/test-logs
402
403SU_LUSER = su - \$(LUSER) -c
404LUSER_HOME = /home/\$(LUSER)
405PRT_DU = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) \$(MOUNT_PT) \`\n"
406PRT_DU_CR = echo -e "\nKB: \`du -skx --exclude=\$(SCRIPT_ROOT) / \`\n"
407
408export PATH := \${PATH}:/usr/sbin
409
410include makefile-functions
411
412EOF
413) > $MKFILE
414
415 # Add chroot commands
416 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
417 i=1
418 for file in chapter06/*chroot* ; do
419 chroot=`cat $file | \
420 sed -e "s@chroot@$CHROOT_LOC@" \
421 -e '/#!\/bin\/sh/d' \
422 -e 's@ \\\@ @g' | \
423 tr -d '\n' | \
424 sed -e 's/ */ /g' \
425 -e 's|\\$|&&|g' \
426 -e 's|exit||g' \
427 -e 's|$| -c|' \
428 -e 's|"$$LFS"|$(MOUNT_PT)|' \
429 -e 's|set -e||'`
430 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
431 i=`expr $i + 1`
432 done
433
434 # Drop in the main target 'all:' and the chapter targets with each sub-target
435 # as a dependency.
436(
437 cat << EOF
438
439all: ck_UID mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_BLFS_TOOL
440 @sudo make do_housekeeping
441 @\$(call echo_finished,$VERSION)
442
443ck_UID:
444 @if [ \`id -u\` = "0" ]; then \\
445 echo "--------------------------------------------------"; \\
446 echo "You cannot run this makefile from the root account"; \\
447 echo "--------------------------------------------------"; \\
448 exit 1; \\
449 fi
450
451mk_SETUP:
452 @\$(call echo_SU_request)
453 @sudo make SETUP
454 @touch \$@
455
456mk_LUSER: mk_SETUP
457 @\$(call echo_SULUSER_request)
458 @( sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make LUSER" )
459 @sudo make restore-luser-env
460 @touch \$@
461
462mk_SUDO: mk_LUSER
463 @sudo make SUDO
464 touch \$@
465#
466# The convoluted piece of code below is necessary to provide 'make' with a valid shell in the
467# chroot environment. (Unless someone knows a different way)
468# Manually create the /bin directory and provide link to the /tools dir.
469# Also change the original symlink creation to include (f)orce to prevent failure due to
470# pre-existing links.
471#
472mk_CHROOT: mk_SUDO
473 @if [ ! -e \$(MOUNT_PT)/bin ]; then \\
474 mkdir \$(MOUNT_PT)/bin; \\
475 cd \$(MOUNT_PT)/bin && \\
476 ln -sf /tools/bin/bash bash; ln -sf bash sh; \\
477 sudo chown -R 0:0 \$(MOUNT_PT)/bin; \\
478 fi;
479 @sudo sed -e 's|^ln -sv |ln -svf |' -i \$(CMDSDIR)/chapter06/063-createfiles
480 @\$(call echo_CHROOT_request)
481 @( sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make CHROOT")
482 @touch \$@
483
484mk_BOOT: mk_CHROOT
485 @\$(call echo_CHROOT_request)
486 @( sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BOOT")
487 @touch \$@
488
489
490SETUP: $chapter4
491
492LUSER: $chapter5
493
494SUDO: 057-changingowner 059-kernfs
495
496CHROOT: $chapter6
497
498BOOT: $chapter789
499
500
501restore-luser-env:
502 @\$(call echo_message, Building)
503 @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
504 mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
505 fi;
506 @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
507 mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
508 fi;
509 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
510 touch \$@ && \\
511 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
512 echo --------------------------------------------------------------------------------\$(WHITE)
513
514do_housekeeping:
515 @-umount \$(MOUNT_PT)/sys
516 @-umount \$(MOUNT_PT)/proc
517 @-umount \$(MOUNT_PT)/dev/shm
518 @-umount \$(MOUNT_PT)/dev/pts
519 @-umount \$(MOUNT_PT)/dev
520 @-rm /tools
521 @-if [ ! -f luser-exist ]; then \\
522 userdel \$(LUSER); \\
523 rm -rf /home/\$(LUSER); \\
524 fi;
525
526
527EOF
528) >> $MKFILE
529
530 # Add SBU-disk_usage report target
531 echo "create-sbu_du-report:" >> $MKFILE
532 if [[ "$REPORT" = "y" ]] ; then
533(
534 cat << EOF
535 @\$(call echo_message, Building)
536 @./create-sbu_du-report.sh logs $VERSION
537 @\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report)
538 @touch \$@
539
540
541EOF
542) >> $MKFILE
543 else echo -e "\t@true\n\n" >> $MKFILE; fi
544
545 # Add BLFS_TOOL targets
546 echo "mk_BLFS_TOOL:" >> $MKFILE
547 if [[ "$BLFS_TOOL" = "y" ]] ; then
548(
549 cat << EOF
550 @\$(call echo_CHROOT_request)
551 @ sudo mkdir -p $BUILDDIR$TRACKING_DIR
552 @( sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BLFS_TOOL")
553 @touch \$@
554
555BLFS_TOOL: $blfs_tool
556
557
558EOF
559) >> $MKFILE
560 else echo -e "\t@true\n\n" >> $MKFILE; fi
561
562 # Bring over the items from the Makefile.tmp
563 cat $MKFILE.tmp >> $MKFILE
564 rm $MKFILE.tmp
565 echo "Creating Makefile... ${BOLD}DONE${OFF}"
566}
Note: See TracBrowser for help on using the repository browser.