source: LFS/master.sh@ 4845f38

experimental
Last change on this file since 4845f38 was 12a5707, checked in by George Boudreau <georgeb@…>, 19 years ago

Adjusting scripts to new structure. Added jhalfs trunk changes. Will now create a lfs makefile.

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