source: LFS/master.sh@ ab7bac5

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since ab7bac5 was ab7bac5, checked in by Jeremy Huntwork <jhuntwork@…>, 18 years ago

Added instructions to always remove source and -build directories before running specific package commands

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