source: HLFS/master.sh@ 090712a

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

The uClibc-locale package and grsecurity patch should be placed into the FTP mirrors in their original formats.

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