source: LFS/master.sh@ 3d75bc2

2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 3d75bc2 was 81fca31, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

On iterative builds, log installed files only for the first build.

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