source: LFS/master.sh@ 93f38e7

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 93f38e7 was 4a444f1, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Look fix.

  • Property mode set to 100755
File size: 17.0 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 \$(MOUNT_PT)/tools && \\
24 rm -f /tools && \\
25 ln -s \$(MOUNT_PT)/tools / && \\
26 touch \$@ && \\
27 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
28 echo --------------------------------------------------------------------------------\$(WHITE)
29
30021-addinguser: 020-creatingtoolsdir
31 @\$(call echo_message, Building)
32 @if [ ! -d /home/lfs ]; then \\
33 groupadd lfs; \\
34 useradd -s /bin/bash -g lfs -m -k /dev/null lfs; \\
35 else \\
36 touch user-lfs-exist; \\
37 fi;
38 @chown lfs \$(MOUNT_PT)/tools && \\
39 chmod a+wt \$(MOUNT_PT)/sources && \\
40 touch \$@ && \\
41 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
42 echo --------------------------------------------------------------------------------\$(WHITE)
43
44022-settingenvironment: 021-addinguser
45 @\$(call echo_message, Building)
46 @if [ -f /home/lfs/.bashrc -a ! -f /home/lfs/.bashrc.XXX ]; then \\
47 mv /home/lfs/.bashrc /home/lfs/.bashrc.XXX; \\
48 fi;
49 @if [ -f /home/lfs/.bash_profile -a ! -f /home/lfs/.bash_profile.XXX ]; then \\
50 mv /home/lfs/.bash_profile /home/lfs/.bash_profile.XXX; \\
51 fi;
52 @echo "set +h" > /home/lfs/.bashrc && \\
53 echo "umask 022" >> /home/lfs/.bashrc && \\
54 echo "LFS=\$(MOUNT_PT)" >> /home/lfs/.bashrc && \\
55 echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
56 echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
57 echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
58 echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
59 chown lfs:lfs /home/lfs/.bashrc && \\
60 touch envars && \\
61 touch \$@ && \\
62 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
63 echo --------------------------------------------------------------------------------\$(WHITE)
64EOF
65) >> $MKFILE.tmp
66}
67
68#----------------------------#
69chapter5_Makefiles() {
70#----------------------------#
71 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter5${R_arrow}"
72
73 for file in chapter05/* ; do
74 # Keep the script file name
75 this_script=`basename $file`
76
77 # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
78 # Fix also locales creation when running chapter05 testsuites (ugly)
79 case "${this_script}" in
80 *tcl) [[ "${TEST}" = "0" ]] && continue ;;
81 *expect) [[ "${TEST}" = "0" ]] && continue ;;
82 *dejagnu) [[ "${TEST}" = "0" ]] && continue ;;
83 *stripping) [[ "${STRIP}" = "0" ]] && continue ;;
84 *glibc) [[ "${TEST}" = "3" ]] && \
85 sed -i 's@/usr/lib/locale@/tools/lib/locale@' $file ;;
86 esac
87
88 # First append each name of the script files to a list (this will become
89 # the names of the targets in the Makefile
90 chapter5="$chapter5 ${this_script}"
91
92 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
93 # and binutils in chapter 5)
94 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
95
96 # Set the dependency for the first target.
97 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
98
99 #--------------------------------------------------------------------#
100 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
101 #--------------------------------------------------------------------#
102 #
103 # Drop in the name of the target on a new line, and the previous target
104 # as a dependency. Also call the echo_message function.
105 wrt_target "${this_script}" "$PREV"
106
107 # Find the version of the command files, if it corresponds with the building of
108 # a specific package
109 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
110
111 # If $vrs isn't empty, we've got a package...
112 if [ "$vrs" != "" ] ; then
113 if [ "$name" = "tcl" ] ; then
114 FILE="$name$vrs-src.tar.*"
115 else
116 FILE="$name-$vrs.tar.*"
117 fi
118
119 # Insert instructions for unpacking the package and to set the PKGDIR variable.
120 wrt_unpack "$FILE"
121 # If the testsuites must be run, initialize the log file
122 [[ "$TEST" = "3" ]] && wrt_test_log "${this_script}"
123 # If using optimizations, write the instructions
124 [[ "$OPTIMIZE" = "2" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
125 fi
126
127 # Insert date and disk usage at the top of the log file, the script run
128 # and date and disk usage again at the bottom of the log file.
129 # The changingowner script must be run as root.
130 case "${this_script}" in
131 *changingowner) wrt_run_as_root "${this_script}" "$file" ;;
132 *) wrt_run_as_su "${this_script}" "$file" ;;
133 esac
134
135 # Remove the build directory(ies) except if the package build fails
136 # (so we can review config.cache, config.log, etc.)
137 if [ "$vrs" != "" ] ; then
138 wrt_remove_build_dirs "$name"
139 fi
140
141 # Include a touch of the target name so make can check
142 # if it's already been made.
143 wrt_touch
144 #
145 #--------------------------------------------------------------------#
146 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
147 #--------------------------------------------------------------------#
148
149 # Keep the script file name for Makefile dependencies.
150 PREV=${this_script}
151 done # end for file in chapter05/*
152}
153
154#----------------------------#
155chapter6_Makefiles() {
156#----------------------------#
157 # Set envars and scripts for iteration targets
158 LOGS="" # Start with an empty global LOGS envar
159 if [[ -z "$1" ]] ; then
160 local N=""
161 else
162 local N=-build_$1
163 local chapter6=""
164 mkdir chapter06$N
165 cp chapter06/* chapter06$N
166 for script in chapter06$N/* ; do
167 # Overwrite existing symlinks, files, and dirs
168 sed -e 's/ln -sv/&f/g' \
169 -e 's/mv -v/&f/g' \
170 -e 's/mkdir -v/&p/g' -i ${script}
171 done
172 # Remove Bzip2 binaries before make install
173 sed -e 's@make install@rm -vf /usr/bin/bz*\n&@' -i chapter06$N/*-bzip2
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 # 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 # Append each name of the script files to a list (this will become
212 # the names of the logs to be moved for each iteration)
213 LOGS="$LOGS ${this_script}"
214
215 #--------------------------------------------------------------------#
216 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
217 #--------------------------------------------------------------------#
218 #
219 # Drop in the name of the target on a new line, and the previous target
220 # as a dependency. Also call the echo_message function.
221 wrt_target "${this_script}${N}" "$PREV"
222
223 # If $vrs isn't empty, we've got a package...
224 # Insert instructions for unpacking the package and changing directories
225 if [ "$vrs" != "" ] ; then
226 FILE="$name-$vrs.tar.*"
227 wrt_unpack2 "$FILE"
228 # If the testsuites must be run, initialize the log file
229 case $name in
230 binutils | gcc | glibc )
231 [[ "$TEST" != "0" ]] && wrt_test_log2 "${this_script}"
232 ;;
233 * )
234 [[ "$TEST" = "2" ]] || [[ "$TEST" = "3" ]] && wrt_test_log2 "${this_script}"
235 ;;
236 esac
237 # If using optimizations, write the instructions
238 [[ "$OPTIMIZE" != "0" ]] && wrt_optimize "$name" && wrt_makeflags "$name"
239 fi
240
241 # In the mount of kernel filesystems we need to set LFS
242 # and not to use chroot.
243 case "${this_script}" in
244 *kernfs) wrt_run_as_root "${this_script}" "$file" ;;
245 *) wrt_run_as_chroot1 "${this_script}" "$file" ;;
246 esac
247
248 # Remove the build directory(ies) except if the package build fails.
249 if [ "$vrs" != "" ] ; then
250 wrt_remove_build_dirs "$name"
251 fi
252
253 # Include a touch of the target name so make can check
254 # if it's already been made.
255 wrt_touch
256 #
257 #--------------------------------------------------------------------#
258 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
259 #--------------------------------------------------------------------#
260
261 # Keep the script file name for Makefile dependencies.
262 PREV=${this_script}${N}
263 # Set system_build envar for iteration targets
264 system_build=$chapter6
265 done # end for file in chapter06/*
266}
267
268#----------------------------#
269chapter789_Makefiles() {
270#----------------------------#
271 echo "${tab_}${GREEN}Processing... ${L_arrow}Chapter7/8/9${R_arrow}"
272
273 for file in chapter0{7,8,9}/* ; do
274 # Keep the script file name
275 this_script=`basename $file`
276
277 # Grub must be configured manually.
278 # The filesystems can't be unmounted via Makefile and the user
279 # should enter the chroot environment to create the root
280 # password, edit several files and setup Grub.
281 #
282 # If no .config file is supplied, the kernel build is skipped
283 #
284 case ${this_script} in
285 *grub) continue ;;
286 *reboot) continue ;;
287 *console) continue ;; # Use the file generated by lfs-bootscripts
288 *kernel) [[ -z ${CONFIG} ]] && continue
289 cp ${CONFIG} $BUILDDIR/sources/kernel-config ;;
290 esac
291
292 # First append each name of the script files to a list (this will become
293 # the names of the targets in the Makefile
294 chapter789="$chapter789 ${this_script}"
295
296 #--------------------------------------------------------------------#
297 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
298 #--------------------------------------------------------------------#
299 #
300 # Drop in the name of the target on a new line, and the previous target
301 # as a dependency. Also call the echo_message function.
302 wrt_target "${this_script}" "$PREV"
303
304 # Find the bootscripts and kernel package names
305 case "${this_script}" in
306 *bootscripts)
307 vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
308 FILE="lfs-bootscripts-$vrs.tar.*"
309 wrt_unpack2 "$FILE"
310 ;;
311 *kernel)
312 vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
313 FILE="linux-$vrs.tar.*"
314 wrt_unpack2 "$FILE"
315 ;;
316 esac
317
318 # Check if we have a real /etc/fstab file
319 case "${this_script}" in
320 *fstab) if [[ -n $FSTAB ]]; then
321 wrt_copy_fstab "${this_script}"
322 else
323 wrt_run_as_chroot2 "$this_script" "$file"
324 fi
325 ;;
326 *) wrt_run_as_chroot2 "$this_script" "$file"
327 ;;
328 esac
329
330 case "${this_script}" in
331 *bootscripts) wrt_remove_build_dirs "dummy" ;;
332 *kernel) wrt_remove_build_dirs "dummy" ;;
333 esac
334
335 # Include a touch of the target name so make can check
336 # if it's already been made.
337 wrt_touch
338 #
339 #--------------------------------------------------------------------#
340 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
341 #--------------------------------------------------------------------#
342
343 # Keep the script file name for Makefile dependencies.
344 PREV=${this_script}
345 done # for file in chapter0{7,8,9}/*
346
347 # Add SBU-disk_usage report target if required
348 if [[ "$REPORT" = "1" ]] ; then wrt_report ; fi
349}
350
351
352#----------------------------#
353build_Makefile() {
354#----------------------------#
355 echo "Creating Makefile... ${BOLD}START${OFF}"
356 cd $JHALFSDIR/${PROGNAME}-commands
357
358 # Start with a clean Makefile.tmp file
359 >$MKFILE.tmp
360
361 chapter4_Makefiles
362 chapter5_Makefiles
363 chapter6_Makefiles
364 # Add the iterations targets, if needed
365 [[ "$COMPARE" != "0" ]] && wrt_compare_targets
366 chapter789_Makefiles
367
368
369 # Add a header, some variables and include the function file
370 # to the top of the real Makefile.
371(
372 cat << EOF
373$HEADER
374
375SRC= /sources
376MOUNT_PT= $BUILDDIR
377PKG_LST= $PKG_LST
378
379include makefile-functions
380
381EOF
382) > $MKFILE
383
384
385 # Add chroot commands
386 i=1
387 for file in chapter06/*chroot* ; do
388 chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
389 -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
390 -e 's|"$$LFS"|$(MOUNT_PT)|' -e 's|set -e||'`
391 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
392 i=`expr $i + 1`
393 done
394
395 # Drop in the main target 'all:' and the chapter targets with each sub-target
396 # as a dependency.
397(
398 cat << EOF
399all: chapter4 chapter5 chapter6 chapter789 do_housekeeping
400 @\$(call echo_finished,$VERSION)
401
402chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
403
404chapter5: chapter4 $chapter5 restore-lfs-env
405
406chapter6: chapter5 $chapter6
407
408chapter789: chapter6 $chapter789
409
410clean-all: clean
411 rm -rf ./{lfs-commands,logs,Makefile,*.xsl,makefile-functions,packages,patches}
412
413clean: clean-chapter789 clean-chapter6 clean-chapter5 clean-chapter4
414
415restart: restart_code all
416
417clean-chapter4:
418 -if [ ! -f user-lfs-exist ]; then \\
419 userdel lfs; \\
420 rm -rf /home/lfs; \\
421 fi;
422 rm -rf \$(MOUNT_PT)/tools
423 rm -f /tools
424 rm -f envars user-lfs-exist
425 rm -f 02* logs/02*.log
426
427clean-chapter5:
428 rm -rf \$(MOUNT_PT)/tools/*
429 rm -f $chapter5 restore-lfs-env sources-dir
430 cd logs && rm -f $chapter5 && cd ..
431
432clean-chapter6:
433 -umount \$(MOUNT_PT)/sys
434 -umount \$(MOUNT_PT)/proc
435 -umount \$(MOUNT_PT)/dev/shm
436 -umount \$(MOUNT_PT)/dev/pts
437 -umount \$(MOUNT_PT)/dev
438 rm -rf \$(MOUNT_PT)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
439 rm -f $chapter6
440 cd logs && rm -f $chapter6 && cd ..
441
442clean-chapter789:
443 rm -f $chapter789
444 cd logs && rm -f $chapter789 && cd ..
445
446restore-lfs-env:
447 @\$(call echo_message, Building)
448 @if [ -f /home/lfs/.bashrc.XXX ]; then \\
449 mv -f /home/lfs/.bashrc.XXX /home/lfs/.bashrc; \\
450 fi;
451 @if [ -f /home/lfs/.bash_profile.XXX ]; then \\
452 mv /home/lfs/.bash_profile.XXX /home/lfs/.bash_profile; \\
453 fi;
454 @chown lfs:lfs /home/lfs/.bash* && \\
455 touch \$@ && \\
456 echo " "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
457 echo --------------------------------------------------------------------------------\$(WHITE)
458
459do_housekeeping:
460 -umount \$(MOUNT_PT)/sys
461 -umount \$(MOUNT_PT)/proc
462 -umount \$(MOUNT_PT)/dev/shm
463 -umount \$(MOUNT_PT)/dev/pts
464 -umount \$(MOUNT_PT)/dev
465 -if [ ! -f user-lfs-exist ]; then \\
466 userdel lfs; \\
467 rm -rf /home/lfs; \\
468 fi;
469
470restart_code:
471 @echo ">>> This feature is experimental, BUGS may exist"
472
473 @if [ ! -L /tools ]; then \\
474 echo -e "\\nERROR::\\n /tools is NOT a symlink.. /tools must point to \$(MOUNT_PT)/tools\\n" && false;\\
475 fi;
476
477 @if [ ! -e /tools ]; then \\
478 echo -e "\\nERROR::\\nThe target /tools points to does not exist.\\nVerify the target.. \$(MOUNT_PT)/tools\\n" && false;\\
479 fi;
480
481 @if ! stat -c %N /tools | grep "\$(MOUNT_PT)/tools" >/dev/null ; then \\
482 echo -e "\\nERROR::\\nThe symlink \\"/tools\\" does not point to \\"\$(MOUNT_PT)/tools\\".\\nCorrect the problem and rerun\\n" && false;\\
483 fi;
484
485 @if [ -f ???-kernfs ]; then \\
486 mkdir -pv \$(MOUNT_PT)/{dev,proc,sys};\\
487 if [ ! -e \$(MOUNT_PT)/dev/console ]; then \\
488 mknod -m 600 \$(MOUNT_PT)/dev/console c 5 1;\\
489 fi;\\
490 if [ ! -e \$(MOUNT_PT)/dev/null ]; then \\
491 mknod -m 666 \$(MOUNT_PT)/dev/null c 1 3;\\
492 fi;\\
493 if ! mount -l | grep bind >/dev/null ; then \\
494 mount --bind /dev \$(MOUNT_PT)/dev;\\
495 fi;\\
496 if ! mount -l | grep "\$(MOUNT_PT)/dev/pts" >/dev/null ; then \\
497 mount -vt devpts devpts \$(MOUNT_PT)/dev/pts;\\
498 fi;\\
499 if ! mount -l | grep "\$(MOUNT_PT)/dev/shm" >/dev/null ; then \\
500 mount -vt tmpfs shm \$(MOUNT_PT)/dev/shm;\\
501 fi;\\
502 if ! mount -l | grep "\$(MOUNT_PT)/proc" >/dev/null ; then \\
503 mount -vt proc proc \$(MOUNT_PT)/proc;\\
504 fi;\\
505 if ! mount -l | grep "$\(MOUNT_PT)/sys" >/dev/null ; then \\
506 mount -vt sysfs sysfs \$(MOUNT_PT)/sys;\\
507 fi;\\
508 fi;
509
510EOF
511) >> $MKFILE
512
513 # Bring over the items from the Makefile.tmp
514 cat $MKFILE.tmp >> $MKFILE
515 rm $MKFILE.tmp
516 echo "Creating Makefile... ${BOLD}DONE${OFF}"
517
518}
519
Note: See TracBrowser for help on using the repository browser.