source: LFS/master.sh@ 38d2de6

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

Typo fix.

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