source: LFS/master.sh@ 54b4b32

experimental
Last change on this file since 54b4b32 was 60cb629, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Improved Module-Init-Tools and Readline reinstallations.

  • Property mode set to 100755
File size: 14.4 KB
Line 
1#!/bin/sh
2
3# $Id$
4
5###################################
6### FUNCTIONS ###
7###################################
8
9
10
11#----------------------------#
12chapter4_Makefiles() {
13#----------------------------#
14 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter4${R_arrow}"
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 && \\
37 chmod a+wt \$(MOUNT_PT)/sources && \\
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#----------------------------#
65 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5${R_arrow}"
66
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
72 # Fix also locales creation when running chapter05 testsuites (ugly)
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 ;;
78 *glibc) [[ "${TEST}" = "3" ]] && \
79 sed -i 's@/usr/lib/locale@/tools/lib/locale@' $file ;;
80 esac
81
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
93 #--------------------------------------------------------------------#
94 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
95 #--------------------------------------------------------------------#
96 #
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
108 FILE="$name$vrs-src.tar.*"
109 else
110 FILE="$name-$vrs.tar.*"
111 fi
112
113 # Insert instructions for unpacking the package and to set the PKGDIR variable.
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.
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
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
135 #
136 #--------------------------------------------------------------------#
137 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
138 #--------------------------------------------------------------------#
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#----------------------------#
148 # Set envars and scripts for iteration targets
149 if [[ -z "$1" ]] ; then
150 local N=""
151 else
152 local N=-build_$1
153 local chapter6=""
154 mkdir chapter06$N
155 cp chapter06/* chapter06$N
156 for script in chapter06$N/* ; do
157 # Overwrite existing symlinks, files, and dirs
158 sed -e 's/ln -sv/&f/g' \
159 -e 's/mv -v/&f/g' \
160 -e 's/mkdir -v/&p/g' -i ${script}
161 done
162 # Remove Bzip2 binaries before make install
163 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i chapter06$N/*-bzip2
164 # Tell Module-Init-Tools that we are reinstalling it and clean-up
165 sed -e 's@make install@make moveold\n&@' \
166 -e 's@make install@&\nrm -v /sbin/*.old@' \
167 -e 's@make install@&\nrm -v /bin/lsmod.old@' \
168 -e 's@make install@&\nrm -v /usr/share/man/man8/*.old.8@' -i chapter06$N/*-module-init-tools
169 # Delete *old Readline libraries and regenerate two links after make install
170 sed -e 's@make install@&\nln -sfv libreadline.so.5.1 /lib/libreadline.so.5@' \
171 -e 's@make install@&\nln -sfv libhistory.so.5.1 /lib/libhistory.so.5@' \
172 -e 's@make install@&\nrm -v /lib/lib{history,readline}*old@' \
173 -e 's@make install@&\nrm -v /lib/lib{history,readline}.so.5@' -i chapter06$N/*-readline
174 # Let some Udev pre-installation commands to fail
175 sed -e 's@/lib/udev/devices/fd@& || true@' \
176 -e 's/mknod -m.*/& || true/' -i chapter06$N/*-udev
177 fi
178
179 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter6$N${R_arrow}"
180
181 for file in chapter06$N/* ; do
182 # Keep the script file name
183 this_script=`basename $file`
184
185 # We'll run the chroot commands differently than the others, so skip them in the
186 # dependencies and target creation.
187 case "${this_script}" in
188 *chroot) continue ;;
189 *stripping*) [[ "${STRIP}" = "0" ]] && continue ;;
190 esac
191
192 # Grab the name of the target
193 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@'`
194
195 # Find the version of the command files, if it corresponds with the building of
196 # a specific package. We need this here to can skip scripts not needed for
197 # iterations rebuilds
198 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
199
200 if [[ "$vrs" = "" ]] && [[ -n "$N" ]] ; then
201 case "${this_script}" in
202 *stripping*) ;;
203 *) continue ;;
204 esac
205 fi
206
207 # First append each name of the script files to a list (this will become
208 # the names of the targets in the Makefile
209 chapter6="$chapter6 ${this_script}${N}"
210
211 #--------------------------------------------------------------------#
212 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
213 #--------------------------------------------------------------------#
214 #
215 # Drop in the name of the target on a new line, and the previous target
216 # as a dependency. Also call the echo_message function.
217 wrt_target "${this_script}${N}" "$PREV"
218
219 # If $vrs isn't empty, we've got a package...
220 # Insert instructions for unpacking the package and changing directories
221 if [ "$vrs" != "" ] ; then
222 FILE="$name-$vrs.tar.*"
223 wrt_unpack2 "$FILE"
224 fi
225
226 # In the mount of kernel filesystems we need to set LFS
227 # and not to use chroot.
228 case "${this_script}" in
229 *kernfs) wrt_run_as_root "${this_script}" "$file" ;;
230 *) wrt_run_as_chroot1 "${this_script}" "$file" ;;
231 esac
232
233 # Remove the build directory(ies) except if the package build fails.
234 if [ "$vrs" != "" ] ; then
235 wrt_remove_build_dirs "$name"
236 fi
237
238 # Include a touch of the target name so make can check
239 # if it's already been made.
240 echo -e '\t@touch $@' >> $MKFILE.tmp
241 #
242 #--------------------------------------------------------------------#
243 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
244 #--------------------------------------------------------------------#
245
246 # Keep the script file name for Makefile dependencies.
247 PREV=${this_script}${N}
248 # Set system_build envar for iteration targets
249 system_build=$chapter6
250 done # end for file in chapter06/*
251}
252
253#----------------------------#
254chapter789_Makefiles() {
255#----------------------------#
256 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8/9${R_arrow}"
257
258 for file in chapter0{7,8,9}/* ; do
259 # Keep the script file name
260 this_script=`basename $file`
261
262 # Grub must be configured manually.
263 # The filesystems can't be unmounted via Makefile and the user
264 # should enter the chroot environment to create the root
265 # password, edit several files and setup Grub.
266 #
267 # If no .config file is supplied, the kernel build is skipped
268 #
269 case ${this_script} in
270 *grub) continue ;;
271 *reboot) continue ;;
272 *console) continue ;; # Use the file generated by lfs-bootscripts
273 *kernel) [[ -z ${CONFIG} ]] && continue
274 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
275 esac
276
277 # First append each name of the script files to a list (this will become
278 # the names of the targets in the Makefile
279 chapter789="$chapter789 ${this_script}"
280
281 #--------------------------------------------------------------------#
282 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
283 #--------------------------------------------------------------------#
284 #
285 # Drop in the name of the target on a new line, and the previous target
286 # as a dependency. Also call the echo_message function.
287 wrt_target "${this_script}" "$PREV"
288
289 # Find the bootscripts and kernel package names
290 case "${this_script}" in
291 *bootscripts)
292 vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
293 FILE="lfs-bootscripts-$vrs.tar.*"
294 wrt_unpack2 "$FILE"
295 ;;
296 *kernel)
297 vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
298 FILE="linux-$vrs.tar.*"
299 wrt_unpack2 "$FILE"
300 ;;
301 esac
302
303 # Check if we have a real /etc/fstab file
304 case "${this_script}" in
305 *fstab) if [[ -n $FSTAB ]]; then
306 wrt_copy_fstab "${this_script}"
307 else
308 wrt_run_as_chroot2 "$this_script" "$file"
309 fi
310 ;;
311 *) wrt_run_as_chroot2 "$this_script" "$file"
312 ;;
313 esac
314
315 case "${this_script}" in
316 *bootscripts) wrt_remove_build_dirs "dummy" ;;
317 *kernel) wrt_remove_build_dirs "dummy" ;;
318 esac
319
320 # Include a touch of the target name so make can check
321 # if it's already been made.
322 echo -e '\t@touch $@' >> $MKFILE.tmp
323 #
324 #--------------------------------------------------------------------#
325 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
326 #--------------------------------------------------------------------#
327
328 # Keep the script file name for Makefile dependencies.
329 PREV=${this_script}
330 done # for file in chapter0{7,8,9}/*
331}
332
333
334#----------------------------#
335build_Makefile() {
336#----------------------------#
337 echo "Creating Makefile... "
338 cd $JHALFSDIR/${PROGNAME}-commands
339
340 # Start with a clean Makefile.tmp file
341 >$MKFILE.tmp
342
343 chapter4_Makefiles
344 chapter5_Makefiles
345 chapter6_Makefiles
346 # Add the ICA/farce targets, if needed
347 [[ "$COMPARE" != "0" ]] && wrt_compare_targets
348 chapter789_Makefiles
349
350
351 # Add a header, some variables and include the function file
352 # to the top of the real Makefile.
353(
354 cat << EOF
355$HEADER
356
357SRC= /sources
358MOUNT_PT= $BUILDDIR
359
360include makefile-functions
361
362EOF
363) > $MKFILE
364
365
366 # Add chroot commands
367 i=1
368 for file in chapter06/*chroot* ; do
369 chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
370 -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
371 -e 's|"$$LFS"|$(MOUNT_PT)|' -e 's|set -e||'`
372 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
373 i=`expr $i + 1`
374 done
375
376 # Drop in the main target 'all:' and the chapter targets with each sub-target
377 # as a dependency.
378(
379 cat << EOF
380all: chapter4 chapter5 chapter6 chapter789
381 @\$(call echo_finished,$VERSION)
382
383chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
384
385chapter5: chapter4 $chapter5 restore-lfs-env
386
387chapter6: chapter5 $chapter6
388
389chapter789: chapter6 $chapter789
390
391clean-all: clean
392 rm -rf ./{lfs-commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
393
394clean: clean-chapter789 clean-chapter6 clean-chapter5 clean-chapter4
395
396clean-chapter4:
397 -if [ ! -f user-lfs-exist ]; then \\
398 userdel lfs; \\
399 rm -rf /home/lfs; \\
400 fi;
401 rm -rf \$(MOUNT_PT)/tools
402 rm -f /tools
403 rm -f envars user-lfs-exist
404 rm -f 02* logs/02*.log
405
406clean-chapter5:
407 rm -rf \$(MOUNT_PT)/tools/*
408 rm -f $chapter5 restore-lfs-env sources-dir
409 cd logs && rm -f $chapter5 && cd ..
410
411clean-chapter6:
412 -umount \$(MOUNT_PT)/sys
413 -umount \$(MOUNT_PT)/proc
414 -umount \$(MOUNT_PT)/dev/shm
415 -umount \$(MOUNT_PT)/dev/pts
416 -umount \$(MOUNT_PT)/dev
417 rm -rf \$(MOUNT_PT)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
418 rm -f $chapter6
419 cd logs && rm -f $chapter6 && cd ..
420
421clean-chapter789:
422 rm -f $chapter789
423 cd logs && rm -f $chapter789 && cd ..
424
425restore-lfs-env:
426 @\$(call echo_message, Building)
427 @if [ -f /home/lfs/.bashrc.XXX ]; then \\
428 mv -fv /home/lfs/.bashrc.XXX /home/lfs/.bashrc; \\
429 fi;
430 @if [ -f /home/lfs/.bash_profile.XXX ]; then \\
431 mv -v /home/lfs/.bash_profile.XXX /home/lfs/.bash_profile; \\
432 fi;
433 @chown lfs:lfs /home/lfs/.bash* && \\
434 touch \$@
435
436EOF
437) >> $MKFILE
438
439 # Bring over the items from the Makefile.tmp
440 cat $MKFILE.tmp >> $MKFILE
441 rm $MKFILE.tmp
442 echo "done"
443}
444
445
Note: See TracBrowser for help on using the repository browser.