source: HLFS/master.sh@ d3f24df

experimental
Last change on this file since d3f24df was 9199a13, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Merged r2754:2768 from trunk.

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