source: LFS/master.sh@ 944d69d

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

Simplified Readline reinstallation.

  • Property mode set to 100755
File size: 14.0 KB
RevLine 
[0170229]1#!/bin/sh
2
[a46ada0]3# $Id$
[0170229]4
5###################################
6### FUNCTIONS ###
7###################################
8
9
10
11#----------------------------#
12chapter4_Makefiles() {
13#----------------------------#
[e10232b]14 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter4${R_arrow}"
[0170229]15
16# If /home/lfs is already present in the host, we asume that the
17# lfs user and group are also presents in the host, and a backup
18# of their bash init files is made.
19(
20 cat << EOF
21020-creatingtoolsdir:
22 @\$(call echo_message, Building)
23 @mkdir -v \$(MOUNT_PT)/tools && \\
24 rm -fv /tools && \\
25 ln -sv \$(MOUNT_PT)/tools / && \\
26 touch \$@
27
28021-addinguser: 020-creatingtoolsdir
29 @\$(call echo_message, Building)
30 @if [ ! -d /home/lfs ]; then \\
31 groupadd lfs; \\
32 useradd -s /bin/bash -g lfs -m -k /dev/null lfs; \\
33 else \\
34 touch user-lfs-exist; \\
35 fi;
36 @chown lfs \$(MOUNT_PT)/tools && \\
[dacaa85]37 chmod a+wt \$(MOUNT_PT)/sources && \\
[0170229]38 touch \$@
39
40022-settingenvironment: 021-addinguser
41 @\$(call echo_message, Building)
42 @if [ -f /home/lfs/.bashrc -a ! -f /home/lfs/.bashrc.XXX ]; then \\
43 mv -v /home/lfs/.bashrc /home/lfs/.bashrc.XXX; \\
44 fi;
45 @if [ -f /home/lfs/.bash_profile -a ! -f /home/lfs/.bash_profile.XXX ]; then \\
46 mv -v /home/lfs/.bash_profile /home/lfs/.bash_profile.XXX; \\
47 fi;
48 @echo "set +h" > /home/lfs/.bashrc && \\
49 echo "umask 022" >> /home/lfs/.bashrc && \\
50 echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
51 echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
52 echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
53 echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
54 echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
55 chown lfs:lfs /home/lfs/.bashrc && \\
56 touch envars && \\
57 touch \$@
58EOF
59) >> $MKFILE.tmp
60}
61
62#----------------------------#
63chapter5_Makefiles() {
64#----------------------------#
[12a5707]65 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5${R_arrow}"
66
[0170229]67 for file in chapter05/* ; do
68 # Keep the script file name
69 this_script=`basename $file`
70
71 # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
[fed9756]72 # Fix also locales creation when running chapter05 testsuites (ugly)
[af4c7b1]73 case "${this_script}" in
74 *tcl) [[ "${TEST}" = "0" ]] && continue ;;
75 *expect) [[ "${TEST}" = "0" ]] && continue ;;
76 *dejagnu) [[ "${TEST}" = "0" ]] && continue ;;
77 *stripping) [[ "${STRIP}" = "0" ]] && continue ;;
[fed9756]78 *glibc) [[ "${TEST}" = "3" ]] && \
79 sed -i 's@/usr/lib/locale@/tools/lib/locale@' $file ;;
[af4c7b1]80 esac
[6b1576a]81
[0170229]82 # First append each name of the script files to a list (this will become
83 # the names of the targets in the Makefile
84 chapter5="$chapter5 ${this_script}"
85
86 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
87 # and binutils in chapter 5)
88 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
89
90 # Set the dependency for the first target.
91 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
92
[3f858ca]93 #--------------------------------------------------------------------#
94 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
95 #--------------------------------------------------------------------#
96 #
[0170229]97 # Drop in the name of the target on a new line, and the previous target
98 # as a dependency. Also call the echo_message function.
99 wrt_target "${this_script}" "$PREV"
100
101 # Find the version of the command files, if it corresponds with the building of
102 # a specific package
103 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
104
105 # If $vrs isn't empty, we've got a package...
106 if [ "$vrs" != "" ] ; then
107 if [ "$name" = "tcl" ] ; then
[c3c4e1d]108 FILE="$name$vrs-src.tar.*"
[0170229]109 else
[c3c4e1d]110 FILE="$name-$vrs.tar.*"
[0170229]111 fi
112
[3f858ca]113 # Insert instructions for unpacking the package and to set the PKGDIR variable.
[0170229]114 wrt_unpack "$FILE"
115 echo -e '\ttrue' >> $MKFILE.tmp
116 fi
117
118 # Insert date and disk usage at the top of the log file, the script run
119 # and date and disk usage again at the bottom of the log file.
[fed9756]120 # The changingowner script must be run as root.
121 case "${this_script}" in
122 *changingowner) wrt_run_as_root "${this_script}" "$file" ;;
123 *) wrt_run_as_su "${this_script}" "$file" ;;
124 esac
[0170229]125
126 # Remove the build directory(ies) except if the package build fails
127 # (so we can review config.cache, config.log, etc.)
128 if [ "$vrs" != "" ] ; then
129 wrt_remove_build_dirs "$name"
130 fi
131
132 # Include a touch of the target name so make can check
133 # if it's already been made.
134 echo -e '\t@touch $@' >> $MKFILE.tmp
[3f858ca]135 #
136 #--------------------------------------------------------------------#
137 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
138 #--------------------------------------------------------------------#
[0170229]139
140 # Keep the script file name for Makefile dependencies.
141 PREV=${this_script}
142 done # end for file in chapter05/*
143}
144
145#----------------------------#
146chapter6_Makefiles() {
147#----------------------------#
[615e37d]148 # Set envars and scripts for iteration targets
[b242136]149 if [[ -z "$1" ]] ; then
[aa08925]150 local N=""
151 else
152 local N=-build_$1
153 local chapter6=""
[615e37d]154 mkdir chapter06$N
155 cp chapter06/* chapter06$N
156 for script in chapter06$N/* ; do
[7aee0dd]157 # Overwrite existing symlinks, files, and dirs
[615e37d]158 sed -e 's/ln -sv/&f/g' \
159 -e 's/mv -v/&f/g' \
[7aee0dd]160 -e 's/mkdir -v/&p/g' -i ${script}
[615e37d]161 done
[3135831]162 # Remove Bzip2 binaries before make install
[c2fdc03]163 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i chapter06$N/*-bzip2
[944d69d]164 # Fix how Module-Init-Tools do the install target
[79439ec]165 sed -e 's@make install@make INSTALL=install install@' -i chapter06$N/*-module-init-tools
[944d69d]166 # Delete *old Readline libraries just after make install
167 sed -e 's@make install@&\nrm -v /lib/lib{history,readline}*old@' -i chapter06$N/*-readline
[7aee0dd]168 # Let some Udev pre-installation commands to fail
169 sed -e 's@/lib/udev/devices/fd@& || true@' \
170 -e 's/mknod -m.*/& || true/' -i chapter06$N/*-udev
[aa08925]171 fi
172
173 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N${R_arrow}"
[af4c7b1]174
[615e37d]175 for file in chapter06$N/* ; do
[0170229]176 # Keep the script file name
177 this_script=`basename $file`
178
179 # We'll run the chroot commands differently than the others, so skip them in the
180 # dependencies and target creation.
[af4c7b1]181 case "${this_script}" in
182 *chroot) continue ;;
[eb024db]183 *stripping*) [[ "${STRIP}" = "0" ]] && continue ;;
[af4c7b1]184 esac
[0170229]185
[b242136]186 # Grab the name of the target
187 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@'`
188
189 # Find the version of the command files, if it corresponds with the building of
190 # a specific package. We need this here to can skip scripts not needed for
191 # iterations rebuilds
192 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
193
194 if [[ "$vrs" = "" ]] && [[ -n "$N" ]] ; then
195 case "${this_script}" in
196 *stripping*) ;;
197 *) continue ;;
198 esac
199 fi
200
[0170229]201 # First append each name of the script files to a list (this will become
202 # the names of the targets in the Makefile
[aa08925]203 chapter6="$chapter6 ${this_script}${N}"
[0170229]204
[3f858ca]205 #--------------------------------------------------------------------#
206 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
207 #--------------------------------------------------------------------#
208 #
[0170229]209 # Drop in the name of the target on a new line, and the previous target
210 # as a dependency. Also call the echo_message function.
[aa08925]211 wrt_target "${this_script}${N}" "$PREV"
[0170229]212
213 # If $vrs isn't empty, we've got a package...
214 # Insert instructions for unpacking the package and changing directories
215 if [ "$vrs" != "" ] ; then
216 FILE="$name-$vrs.tar.*"
217 wrt_unpack2 "$FILE"
218 fi
219
220 # In the mount of kernel filesystems we need to set LFS
221 # and not to use chroot.
[af4c7b1]222 case "${this_script}" in
223 *kernfs) wrt_run_as_root "${this_script}" "$file" ;;
224 *) wrt_run_as_chroot1 "${this_script}" "$file" ;;
225 esac
[0170229]226
227 # Remove the build directory(ies) except if the package build fails.
228 if [ "$vrs" != "" ] ; then
[a46ada0]229 wrt_remove_build_dirs "$name"
[0170229]230 fi
231
232 # Include a touch of the target name so make can check
233 # if it's already been made.
234 echo -e '\t@touch $@' >> $MKFILE.tmp
[3f858ca]235 #
236 #--------------------------------------------------------------------#
237 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
238 #--------------------------------------------------------------------#
[0170229]239
240 # Keep the script file name for Makefile dependencies.
[aa08925]241 PREV=${this_script}${N}
242 # Set system_build envar for iteration targets
243 system_build=$chapter6
[0170229]244 done # end for file in chapter06/*
245}
246
247#----------------------------#
248chapter789_Makefiles() {
249#----------------------------#
[c0613fe]250 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8/9${R_arrow}"
[af4c7b1]251
[0170229]252 for file in chapter0{7,8,9}/* ; do
253 # Keep the script file name
254 this_script=`basename $file`
255
256 # Grub must be configured manually.
257 # The filesystems can't be unmounted via Makefile and the user
258 # should enter the chroot environment to create the root
259 # password, edit several files and setup Grub.
[0271c0c]260 #
[0170229]261 # If no .config file is supplied, the kernel build is skipped
[0271c0c]262 #
263 case ${this_script} in
264 *grub) continue ;;
265 *reboot) continue ;;
[6b1576a]266 *console) continue ;; # Use the file generated by lfs-bootscripts
[0271c0c]267 *kernel) [[ -z ${CONFIG} ]] && continue
268 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
269 esac
[0170229]270
271 # First append each name of the script files to a list (this will become
272 # the names of the targets in the Makefile
273 chapter789="$chapter789 ${this_script}"
274
[3f858ca]275 #--------------------------------------------------------------------#
276 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
277 #--------------------------------------------------------------------#
278 #
[0170229]279 # Drop in the name of the target on a new line, and the previous target
280 # as a dependency. Also call the echo_message function.
281 wrt_target "${this_script}" "$PREV"
282
283 # Find the bootscripts and kernel package names
[af4c7b1]284 case "${this_script}" in
285 *bootscripts)
286 vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
287 FILE="lfs-bootscripts-$vrs.tar.*"
288 wrt_unpack2 "$FILE"
289 ;;
290 *kernel)
291 vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
292 FILE="linux-$vrs.tar.*"
293 wrt_unpack2 "$FILE"
294 ;;
295 esac
[6b1576a]296
[0170229]297 # Check if we have a real /etc/fstab file
[af4c7b1]298 case "${this_script}" in
299 *fstab) if [[ -n $FSTAB ]]; then
300 wrt_copy_fstab "${this_script}"
301 else
302 wrt_run_as_chroot2 "$this_script" "$file"
303 fi
304 ;;
305 *) wrt_run_as_chroot2 "$this_script" "$file"
306 ;;
307 esac
[0170229]308
[af4c7b1]309 case "${this_script}" in
310 *bootscripts) wrt_remove_build_dirs "dummy" ;;
311 *kernel) wrt_remove_build_dirs "dummy" ;;
312 esac
[6b1576a]313
[0170229]314 # Include a touch of the target name so make can check
315 # if it's already been made.
316 echo -e '\t@touch $@' >> $MKFILE.tmp
[3f858ca]317 #
318 #--------------------------------------------------------------------#
319 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
320 #--------------------------------------------------------------------#
[0170229]321
322 # Keep the script file name for Makefile dependencies.
323 PREV=${this_script}
324 done # for file in chapter0{7,8,9}/*
325}
326
327
328#----------------------------#
329build_Makefile() {
330#----------------------------#
[e10232b]331 echo "Creating Makefile... "
[0170229]332 cd $JHALFSDIR/${PROGNAME}-commands
333
334 # Start with a clean Makefile.tmp file
335 >$MKFILE.tmp
336
337 chapter4_Makefiles
338 chapter5_Makefiles
339 chapter6_Makefiles
[eb024db]340 # Add the ICA/farce targets, if needed
[d27c9ca]341 [[ "$COMPARE" != "0" ]] && wrt_compare_targets
[0170229]342 chapter789_Makefiles
343
344
345 # Add a header, some variables and include the function file
346 # to the top of the real Makefile.
347(
348 cat << EOF
349$HEADER
350
351SRC= /sources
352MOUNT_PT= $BUILDDIR
353
354include makefile-functions
355
356EOF
357) > $MKFILE
358
359
360 # Add chroot commands
361 i=1
362 for file in chapter06/*chroot* ; do
363 chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
364 -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
365 -e 's|"$$LFS"|$(MOUNT_PT)|' -e 's|set -e||'`
366 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
367 i=`expr $i + 1`
368 done
369
370 # Drop in the main target 'all:' and the chapter targets with each sub-target
371 # as a dependency.
372(
373 cat << EOF
374all: chapter4 chapter5 chapter6 chapter789
375 @\$(call echo_finished,$VERSION)
376
377chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
378
379chapter5: chapter4 $chapter5 restore-lfs-env
380
381chapter6: chapter5 $chapter6
382
383chapter789: chapter6 $chapter789
384
385clean-all: clean
[db187c74]386 rm -rf ./{lfs-commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
[0170229]387
388clean: clean-chapter789 clean-chapter6 clean-chapter5 clean-chapter4
389
390clean-chapter4:
391 -if [ ! -f user-lfs-exist ]; then \\
392 userdel lfs; \\
393 rm -rf /home/lfs; \\
394 fi;
395 rm -rf \$(MOUNT_PT)/tools
396 rm -f /tools
397 rm -f envars user-lfs-exist
398 rm -f 02* logs/02*.log
399
400clean-chapter5:
401 rm -rf \$(MOUNT_PT)/tools/*
402 rm -f $chapter5 restore-lfs-env sources-dir
403 cd logs && rm -f $chapter5 && cd ..
404
405clean-chapter6:
406 -umount \$(MOUNT_PT)/sys
407 -umount \$(MOUNT_PT)/proc
408 -umount \$(MOUNT_PT)/dev/shm
409 -umount \$(MOUNT_PT)/dev/pts
410 -umount \$(MOUNT_PT)/dev
411 rm -rf \$(MOUNT_PT)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
412 rm -f $chapter6
413 cd logs && rm -f $chapter6 && cd ..
414
415clean-chapter789:
416 rm -f $chapter789
417 cd logs && rm -f $chapter789 && cd ..
418
419restore-lfs-env:
420 @\$(call echo_message, Building)
421 @if [ -f /home/lfs/.bashrc.XXX ]; then \\
422 mv -fv /home/lfs/.bashrc.XXX /home/lfs/.bashrc; \\
423 fi;
424 @if [ -f /home/lfs/.bash_profile.XXX ]; then \\
425 mv -v /home/lfs/.bash_profile.XXX /home/lfs/.bash_profile; \\
426 fi;
427 @chown lfs:lfs /home/lfs/.bash* && \\
428 touch \$@
429
[42346b2]430EOF
431) >> $MKFILE
432
[0170229]433 # Bring over the items from the Makefile.tmp
434 cat $MKFILE.tmp >> $MKFILE
435 rm $MKFILE.tmp
[e10232b]436 echo "done"
[0170229]437}
438
439
Note: See TracBrowser for help on using the repository browser.