source: LFS/master.sh@ dbcdfd7

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

Reimplemented support for partial builds.

  • Property mode set to 100644
File size: 16.7 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 /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 @\$(call housekeeping)
29
30021-addinguser: 020-creatingtoolsdir
31 @\$(call echo_message, Building)
32 @if [ ! -d /home/\$(LUSER) ]; 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 /home/\$(LUSER)/.bashrc -a ! -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
46 mv /home/\$(LUSER)/.bashrc /home/\$(LUSER)/.bashrc.XXX; \\
47 fi;
48 @if [ -f /home/\$(LUSER)/.bash_profile -a ! -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
49 mv /home/\$(LUSER)/.bash_profile /home/\$(LUSER)/.bash_profile.XXX; \\
50 fi;
51 @echo "set +h" > /home/\$(LUSER)/.bashrc && \\
52 echo "umask 022" >> /home/\$(LUSER)/.bashrc && \\
53 echo "LFS=\$(MOUNT_PT)" >> /home/\$(LUSER)/.bashrc && \\
54 echo "LC_ALL=POSIX" >> /home/\$(LUSER)/.bashrc && \\
55 echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/\$(LUSER)/.bashrc && \\
56 echo "export LFS LC_ALL PATH" >> /home/\$(LUSER)/.bashrc && \\
57 echo "source $JHALFSDIR/envars" >> /home/\$(LUSER)/.bashrc && \\
58 chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.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 CHROOT_Unpack "$pkg_tarball"
236 # If the testsuites must be run, initialize the log file
237 case $name in
238 binutils | gcc | glibc )
239 [[ "$TEST" != "0" ]] && CHROOT_wrt_test_log "${this_script}"
240 ;;
241 * )
242 [[ "$TEST" = "2" ]] || [[ "$TEST" = "3" ]] && CHROOT_wrt_test_log "${this_script}"
243 ;;
244 esac
245 # If using optimizations, write the instructions
246 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
247 fi
248
249 # In the mount of kernel filesystems we need to set LFS
250 # and not to use chroot.
251 case "${this_script}" in
252 *kernfs) wrt_RunAsRoot "$file" ;;
253 *) CHROOT_wrt_RunAsRoot "$file" ;;
254 esac
255
256 # Remove the build directory(ies) except if the package build fails.
257 if [ "$pkg_tarball" != "" ] ; then
258 CHROOT_wrt_RemoveBuildDirs "$name"
259 fi
260
261 # Include a touch of the target name so make can check
262 # if it's already been made.
263 wrt_touch
264 #
265 #--------------------------------------------------------------------#
266 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
267 #--------------------------------------------------------------------#
268
269 # Keep the script file name for Makefile dependencies.
270 PREV=${this_script}
271 # Set system_build envar for iteration targets
272 system_build=$chapter6
273 done # end for file in chapter06/*
274}
275
276#----------------------------#
277chapter78_Makefiles() {
278#----------------------------#
279 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8 ( BOOT ) ${R_arrow}"
280
281 for file in chapter0{7,8}/* ; do
282 # Keep the script file name
283 this_script=`basename $file`
284
285 # Grub must be configured manually.
286 # Handle fstab creation.
287 # If no .config file is supplied, the kernel build is skipped
288 case ${this_script} in
289 *grub) continue ;;
290 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
291 *kernel) [[ -z ${CONFIG} ]] && continue
292 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
293 esac
294
295 # First append each name of the script files to a list (this will become
296 # the names of the targets in the Makefile
297 chapter78="$chapter78 ${this_script}"
298
299 #--------------------------------------------------------------------#
300 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
301 #--------------------------------------------------------------------#
302 #
303 # Drop in the name of the target on a new line, and the previous target
304 # as a dependency. Also call the echo_message function.
305 CHROOT_wrt_target "${this_script}" "$PREV"
306
307 # Find the bootscripts and kernel package names
308 case "${this_script}" in
309 *bootscripts)
310 name="lfs-bootscripts"
311 pkg_tarball=$(get_package_tarball_name $name)
312 CHROOT_Unpack "$pkg_tarball"
313 ;;
314 *kernel)
315 name="linux"
316 pkg_tarball=$(get_package_tarball_name $name)
317 CHROOT_Unpack "$pkg_tarball"
318 ;;
319 esac
320
321 # Check if we have a real /etc/fstab file
322 case "${this_script}" in
323 *fstab) if [[ -n $FSTAB ]]; then
324 CHROOT_wrt_CopyFstab
325 else
326 CHROOT_wrt_RunAsRoot "$file"
327 fi
328 ;;
329 *) CHROOT_wrt_RunAsRoot "$file"
330 ;;
331 esac
332
333 case "${this_script}" in
334 *bootscripts) CHROOT_wrt_RemoveBuildDirs "dummy" ;;
335 *kernel) CHROOT_wrt_RemoveBuildDirs "dummy" ;;
336 esac
337
338 # Include a touch of the target name so make can check
339 # if it's already been made.
340 wrt_touch
341 #
342 #--------------------------------------------------------------------#
343 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
344 #--------------------------------------------------------------------#
345
346 # Keep the script file name for Makefile dependencies.
347 PREV=${this_script}
348 done # for file in chapter0{7,8}/*
349
350}
351
352
353
354#----------------------------#
355build_Makefile() { #
356#----------------------------#
357
358 echo "Creating Makefile... ${BOLD}START${OFF}"
359
360 cd $JHALFSDIR/${PROGNAME}-commands
361
362 # Start with a clean Makefile.tmp file
363 >$MKFILE
364
365 chapter4_Makefiles
366 chapter5_Makefiles
367 chapter6_Makefiles
368 # Add the iterations targets, if needed
369 [[ "$COMPARE" = "y" ]] && wrt_compare_targets
370 chapter78_Makefiles
371 # Add the CUSTOM_TOOLS targets, if needed
372 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
373 # Add the BLFS_TOOL targets, if needed
374 [[ "$BLFS_TOOL" = "y" ]] && wrt_blfs_tool_targets
375
376 # Add a header, some variables and include the function file
377 # to the top of the real Makefile.
378 wrt_Makefile_header
379
380 # Add chroot commands
381 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
382 i=1
383 for file in chapter06/*chroot* ; do
384 chroot=`cat $file | \
385 sed -e "s@chroot@$CHROOT_LOC@" \
386 -e '/#!\/bin\/bash/d' \
387 -e 's@ \\\@ @g' | \
388 tr -d '\n' | \
389 sed -e 's/ */ /g' \
390 -e 's|\\$|&&|g' \
391 -e 's|exit||g' \
392 -e 's|$| -c|' \
393 -e 's|"$$LFS"|$(MOUNT_PT)|' \
394 -e 's|set -e||' \
395 -e 's|set +h||'`
396 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
397 i=`expr $i + 1`
398 done
399
400 # Drop in the main target 'all:' and the chapter targets with each sub-target
401 # as a dependency.
402(
403 cat << EOF
404
405all: ck_UID mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_CUSTOM_TOOLS mk_BLFS_TOOL
406 @sudo make do_housekeeping
407 @echo "$VERSION - jhalfs build" > lfs-release && \\
408 sudo mv lfs-release \$(MOUNT_PT)/etc
409 @\$(call echo_finished,$VERSION)
410
411ck_UID:
412 @if [ \`id -u\` = "0" ]; then \\
413 echo "--------------------------------------------------"; \\
414 echo "You cannot run this makefile from the root account"; \\
415 echo "--------------------------------------------------"; \\
416 exit 1; \\
417 fi
418
419mk_SETUP:
420 @\$(call echo_SU_request)
421 @sudo make BREAKPOINT=\$(BREAKPOINT) SETUP
422 @touch \$@
423
424mk_LUSER: mk_SETUP
425 @\$(call echo_SULUSER_request)
426 @( sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) LUSER" )
427 @sudo make restore-luser-env
428 @touch \$@
429
430mk_SUDO: mk_LUSER
431 @sudo make BREAKPOINT=\$(BREAKPOINT) SUDO
432 @touch \$@
433
434mk_CHROOT: mk_SUDO
435 @\$(call echo_CHROOT_request)
436 @( sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CHROOT")
437 @touch \$@
438
439mk_BOOT: mk_CHROOT
440 @\$(call echo_CHROOT_request)
441 @( sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BOOT")
442 @touch \$@
443
444mk_CUSTOM_TOOLS: create-sbu_du-report
445 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
446 \$(call sh_echo_PHASE,Building CUSTOM_TOOLS); \\
447 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
448 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) CUSTOM_TOOLS"); \\
449 fi;
450 @touch \$@
451
452mk_BLFS_TOOL: mk_CUSTOM_TOOLS
453 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
454 \$(call sh_echo_PHASE,Building BLFS_TOOL); \\
455 sudo mkdir -p $BUILDDIR$TRACKING_DIR; \\
456 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BREAKPOINT=\$(BREAKPOINT) BLFS_TOOL"); \\
457 fi;
458 @touch \$@
459
460
461SETUP: $chapter4
462LUSER: $chapter5
463SUDO: $runasroot
464CHROOT: SHELL=/tools/bin/bash
465CHROOT: $chapter6
466BOOT: $chapter78
467CUSTOM_TOOLS: $custom_list
468BLFS_TOOL: $blfs_tool
469
470
471create-sbu_du-report: mk_BOOT
472 @\$(call echo_message, Building)
473 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
474 ./create-sbu_du-report.sh logs $VERSION; \\
475 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
476 fi;
477 @touch \$@
478
479restore-luser-env:
480 @\$(call echo_message, Building)
481 @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
482 mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
483 fi;
484 @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
485 mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
486 fi;
487 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash*
488 @\$(call housekeeping)
489
490do_housekeeping:
491 @-umount \$(MOUNT_PT)/sys
492 @-umount \$(MOUNT_PT)/proc
493 @-umount \$(MOUNT_PT)/dev/shm
494 @-umount \$(MOUNT_PT)/dev/pts
495 @-umount \$(MOUNT_PT)/dev
496 @-rm /tools
497 @-if [ ! -f luser-exist ]; then \\
498 userdel \$(LUSER); \\
499 rm -rf /home/\$(LUSER); \\
500 fi;
501
502
503EOF
504) >> $MKFILE
505
506 # Bring over the items from the Makefile.tmp
507 cat $MKFILE.tmp >> $MKFILE
508 rm $MKFILE.tmp
509 echo "Creating Makefile... ${BOLD}DONE${OFF}"
510}
Note: See TracBrowser for help on using the repository browser.