source: LFS/master.sh@ f8615e5

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

Updated experimental to current trunk.

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