source: LFS/master.sh@ 972467e

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

Changed how Readline reistallation is fixed.

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