source: HLFS/master.sh@ 5f7d08f

experimental
Last change on this file since 5f7d08f was 3e7af38, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Keeping sinchronized experimental branch with trunk.

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