source: LFS/master.sh@ c2fdc03

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

Fixed Bzip2 reinstallations.

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