source: HLFS/master.sh@ ab7bac5

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since ab7bac5 was ab7bac5, checked in by Jeremy Huntwork <jhuntwork@…>, 18 years ago

Added instructions to always remove source and -build directories before running specific package commands

  • Property mode set to 100755
File size: 18.9 KB
Line 
1#!/bin/sh
2set -e # Enable error trapping
3
4# $Id$
5
6###################################
7### FUNCTIONS ###
8###################################
9
10
11#----------------------------#
12chapter3_Makefiles() { # Initialization of the system
13#----------------------------#
14 local TARGET LOADER
15
16 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter3${R_arrow}"
17
18 # Define a few model dependant variables
19 if [[ ${MODEL} = "uclibc" ]]; then
20 TARGET="tools-linux-uclibc"; LOADER="ld-uClibc.so.0"
21 else
22 TARGET="tools-linux-gnu"; LOADER="ld-linux.so.2"
23 fi
24
25 # NOTE: We use the lfs username and groupname also in HLFS
26 # If /home/lfs is already present in the host, we asume that the
27 # lfs user and group are also presents in the host, and a backup
28 # of their bash init files is made.
29(
30cat << EOF
31020-creatingtoolsdir:
32 @\$(call echo_message, Building)
33 @mkdir -v \$(MOUNT_PT)/tools && \\
34 rm -fv /tools && \\
35 ln -sv \$(MOUNT_PT)/tools /
36 @if [ ! -d \$(MOUNT_PT)/sources ]; then \\
37 mkdir \$(MOUNT_PT)/sources; \\
38 fi;
39 @chmod a+wt \$(MOUNT_PT)/sources && \\
40 touch \$@
41
42021-addinguser: 020-creatingtoolsdir
43 @\$(call echo_message, Building)
44 @if [ ! -d /home/lfs ]; then \\
45 groupadd lfs; \\
46 useradd -s /bin/bash -g lfs -m -k /dev/null lfs; \\
47 else \\
48 touch user-lfs-exist; \\
49 fi;
50 @chown lfs \$(MOUNT_PT)/tools && \\
51 chown lfs \$(MOUNT_PT)/sources && \\
52 touch \$@
53
54022-settingenvironment: 021-addinguser
55 @\$(call echo_message, Building)
56 @if [ -f /home/lfs/.bashrc -a ! -f /home/lfs/.bashrc.XXX ]; then \\
57 mv -v /home/lfs/.bashrc /home/lfs/.bashrc.XXX; \\
58 fi;
59 @if [ -f /home/lfs/.bash_profile -a ! -f /home/lfs/.bash_profile.XXX ]; then \\
60 mv -v /home/lfs/.bash_profile /home/lfs/.bash_profile.XXX; \\
61 fi;
62 @echo "set +h" > /home/lfs/.bashrc && \\
63 echo "umask 022" >> /home/lfs/.bashrc && \\
64 echo "HLFS=\$(MOUNT_PT)" >> /home/lfs/.bashrc && \\
65 echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
66 echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
67 echo "export HLFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
68 echo "" >> /home/lfs/.bashrc && \\
69 echo "target=$(uname -m)-${TARGET}" >> /home/lfs/.bashrc && \\
70 echo "ldso=/tools/lib/${LOADER}" >> /home/lfs/.bashrc && \\
71 echo "export target ldso" >> /home/lfs/.bashrc && \\
72 echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
73 chown lfs:lfs /home/lfs/.bashrc && \\
74 touch envars && \\
75 touch \$@
76EOF
77) >> $MKFILE.tmp
78
79}
80
81#----------------------------#
82chapter5_Makefiles() { # Bootstrap or temptools phase
83#----------------------------#
84 local file
85 local this_script
86
87 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5${R_arrow}"
88
89 for file in chapter05/* ; do
90 # Keep the script file name
91 this_script=`basename $file`
92
93 # Skip this script depending on jhalfs.conf flags set.
94 case $this_script in
95 # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
96 *tcl* ) [[ "$TEST" = "0" ]] && continue; ;;
97 *expect* ) [[ "$TEST" = "0" ]] && continue; ;;
98 *dejagnu* ) [[ "$TEST" = "0" ]] && continue; ;;
99 # Nothing interestin in this script
100 *introduction* ) continue ;;
101 # Test if the stripping phase must be skipped
102 *stripping* ) [[ "$STRIP" = "0" ]] && continue ;;
103 *) ;;
104 esac
105
106 # First append each name of the script files to a list (this will become
107 # the names of the targets in the Makefile
108 chapter5="$chapter5 $this_script"
109
110 # Grab the name of the target (minus the -headers or -cross in the case of gcc
111 # and binutils in chapter 5)
112 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-cross@@' -e 's@-headers@@'`
113
114 # Adjust 'name'
115 case $name in
116 linux-libc) name=linux-libc-headers ;;
117 esac
118
119 # Set the dependency for the first target.
120 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
121
122
123 #--------------------------------------------------------------------#
124 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
125 #--------------------------------------------------------------------#
126 #
127 # Drop in the name of the target on a new line, and the previous target
128 # as a dependency. Also call the echo_message function.
129 wrt_target "$this_script" "$PREV"
130
131 # Find the version of the command files, if it corresponds with the building of
132 # a specific package
133 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
134 # If $vrs isn't empty, we've got a package...
135 if [ "$vrs" != "" ] ; then
136 # Deal with non-standard names
137 case $name in
138 tcl) FILE="$name$vrs-src.tar.*" ;;
139 uclibc) FILE="uClibc-$vrs.tar.*" ;;
140 gcc) FILE="gcc-core-$vrs.tar.*" ;;
141 *) FILE="$name-$vrs.tar.*" ;;
142 esac
143 # Always remove possibly exiting unpacked source directories before beginning
144 # to build. This prevent build failures from fogetting to manually remove
145 # directories from previous runs of jhalfs.
146 wrt_remove_build_dirs "$name"
147 # Insert instructions for unpacking the package and to set the PKGDIR variable.
148 wrt_unpack "$FILE"
149 [[ "$OPTIMIZE" = "2" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
150 fi
151
152 case $this_script in
153 *binutils* ) # Dump the path to sources directory for later removal
154(
155cat << EOF
156 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
157 echo "\$(MOUNT_PT)\$(SRC)/\$\$ROOT" >> sources-dir
158EOF
159) >> $MKFILE.tmp
160 ;;
161 *adjusting* ) # For the Adjusting phase we must to cd to the binutils-build directory.
162 echo -e '\t@echo "export PKGDIR=$(MOUNT_PT)$(SRC)/binutils-build" > envars' >> $MKFILE.tmp
163 ;;
164 esac
165
166 # Insert date and disk usage at the top of the log file, the script run
167 # and date and disk usage again at the bottom of the log file.
168 wrt_run_as_su "${this_script}" "${file}"
169
170 # Remove the build directory(ies) except if the package build fails
171 # (so we can review config.cache, config.log, etc.)
172 # For Binutils the sources must be retained for some time.
173 if [ "$vrs" != "" ] ; then
174 case "${this_script}" in
175 *binutils*) : # do NOTHING
176 ;;
177 *) wrt_remove_build_dirs "$name"
178 ;;
179 esac
180 fi
181
182 # Remove the Binutils pass 1 sources after a successful Adjusting phase.
183 case "${this_script}" in
184 *adjusting*)
185(
186cat << EOF
187 @rm -r \`cat sources-dir\` && \\
188 rm -r \$(MOUNT_PT)\$(SRC)/binutils-build && \\
189 rm sources-dir
190EOF
191) >> $MKFILE.tmp
192 ;;
193 esac
194
195 # Include a touch of the target name so make can check if it's already been made.
196 echo -e '\t@touch $@' >> $MKFILE.tmp
197 #
198 #--------------------------------------------------------------------#
199 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
200 #--------------------------------------------------------------------#
201
202 # Keep the script file name for Makefile dependencies.
203 PREV=$this_script
204 done # end for file in chapter05/*
205}
206
207
208#----------------------------#
209chapter6_Makefiles() { # sysroot or chroot build phase
210#----------------------------#
211 local TARGET LOADER
212 local file
213 local this_script
214 # Set envars and scripts for iteration targets
215 LOGS="" # Start with an empty global LOGS envar
216 if [[ -z "$1" ]] ; then
217 local N=""
218 else
219 local N=-build_$1
220 local chapter6=""
221 mkdir chapter06$N
222 cp chapter06/* chapter06$N
223 for script in chapter06$N/* ; do
224 # Overwrite existing symlinks, files, and dirs
225 sed -e 's/ln -s /ln -sf /g' \
226 -e 's/^mv /&-f/g' -i ${script}
227 done
228 # Remove Bzip2 binaries before make install
229 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i chapter06$N/*-bzip2
230 # Fix how Module-Init-Tools do the install target
231 sed -e 's@make install@make INSTALL=install install@' -i chapter06$N/*-module-init-tools
232 # Delete *old Readline libraries just after make install
233 sed -e 's@make install@&\nrm -v /lib/lib{history,readline}*old@' -i chapter06$N/*-readline
234 # Don't readd already existing groups
235 sed -e '/groupadd/d' -i chapter06$N/*-udev
236 fi
237
238 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N${R_arrow}"
239 #
240 # Set these definitions early and only once
241 #
242 if [[ ${MODEL} = "uclibc" ]]; then
243 TARGET="pc-linux-uclibc"; LOADER="ld-uClibc.so.0"
244 else
245 TARGET="pc-linux-gnu"; LOADER="ld-linux.so.2"
246 fi
247
248 for file in chapter06$N/* ; do
249 # Keep the script file name
250 this_script=`basename $file`
251
252 # Skip this script depending on jhalfs.conf flags set.
253 case $this_script in
254 # We'll run the chroot commands differently than the others, so skip them in the
255 # dependencies and target creation.
256 *chroot* ) continue ;;
257 # Test if the stripping phase must be skipped
258 *-stripping* ) [[ "$STRIP" = "0" ]] && continue ;;
259 esac
260
261 # Grab the name of the target
262 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'`
263
264 # Find the version of the command files, if it corresponds with the building of
265 # a specific package
266 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
267
268 if [[ "$vrs" = "" ]] && [[ -n "$N" ]] ; then
269 case "${this_script}" in
270 *stripping*) ;;
271 *) continue ;;
272 esac
273 fi
274
275 # Append each name of the script files to a list (this will become
276 # the names of the targets in the Makefile
277 chapter6="$chapter6 ${this_script}${N}"
278
279 # Append each name of the script files to a list (this will become
280 # the names of the logs to be moved for each iteration)
281 LOGS="$LOGS ${this_script}"
282
283 #
284 # Sed replacement to fix some rm command that could fail.
285 # That should be fixed in the book sources.
286 #
287 case $name in
288 glibc)
289 sed 's/rm /rm -f /' -i chapter06$N/$this_script
290 ;;
291 gcc)
292 sed 's/rm /rm -f /' -i chapter06$N/$this_script
293 ;;
294 esac
295
296 #--------------------------------------------------------------------#
297 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
298 #--------------------------------------------------------------------#
299 #
300 # Drop in the name of the target on a new line, and the previous target
301 # as a dependency. Also call the echo_message function.
302 wrt_target "${this_script}${N}" "$PREV"
303
304 # If $vrs isn't empty, we've got a package...
305 # Insert instructions for unpacking the package and changing directories
306 if [ "$vrs" != "" ] ; then
307 # Deal with non-standard names
308 case $name in
309 tcl) FILE="$name$vrs-src.tar.*" ;;
310 uclibc) FILE="uClibc-$vrs.tar.*" ;;
311 gcc) FILE="gcc-core-$vrs.tar.*" ;;
312 *) FILE="$name-$vrs.tar.*" ;;
313 esac
314 # Always remove possibly exiting unpacked source directories before beginning
315 # to build. This prevent build failures from fogetting to manually remove
316 # directories from previous runs of jhalfs.
317 wrt_remove_build_dirs "$name"
318 wrt_unpack2 "$FILE"
319 wrt_target_vars
320 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
321 fi
322
323 case $this_script in
324 *readjusting*) # For the Re-Adjusting phase we must to cd to the binutils-build directory.
325 echo -e '\t@echo "export PKGDIR=$(SRC)/binutils-build" > envars' >> $MKFILE.tmp
326 ;;
327 esac
328
329 # In the mount of kernel filesystems we need to set LFS and not to use chroot.
330 case "${this_script}" in
331 *kernfs*)
332 wrt_run_as_root "${this_script}" "${file}"
333 ;;
334 *) # The rest of Chapter06
335 wrt_run_as_chroot1 "${this_script}" "${file}"
336 ;;
337 esac
338 #
339 # Remove the build directory(ies) except if the package build fails.
340 if [ "$vrs" != "" ] ; then
341 wrt_remove_build_dirs "$name"
342 fi
343 #
344 # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
345 case "${this_script}" in
346 *readjusting*)
347(
348cat << EOF
349 @rm -r \`cat sources-dir\` && \\
350 rm -r \$(MOUNT_PT)\$(SRC)/binutils-build && \\
351 rm sources-dir
352EOF
353) >> $MKFILE.tmp
354 ;;
355 esac
356
357 # Include a touch of the target name so make can check if it's already been made.
358 echo -e '\t@touch $@' >> $MKFILE.tmp
359 #
360 #--------------------------------------------------------------------#
361 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
362 #--------------------------------------------------------------------#
363
364 # Keep the script file name for Makefile dependencies.
365 PREV=${this_script}${N}
366 # Set system_build envar for iteration targets
367 system_build=$chapter6
368 done # end for file in chapter06/*
369
370}
371
372#----------------------------#
373chapter7_Makefiles() { # Create a bootable system.. kernel, bootscripts..etc
374#----------------------------#
375 local file
376 local this_script
377
378 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7${R_arrow}"
379 for file in chapter07/*; do
380 # Keep the script file name
381 this_script=`basename $file`
382
383 # Grub must be configured manually.
384 # The filesystems can't be unmounted via Makefile and the user
385 # should enter the chroot environment to create the root
386 # password, edit several files and setup Grub.
387 case $this_script in
388 *usage) continue ;; # Contains example commands
389 *grub) continue ;;
390 *reboot) continue ;;
391 *console) continue ;; # Use the file generated by lfs-bootscripts
392
393 *kernel)
394 # If no .config file is supplied, the kernel build is skipped
395 [[ -z $CONFIG ]] && continue
396 cp $CONFIG $BUILDDIR/sources/kernel-config
397 ;;
398 esac
399
400 # First append then name of the script file to a list (this will become
401 # the names of the targets in the Makefile
402 chapter7="$chapter7 $this_script"
403
404 #--------------------------------------------------------------------#
405 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
406 #--------------------------------------------------------------------#
407 #
408 # Drop in the name of the target on a new line, and the previous target
409 # as a dependency. Also call the echo_message function.
410 wrt_target "$this_script" "$PREV"
411
412 case "${this_script}" in
413 *bootscripts*)
414 vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
415 FILE="lfs-bootscripts-$vrs.tar.*"
416 wrt_unpack2 "$FILE"
417 vrs=`grep "^blfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
418 echo -e "\t@echo \"\$(MOUNT_PT)\$(SRC)/blfs-bootscripts-$vrs\" >> sources-dir" >> $MKFILE.tmp
419 ;;
420 esac
421
422 case "${this_script}" in
423 *fstab*) # Check if we have a real /etc/fstab file
424 if [[ -n "$FSTAB" ]] ; then
425 wrt_copy_fstab "$this_script"
426 else # Initialize the log and run the script
427 wrt_run_as_chroot2 "${this_script}" "${file}"
428 fi
429 ;;
430 *) # All other scripts
431 wrt_run_as_chroot2 "${this_script}" "${file}"
432 ;;
433 esac
434
435 # Remove the build directory except if the package build fails.
436 case "${this_script}" in
437 *bootscripts*)
438(
439cat << EOF
440 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
441 rm -r \$(MOUNT_PT)\$(SRC)/\$\$ROOT
442 @rm -r \`cat sources-dir\` && \\
443 rm sources-dir
444EOF
445) >> $MKFILE.tmp
446 ;;
447 esac
448
449 # Include a touch of the target name so make can check if it's already been made.
450 echo -e '\t@touch $@' >> $MKFILE.tmp
451 #
452 #--------------------------------------------------------------------#
453 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
454 #--------------------------------------------------------------------#
455
456 # Keep the script file name for Makefile dependencies.
457 PREV=$this_script
458 done # for file in chapter07/*
459
460 # Add SBU-disk_usage report target if required
461 if [[ "$REPORT" = "1" ]] ; then wrt_report ; fi
462}
463
464
465#----------------------------#
466build_Makefile() { # Construct a Makefile from the book scripts
467#----------------------------#
468 echo "Creating Makefile... ${BOLD}START${OFF}"
469
470 cd $JHALFSDIR/${PROGNAME}-commands
471 # Start with a clean Makefile.tmp file
472 >$MKFILE.tmp
473
474 chapter3_Makefiles
475 chapter5_Makefiles
476 chapter6_Makefiles
477 # Add the iterations targets, if needed
478 [[ "$COMPARE" != "0" ]] && wrt_compare_targets
479 chapter7_Makefiles
480
481 # Add a header, some variables and include the function file
482 # to the top of the real Makefile.
483(
484 cat << EOF
485$HEADER
486
487SRC= /sources
488MOUNT_PT= $BUILDDIR
489
490include makefile-functions
491
492EOF
493) > $MKFILE
494
495
496 # Add chroot commands
497 i=1
498 for file in chapter06/*chroot* ; do
499 chroot=`cat $file | sed -e '/#!\/bin\/sh/d' \
500 -e '/^export/d' \
501 -e '/^logout/d' \
502 -e 's@ \\\@ @g' | tr -d '\n' | sed -e 's/ */ /g' \
503 -e 's|\\$|&&|g' \
504 -e 's|exit||g' \
505 -e 's|$| -c|' \
506 -e 's|"$$HLFS"|$(MOUNT_PT)|'\
507 -e 's|set -e||'`
508 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
509 i=`expr $i + 1`
510 done
511
512 # Drop in the main target 'all:' and the chapter targets with each sub-target
513 # as a dependency.
514(
515 cat << EOF
516all: chapter3 chapter5 chapter6 chapter7 do-housekeeping
517 @\$(call echo_finished,$VERSION)
518
519chapter3: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
520
521chapter5: chapter3 $chapter5 restore-lfs-env
522
523chapter6: chapter5 $chapter6
524
525chapter7: chapter6 $chapter7
526
527clean-all: clean
528 rm -rf ./{hlfs-commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
529
530clean: clean-chapter7 clean-chapter6 clean-chapter5 clean-chapter3
531
532clean-chapter3:
533 -if [ ! -f user-lfs-exist ]; then \\
534 userdel lfs; \\
535 rm -rf /home/lfs; \\
536 fi;
537 rm -rf \$(MOUNT_PT)/tools
538 rm -f /tools
539 rm -f envars user-lfs-exist
540 rm -f 02* logs/02*.log
541
542clean-chapter5:
543 rm -rf \$(MOUNT_PT)/tools/*
544 rm -f $chapter5 restore-lfs-env sources-dir
545 cd logs && rm -f $chapter5 && cd ..
546
547clean-chapter6:
548 -umount \$(MOUNT_PT)/sys
549 -umount \$(MOUNT_PT)/proc
550 -umount \$(MOUNT_PT)/dev/shm
551 -umount \$(MOUNT_PT)/dev/pts
552 -umount \$(MOUNT_PT)/dev
553 rm -rf \$(MOUNT_PT)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
554 rm -f $chapter6
555 cd logs && rm -f $chapter6 && cd ..
556
557clean-chapter7:
558 rm -f $chapter7
559 cd logs && rm -f $chapter7 && cd ..
560
561restore-lfs-env:
562 @\$(call echo_message, Building)
563 @if [ -f /home/lfs/.bashrc.XXX ]; then \\
564 mv -fv /home/lfs/.bashrc.XXX /home/lfs/.bashrc; \\
565 fi;
566 @if [ -f /home/lfs/.bash_profile.XXX ]; then \\
567 mv -v /home/lfs/.bash_profile.XXX /home/lfs/.bash_profile; \\
568 fi;
569 @chown lfs:lfs /home/lfs/.bash* && \\
570 touch \$@
571
572do-housekeeping:
573 -umount \$(MOUNT_PT)/dev/pts
574 -umount \$(MOUNT_PT)/dev/shm
575 -umount \$(MOUNT_PT)/dev
576 -umount \$(MOUNT_PT)/sys
577 -umount \$(MOUNT_PT)/proc
578 -if [ ! -f user-lfs-exist ]; then \\
579 userdel lfs; \\
580 rm -rf /home/lfs; \\
581 fi;
582 -rm -f /tmp/unpacked
583
584EOF
585) >> $MKFILE
586
587 # Bring over the items from the Makefile.tmp
588 cat $MKFILE.tmp >> $MKFILE
589 rm $MKFILE.tmp
590 echo "Creating Makefile... ${BOLD}DONE${OFF}"
591
592}
Note: See TracBrowser for help on using the repository browser.