source: LFS/master.sh@ 11b4d99

2.3 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 11b4d99 was 0850553, checked in by George Boudreau <georgeb@…>, 16 years ago

LFS has new build method. Added new vars to LFS/master.sh (JHuntwork)

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