source: LFS/master.sh@ 2b016ea

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

Added Id key to some file to see in what of them is expanded and in what not.

  • Property mode set to 100755
File size: 11.5 KB
RevLine 
[0170229]1#!/bin/sh
2
[a46ada0]3# $Id$
[0170229]4
5###################################
6### FUNCTIONS ###
7###################################
8
9
10
11#----------------------------#
12chapter4_Makefiles() {
13#----------------------------#
14
15# If /home/lfs 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 -v \$(MOUNT_PT)/tools && \\
23 rm -fv /tools && \\
24 ln -sv \$(MOUNT_PT)/tools / && \\
25 touch \$@
26
27021-addinguser: 020-creatingtoolsdir
28 @\$(call echo_message, Building)
29 @if [ ! -d /home/lfs ]; then \\
30 groupadd lfs; \\
31 useradd -s /bin/bash -g lfs -m -k /dev/null lfs; \\
32 else \\
33 touch user-lfs-exist; \\
34 fi;
35 @chown lfs \$(MOUNT_PT)/tools && \\
36 chown lfs \$(MOUNT_PT)/sources && \\
37 touch \$@
38
39022-settingenvironment: 021-addinguser
40 @\$(call echo_message, Building)
41 @if [ -f /home/lfs/.bashrc -a ! -f /home/lfs/.bashrc.XXX ]; then \\
42 mv -v /home/lfs/.bashrc /home/lfs/.bashrc.XXX; \\
43 fi;
44 @if [ -f /home/lfs/.bash_profile -a ! -f /home/lfs/.bash_profile.XXX ]; then \\
45 mv -v /home/lfs/.bash_profile /home/lfs/.bash_profile.XXX; \\
46 fi;
47 @echo "set +h" > /home/lfs/.bashrc && \\
48 echo "umask 022" >> /home/lfs/.bashrc && \\
49 echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
50 echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
51 echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
52 echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
53 echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
54 chown lfs:lfs /home/lfs/.bashrc && \\
55 touch envars && \\
56 touch \$@
57EOF
58) >> $MKFILE.tmp
59}
60
61#----------------------------#
62chapter5_Makefiles() {
63#----------------------------#
64 for file in chapter05/* ; do
65 # Keep the script file name
66 this_script=`basename $file`
67
68 # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
69 if [ "$TOOLCHAINTEST" = "0" ]; then
70 if [[ `_IS_ ${this_script} tcl` ]] || [[ `_IS_ ${this_script} expect` ]] || [[ `_IS_ ${this_script} dejagnu` ]] ; then
71 continue
72 fi
73 fi
74
75 # Test if the stripping phase must be skipped
76 if [ "$STRIP" = "0" ] && [[ `_IS_ ${this_script} stripping` ]] ; then
77 continue
78 fi
79
80# NOTE Replace with xsl work...
81 if [[ `_IS_ $this_script adjusting` ]]; then
82 sed '/cd $PKGDIR/d' -i chapter05/$this_script
83 fi
84
85 # First append each name of the script files to a list (this will become
86 # the names of the targets in the Makefile
87 chapter5="$chapter5 ${this_script}"
88
89 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
90 # and binutils in chapter 5)
91 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
92
93 # Set the dependency for the first target.
94 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
95
96 # Drop in the name of the target on a new line, and the previous target
97 # as a dependency. Also call the echo_message function.
98 wrt_target "${this_script}" "$PREV"
99
100 # Find the version of the command files, if it corresponds with the building of
101 # a specific package
102 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
103
104 # If $vrs isn't empty, we've got a package...
105 if [ "$vrs" != "" ] ; then
106 if [ "$name" = "tcl" ] ; then
107 FILE="$name$vrs-src.tar"
108 else
109 FILE="$name-$vrs.tar"
110 fi
111
112 # Insert instructions for unpacking the package and to set
113 # 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 wrt_run_as_su "${this_script}" "$file"
121
122 # Remove the build directory(ies) except if the package build fails
123 # (so we can review config.cache, config.log, etc.)
124 if [ "$vrs" != "" ] ; then
125 wrt_remove_build_dirs "$name"
126 fi
127
128 # Include a touch of the target name so make can check
129 # if it's already been made.
130 echo -e '\t@touch $@' >> $MKFILE.tmp
131
132 # Keep the script file name for Makefile dependencies.
133 PREV=${this_script}
134 done # end for file in chapter05/*
135}
136
137#----------------------------#
138chapter6_Makefiles() {
139#----------------------------#
140 for file in chapter06/* ; do
141 # Keep the script file name
142 this_script=`basename $file`
143
144 # We'll run the chroot commands differently than the others, so skip them in the
145 # dependencies and target creation.
146 if [[ `_IS_ ${this_script} chroot` ]] ; then
147 continue
148 fi
149
150 # Test if the stripping phase must be skipped
151 if [ "$STRIP" = "0" ] && [[ `_IS_ ${this_script} stripping` ]] ; then
152 continue
153 fi
154
155# NOTE Replace with xsl work...
156 if [[ `_IS_ $this_script adjusting` ]]; then
157 sed '/cd $PKGDIR/d' -i chapter06/$this_script
158 fi
159
160 # First append each name of the script files to a list (this will become
161 # the names of the targets in the Makefile
162 chapter6="$chapter6 ${this_script}"
163
164 # Grab the name of the target
165 name=`echo ${this_script} | sed -e 's@[0-9]\{3\}-@@'`
166
167 # Drop in the name of the target on a new line, and the previous target
168 # as a dependency. Also call the echo_message function.
169 wrt_target "${this_script}" "$PREV"
170
171 # Find the version of the command files, if it corresponds with the building of
172 # a specific package
173 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
174
175 # If $vrs isn't empty, we've got a package...
176 # Insert instructions for unpacking the package and changing directories
177 if [ "$vrs" != "" ] ; then
178 FILE="$name-$vrs.tar.*"
179 wrt_unpack2 "$FILE"
180 fi
181
182 if [[ `_IS_ ${this_script} glibc` ]] ; then # For Glibc we need to set TIMEZONE envar.
183 wrt_export_timezone
184 elif [[ `_IS_ ${this_script} groff` ]] ; then # For Groff we need to set PAGE envar.
185 wrt_export_pagesize
186 fi
187
188 # In the mount of kernel filesystems we need to set LFS
189 # and not to use chroot.
190 if [[ `_IS_ ${this_script} kernfs` ]] ; then
191 wrt_run_as_root "${this_script}" "$file"
192 else # The rest of Chapter06
193 wrt_run_as_chroot1 "${this_script}" "$file"
194 fi
195
196 # Remove the build directory(ies) except if the package build fails.
197 if [ "$vrs" != "" ] ; then
[a46ada0]198 wrt_remove_build_dirs "$name"
[0170229]199 fi
200
201 # Include a touch of the target name so make can check
202 # if it's already been made.
203 echo -e '\t@touch $@' >> $MKFILE.tmp
204
205 # Keep the script file name for Makefile dependencies.
206 PREV=${this_script}
207 done # end for file in chapter06/*
208}
209
210#----------------------------#
211chapter789_Makefiles() {
212#----------------------------#
213 for file in chapter0{7,8,9}/* ; do
214 # Keep the script file name
215 this_script=`basename $file`
216
217 # Grub must be configured manually.
218 # The filesystems can't be unmounted via Makefile and the user
219 # should enter the chroot environment to create the root
220 # password, edit several files and setup Grub.
221 if [[ `_IS_ ${this_script} grub` ]] || [[ `_IS_ ${this_script} reboot` ]] ; then
222 continue
223 fi
224
225 # If no .config file is supplied, the kernel build is skipped
226 if [ -z $CONFIG ] && [[ `_IS_ ${this_script} kernel` ]] ; then
227 continue
228 fi
229
230 # First append each name of the script files to a list (this will become
231 # the names of the targets in the Makefile
232 chapter789="$chapter789 ${this_script}"
233
234 # Drop in the name of the target on a new line, and the previous target
235 # as a dependency. Also call the echo_message function.
236 wrt_target "${this_script}" "$PREV"
237
238 # Find the bootscripts and kernel package names
239 if [[ `_IS_ ${this_script} bootscripts` ]] || [[ `_IS_ ${this_script} kernel` ]] ; then
240 if [[ `_IS_ ${this_script} bootscripts` ]] ; then
241 vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
242 FILE="lfs-bootscripts-$vrs.tar.*"
243 elif [[ `_IS_ ${this_script} kernel` ]] ; then
244 vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
245 FILE="linux-$vrs.tar.*"
246 fi
247 wrt_unpack2 "$FILE"
248 fi
249
250 # Put in place the kernel .config file
251 if [[ `_IS_ ${this_script} kernel` ]] ; then
252(
253 cat << EOF
254 @cp $CONFIG \$(MOUNT_PT)/sources/kernel-config
255EOF
256) >> $MKFILE.tmp
257 fi
258
259 # Check if we have a real /etc/fstab file
260 if [[ `_IS_ ${this_script} fstab` ]] && [[ -n "$FSTAB" ]] ; then
261 wrt_copy_fstab "${this_script}"
262 else
263 # Initialize the log and run the script
264 wrt_run_as_chroot2 "$this_script" "$file"
265 fi
266
267 # Remove the build directory except if the package build fails.
268 if [[ `_IS_ ${this_script} bootscripts` ]] || [[ `_IS_ ${this_script} kernel` ]] ; then
269 wrt_remove_build_dirs "dummy"
270 fi
271
272 # Include a touch of the target name so make can check
273 # if it's already been made.
274 echo -e '\t@touch $@' >> $MKFILE.tmp
275
276 # Keep the script file name for Makefile dependencies.
277 PREV=${this_script}
278 done # for file in chapter0{7,8,9}/*
279}
280
281
282#----------------------------#
283build_Makefile() {
284#----------------------------#
285 echo -n "Creating Makefile... "
286 cd $JHALFSDIR/${PROGNAME}-commands
287
288 # Start with a clean Makefile.tmp file
289 >$MKFILE.tmp
290
291 chapter4_Makefiles
292 chapter5_Makefiles
293 chapter6_Makefiles
294 chapter789_Makefiles
295
296
297 # Add a header, some variables and include the function file
298 # to the top of the real Makefile.
299(
300 cat << EOF
301$HEADER
302
303SRC= /sources
304MOUNT_PT= $BUILDDIR
305PAGE= $PAGE
306TIMEZONE= $TIMEZONE
307
308include makefile-functions
309
310EOF
311) > $MKFILE
312
313
314 # Add chroot commands
315 i=1
316 for file in chapter06/*chroot* ; do
317 chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
318 -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
319 -e 's|"$$LFS"|$(MOUNT_PT)|' -e 's|set -e||'`
320 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
321 i=`expr $i + 1`
322 done
323
324 # Drop in the main target 'all:' and the chapter targets with each sub-target
325 # as a dependency.
326(
327 cat << EOF
328all: chapter4 chapter5 chapter6 chapter789
329 @\$(call echo_finished,$VERSION)
330
331chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
332
333chapter5: chapter4 $chapter5 restore-lfs-env
334
335chapter6: chapter5 $chapter6
336
337chapter789: chapter6 $chapter789
338
339clean-all: clean
340 rm -rf ./{lfs-commands,logs,Makefile,dump-lfs-scripts.xsl,functions,packages,patches}
341
342clean: clean-chapter789 clean-chapter6 clean-chapter5 clean-chapter4
343
344clean-chapter4:
345 -if [ ! -f user-lfs-exist ]; then \\
346 userdel lfs; \\
347 rm -rf /home/lfs; \\
348 fi;
349 rm -rf \$(MOUNT_PT)/tools
350 rm -f /tools
351 rm -f envars user-lfs-exist
352 rm -f 02* logs/02*.log
353
354clean-chapter5:
355 rm -rf \$(MOUNT_PT)/tools/*
356 rm -f $chapter5 restore-lfs-env sources-dir
357 cd logs && rm -f $chapter5 && cd ..
358
359clean-chapter6:
360 -umount \$(MOUNT_PT)/sys
361 -umount \$(MOUNT_PT)/proc
362 -umount \$(MOUNT_PT)/dev/shm
363 -umount \$(MOUNT_PT)/dev/pts
364 -umount \$(MOUNT_PT)/dev
365 rm -rf \$(MOUNT_PT)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
366 rm -f $chapter6
367 cd logs && rm -f $chapter6 && cd ..
368
369clean-chapter789:
370 rm -f $chapter789
371 cd logs && rm -f $chapter789 && cd ..
372
373restore-lfs-env:
374 @\$(call echo_message, Building)
375 @if [ -f /home/lfs/.bashrc.XXX ]; then \\
376 mv -fv /home/lfs/.bashrc.XXX /home/lfs/.bashrc; \\
377 fi;
378 @if [ -f /home/lfs/.bash_profile.XXX ]; then \\
379 mv -v /home/lfs/.bash_profile.XXX /home/lfs/.bash_profile; \\
380 fi;
381 @chown lfs:lfs /home/lfs/.bash* && \\
382 touch \$@
383
384EOF
385) >> $MKFILE
386
387 # Bring over the items from the Makefile.tmp
388 cat $MKFILE.tmp >> $MKFILE
389 rm $MKFILE.tmp
390 echo -ne "done\n"
391}
392
393
Note: See TracBrowser for help on using the repository browser.