source: LFS/master.sh@ eae0c9d

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

Skip unwanted scripts for iteration builds.

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