source: LFS/master.sh@ 0170229

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

Added base files from George's jhalfs-experimental-2 POC.
WARNING: This code is broken due files renaming.

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