source: LFS/master.sh@ 0a1c668

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

Fix ICA run on current SVN book

  • Property mode set to 100644
File size: 17.8 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 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 chmod -R a+wt \$(MOUNT_PT)/\$(SCRIPT_ROOT) && \\
42 chmod a+wt \$(SRCSDIR) && \\
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, it need be run as root.
99 # A hack is necessary: create script in chap5 BUT run as a dependency for
100 # SUDO target
101 case "${this_script}" in
102 *changingowner) runasroot="$runasroot ${this_script}" ;;
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 "$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 if [[ -z "$1" ]] ; then
169 local N=""
170 else
171 local N=-build_$1
172 local chapter6=""
173 mkdir chapter06$N
174 cp chapter06/* chapter06$N
175 for script in chapter06$N/* ; do
176 # Overwrite existing symlinks, files, and dirs
177 sed -e 's/ln -sv/&f/g' \
178 -e 's/mv -v/&f/g' \
179 -e 's/mkdir -v/&p/g' -i ${script}
180 # Rename the scripts
181 mv ${script} ${script}$N
182 done
183 # Remove Bzip2 binaries before make install
184 sed -e 's@make PREFIX=/usr install@rm -vf /usr/bin/bz*\n&@' -i chapter06$N/*-bzip2$N
185 fi
186
187 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N ( CHROOT ) ${R_arrow}"
188
189 for file in chapter06$N/* ; do
190 # Keep the script file name
191 this_script=`basename $file`
192
193 # We'll run the chroot commands differently than the others, so skip them in the
194 # dependencies and target creation.
195 # Skip also linux-headers in iterative builds.
196 case "${this_script}" in
197 *chroot) continue ;;
198 *stripping*) [[ "${STRIP}" = "n" ]] && continue ;;
199 *linux-headers*) [[ -n "$N" ]] && continue ;;
200 esac
201
202 # Grab the name of the target.
203 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's,'$N',,'`
204
205 # Find the version of the command files, if it corresponds with the building of
206 # a specific package. We need this here to can skip scripts not needed for
207 # iterations rebuilds
208 pkg_tarball=$(get_package_tarball_name $name)
209
210 if [[ "$pkg_tarball" = "" ]] && [[ -n "$N" ]] ; then
211 case "${this_script}" in
212 *stripping*) ;;
213 *) continue ;;
214 esac
215 fi
216
217 # Append each name of the script files to a list (this will become
218 # the names of the targets in the Makefile)
219 # The kernfs script must be run as part of SUDO target.
220 case "${this_script}" in
221 *kernfs) runasroot="$runasroot ${this_script}" ;;
222 *) chapter6="$chapter6 ${this_script}" ;;
223 esac
224
225 #--------------------------------------------------------------------#
226 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
227 #--------------------------------------------------------------------#
228 #
229 # Drop in the name of the target on a new line, and the previous target
230 # as a dependency. Also call the echo_message function.
231 # In the mount of kernel filesystems we need to set LFS
232 # and not to use chroot.
233 case "${this_script}" in
234 *kernfs) LUSER_wrt_target "${this_script}" "$PREV" ;;
235 *) CHROOT_wrt_target "${this_script}" "$PREV" ;;
236 esac
237
238 # If $pkg_tarball isn't empty, we've got a package...
239 # Insert instructions for unpacking the package and changing directories
240 if [ "$pkg_tarball" != "" ] ; then
241 CHROOT_Unpack "$pkg_tarball"
242 # If the testsuites must be run, initialize the log file
243 case $name in
244 binutils | gcc | glibc )
245 [[ "$TEST" != "0" ]] && CHROOT_wrt_test_log "${this_script}"
246 ;;
247 * )
248 [[ "$TEST" = "2" ]] || [[ "$TEST" = "3" ]] && CHROOT_wrt_test_log "${this_script}"
249 ;;
250 esac
251 # If using optimizations, write the instructions
252 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
253 fi
254
255 # In the mount of kernel filesystems we need to set LFS
256 # and not to use chroot.
257 case "${this_script}" in
258 *kernfs) wrt_RunAsRoot "$file" ;;
259 *) CHROOT_wrt_RunAsRoot "$file" ;;
260 esac
261
262 # Remove the build directory(ies) except if the package build fails.
263 if [ "$pkg_tarball" != "" ] ; then
264 CHROOT_wrt_RemoveBuildDirs "$name"
265 fi
266
267 # Include a touch of the target name so make can check
268 # if it's already been made.
269 wrt_touch
270 #
271 #--------------------------------------------------------------------#
272 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
273 #--------------------------------------------------------------------#
274
275 # Keep the script file name for Makefile dependencies.
276 PREV=${this_script}
277 # Set system_build envar for iteration targets
278 system_build=$chapter6
279 done # end for file in chapter06/*
280}
281
282#----------------------------#
283chapter78_Makefiles() {
284#----------------------------#
285 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8 ( BOOT ) ${R_arrow}"
286
287 for file in chapter0{7,8}/* ; do
288 # Keep the script file name
289 this_script=`basename $file`
290
291 # Grub must be configured manually.
292 # Handle fstab creation.
293 # If no .config file is supplied, the kernel build is skipped
294 case ${this_script} in
295 *grub) continue ;;
296 *fstab) [[ ! -z ${FSTAB} ]] && cp ${FSTAB} $BUILDDIR/sources/fstab ;;
297 *kernel) [[ -z ${CONFIG} ]] && continue
298 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
299 esac
300
301 # First append each name of the script files to a list (this will become
302 # the names of the targets in the Makefile
303 chapter78="$chapter78 ${this_script}"
304
305 #--------------------------------------------------------------------#
306 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
307 #--------------------------------------------------------------------#
308 #
309 # Drop in the name of the target on a new line, and the previous target
310 # as a dependency. Also call the echo_message function.
311 CHROOT_wrt_target "${this_script}" "$PREV"
312
313 # Find the bootscripts and kernel package names
314 case "${this_script}" in
315 *bootscripts)
316 name="lfs-bootscripts"
317 pkg_tarball=$(get_package_tarball_name $name)
318 CHROOT_Unpack "$pkg_tarball"
319 ;;
320 *kernel)
321 name="linux"
322 pkg_tarball=$(get_package_tarball_name $name)
323 CHROOT_Unpack "$pkg_tarball"
324 ;;
325 esac
326
327 # Check if we have a real /etc/fstab file
328 case "${this_script}" in
329 *fstab) if [[ -n $FSTAB ]]; then
330 CHROOT_wrt_CopyFstab
331 else
332 CHROOT_wrt_RunAsRoot "$file"
333 fi
334 ;;
335 *) CHROOT_wrt_RunAsRoot "$file"
336 ;;
337 esac
338
339 case "${this_script}" in
340 *bootscripts) CHROOT_wrt_RemoveBuildDirs "dummy" ;;
341 *kernel) CHROOT_wrt_RemoveBuildDirs "dummy" ;;
342 esac
343
344 # Include a touch of the target name so make can check
345 # if it's already been made.
346 wrt_touch
347 #
348 #--------------------------------------------------------------------#
349 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
350 #--------------------------------------------------------------------#
351
352 # Keep the script file name for Makefile dependencies.
353 PREV=${this_script}
354 done # for file in chapter0{7,8}/*
355
356}
357
358
359
360#----------------------------#
361build_Makefile() { #
362#----------------------------#
363
364 echo "Creating Makefile... ${BOLD}START${OFF}"
365
366 cd $JHALFSDIR/${PROGNAME}-commands
367
368 # Start with a clean Makefile.tmp file
369 >$MKFILE
370
371 chapter4_Makefiles
372 chapter5_Makefiles
373 chapter6_Makefiles
374 # Add the iterations targets, if needed
375 [[ "$COMPARE" = "y" ]] && wrt_compare_targets
376 chapter78_Makefiles
377 # Add the CUSTOM_TOOLS targets, if needed
378 [[ "$CUSTOM_TOOLS" = "y" ]] && wrt_CustomTools_target
379 # Add the BLFS_TOOL targets, if needed
380 [[ "$BLFS_TOOL" = "y" ]] && wrt_blfs_tool_targets
381
382 # Add a header, some variables and include the function file
383 # to the top of the real Makefile.
384 wrt_Makefile_header
385
386 # Add chroot commands
387 CHROOT_LOC="`whereis -b chroot | cut -d " " -f2`"
388 i=1
389 for file in chapter06/*chroot* ; do
390 chroot=`cat $file | \
391 sed -e "s@chroot@$CHROOT_LOC@" \
392 -e '/#!\/bin\/bash/d' \
393 -e 's@ \\\@ @g' | \
394 tr -d '\n' | \
395 sed -e 's/ */ /g' \
396 -e 's|\\$|&&|g' \
397 -e 's|exit||g' \
398 -e 's|$| -c|' \
399 -e 's|"$$LFS"|$(MOUNT_PT)|' \
400 -e 's|set -e||' \
401 -e 's|set +h||'`
402 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
403 i=`expr $i + 1`
404 done
405
406 # Drop in the main target 'all:' and the chapter targets with each sub-target
407 # as a dependency.
408(
409 cat << EOF
410
411all: ck_UID mk_SETUP mk_LUSER mk_SUDO mk_CHROOT mk_BOOT create-sbu_du-report mk_CUSTOM_TOOLS mk_BLFS_TOOL
412 @sudo make do_housekeeping
413 @echo "$VERSION - jhalfs build" > lfs-release && \\
414 sudo mv lfs-release \$(MOUNT_PT)/etc
415 @\$(call echo_finished,$VERSION)
416
417ck_UID:
418 @if [ \`id -u\` = "0" ]; then \\
419 echo "--------------------------------------------------"; \\
420 echo "You cannot run this makefile from the root account"; \\
421 echo "--------------------------------------------------"; \\
422 exit 1; \\
423 fi
424
425mk_SETUP:
426 @\$(call echo_SU_request)
427 @sudo make SHELL=/bin/bash SETUP
428 @touch \$@
429
430mk_LUSER: mk_SETUP
431 @\$(call echo_SULUSER_request)
432 @( sudo \$(SU_LUSER) "source .bashrc && cd \$(MOUNT_PT)/\$(SCRIPT_ROOT) && make SHELL=/bin/bash LUSER" )
433 @sudo make restore-luser-env
434 @touch \$@
435
436mk_SUDO: mk_LUSER
437 @sudo make SHELL=/bin/bash SUDO
438 touch \$@
439#
440# The convoluted piece of code below is necessary to provide 'make' with a valid shell in the
441# chroot environment. (Unless someone knows a different way)
442# Manually create the /bin directory and provide link to the /tools dir.
443# Also change the original symlink creation to include (f)orce to prevent failure due to
444# pre-existing links.
445#
446mk_CHROOT: mk_SUDO
447 @if [ ! -e \$(MOUNT_PT)/bin ]; then \\
448 mkdir \$(MOUNT_PT)/bin; \\
449 cd \$(MOUNT_PT)/bin && \\
450 ln -sf /tools/bin/bash bash; ln -sf bash sh; \\
451 sudo chown -R 0:0 \$(MOUNT_PT)/bin; \\
452 fi;
453 @sudo sed -e 's|^ln -sv |ln -svf |' -i \$(CMDSDIR)/chapter06/*-createfiles
454 @\$(call echo_CHROOT_request)
455 @( sudo \$(CHROOT1) "cd \$(SCRIPT_ROOT) && make CHROOT")
456 @touch \$@
457
458mk_BOOT: mk_CHROOT
459 @\$(call echo_CHROOT_request)
460 @( sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BOOT")
461 @touch \$@
462
463mk_CUSTOM_TOOLS: create-sbu_du-report
464 @if [ "\$(ADD_CUSTOM_TOOLS)" = "y" ]; then \\
465 \$(call echo_PHASE,Building CUSTOM_TOOLS); \\
466 \$(call echo_CHROOT_request); \\
467 sudo mkdir -p ${BUILDDIR}${TRACKING_DIR}; \\
468 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make CUSTOM_TOOLS"); \\
469 fi;
470 @touch \$@
471
472mk_BLFS_TOOL: mk_CUSTOM_TOOLS
473 @if [ "\$(ADD_BLFS_TOOLS)" = "y" ]; then \\
474 \$(call echo_PHASE,Building BLFS_TOOL); \\
475 \$(call echo_CHROOT_request); \\
476 sudo mkdir -p $BUILDDIR$TRACKING_DIR; \\
477 (sudo \$(CHROOT2) "cd \$(SCRIPT_ROOT) && make BLFS_TOOL"); \\
478 fi;
479 @touch \$@
480
481
482SETUP: $chapter4
483LUSER: $chapter5
484SUDO: $runasroot
485CHROOT: $chapter6
486BOOT: $chapter78
487CUSTOM_TOOLS: $custom_list
488BLFS_TOOL: $blfs_tool
489
490
491create-sbu_du-report: mk_BOOT
492 @\$(call echo_message, Building)
493 @if [ "\$(ADD_REPORT)" = "y" ]; then \\
494 ./create-sbu_du-report.sh logs $VERSION; \\
495 \$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report); \\
496 fi;
497 @touch \$@
498
499restore-luser-env:
500 @\$(call echo_message, Building)
501 @if [ -f /home/\$(LUSER)/.bashrc.XXX ]; then \\
502 mv -f /home/\$(LUSER)/.bashrc.XXX /home/\$(LUSER)/.bashrc; \\
503 fi;
504 @if [ -f /home/\$(LUSER)/.bash_profile.XXX ]; then \\
505 mv /home/\$(LUSER)/.bash_profile.XXX /home/\$(LUSER)/.bash_profile; \\
506 fi;
507 @chown \$(LUSER):\$(LGROUP) /home/\$(LUSER)/.bash* && \\
508 touch \$@ && \\
509 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
510 echo --------------------------------------------------------------------------------\$(WHITE)
511
512do_housekeeping:
513 @-umount \$(MOUNT_PT)/sys
514 @-umount \$(MOUNT_PT)/proc
515 @-umount \$(MOUNT_PT)/dev/shm
516 @-umount \$(MOUNT_PT)/dev/pts
517 @-umount \$(MOUNT_PT)/dev
518 @-rm /tools
519 @-if [ ! -f luser-exist ]; then \\
520 userdel \$(LUSER); \\
521 rm -rf /home/\$(LUSER); \\
522 fi;
523
524
525EOF
526) >> $MKFILE
527
528 # Bring over the items from the Makefile.tmp
529 cat $MKFILE.tmp >> $MKFILE
530 rm $MKFILE.tmp
531 echo "Creating Makefile... ${BOLD}DONE${OFF}"
532}
Note: See TracBrowser for help on using the repository browser.