source: LFS/master.sh@ d057075

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

Added COMPARE config option to avoid to have to test if RUN_ICA or RUN_FARCE are set.
Changed ICA_rebuild by system_rebuild.

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