source: HLFS/master.sh@ 34cabf6

experimental
Last change on this file since 34cabf6 was bc097cd, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Forgot to remove patcheslist.xsl.

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