source: HLFS/master.sh@ b7faa5a

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

Reverting r2729 until a better solution is found

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