source: LFS/master.sh@ 401f81e

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

Ported Makefile clean-up and 0/1 to n/y migration code from experimental.
There is no obvious bugs, let users to find hidden bugs.

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